/* ==== Токены: тёмная графит + салатовая тема (бренд трека) ==== */
:root {
  --bg:        #131512;
  --surface:   #1b1e19;
  --surface-2: #232720;
  --surface-3: #2c3128;
  --border:    #333a2e;
  --border-2:  #414937;

  --text:      #e9ece3;
  --text-dim:  #99a08f;
  --text-mut:  #6f7565;

  --accent:      #a3e635;   /* салатовый */
  --accent-ink:  #1a2107;   /* текст на акценте */
  --accent-dim:  #4f6b1f;

  /* Статусы */
  --pay-ok:   #4ade80;   /* оплачено */
  --pay-debt: #f87171;   /* долг */
  --rest-ok:    #99a08f; /* остаток норм */
  --rest-warn:  #fb923c; /* осталась 1 */
  --rest-empty: #f87171; /* 0 */

  --radius: 14px;
  --radius-sm: 9px;
  --tap: 44px;

  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --ease: cubic-bezier(.22,.61,.36,1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, system-ui, sans-serif;
  font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body { overscroll-behavior: none; }

.tnum { font-variant-numeric: tabular-nums; }

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* ==== Каркас приложения ==== */
#app {
  max-width: 520px; margin: 0 auto; min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .2px; }
.topbar .month-nav { display: flex; align-items: center; gap: 4px; }
.iconbtn {
  min-width: var(--tap); min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: 22px;
}
.iconbtn:active { background: var(--surface-2); }

/* ==== Месяц ==== */
.weekhead {
  display: grid; grid-template-columns: repeat(7, 1fr);
  padding: 4px 8px; gap: 4px;
}
.weekhead span {
  text-align: center; font-size: 11px; font-weight: 600;
  color: var(--text-mut); letter-spacing: .5px;
}
.weekhead span.sun { color: #d98a8a; }

.month {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 4px; padding: 0 8px 12px; flex: 1;
}
.daycell {
  background: var(--surface); border: 1px solid transparent;
  border-radius: 10px; min-height: 74px; padding: 5px 5px 4px;
  display: flex; flex-direction: column; gap: 3px;
  overflow: hidden; text-align: left;
}
.daycell.out { background: transparent; }
.daycell.out .dnum { color: var(--text-mut); opacity: .5; }
.daycell.today { border-color: var(--accent); }
.daycell:active { background: var(--surface-2); }

.dnum { font-size: 13px; font-weight: 600; color: var(--text-dim); line-height: 1; }
.daycell.today .dnum {
  color: var(--accent-ink); background: var(--accent);
  width: 20px; height: 20px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center; align-self: flex-start;
}

.mini { display: flex; align-items: center; gap: 4px; min-width: 0; }
.mini .bar { width: 3px; align-self: stretch; min-height: 12px; border-radius: 2px; flex: none; }
.mini .nm {
  font-size: 10.5px; color: var(--text-dim); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; line-height: 1.25;
}
.mini.debt .nm { color: #e8b4b4; }
.mini .more { font-size: 10px; color: var(--text-mut); }

/* ==== Модальное окно дня (окно поверх месяца) ==== */
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  padding: 22px 12px; z-index: 100;
  opacity: 0; transition: opacity .18s var(--ease);
}
.scrim.show { opacity: 1; }

.sheet {
  width: 100%; max-width: 480px; max-height: 86dvh;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
  transform: scale(.94); opacity: 0;
  transition: transform .2s var(--ease), opacity .2s var(--ease);
}
.scrim.show .sheet { transform: scale(1); opacity: 1; }

.sheet-head {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px 12px 18px; border-bottom: 1px solid var(--border);
}
/* Без capitalize: он делал заглавным и месяц — «Пятница, 21 Августа».
   Регистр задаётся в calendar.js: день недели с большой, месяц с маленькой. */
.sheet-head .dtitle { font-size: 19px; font-weight: 700; }
.sheet-head .navs { display: flex; align-items: center; gap: 2px; }

.day-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 12px 14px; }

/* Строка слота */
.slot {
  display: flex; align-items: stretch; gap: 12px;
  padding: 12px 8px; border-bottom: 1px solid var(--border);
  width: 100%; background: transparent; border-left: 0; border-right: 0; border-top: 0;
  text-align: left; min-height: var(--tap);
}
.slot:last-child { border-bottom: 0; }
.slot:active { background: var(--surface-2); }
/* Ширина под «11:00 – 12:00» в одну строку. Одинакова у занятых и свободных часов,
   иначе имена клиентов начинались бы на разном отступе. */
.slot .time { font-size: 14px; font-weight: 600; color: var(--text); width: 92px; flex: none; white-space: nowrap; }
.slot .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.slot.done { opacity: .6; }

/* Свободный час в сетке дня — тише записи, но кликабельный (тап = запись на это время) */
.slot.free { min-height: 44px; padding: 9px 8px; align-items: center; }
.slot.free .time { color: var(--text-mut); font-weight: 500; }
.slot.free.past { opacity: .45; }
.slot.free:active { background: var(--surface-3); }

.pline { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pline .bar { width: 3px; height: 15px; border-radius: 2px; flex: none; }
.pline .pname { font-size: 14.5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pline .checked { color: var(--accent); font-size: 13px; flex: none; }

/* Бейджи строки дня: код 2/12/5 · точка-светофор остатка · оплата */
.badges { display: flex; align-items: center; gap: 6px; flex: none; }
.code {
  font-size: 12.5px; font-weight: 700; padding: 2px 7px; border-radius: 7px;
  background: var(--surface-3); color: var(--text-dim); white-space: nowrap; letter-spacing: .3px;
}
.tag {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  white-space: nowrap; letter-spacing: .2px;
}
.tag.warn  { color: #201603; background: var(--rest-warn); }
.tag.empty { color: #2a0d0d; background: var(--rest-empty); }
.tag.trial { color: var(--text-dim); background: var(--surface-3); border: 1px dashed var(--border-2); }

/* Пробный клиент */
.mode-row { display: flex; gap: 8px; margin: 10px 0; }
.mode-btn {
  flex: 1; min-height: 40px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border-2); color: var(--text-dim);
  font-size: 13.5px; font-weight: 600;
}
.mode-btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.trial-hint { font-size: 12.5px; color: var(--text-dim); margin: 4px 2px 2px; line-height: 1.4; }
.trial-tag { font-size: 12px; font-weight: 700; color: var(--text-dim); margin-top: 3px; }
.enroll-btn {
  margin-top: 12px; width: 100%; min-height: var(--tap);
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: var(--radius);
  font-size: 14.5px; font-weight: 700;
}
.enroll-btn:active { transform: scale(.98); }

.pay {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 999px;
}
.pay .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.pay.ok   { color: var(--pay-ok);   background: rgba(74,222,128,.12); }
.pay.ok   .dot { background: var(--pay-ok); }
.pay.debt { color: var(--pay-debt); background: rgba(248,113,113,.14); }
.pay.debt .dot { background: var(--pay-debt); }

.day-empty { text-align: center; color: var(--text-mut); padding: 40px 20px; font-size: 14px; }

/* Только плюс, без подписи — размер крупнее, чтобы знак не терялся в пустой кнопке */
.addbtn {
  margin: 8px 4px 2px; width: calc(100% - 8px); min-height: var(--tap);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface-2); border: 1px dashed var(--border-2);
  border-radius: var(--radius); color: var(--text-dim); font-size: 20px; font-weight: 600;
}
.addbtn:active { background: var(--surface-3); }

/* ==== Редактор слота ==== */
.editor-head {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px 12px 18px; border-bottom: 1px solid var(--border);
}
.editor-head .etitle { font-size: 18px; font-weight: 700; }
.editor-head .etitle small { display: block; font-size: 12px; color: var(--text-dim); font-weight: 500; }
.editor-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 14px 16px; }

.pcard {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; margin-top: 10px;
}
.pcard-top { display: flex; align-items: center; gap: 10px; }
.pcard .bar { width: 4px; align-self: stretch; min-height: 34px; border-radius: 3px; flex: none; }
.pcard .who { flex: 1; min-width: 0; }
.pcard .who .nm2 { font-size: 15.5px; font-weight: 600; }
.pcard .who .sub2 { font-size: 12px; color: var(--text-dim); }
.rest-note { font-size: 12px; font-weight: 700; margin-top: 3px; }
.rest-note.warn  { color: var(--rest-warn); }
.rest-note.empty { color: var(--rest-empty); }

.done-btn {
  min-height: var(--tap); padding: 0 16px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); border: 0;
  font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; gap: 6px;
  transition: transform .12s var(--ease);
}
.done-btn:active { transform: scale(.96); }
.done-btn.undo { background: var(--surface-3); color: var(--text-dim); font-weight: 600; }

/* Следующий комплект: оформлен наперёд / форма оформления */
.next-sub {
  margin-top: 10px; padding: 8px 10px; border-radius: 10px;
  background: rgba(74,222,128,.10); border: 1px solid var(--border);
  color: var(--pay-ok); font-size: 12.5px; font-weight: 600;
}
.next-sub.debt { background: rgba(248,113,113,.12); color: var(--pay-debt); }

.prepay { margin-top: 10px; }
.prepay .form-label { margin: 10px 2px 6px; }
.prepay .enroll-btn { margin-top: 2px; background: var(--surface-3); color: var(--text); font-size: 13.5px; }
.prepay .save-btn { margin-top: 12px; }
.prepay-cancel {
  width: 100%; min-height: 38px; margin-top: 6px;
  background: transparent; border: 0; color: var(--text-mut);
  font-size: 13px; font-weight: 600;
}

.pcard-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border);
}
.pcard-row .lbl { font-size: 12.5px; color: var(--text-dim); }
.pay-toggle {
  min-height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-2);
  background: transparent; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.pay-toggle .dot { width: 8px; height: 8px; border-radius: 50%; }
.pay-toggle.ok   { color: var(--pay-ok); }   .pay-toggle.ok   .dot { background: var(--pay-ok); }
.pay-toggle.debt { color: var(--pay-debt); } .pay-toggle.debt .dot { background: var(--pay-debt); }

.all-btn {
  margin-top: 12px; width: 100%; min-height: var(--tap);
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border-2);
  border-radius: var(--radius); font-weight: 700; font-size: 14.5px;
}
.all-btn:active { background: var(--surface-2); }

.closed-note {
  margin-top: 10px; padding: 12px; border-radius: var(--radius);
  background: rgba(248,113,113,.10); border: 1px solid rgba(248,113,113,.3);
  font-size: 13px; color: #f3b6b6;
}
.closed-note button {
  margin-top: 8px; min-height: 40px; padding: 0 14px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); border: 0; font-weight: 700; font-size: 13.5px;
}

/* Свободное окно */
.free-slot { font-size: 14px; color: var(--text-mut); font-style: italic; }

/* Добавление второго клиента в существующее время (групповая) */
.add-client { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.add-client .addbtn { margin: 0; width: 100%; }
.add-client .client-list { margin-top: 4px; }

/* «✓ проведена» — прошедшая по времени */
.chip-done {
  margin-left: 8px; font-size: 11px; font-weight: 600; color: var(--accent);
  background: rgba(163,230,53,.12); padding: 1px 7px; border-radius: 999px; vertical-align: middle;
}

/* Знак удаления участника */
.del-p {
  min-width: 40px; min-height: 40px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: 10px; color: var(--text-mut);
}
.del-p:active { background: rgba(248,113,113,.14); color: var(--pay-debt); }

/* Удалить весь слот */
.del-slot {
  margin-top: 14px; width: 100%; min-height: var(--tap);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: transparent; border: 1px solid rgba(248,113,113,.35);
  border-radius: var(--radius); color: var(--pay-debt); font-size: 14px; font-weight: 600;
}
.del-slot:active { background: rgba(248,113,113,.12); }

/* Тост с «Отменить» */
.toast-host {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
  display: flex; justify-content: center; padding: 0 12px calc(16px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px;
  max-width: 480px; width: 100%;
  background: #2a2f24; border: 1px solid var(--border-2); border-radius: 12px;
  padding: 12px 14px; box-shadow: var(--shadow);
  font-size: 14px; color: var(--text);
  transform: translateY(140%); opacity: 0; transition: transform .22s var(--ease), opacity .22s var(--ease);
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast span { flex: 1; }
.toast-action {
  flex: none; min-height: 36px; padding: 0 14px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); border: 0; font-weight: 700; font-size: 13.5px;
}

/* ==== Форма «Новая запись» ==== */
.form-label { font-size: 12.5px; color: var(--text-dim); font-weight: 600; margin: 14px 2px 7px; }

.time-input { display: flex; align-items: center; gap: 6px; }
.ti-field {
  width: 62px; min-height: var(--tap); text-align: center;
  font-size: 22px; font-weight: 700; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 12px;
  outline: none;
}
.ti-field:focus { border-color: var(--accent); }
.ti-colon { font-size: 22px; font-weight: 700; color: var(--text-dim); }

/* Поля времени окончания — тише и мельче начала: обычно их не трогают,
   значение подставляется само. Но поправить можно. */
.time-input { flex-wrap: nowrap; }
.ti-field.ti-small { width: 52px; font-size: 18px; font-weight: 600; color: var(--text-dim); }
.ti-field.ti-small:focus { color: var(--text); border-color: var(--accent); }
.ti-colon.small { font-size: 18px; }
.ti-dash { margin: 0 2px; font-size: 18px; color: var(--text-mut); }

.client-list { display: flex; flex-wrap: wrap; gap: 8px; }
.client-chip {
  min-height: var(--tap); padding: 0 14px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border-2); color: var(--text);
  font-size: 14px; font-weight: 600;
}
.client-chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.client-chip.new { color: var(--accent); border-style: dashed; }
.client-chip:active { transform: scale(.97); }

.new-client {
  margin-top: 10px; padding: 12px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border);
}
.nc-name {
  width: 100%; min-height: var(--tap); padding: 0 14px;
  background: var(--surface); border: 1px solid var(--border-2); border-radius: 12px;
  color: var(--text); font-size: 15px; outline: none;
}
.nc-name:focus { border-color: var(--accent); }
.kupleno-opts { display: flex; gap: 8px; align-items: center; }
.kbtn {
  min-width: 52px; min-height: 40px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border-2); color: var(--text);
  font-size: 15px; font-weight: 700;
}
.kbtn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.kupleno-custom {
  width: 74px; min-height: 40px; text-align: center;
  background: var(--surface); border: 1px solid var(--border-2); border-radius: 10px;
  color: var(--text); font-size: 15px; outline: none;
}
.kupleno-custom:focus { border-color: var(--accent); }

.save-btn {
  margin-top: 18px; width: 100%; min-height: var(--tap);
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: var(--radius);
  font-size: 15.5px; font-weight: 700;
}
.save-btn:disabled { opacity: .4; }
.save-btn:active:not(:disabled) { transform: scale(.98); }
.save-btn.ghost { margin-top: 12px; background: var(--surface-3); color: var(--text); }

@media (prefers-reduced-motion: reduce) {
  .scrim, .sheet, .done-btn, .toast, .client-chip, .save-btn { transition: none; }
}
