:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f4f1ef);
  --text: var(--tg-theme-text-color, #1d1715);
  --hint: var(--tg-theme-hint-color, #8a7f7a);
  --sep: var(--tg-theme-section-separator-color, rgba(0, 0, 0, 0.08));
  --link: var(--tg-theme-link-color, #b4583b);
  --peach: #F9A98D;
  --peach-tint: #FDEBE2;
  --ink: #3B2A24;
  --rose: #E86AA6;
  --danger: #C0392B;
  --row: 44px;
  --radius-block: 10px;
  --radius-control: 12px;
  --font-body: "Golos Text", -apple-system, Roboto, sans-serif;
  --font-display: "Prata", Georgia, serif;
}
:root[data-theme="dark"] {
  --peach-tint: rgba(249, 169, 141, 0.16);
  --sep: var(--tg-theme-section-separator-color, rgba(255, 255, 255, 0.1));
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body); font-size: 16px; line-height: 1.4;
  color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { opacity: 0.6; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg2); border: 0;
  border-radius: var(--radius-control); padding: 10px 14px; width: 100%; min-height: 44px;
}
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
:root[data-theme="dark"] :focus-visible { outline-color: var(--peach); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* Шапка */
.top { display: flex; align-items: center; gap: 12px; height: 48px; padding: 0 16px; }
.monogram { font-family: var(--font-display); color: var(--rose); font-size: 18px; letter-spacing: 0.08em; }
.top-title { font-weight: 500; }
/* Плашка переключения роли: только тестовый бот (ROLE_SWITCH=1) */
.role-pill {
  margin-left: auto; height: 28px; padding: 0 12px;
  border: 1px solid var(--peach); border-radius: 14px; background: var(--peach-tint);
  color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
}
.role-pill:disabled { opacity: 0.6; }
.back-fallback { color: var(--link); min-height: 44px; margin-right: 4px; }

/* Общее */
.screen { padding: 0 16px 16px; }
.screen.busy { opacity: 0.6; pointer-events: none; }
.section { margin: 0 0 24px; }
.hint { color: var(--hint); font-size: 14px; }
.center { text-align: center; }
.empty-title { font-family: var(--font-display); font-weight: 400; font-size: 22px; text-align: center; margin: 32px 0 8px; }
.group-title { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
.group-title a { color: var(--link); }
.badge {
  display: inline-block; font-size: 12px; color: var(--hint); border: 1px solid var(--sep);
  border-radius: 999px; padding: 1px 8px; vertical-align: middle;
}
.btn-text { color: var(--link); font-weight: 500; min-height: 44px; display: inline-flex; align-items: center; }
.btn-primary, .btn-secondary, .btn-danger, .btn-danger-fill {
  min-height: 48px; border-radius: var(--radius-control); font-weight: 500; width: 100%;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 16px;
}
.btn-primary { background: var(--peach); color: var(--ink); }
.btn-secondary { background: var(--bg2); color: var(--text); }
.btn-danger { color: var(--danger); border: 1px solid var(--sep); }
.btn-danger-fill { background: var(--danger); color: #fff; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions > * { flex: 1; }
.main-fallback {
  position: fixed; left: 16px; right: 16px; width: auto; z-index: 5;
  bottom: calc(72px + env(safe-area-inset-bottom));
}

/* День */
.day-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0; }
.day-title { font-family: var(--font-display); font-weight: 400; font-size: 24px; margin: 0; text-align: center; }
.icon-btn {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 28px; color: var(--hint); border-radius: var(--radius-control);
}
.day-tools { display: flex; align-items: center; gap: 12px; margin: 4px 0 12px; }
.date-input { width: auto; min-width: 160px; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 16px; }
.week-day {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border-radius: var(--radius-control); min-height: 60px;
}
.week-wd { font-size: 12px; color: var(--hint); }
.week-num {
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; font-variant-numeric: tabular-nums;
}
.week-day.today .week-num { outline: 2px solid var(--peach); outline-offset: -2px; }
.week-day.today.current .week-num { outline-color: var(--ink); }
.week-day.current .week-num { background: var(--peach); color: var(--ink); font-weight: 600; }
.week-dot { width: 5px; height: 5px; border-radius: 50%; background: transparent; }
.week-dot.on { background: var(--peach); }

.timeline { position: relative; display: grid; grid-template-columns: 56px 1fr; column-gap: 8px; }
.slot-time {
  grid-column: 1; font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums;
  padding-top: 2px; border-top: 1px solid var(--sep);
}
.slot-free {
  grid-column: 2; border-top: 1px solid var(--sep); text-align: right; padding-right: 14px;
  color: var(--hint); font-size: 22px; line-height: 1;
}
.slot-free:active { background: var(--bg2); }
/* ряды вне рабочих часов: видны только ради записей, сделанных до смены часов */
.slot-time-off { opacity: 0.55; }
.slot-free-off { opacity: 0.55; }
.slot-off { grid-column: 2; border-top: 1px solid var(--sep); }
.block {
  grid-column: 2; margin: 2px 0; padding: 6px 12px; background: var(--peach-tint);
  border-radius: var(--radius-block); display: flex; flex-direction: column; gap: 2px; overflow: hidden;
}
.block-name { font-weight: 600; }
.block-meta { font-size: 13px; color: var(--hint); }
.block-short .block-meta { display: none; }
:root[data-theme="dark"] .block-name { color: var(--peach); }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--peach); pointer-events: none; }
.now-line::before {
  content: ""; position: absolute; left: 0; top: -4px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--peach);
}

/* Списки */
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; grid-template-columns: 1fr; padding: 10px 0;
  border-bottom: 1px solid var(--sep); min-height: 44px;
}
.row.with-time { grid-template-columns: 56px 1fr; column-gap: 8px; }
.row.with-time .row-time { grid-row: 1 / span 2; font-variant-numeric: tabular-nums; color: var(--hint); font-size: 14px; padding-top: 2px; }
.row-main { }
.row-sub { font-size: 14px; color: var(--hint); }
.row.with-avatar { grid-template-columns: 36px 1fr; column-gap: 12px; align-items: center; }
.row.with-avatar .avatar { grid-row: 1 / span 2; }
.row[data-href] { cursor: pointer; }
.ig { color: var(--link); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; overflow: hidden; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--peach-tint); color: var(--ink); font-weight: 600;
}
:root[data-theme="dark"] .avatar { color: var(--peach); }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.filter-count { color: var(--hint); font-variant-numeric: tabular-nums; margin-left: 4px; }
.card-ig .ig { display: inline-block; min-height: 44px; line-height: 44px; }
.row-actions { display: flex; gap: 12px; }

/* Формы */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 14px; color: var(--hint); }
.segment { display: flex; gap: 4px; background: var(--bg2); border-radius: var(--radius-control); padding: 4px; margin-bottom: 8px; }
.seg { flex: 1; min-height: 44px; border-radius: 10px; color: var(--hint); }
.seg.active { background: var(--bg); color: var(--text); font-weight: 500; }
.results { display: flex; flex-direction: column; }
.result { text-align: left; padding: 10px 14px; min-height: 44px; border-bottom: 1px solid var(--sep); }
.chosen {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--peach-tint); border-radius: var(--radius-block);
}
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.slots > .hint { grid-column: 1 / -1; }
.slot-btn { min-height: 44px; background: var(--bg2); border: 1px solid transparent; border-radius: var(--radius-control); font-variant-numeric: tabular-nums; }
.slot-btn.current { border: 1px solid var(--peach); }
.service-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--sep); }
.service-row input { flex: 1; }

/* Карточка записи */
.card-name { font-size: 22px; font-weight: 600; margin: 8px 0 2px; }
.card-phone { color: var(--link); display: inline-block; min-height: 44px; line-height: 44px; }
.card-line { margin: 4px 0; }

/* Нижнее меню */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--bg); border-top: 1px solid var(--sep); padding-bottom: env(safe-area-inset-bottom); z-index: 10;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px; font-size: 11px; color: var(--hint);
}
.nav-item.active { color: var(--text); }
.nav-item.active svg { color: var(--peach); }

/* Всплывающее уведомление */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom));
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--radius-control);
  text-align: center; opacity: 0; transform: translateY(8px);
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20;
}
.toast.show { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* Переключатель в настройках и ряд с кнопкой отмены */
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.field-row input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--peach); }
.row-cancel { grid-column: 1 / -1; justify-self: start; margin-top: 4px; }

/* Диалог подтверждения вне Telegram */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  width: 100%; max-width: 360px; background: var(--bg); color: var(--text);
  border-radius: var(--radius-control); padding: 20px 16px 16px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}
.modal-text { margin: 0 0 16px; }
.modal .actions { margin-top: 0; }
.danger-zone { margin-top: 8px; }
