/*
 * Цвета берутся из темы Telegram (--tg-theme-*), которую telegram-web-app.js
 * выставляет на <html>. Значения после запятой — запасные для обычного браузера.
 */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --accent-fg: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, #2481cc));
  --section-header: var(--tg-theme-section-header-text-color, #6d6d72);
  --subtitle: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #8e8e93));
  --destructive: var(--tg-theme-destructive-text-color, #e53935);
  --separator: var(--tg-theme-section-separator-color, rgba(60, 60, 67, 0.16));
  --success: #34c759;
  /* Светлый оттенок кнопки — рабочие дни в календаре графика */
  --accent-soft: rgba(36, 129, 204, 0.16);
  --radius: 12px;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  /* Схема — по теме Telegram, а не системы: иначе при тёмном Telegram на светлой Windows
     поля даты и времени рисуются светлыми */
  color-scheme: var(--tg-color-scheme, light dark);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-secondary-bg-color, #000000);
    --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1c1c1e));
    --text: var(--tg-theme-text-color, #ffffff);
    --hint: var(--tg-theme-hint-color, #98989e);
    --link: var(--tg-theme-link-color, #3e88f7);
    --accent: var(--tg-theme-button-color, #3e88f7);
    --accent-fg: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, #3e88f7));
    --section-header: var(--tg-theme-section-header-text-color, #8d8e93);
    --separator: var(--tg-theme-section-separator-color, rgba(84, 84, 88, 0.6));
  }
}

@supports (background: color-mix(in srgb, red 50%, transparent)) {
  :root {
    --accent-soft: color-mix(in srgb, var(--accent) 18%, transparent);
  }
}

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

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: var(--tg-viewport-stable-height, 100vh);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--link);
  text-decoration: none;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(24px + var(--safe-bottom));
}

.app.with-fallback-bar {
  padding-bottom: calc(96px + var(--safe-bottom));
}

.screen.enter {
  animation: screen-in 0.18s ease-out;
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ---------- заголовки ---------- */

.page-title {
  margin: 8px 4px 4px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.page-subtitle {
  margin: 0 4px 16px;
  color: var(--hint);
  font-size: 15px;
}

.section-title {
  margin: 20px 16px 6px;
  color: var(--section-header);
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.section-note {
  margin: 6px 16px 0;
  color: var(--hint);
  font-size: 13px;
}

.steps {
  display: flex;
  gap: 4px;
  margin: 4px 4px 12px;
}

.steps span {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: var(--separator);
}

.steps span.done {
  background: var(--accent);
}

.fallback-back {
  margin: 0 0 4px;
  padding: 6px 4px;
  border: 0;
  background: none;
  color: var(--link);
  font-size: 16px;
}

/* ---------- карточки и списки ---------- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
}

.card + .card {
  margin-top: 12px;
}

.card-pad {
  padding: 14px 16px;
}

.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 10px 16px;
  border: 0;
  background: none;
  text-align: left;
}

.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 1px;
  background: var(--separator);
  transform: scaleY(0.5);
}

button.row:active {
  background: var(--separator);
}

.row-main {
  flex: 1;
  min-width: 0;
}

.row-title {
  font-size: 16px;
  word-break: break-word;
}

.row-sub {
  margin-top: 2px;
  color: var(--subtitle);
  font-size: 14px;
  word-break: break-word;
}

.row-value {
  flex-shrink: 0;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
}

.row-value.hint {
  color: var(--hint);
  font-weight: 400;
}

.check {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid var(--hint);
  border-radius: 50%;
  color: var(--accent-text);
  font-size: 14px;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s;
}

.row.selected .check {
  border-color: var(--accent);
  background: var(--accent);
}

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--separator);
  color: var(--hint);
  font-size: 12px;
  vertical-align: middle;
}

.summary-bar {
  display: flex;
  justify-content: space-between;
  margin: 12px 4px 0;
  color: var(--hint);
  font-size: 15px;
}

.summary-bar strong {
  color: var(--text);
}

/* ---------- главный экран ---------- */

.hero {
  padding: 28px 16px 24px;
  text-align: center;
}

.hero-icon {
  display: grid;
  place-items: center;
  width: 88px;
  height: 88px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--card);
  font-size: 44px;
}

.hero h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
}

.hero p {
  margin: 0 auto;
  max-width: 340px;
  color: var(--hint);
}

.features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 4px;
}

.feature {
  padding: 12px 8px;
  border-radius: var(--radius);
  background: var(--card);
  text-align: center;
  font-size: 13px;
  color: var(--subtitle);
}

.feature b {
  display: block;
  margin-bottom: 4px;
  font-size: 22px;
}

.booking-card .row-title {
  font-weight: 600;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  font-size: 15px;
}

.link-button.danger {
  color: var(--destructive);
}

.text-danger {
  color: var(--destructive);
}

.text-accent {
  color: var(--accent-fg);
}

.text-success {
  color: var(--success);
}

/* ---------- календарь ---------- */

.calendar {
  padding: 8px 8px 12px;
}

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 8px;
}

.cal-title {
  font-size: 17px;
  font-weight: 600;
}

.cal-nav {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--accent-fg);
  font-size: 22px;
}

.cal-nav:disabled {
  color: var(--hint);
  opacity: 0.35;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-wd {
  padding: 4px 0;
  color: var(--hint);
  font-size: 12px;
  text-align: center;
  text-transform: uppercase;
}

.cal-day {
  position: relative;
  aspect-ratio: 1;
  max-height: 48px;
  border: 0;
  border-radius: 50%;
  background: none;
  font-size: 16px;
  font-weight: 500;
}

.cal-day:disabled {
  color: var(--hint);
  font-weight: 400;
  opacity: 0.45;
}

.cal-day.available::after {
  content: "";
  position: absolute;
  bottom: 6px;
  left: 50%;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  border-radius: 50%;
  background: var(--accent);
}

.cal-day.today {
  color: var(--accent-fg);
}

.cal-day.selected {
  background: var(--accent);
  color: var(--accent-text);
}

.cal-day.selected::after {
  background: var(--accent-text);
}

/* Календарь графика в админ-панели: рабочие дни подкрашены, у дней с записями — счётчик */

.cal-day.work:not(.selected) {
  background: var(--accent-soft);
}

.cal-day.off:not(.selected) {
  color: var(--hint);
}

.cal-day.closed:not(.selected) {
  opacity: 0.5;
}

/* «пн», «вт»… в шапке — кнопки: выбирают все такие дни месяца */
.cal-wd.pick {
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--accent-fg);
  font-weight: 500;
}

.cal-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 10px;
  font-weight: 600;
  line-height: 16px;
}

.cal-day.selected .cal-badge {
  background: var(--accent-text);
  color: var(--accent);
}

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  padding: 12px 4px 0;
  color: var(--hint);
  font-size: 13px;
}

.cal-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cal-legend i {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-style: normal;
}

.legend-work {
  background: var(--accent-soft);
}

.legend-off {
  box-shadow: inset 0 0 0 1px var(--separator);
}

.legend-booked {
  background: var(--accent);
  color: var(--accent-text);
  font-size: 10px;
  font-weight: 600;
}

.hours-row .row-title {
  flex-shrink: 0;
}

.hours-row .time-range input {
  width: 86px;
}

.icon-button {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-right: -4px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--hint);
  font-size: 15px;
}

.icon-spacer {
  flex-shrink: 0;
  width: 24px;
}

.row.add-row {
  color: var(--link);
  font-size: 15px;
}

.editor-actions {
  position: relative;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 16px;
}

.editor-actions::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 1px;
  background: var(--separator);
  transform: scaleY(0.5);
}

.slots {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px;
}

.slot {
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: var(--bg);
  font-size: 15px;
  font-weight: 500;
  transition: background 0.12s;
}

.slot.selected {
  background: var(--accent);
  color: var(--accent-text);
}

.placeholder {
  padding: 20px 16px;
  color: var(--hint);
  text-align: center;
  font-size: 15px;
}

/* ---------- формы ---------- */

.field {
  display: block;
  padding: 10px 16px 12px;
}

.field + .field {
  border-top: 0.5px solid var(--separator);
}

.field-label {
  display: block;
  margin-bottom: 4px;
  color: var(--hint);
  font-size: 13px;
}

.input {
  width: 100%;
  padding: 4px 0;
  border: 0;
  outline: none;
  background: none;
  font-size: 17px;
}

.input::placeholder {
  color: var(--hint);
  opacity: 0.7;
}

textarea.input {
  resize: vertical;
  min-height: 60px;
}

/* Кнопки-подсказки под полем: уже заведённые группы услуг */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  padding: 6px 12px;
  border: 0;
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.chip.active {
  background: var(--accent);
  color: var(--accent-text);
}

/* Поле-кнопка выпадающего списка (App.picker) */
.picker {
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
}

.picker:active {
  background: var(--separator);
}

.picker-value {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  font-size: 17px;
}

.picker-value::after {
  content: "";
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  margin-right: 4px;
  border-right: 2px solid var(--hint);
  border-bottom: 2px solid var(--hint);
  transform: translateY(-3px) rotate(45deg);
}

.field.invalid .field-label {
  color: var(--destructive);
}

.error-text {
  margin: 8px 16px 0;
  color: var(--destructive);
  font-size: 14px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 16px;
  font-weight: 600;
}

.btn:disabled {
  opacity: 0.45;
}

.btn.secondary {
  background: var(--card);
  color: var(--accent-fg);
}

.btn.danger {
  background: var(--card);
  color: var(--destructive);
}

.btn + .btn {
  margin-top: 8px;
}

.mt {
  margin-top: 16px;
}

/* ---------- итог ---------- */

.total-row .row-title,
.total-row .row-value {
  font-size: 17px;
  font-weight: 700;
}

.success {
  padding: 40px 16px 24px;
  text-align: center;
}

.success-icon {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-size: 52px;
  animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes pop {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
}

.success h1 {
  margin: 0 0 8px;
  font-size: 26px;
}

.success p {
  margin: 0 auto;
  max-width: 320px;
  color: var(--hint);
}

/* ---------- админка ---------- */

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 2px;
  margin: 0 -16px 8px;
  padding: 8px 16px;
  background: var(--bg);
}

.tabs-inner {
  display: flex;
  flex: 1;
  padding: 2px;
  border-radius: 10px;
  background: var(--separator);
}

.tab {
  flex: 1;
  padding: 7px 4px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 14px;
  font-weight: 500;
}

.tab.active {
  background: var(--card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.segmented {
  display: flex;
  padding: 2px;
  border-radius: 9px;
  background: var(--bg);
}

.segmented button {
  flex: 1;
  padding: 6px 8px;
  border: 0;
  border-radius: 7px;
  background: none;
  font-size: 14px;
}

.segmented button.active {
  background: var(--accent);
  color: var(--accent-text);
}

.switch {
  position: relative;
  flex-shrink: 0;
  width: 51px;
  height: 31px;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: var(--separator);
  transition: background 0.2s;
  pointer-events: none;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}

.switch input:checked + span {
  background: var(--success);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.day-row {
  flex-wrap: wrap;
}

.day-row .row-title {
  width: 32px;
  font-weight: 500;
}

.time-range {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: flex-end;
  color: var(--hint);
}

.time-range input {
  width: 92px;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: var(--bg);
  font-size: 15px;
  text-align: center;
}

.time-range.off {
  opacity: 0.4;
  pointer-events: none;
}

.inline-form {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
}

.inline-form .input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 15px;
}

.inline-form .btn {
  width: auto;
  min-height: 0;
  padding: 8px 14px;
  font-size: 15px;
}

.date-header {
  margin: 20px 16px 6px;
  font-size: 15px;
  font-weight: 600;
}

.booking-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 6px;
  font-size: 14px;
}

/* Пожелания клиента к записи */
.comment-row .row-title {
  white-space: pre-line;
}

.booking-comment {
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 14px;
  white-space: pre-line;
  word-break: break-word;
}

.cancelled {
  opacity: 0.55;
}

.cancelled .row-title {
  text-decoration: line-through;
}

/* ---------- лист снизу со списком вариантов ---------- */

body.sheet-open {
  overflow: hidden;
}

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  animation: fade-in 0.18s ease-out;
}

.sheet {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  max-height: calc(var(--tg-viewport-height, 100vh) * 0.7);
  padding-bottom: var(--safe-bottom);
  border-radius: 16px 16px 0 0;
  background: var(--card);
  animation: sheet-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.sheet-title {
  flex-shrink: 0;
  padding: 16px 16px 12px;
  border-bottom: 0.5px solid var(--separator);
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}

.sheet-list {
  position: relative;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet-option.selected {
  color: var(--accent-fg);
  font-weight: 500;
}

.sheet-check {
  flex-shrink: 0;
  font-size: 18px;
}

.sheet-overlay.closing {
  animation: fade-out 0.18s ease-in forwards;
}

.sheet-overlay.closing .sheet {
  animation: sheet-out 0.18s ease-in forwards;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes fade-out {
  to {
    opacity: 0;
  }
}

@keyframes sheet-in {
  from {
    transform: translateY(100%);
  }
}

@keyframes sheet-out {
  to {
    transform: translateY(100%);
  }
}

/* ---------- запасная кнопка вне Telegram ---------- */

.fallback-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 8px 16px calc(8px + var(--safe-bottom));
  background: var(--bg);
  border-top: 0.5px solid var(--separator);
}

.fallback-bar .btn {
  max-width: 528px;
  margin: 0 auto;
}

.spinner {
  width: 28px;
  height: 28px;
  margin: 48px auto;
  border: 3px solid var(--separator);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-bottom));
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  font-size: 14px;
  transform: translateX(-50%);
  animation: screen-in 0.2s ease-out;
}

[hidden] {
  display: none !important;
}

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