/* Цвета берутся из темы Telegram (светлой или тёмной) — приложение выглядит родным в любом клиенте. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #141414);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2a7fd4);
  --btn: var(--tg-theme-button-color, #2a7fd4);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --page: var(--tg-theme-secondary-bg-color, #f0f1f4);
  --card: var(--tg-theme-section-bg-color, var(--bg));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --line: var(--tg-theme-section-separator-color, rgba(127, 127, 127, 0.2));
  --ok: #2f9e5b;
  --warn: #e08a00;
  --radius: 14px;

  /* Экран записи: оранжевые свободные слоты */
  --orange: #ff6b35;
  --orange-ink: #c2410c;                  /* текст на светлом фоне — контрастнее */
  --orange-soft: rgba(255, 107, 53, 0.13);
  --bar-busy: rgba(120, 120, 128, 0.16);
  --card-line: rgba(127, 127, 127, 0.16);
}
:root[data-scheme="dark"] {
  --orange-ink: #ff7a45;
  --orange-soft: rgba(255, 107, 53, 0.15);
  --bar-busy: rgba(255, 255, 255, 0.09);
  --card-line: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; background: var(--page); color: var(--text); }

body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: 0 12px calc(28px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }

/* ───── Вкладки ───── */
.tabs {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 6px;
  padding: 10px 0;
  background: var(--page);
}
.tab {
  flex: 1; position: relative;
  border: 0; border-radius: 10px;
  padding: 9px 6px;
  background: var(--card); color: var(--text);
  font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tab.active { background: var(--btn); color: var(--btn-text); }
.badge {
  display: inline-block; min-width: 18px; margin-left: 6px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff;
  font-size: 12px; font-weight: 600; line-height: 18px; text-align: center;
}

/* ───── Карточки и текст ───── */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
h2 {
  margin: 0 0 10px; font-size: 12.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--hint);
}
.title { font-weight: 600; }
.hint { color: var(--hint); font-size: 13px; }
.note { color: var(--hint); font-size: 12.5px; margin: 12px 0 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.capitalize::first-letter { text-transform: uppercase; }

/* ───── Экран записи: «Свободное время для встреч» ───── */
.bk-head { padding: 10px 4px 2px; }
.bk-head h1 {
  margin: 0 0 8px;
  font-size: clamp(20px, 5.6vw, 28px); line-height: 1.15; font-weight: 700; letter-spacing: -0.01em;
}
.bk-sub { margin: 0; color: var(--hint); font-size: 15px; line-height: 1.45; }
.nowrap { white-space: nowrap; }
.bk-note { margin: 8px 0 0; color: var(--hint); font-size: 13px; }

.bk-legend {
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  margin: 18px 4px 16px;
  color: var(--hint); font-size: 14px;
}
.bk-legend span { display: inline-flex; align-items: center; gap: 8px; }
.bk-legend i { width: 20px; height: 12px; border-radius: 3px; }
.lg-busy { background: var(--bar-busy); box-shadow: inset 0 0 0 1px var(--card-line); }
.lg-free { background: var(--orange); }
.lg-mine { background: var(--btn); }

/* Свои записи к этому человеку — с отменой */
.bk-mine {
  margin: 16px 0 0; padding: 12px 14px;
  background: var(--card); border: 1px solid var(--card-line); border-radius: 18px;
  scroll-margin-top: 64px; /* чтобы при прокрутке блок не прятался под вкладками */
}
.bk-mine-title {
  margin-bottom: 4px;
  color: var(--hint); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
}
.bk-mine-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.bk-mine-row + .bk-mine-row { border-top: 1px solid var(--card-line); }
.bk-mine-info { min-width: 0; }
.bk-mine-when { margin-bottom: 5px; font-weight: 600; }
.bk-mine .btn.bk-cancel {
  flex: none; padding: 8px 14px; font-size: 14px;
  background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger);
}

.bk-day {
  background: var(--card);
  border: 1px solid var(--card-line); border-radius: 18px;
  padding: 16px 14px 14px; margin-bottom: 12px;
  transition: border-color 0.15s;
}
.bk-day.active { border-color: var(--orange); }
.bk-day-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.bk-day-title { font-size: 17px; font-weight: 600; }
.bk-day-free { flex: none; color: var(--hint); font-size: 13px; }

/* Подписи часов и полоса рабочего дня */
.bk-ticks { position: relative; height: 15px; margin: 14px 0 7px; }
.bk-ticks span {
  position: absolute; top: 0; transform: translateX(-50%);
  color: var(--hint); font-size: 11.5px; line-height: 15px; font-variant-numeric: tabular-nums;
}
.bk-bar {
  display: flex; height: 26px;
  border-radius: 7px; overflow: hidden;
  background: var(--bar-busy);
}
.bk-bar .cell { flex: 1 1 0; min-width: 0; border: 0; padding: 0; background: transparent; }
.bk-bar .cell.free { background: var(--orange); }
.bk-bar .cell.mine { background: var(--btn); }
.bk-bar .cell.free.selected { box-shadow: inset 0 0 0 2px var(--text); }

/* Слоты под полосой */
.bk-chips {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(102px, 1fr)); gap: 8px;
  margin-top: 12px;
}
.bk-chip {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 34px; padding: 6px 4px;
  border: 0; border-radius: 8px;
  background: var(--orange-soft); color: var(--orange-ink);
  font: 500 13px/1.2 ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: -0.04em; white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}
.bk-chip b { font-weight: inherit; }
.bk-chip.selected { background: var(--orange); color: #1c0a02; }
.bk-chip.mine {
  background: transparent; color: var(--text);
  box-shadow: inset 0 0 0 1.5px var(--btn);
}
.bk-chip.mine:disabled { opacity: 0.6; }
.bk-chip.mine small { color: var(--hint); }
.bk-form { margin-top: 4px; }

/* ───── «Мои слоты»: своя неделя в виде экрана записи ───── */
.lg-pending { background: var(--warn); }
.lg-confirmed { background: var(--ok); }
.lg-cal, .bk-bar .cell.cal {
  background: repeating-linear-gradient(135deg, var(--bar-busy) 0 4px, rgba(127, 127, 127, 0.38) 4px 6px);
}
.bk-bar .cell.pending { background: var(--warn); }
.bk-bar .cell.confirmed { background: var(--ok); }

.bk-chip small {
  display: block; max-width: 100%; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis;
  font: 500 11px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; letter-spacing: 0;
}
.bk-chip.cal { background: var(--bar-busy); color: var(--hint); }
.bk-chip.cal small { color: var(--hint); }
.bk-chip.pending, .bk-chip.confirmed { background: transparent; color: var(--text); }
.bk-chip.pending { box-shadow: inset 0 0 0 1.5px var(--warn); }
.bk-chip.confirmed { box-shadow: inset 0 0 0 1.5px var(--ok); }
.bk-chip.pending small { color: var(--warn); }
.bk-chip.confirmed small { color: var(--ok); }
.bk-chip.past { opacity: 0.55; }

.bk-day.off { padding: 13px 14px; }
.bk-day.off .bk-day-title { color: var(--hint); font-weight: 500; }

.own-status { margin-bottom: 0; }
.own-status-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.own-status-row .btn { flex: none; padding: 9px 16px; font-size: 14px; }
.own-status .note { margin-top: 8px; }
.own-foot { margin: 4px 4px 8px; }
.back { margin: 2px 4px 10px; font-size: 15px; }

/* ───── Календари в настройках ───── */
.cal-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.cal-row:first-of-type { padding-top: 0; }
.cal-row + .cal-row { border-top: 1px solid var(--line); }
.cal-info { min-width: 0; overflow-wrap: anywhere; }
.cal-info .title { overflow-wrap: anywhere; }
.btn.cal-off { flex: none; padding: 8px 12px; font-size: 13.5px; }
.cal-add { margin-bottom: 10px; font-weight: 600; }
hr.sep { margin: 16px 0 14px; border: 0; border-top: 1px solid var(--line); }

/* ───── Полоса дней ───── */
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.day {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 0 6px; border: 0; border-radius: 10px;
  background: var(--page); color: var(--text);
}
.day .wd { font-size: 11px; color: var(--hint); }
.day .num { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.day .sub { font-size: 10.5px; color: var(--hint); min-height: 14px; }
.day.off .num { color: var(--hint); font-weight: 500; }
.day.nofree .num { color: var(--hint); }
.day.has-b::after {
  content: ""; position: absolute; top: 6px; right: 6px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--warn);
}
.day.active { background: var(--btn); color: var(--btn-text); }
.day.active .wd, .day.active .sub, .day.active .num { color: var(--btn-text); }
.day.active .sub, .day.active .wd { opacity: 0.85; }

/* ───── Сетка слотов ───── */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.slot {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 46px; padding: 6px 4px;
  border: 1.5px solid transparent; border-radius: 10px;
  background: var(--page); color: var(--text);
  font-size: 14px; font-variant-numeric: tabular-nums; text-align: center;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.slot b { font-weight: 600; white-space: nowrap; }
.slot small {
  max-width: 100%; margin-top: 1px;
  font-size: 11px; opacity: 0.9;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* для владельца */
.slot.open {
  border-color: var(--btn); color: var(--btn);
  background: rgba(42, 127, 212, 0.1);
  background: color-mix(in srgb, var(--btn) 12%, transparent);
}
.slot.closed { color: var(--hint); }
.slot.closed b { font-weight: 500; }
.slot.pending {
  border-color: var(--warn);
  background: rgba(224, 138, 0, 0.14);
  background: color-mix(in srgb, var(--warn) 15%, transparent);
}
.slot.confirmed {
  border-color: var(--ok);
  background: rgba(47, 158, 91, 0.14);
  background: color-mix(in srgb, var(--ok) 15%, transparent);
}
.slot.busy {
  color: var(--hint);
  border-color: rgba(127, 127, 127, 0.35);
  background: repeating-linear-gradient(135deg, transparent 0 6px, rgba(127, 127, 127, 0.16) 6px 8px);
}
.slot.past { opacity: 0.4; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 12px; color: var(--hint); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 11px; height: 11px; border-radius: 3px; border: 1.5px solid; }
.legend .l-open { border-color: var(--btn); background: color-mix(in srgb, var(--btn) 12%, transparent); }
.legend .l-closed { border-color: var(--line); background: var(--page); }
.legend .l-pending { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); }
.legend .l-confirmed { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.legend .l-busy {
  border-color: rgba(127, 127, 127, 0.45);
  background: repeating-linear-gradient(135deg, transparent 0 3px, rgba(127, 127, 127, 0.3) 3px 4px);
}

/* ───── Шаблон недели ───── */
.weekdays { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.wdchip {
  padding: 9px 0; border: 0; border-radius: 10px;
  background: var(--page); color: var(--hint);
  font-size: 13.5px; font-weight: 600;
}
.wdchip.on { background: var(--btn); color: var(--btn-text); }
.hours { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.field { display: block; margin-top: 12px; }
.field > span { display: block; margin-bottom: 5px; font-size: 12.5px; color: var(--hint); }
select, textarea, input[type="text"], input[type="url"] {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--page); color: var(--text);
  font: inherit; font-size: 15px;
  -webkit-appearance: none; appearance: none;
}
select {
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238a8a8e' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
textarea { resize: vertical; min-height: 64px; }
select:focus, textarea:focus, input[type="text"]:focus, input[type="url"]:focus { outline: none; border-color: var(--btn); }
input[type="url"] { font-size: 14px; }
.hint.lead { margin: 0 0 10px; }

/* ───── Подсказка «где взять ссылку» ───── */
.howto { margin-top: 12px; font-size: 13.5px; }
.howto summary { color: var(--link); cursor: pointer; list-style: none; }
.howto summary::-webkit-details-marker { display: none; }
.howto summary::after { content: " ›"; }
.howto[open] summary::after { content: " ⌄"; }
.howto p { margin: 8px 0 0; color: var(--text); }
input::placeholder, textarea::placeholder { color: var(--hint); }
.error-text { color: var(--danger); font-size: 13px; margin-top: 8px; }

/* ───── Переключатель ───── */
.switch { position: relative; flex: none; display: inline-block; width: 46px; height: 28px; }
.switch input { position: absolute; width: 0; height: 0; opacity: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 14px;
  background: rgba(127, 127, 127, 0.35);
  transition: background-color 0.2s;
}
.switch span::before {
  content: ""; position: absolute; left: 3px; top: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.switch input:checked + span { background: var(--btn); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--hint); }

/* ───── Кнопки ───── */
.btns { display: flex; gap: 8px; margin-top: 12px; }
.btn {
  flex: 1; padding: 11px 12px; border: 0; border-radius: 10px;
  background: var(--btn); color: var(--btn-text);
  font-size: 14.5px; font-weight: 600;
}
.btn.secondary { background: color-mix(in srgb, var(--btn) 12%, transparent); color: var(--btn); }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn.ghost { background: var(--page); color: var(--text); }
.btn.block { display: block; width: 100%; margin-top: 14px; }
.btn:disabled { opacity: 0.45; }
.linkbtn { padding: 0; border: 0; background: none; color: var(--link); font-size: inherit; }

.share {
  margin-top: 12px; padding: 10px 12px; border-radius: 10px;
  background: var(--page);
  font: 13px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all; user-select: all;
}

/* ───── Встречи ───── */
.meeting + .meeting { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.m-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.m-when { margin-top: 6px; font-variant-numeric: tabular-nums; }
.m-comment {
  margin-top: 8px; padding: 8px 10px; border-radius: 8px;
  background: var(--page); font-size: 13.5px;
  white-space: pre-wrap; word-break: break-word;
}
.status {
  flex: none; padding: 3px 9px; border-radius: 20px;
  background: var(--page); color: var(--hint);
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.status.pending { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.status.confirmed { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.status.rejected, .status.cancelled { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.meeting.compact .m-when { margin-top: 2px; font-size: 13px; color: var(--hint); }

/* ───── Пустые состояния, загрузка, тост ───── */
.empty { padding: 22px 10px; text-align: center; color: var(--hint); }
.empty .icon { font-size: 30px; margin-bottom: 6px; }
.empty .title { color: var(--text); margin-bottom: 4px; }
.empty.small { padding: 16px 0 6px; }

.loader {
  width: 28px; height: 28px; margin: 48px auto;
  border: 3px solid rgba(127, 127, 127, 0.25); border-top-color: var(--btn);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 12px; right: 12px; z-index: 20;
  bottom: calc(16px + env(safe-area-inset-bottom));
  padding: 12px 14px; border-radius: 12px;
  background: var(--text); color: var(--bg);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  font-size: 14px; text-align: center;
  animation: toast-in 0.2s ease-out;
}
.toast.error { background: #c62f34; color: #fff; }
.toast[hidden] { display: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
