:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --text: #16202e;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #1565c0;
  --primary-soft: #e3effd;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --off: #eef1f5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141c;
    --card: #17202b;
    --text: #e6edf5;
    --muted: #93a3b8;
    --line: #273445;
    --primary: #5aa2f0;
    --primary-soft: #1a2f48;
    --ok: #4ade80;
    --ok-soft: #15301f;
    --warn: #fbbf24;
    --warn-soft: #3a2c10;
    --danger: #f87171;
    --danger-soft: #3b1a1a;
    --off: #1d2733;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

/* ---------- каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--primary); color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  display: flex; align-items: center; gap: 12px;
}
@media (prefers-color-scheme: dark) { .topbar { background: #112a47; } }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: 12px; opacity: .8; font-weight: 400; }
.topbar button { background: rgba(255,255,255,.16); border: 0; color: #fff; border-radius: 10px; padding: 7px 12px; font-size: 14px; cursor: pointer; }
.page { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 96px); }
.page.wide { max-width: 1200px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; text-align: center; padding: 8px 2px 9px; text-decoration: none;
  color: var(--muted); font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabbar a .ico { font-size: 21px; line-height: 1.1; }
.tabbar a.active { color: var(--primary); font-weight: 600; }

/* ---------- элементы ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; border: 1px solid var(--line); }
.card h2, .section-title { font-size: 17px; margin: 0 0 10px; }
.section-title { margin: 20px 4px 10px; }
.section-title:first-child { margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; cursor: pointer;
  background: var(--primary); color: #fff; text-decoration: none; min-height: 46px;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--primary-soft); color: var(--primary); }
.btn.ghost { background: transparent; color: var(--primary); border: 1px solid var(--line); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.small { min-height: 36px; padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; margin-top: 14px; }
.btn-row .btn { flex: 1; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 11px;
  padding: 11px 12px; min-height: 46px; outline: none; appearance: none;
}
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.input:focus { border-color: var(--primary); }
textarea.input { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

.seg { display: flex; background: var(--off); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 9px; cursor: pointer; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.seg button:disabled { opacity: .35; cursor: default; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 8px 12px; cursor: pointer; text-align: center; min-width: 64px;
}
.chip .d1 { font-size: 12px; color: var(--muted); }
.chip .d2 { font-weight: 700; font-size: 17px; }
.chip .d3 { font-size: 11px; color: var(--ok); }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.on .d1, .chip.on .d3 { color: rgba(255,255,255,.85); }
.chip:disabled { opacity: .4; cursor: default; }
.chip:disabled .d3 { color: var(--muted); }

.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--off); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.blue { background: var(--primary-soft); color: var(--primary); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.list { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; margin-bottom: 12px; box-shadow: var(--shadow); }
.item { display: flex; gap: 12px; align-items: center; padding: 13px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item .t { font-weight: 600; }
.item .time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 54px; }
.item .time small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }

/* ---------- клиентская запись ---------- */
.hero { text-align: center; padding: 8px 0 4px; }
.hero h2 { margin: 6px 0 4px; font-size: 22px; }
.disc-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.disc-btn {
  border: 2px solid var(--line); background: var(--card); border-radius: 18px; padding: 22px 8px;
  cursor: pointer; font-size: 17px; font-weight: 600; box-shadow: var(--shadow);
}
.disc-btn .e { font-size: 42px; display: block; margin-bottom: 6px; }
.disc-btn.on { border-color: var(--primary); background: var(--primary-soft); }
.slot-btn {
  display: flex; align-items: center; width: 100%; gap: 12px; text-align: left;
  border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 8px; cursor: pointer;
}
.slot-btn .tm { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.slot-btn:disabled { opacity: .45; cursor: default; }
.slot-btn.on { border-color: var(--primary); background: var(--primary-soft); }
.lunch { text-align: center; color: var(--muted); font-size: 13px; padding: 6px; }
.success { text-align: center; padding: 10px 0; }
.success .big { font-size: 56px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; text-align: left; margin: 14px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.foot-link { display: block; text-align: center; margin: 30px 0 10px; color: var(--muted); font-size: 14px; }

/* ---------- сетка дня (админ) ---------- */
.daynav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.daynav .btn { min-width: 44px; padding: 0 10px; }
.daynav .input { text-align: center; font-weight: 600; }
.grid-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
.grid th, .grid td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 4px; vertical-align: top; }
.grid thead th { position: sticky; top: 0; background: var(--card); padding: 8px 6px; font-weight: 600; min-width: 112px; text-align: left; }
.grid thead th .muted { font-weight: 400; }
.grid .tcol { position: sticky; left: 0; background: var(--card); z-index: 2; min-width: 58px; width: 58px; font-variant-numeric: tabular-nums; font-weight: 700; text-align: center; }
.grid .tcol small { display: block; color: var(--muted); font-weight: 400; }
.grid thead .tcol { z-index: 3; }
.grid tr.lunch-row td { background: var(--off); color: var(--muted); text-align: center; padding: 6px; font-size: 12px; }
.cell { border-radius: 8px; padding: 6px 7px; min-height: 48px; cursor: pointer; display: flex; flex-direction: column; justify-content: center; }
.cell.off { background: repeating-linear-gradient(-45deg, var(--off), var(--off) 6px, transparent 6px, transparent 12px); color: var(--muted); }
.cell.free { background: var(--ok-soft); color: var(--ok); align-items: center; font-weight: 600; }
.cell.busy { background: var(--primary-soft); color: var(--text); }
.cell.busy .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.cell.busy .p { color: var(--muted); font-size: 12px; white-space: nowrap; }
.cell.past { opacity: .55; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 10px 2px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }

/* ---------- календарь выбора дней ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal .wd { text-align: center; font-size: 11px; color: var(--muted); padding-bottom: 2px; }
.cal button { aspect-ratio: 1; border: 1px solid var(--line); background: var(--card); border-radius: 10px; cursor: pointer; font-weight: 600; padding: 0; position: relative; }
.cal button .m { position: absolute; top: 2px; left: 0; right: 0; font-size: 9px; font-weight: 400; color: var(--muted); }
.cal button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.cal button.on .m { color: rgba(255,255,255,.8); }
.cal button.has { border-color: var(--ok); }
.cal button:disabled { visibility: hidden; }

/* ---------- шторка ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(8, 15, 25, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(env(safe-area-inset-bottom) + 18px); animation: up .2s ease-out;
}
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 20px; } }
.sheet .grab { width: 40px; height: 5px; background: var(--line); border-radius: 9px; margin: 2px auto 10px; }
.sheet-head { display: flex; align-items: center; margin-bottom: 12px; }
.sheet-head h3 { margin: 0; flex: 1; font-size: 18px; }
.sheet-head button { border: 0; background: var(--off); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 16px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

#toasts { position: fixed; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 10px); z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 16px; }
.toast { background: #1e293b; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: up .2s; max-width: 480px; }
.toast.err { background: #b91c1c; }
.toast.ok { background: #15803d; }

.login-box { max-width: 380px; margin: 30px auto; }
.search { position: sticky; top: 64px; z-index: 5; margin-bottom: 10px; }
.fab { position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 76px); z-index: 15; border-radius: 99px; box-shadow: 0 6px 18px rgba(21,101,192,.35); padding: 14px 20px; }
.date-head { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; margin: 16px 4px 6px; }
.slots-preview { display: flex; flex-wrap: wrap; gap: 6px; }
