:root {
  --bg: #14110f; --surface: #1c1815; --surface-2: #242019; --line: #322b25; --line-soft: #26211c;
  --text: #f3ede6; --muted: #a59b90; --faint: #6f665d;
  --accent: #e8a33d; --accent-ink: #1a1206; --danger: #e5604f; --ok: #5cb87a;
  --st-booked: #3a5f8f; --st-booked-b: #6f9ad1; --st-arrived: #2f6b45; --st-arrived-b: #6cc58e;
  --st-closed: #3a3530; --st-closed-b: #7d736a;
  --hour: 56px; --name-w: 150px; --row-h: 48px; --radius: 10px;
  color-scheme: dark;
  font-family: Manrope, system-ui, -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f3ef; --surface: #ffffff; --surface-2: #f1ece6; --line: #ddd5cc; --line-soft: #ebe5de;
    --text: #1f1a16; --muted: #6d645b; --faint: #a0968c; --accent: #c77d12; --accent-ink: #fff;
    --st-booked: #dbe7f6; --st-booked-b: #4f7fbf; --st-arrived: #d9f0e0; --st-arrived-b: #3c9a5f;
    --st-closed: #ebe6e1; --st-closed-b: #9a9087;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 14px; line-height: 1.4; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* --- верхняя панель */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line-soft); }
.brand { font-weight: 800; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand img { width: 26px; height: 26px; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; white-space: nowrap; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.on { color: var(--text); background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--accent); }
.me { display: flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; }

main { padding: 16px; max-width: 1600px; margin: 0 auto; }

/* --- кнопки и поля */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 36px; padding: 0; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .booking:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input, select, textarea { height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); min-width: 0; }
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input[type=checkbox] { height: 18px; width: 18px; accent-color: var(--accent); }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { font-size: 14px; font-weight: 500; color: var(--text); width: 100%; }
label.f > .seg { display: flex; width: 100%; }
label.f > .seg button { flex: 1; padding: 0 6px; font-size: 13px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 0 12px; height: 34px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }

/* --- панель инструментов дня */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.date-title { font-size: 20px; font-weight: 800; min-width: 210px; }
.date-title small { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
.stats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 8px 12px; min-width: 110px; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 600; }

/* --- шахматка */
.grid-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--surface); }
.grid { position: relative; min-width: calc(var(--name-w) + var(--hour) * var(--hours)); }
.g-head, .g-row { display: flex; }
.g-head { position: sticky; top: 0; z-index: 3; background: var(--surface); border-bottom: 1px solid var(--line); height: 34px; }
.g-name { position: sticky; left: 0; z-index: 2; width: var(--name-w); flex: none; padding: 6px 10px; background: var(--surface);
  border-right: 1px solid var(--line); display: flex; flex-direction: column; justify-content: center; }
.g-name b { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-name small { color: var(--faint); font-size: 11px; font-weight: 600; }
.g-hours { position: relative; flex: none; width: calc(var(--hour) * var(--hours)); }
.g-hours .h { position: absolute; top: 0; bottom: 0; font-size: 11px; font-weight: 700; color: var(--muted); padding: 9px 0 0 4px; border-left: 1px solid var(--line-soft); }
.g-row { height: var(--row-h); border-bottom: 1px solid var(--line-soft); }
.g-row:last-child { border-bottom: 0; }
.g-track { position: relative; flex: none; width: calc(var(--hour) * var(--hours)); cursor: copy;
  background-image: linear-gradient(to right, var(--line-soft) 1px, transparent 1px), linear-gradient(to right, color-mix(in srgb, var(--line-soft) 50%, transparent) 1px, transparent 1px);
  background-size: var(--hour) 100%, calc(var(--hour) / 2) 100%; }
.g-track:hover { background-color: color-mix(in srgb, var(--accent) 4%, transparent); }
.g-group { position: sticky; left: 0; padding: 8px 10px; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--accent);
  background: var(--surface-2); border-bottom: 1px solid var(--line-soft); }
.now-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); z-index: 1; pointer-events: none; }
.now-line::before { content: ''; position: absolute; top: 0; left: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }

.booking { position: absolute; top: 4px; bottom: 4px; border-radius: 7px; padding: 3px 7px; overflow: hidden; cursor: pointer;
  background: var(--st-booked); border-left: 3px solid var(--st-booked-b); font-size: 12px; line-height: 1.25; text-align: left; border-top: 0; border-right: 0; border-bottom: 0; color: var(--text); }
.booking:hover { filter: brightness(1.12); z-index: 2; }
.booking b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.booking span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 11px; font-weight: 600; }
.booking.arrived { background: var(--st-arrived); border-left-color: var(--st-arrived-b); }
.booking.closed { background: var(--st-closed); border-left-color: var(--st-closed-b); }
.booking .pp { position: absolute; top: 3px; right: 5px; font-size: 10px; font-weight: 800; color: var(--accent); }
.booking .pp.paid { color: var(--ok); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; color: var(--muted); font-size: 12px; font-weight: 600; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; }

/* --- список (мобильный вид) */
.list { display: grid; gap: 8px; }
.card { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 12px; }
.bk-card { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center; cursor: pointer; border-left: 3px solid var(--st-booked-b); }
.bk-card.arrived { border-left-color: var(--st-arrived-b); }
.bk-card.closed { border-left-color: var(--st-closed-b); opacity: .8; }
.bk-card .t { font-weight: 800; font-variant-numeric: tabular-nums; }
.bk-card .t small { display: block; color: var(--muted); font-weight: 600; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.chip.booked { color: var(--st-booked-b); } .chip.arrived { color: var(--st-arrived-b); } .chip.closed { color: var(--st-closed-b); }
.chip.cancelled, .chip.noshow { color: var(--danger); }

/* --- таблицы */
.table-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td a { white-space: nowrap; }
tr.total td { font-weight: 800; background: var(--surface-2); }
tr.weekend td:first-child { color: var(--accent); }
tbody tr.click { cursor: pointer; } tbody tr.click:hover td { background: var(--surface-2); }

h2 { font-size: 20px; margin: 0; font-weight: 800; }
h3 { font-size: 14px; margin: 24px 0 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 12px 14px; }
.kpi span { font-size: 12px; font-weight: 600; color: var(--muted); }
.kpi b { display: block; font-size: 22px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--faint); font-weight: 600; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding: 12px; background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); }
.bars .bar { flex: 1; display: flex; flex-direction: column-reverse; min-width: 4px; height: 100%; position: relative; cursor: default; }
.bars .bar i { display: block; width: 100%; }
.bars .bar i.c { background: var(--accent); border-radius: 0 0 2px 2px; }
.bars .bar i.h { background: color-mix(in srgb, var(--accent) 45%, var(--surface)); border-radius: 2px 2px 0 0; }
.bars .bar:hover::after { content: attr(data-tip); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--line);
  padding: 4px 8px; border-radius: 6px; white-space: nowrap; font-size: 12px; z-index: 5; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.cols h3 { margin-top: 8px; }

/* --- модальное окно */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); width: min(760px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: rgb(0 0 0 / .55); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dlg-head h2 { flex: 1; font-size: 17px; }
.dlg-body { padding: 16px 18px; display: grid; gap: 14px; }
.dlg-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line-soft); position: sticky; bottom: 0; background: var(--surface); }
.dlg-foot .spacer { flex: 1; }
.row { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.row.r2 { grid-template-columns: 2fr 1fr; }
fieldset { border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 12px; margin: 0; display: grid; gap: 10px; }
legend { padding: 0 6px; font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.hint { font-size: 12px; color: var(--muted); font-weight: 600; }
.hint.warn { color: var(--accent); } .hint.err { color: var(--danger); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.history { display: grid; gap: 4px; font-size: 12px; max-height: 120px; overflow: auto; }

/* --- вход */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--line-soft); padding: 28px; border-radius: 16px; }
.login .brand { font-size: 20px; justify-content: center; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); opacity: 0; transition: .2s; background: var(--surface-2); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 100; pointer-events: none; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { border-color: var(--danger); color: var(--danger); }

.settings-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.dict-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.dict-list .chip { cursor: pointer; border: 1px solid var(--line-soft); font-size: 13px; padding: 4px 10px; color: var(--text); }
.dict-list .chip.off { text-decoration: line-through; color: var(--faint); }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input, .inline-form select { flex: 1; min-width: 120px; }
.booking .prog { position: absolute; bottom: 3px; right: 5px; font-size: 10px; font-weight: 800; color: var(--danger); }
.btn.wa { color: #25a35a; }
.variants { display: grid; gap: 6px; max-height: 320px; overflow: auto; }
.variant { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line-soft); border-radius: 8px; cursor: pointer; }
.variant.exact { border-color: color-mix(in srgb, var(--ok) 50%, var(--line-soft)); }
.steps { display: grid; gap: 8px; }
.step-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; min-height: 32px; }
.step-input { max-width: 220px; height: 30px; }
.range { display: flex; align-items: center; gap: 6px; }
.range input { flex: 1; min-width: 0; }
.dlg-tabs { padding: 10px 18px 0; }
.dlg-tabs .seg { display: flex; }
.dlg-tabs .seg button { flex: 1; height: 38px; font-size: 14px; }
.dlg-tabs .chip { margin-left: 4px; color: var(--danger); }
.dlg-tabs .chip.ok { color: var(--ok); }
.dlg-pane { display: grid; gap: 14px; }
.next-step { width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; cursor: pointer; font-size: 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); color: var(--text); }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress-bar { height: 100%; background: var(--ok); transition: width .2s; }
.stepper { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.step { display: grid; grid-template-columns: 30px 1fr; gap: 12px; padding: 12px; border: 1px solid var(--line-soft); border-radius: 12px; }
.step-num { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--surface-2); color: var(--muted); }
.step-body { display: grid; gap: 8px; min-width: 0; }
.step-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: 30px; }
.step-title .btn { margin-left: auto; }
.step-what { color: var(--muted); font-weight: 500; }
.step.current { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.step.current .step-num { background: var(--accent); color: var(--accent-ink); }
.step.done { opacity: .75; padding-top: 8px; padding-bottom: 8px; }
.step.done .step-num { background: color-mix(in srgb, var(--ok) 25%, var(--surface)); color: var(--ok); }
.step.todo .step-what, .step.todo .quick { opacity: .8; }
.step.todo .btn.primary { background: var(--surface); border-color: var(--line); color: var(--text); }
.chip.now { background: var(--accent); color: var(--accent-ink); }
.task { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.task-main { cursor: pointer; flex: 1 1 260px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

@media (max-width: 720px) {
  :root { --name-w: 104px; --hour: 48px; }
  .top { flex-wrap: wrap; gap: 8px 12px; padding: 8px 16px; }
  .nav { order: 3; flex-basis: 100%; }
  .me .who { max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
  main { padding: 12px 16px; }
  .date-title { min-width: 0; font-size: 17px; flex-basis: 100%; order: -1; }
  .stat { min-width: 0; flex: 1 1 30%; }
  .dlg-body { padding: 14px; }
  .row.r2 { grid-template-columns: 1fr; }
}

/* --- филиалы и админка */
.branch-pick { height: 32px; font-weight: 700; max-width: 200px; }
.branch-name { font-weight: 700; color: var(--muted); white-space: nowrap; }
.g-track.readonly { cursor: default; }
.user-card { display: grid; gap: 10px; }
.user-card.new { border-color: color-mix(in srgb, var(--accent) 40%, var(--line-soft)); margin: 10px 0; }
.branch-boxes { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 4px; }
label.check.sm { font-size: 13px; font-weight: 600; }
.dict-item { display: inline-flex; align-items: center; }
.icon-sm { width: 26px; height: 26px; padding: 0; color: var(--muted); }
@media (max-width: 720px) { .branch-pick { max-width: 140px; } }
.toolbar .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg button { white-space: nowrap; }
.history-box summary { cursor: pointer; font-weight: 700; color: var(--muted); font-size: 13px; }
.history-box .history { max-height: 200px; margin-top: 8px; }
.me .who { color: var(--muted); font-weight: 600; }

/* --- лист ожидания */
.wl-card { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: start; }
.wl-card.has-free { border-color: color-mix(in srgb, var(--ok) 55%, var(--line-soft)); }
.wl-main { display: grid; gap: 3px; min-width: 0; }
.wl-free { display: grid; gap: 6px; justify-items: end; max-width: 360px; }
.wl-free .quick { justify-content: flex-end; }
.hint.ok { color: var(--ok); }
a.stat-link { text-decoration: none; color: var(--text); }
a.stat-link.alert { border-color: var(--ok); }
a.stat-link.alert span { color: var(--ok); }
.notice { position: fixed; right: 16px; bottom: 16px; z-index: 90; width: min(380px, calc(100vw - 32px)); display: grid; gap: 6px;
  background: var(--surface); border: 1px solid var(--ok); border-radius: 12px; padding: 12px 14px; box-shadow: 0 10px 30px rgb(0 0 0 / .35); }
@media (max-width: 720px) { .wl-card { grid-template-columns: 1fr; } .wl-free { justify-items: start; max-width: none; } .wl-free .quick { justify-content: flex-start; } }

/* --- кабины в админке: свёрнутые строки */
.res-list { display: grid; border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.res-item + .res-item { border-top: 1px solid var(--line-soft); }
.res-item summary { display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer; list-style: none; }
.res-item summary::-webkit-details-marker { display: none; }
.res-item summary::before { content: '›'; color: var(--muted); font-weight: 800; transition: transform .15s; }
.res-item[open] summary::before { transform: rotate(90deg); }
.res-item summary:hover { background: var(--surface-2); }
.res-item .res-edit { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--muted); }
.res-item[open] .res-edit { visibility: hidden; }
.res-item.off summary b { color: var(--faint); text-decoration: line-through; }
.res-form { display: grid; gap: 10px; padding: 4px 14px 14px; background: var(--surface-2); }
