:root {
  --bg: #15171f;
  --surface: #1e212c;
  --surface-2: #272b39;
  --line: #333849;
  --text: #ece8e1;
  --muted: #9b9cab;
  --lamp: #f0b45a;
  --lamp-ink: #2a1d05;
  --err: #ff8a80;
  --ok: #7ee0a3;
  --radius: 14px;
  --nav-h: 62px;
  --top-h: 54px;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

h1 { font-size: 1.55rem; line-height: 1.2; margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; line-height: 1.3; margin: 0 0 .5rem; font-weight: 600; }
p { margin: 0 0 .75rem; }
a { color: var(--lamp); }
.lead { color: var(--muted); }
.muted { color: var(--muted); font-size: .92rem; }
.center { text-align: center; }

/* ---------- каркас: шапка, нижняя панель, содержимое ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  display: flex; align-items: center; justify-content: space-between;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.25rem; letter-spacing: .01em; }
.brand::before { content: ""; display: inline-block; width: .55em; height: .55em; margin-right: .4em; border-radius: 2px; background: var(--lamp); transform: translateY(-.05em); }
.who-chip-form { margin: 0; }
.who-chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px;
  padding: 4px 10px 4px 5px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text); font: inherit; cursor: pointer;
}
.who-chip .ico { width: 18px; height: 18px; color: var(--muted); }
.dot {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  color: #14161c; font-weight: 700; font-size: .95rem;
}

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; padding: 4px 2px; text-align: center; line-height: 1.15;
}
.nav a.on { color: var(--lamp); }

.page {
  width: 100%; max-width: 760px; margin: 0 auto;
  padding: 18px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}
body.bare .page { padding-bottom: 32px; }

@media (min-width: 900px) {
  body:not(.bare) { padding-left: 220px; }
  .top { padding-left: 24px; padding-right: 24px; }
  .nav {
    top: 0; right: auto; bottom: 0; width: 220px; height: auto;
    display: flex; flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: calc(var(--top-h) + 14px) 12px 12px; border-top: 0; border-right: 1px solid var(--line);
  }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 1rem; padding: 10px 12px; border-radius: 10px; text-align: left; }
  .nav a.on { background: var(--surface-2); }
  .top { margin-left: -220px; padding-left: calc(220px + 24px); }
  .page { padding: 28px 24px 48px; margin: 0; }
}

/* ---------- карточки ---------- */
.cards { display: grid; gap: 12px; margin-top: 16px; }
@media (min-width: 640px) { .cards { grid-template-columns: 1fr 1fr; } }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-top: 14px;
}
.cards .card { margin-top: 0; }
.card.soon { background: transparent; border-style: dashed; }
.card.soon h2 { color: var(--text); }
.card.soon p { margin-bottom: .25rem; }
.prose p:last-child { margin-bottom: 0; }

/* ---------- формы и кнопки ---------- */
.stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: .92rem; color: var(--muted); }
input[type=text], input[type=password], input:not([type]) {
  width: 100%; min-height: 48px; padding: 10px 12px; font: inherit; font-size: 1rem;
  color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }
label.check { display: flex; align-items: center; gap: 10px; color: var(--text); }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--lamp); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 10px 18px;
  font: inherit; font-weight: 600; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 12px; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--lamp); color: var(--lamp-ink); border-color: var(--lamp); }
.btn.danger { color: var(--err); }
.btn.link { background: none; border: 0; color: var(--muted); font-weight: 500; text-decoration: underline; min-height: 44px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; }
.row form { margin: 0; }

.note { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); }
.note.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 50%, transparent); }
.note.okay { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.note.warn { color: var(--lamp); border-color: color-mix(in srgb, var(--lamp) 45%, transparent); }

/* ---------- вход, «Кто вы?», PIN ---------- */
.gate { max-width: 360px; margin: 0 auto; padding-top: max(6vh, 24px); text-align: center; }
.gate .stack { text-align: left; }
.logo-mark {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px; background: var(--surface);
  border: 1px solid var(--line); position: relative;
}
.logo-mark::after { content: ""; position: absolute; left: 20px; top: 20px; width: 24px; height: 24px; border-radius: 4px; background: var(--lamp); box-shadow: 0 0 22px color-mix(in srgb, var(--lamp) 55%, transparent); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 22px 0 18px; }
.tile {
  display: grid; justify-items: center; gap: 12px; padding: 22px 8px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text); text-decoration: none;
}
.tile:active { background: var(--surface-2); }
.tile-dot {
  display: grid; place-items: center; width: 72px; height: 72px; border-radius: 50%;
  background: var(--c); color: #14161c; font-size: 2rem; font-weight: 700;
}
.tile-dot.big { margin: 0 auto 10px; }
.tile-name { font-weight: 600; overflow-wrap: anywhere; }

.pin-dots { display: flex; justify-content: center; gap: 16px; margin: 4px 0; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.on { background: var(--lamp); border-color: var(--lamp); }
.pin-input { text-align: center; letter-spacing: .6em; }
.js .pin-input { position: absolute; opacity: 0; pointer-events: none; height: 1px; width: 1px; min-height: 0; padding: 0; }
.numpad { display: none; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 280px; margin: 8px auto 0; }
.js .numpad { display: grid; }
.numpad button {
  min-height: 62px; font: inherit; font-size: 1.5rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; cursor: pointer;
}
.numpad button:active { background: var(--surface-2); }

/* ---------- копии данных ---------- */
.runs { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.run { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg); border-left: 3px solid var(--line); font-size: .92rem; }
.run.ok { border-left-color: var(--ok); }
.run.error { border-left-color: var(--err); }
.run-when { color: var(--muted); }
.run-kind { font-weight: 600; }
.run-msg { grid-column: 1 / -1; color: var(--muted); overflow-wrap: anywhere; }
.code { font-family: ui-monospace, Consolas, monospace; font-size: 1.3rem; padding: 12px; background: var(--bg); border: 1px dashed var(--lamp); border-radius: 10px; text-align: center; user-select: all; }

/* ---------- еда: вкладки, списки, сканер ---------- */
.tabs { display: flex; gap: 6px; margin: 4px 0 14px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.tabs a { flex: 1; text-align: center; padding: 9px 6px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .95rem; }
.tabs a.on { background: var(--surface-2); color: var(--text); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 12px; }
.actions .btn { flex: 1 1 140px; gap: 8px; }
.btn .ico { width: 20px; height: 20px; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: .9rem; font-weight: 500; }
.search { margin: 0 0 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 0 8px; padding-bottom: 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); text-decoration: none; font-size: .92rem; white-space: nowrap; }
.chip.on { background: var(--lamp); border-color: var(--lamp); color: var(--lamp-ink); font-weight: 600; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row-link { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; min-height: 60px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: var(--text); text-decoration: none; }
.row-link:active { background: var(--surface-2); }
.row-main { display: grid; gap: 2px; min-width: 0; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: .86rem; overflow-wrap: anywhere; }
.row-side { display: grid; gap: 4px; justify-items: end; flex: none; text-align: right; }
.row-qty { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-qty.none { color: var(--muted); font-weight: 400; }
.badge { font-size: .78rem; font-weight: 500; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.warn { color: var(--lamp); border-color: color-mix(in srgb, var(--lamp) 55%, transparent); }
.badge.bad { color: var(--err); border-color: color-mix(in srgb, var(--err) 55%, transparent); }
.empty { color: var(--muted); padding: 22px 12px; text-align: center; border: 1px dashed var(--line); border-radius: 12px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; min-height: 40px; }
.back .ico { width: 18px; height: 18px; }
.big-qty { font-size: 1.5rem; font-weight: 650; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
select, input[type=date] {
  width: 100%; min-height: 48px; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
select:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }
fieldset.kbju { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 12px; margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; min-width: 0; }
fieldset.kbju legend { color: var(--muted); font-size: .86rem; padding: 0 4px; }
fieldset.kbju input { padding: 10px 6px; text-align: center; }
.line { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; margin: 0; }
.line + .stack { margin-top: 12px; }
.line-grow { display: flex; gap: 8px; flex: 1; min-width: 0; margin: 0; }
.line-grow input { min-width: 0; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.scanner { position: relative; aspect-ratio: 4 / 3; max-height: 56vh; width: 100%; background: #000; border-radius: var(--radius); overflow: hidden; margin-bottom: 10px; border: 1px solid var(--line); }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner-frame { position: absolute; left: 10%; right: 10%; top: 32%; bottom: 32%; border: 2px solid var(--lamp); border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); opacity: 0; }
.scanner.live .scanner-frame { opacity: 1; }
.attention { list-style: none; padding: 0; margin: 0 0 10px; display: grid; }
.attention a { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--text); text-decoration: none; padding: 9px 0; border-bottom: 1px solid var(--line); }
.attention li:last-child a { border-bottom: 0; }
.attention .what { overflow-wrap: anywhere; }
.card-link { color: var(--muted); font-size: .92rem; }

/* ---------- этап 2: полоски, факты, дневник ---------- */
.tabs { overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: 1 0 auto; padding: 9px 12px; white-space: nowrap; }
.meter { margin: 0 0 12px; }
.meter-top { display: flex; justify-content: space-between; gap: 10px; font-size: .95rem; }
.meter-num { font-variant-numeric: tabular-nums; color: var(--muted); }
.meter-bar { height: 8px; margin-top: 5px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.meter-bar i { display: block; height: 100%; background: var(--lamp); border-radius: 999px; }
.meter-bar i.over { background: var(--err); }
.facts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin-bottom: 4px; }
.facts b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.facts span { color: var(--muted); font-size: .8rem; }
.btn.wide { width: 100%; }
.btn.ghost { visibility: hidden; }
.daynav { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; }
.daynav .btn { min-width: 48px; }
h2.group { margin: 18px 0 8px; font-size: .95rem; color: var(--muted); font-weight: 600; }
h3.sub { margin: 12px 0 4px; font-size: .95rem; color: var(--muted); font-weight: 600; }
.entry { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.entry form { margin: 0; }
.plain { list-style: none; padding: 0; margin: 0 0 12px; }
.plain .line { border-bottom: 1px solid var(--line); padding: 8px 0; }
details.fold { padding: 0; margin-top: 10px; }
details.fold summary { cursor: pointer; padding: 14px 16px; font-weight: 600; min-height: 48px; list-style: none; }
details.fold summary::-webkit-details-marker { display: none; }
details.fold summary::after { content: "＋"; float: right; color: var(--muted); }
details.fold[open] summary::after { content: "−"; }
details.fold form { padding: 0 16px 16px; }
details.fold > p { padding: 0 16px 16px; margin: 0; }
textarea { width: 100%; padding: 10px 12px; font: inherit; font-size: 1rem; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; resize: vertical; }
textarea:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }

.plan-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.plan-row:last-child { border-bottom: 0; }
.plan-row form { margin: 0; flex: none; }
.weekstrip { display: grid; grid-template-columns: auto repeat(7, 1fr) auto; gap: 4px; align-items: stretch; margin: 0 0 12px; }
.weekstrip .nav-arrow { display: grid; place-items: center; min-width: 28px; color: var(--muted); text-decoration: none; border-radius: 10px; font-size: 1.3rem; }
.weekstrip a.day { display: grid; justify-items: center; gap: 2px; padding: 6px 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--muted); text-decoration: none; font-size: .78rem; }
.weekstrip a.day b { font-size: 1rem; color: var(--text); }
.weekstrip a.day.on { background: var(--lamp); border-color: var(--lamp); color: var(--lamp-ink); }
.weekstrip a.day.on b { color: var(--lamp-ink); }
.weekstrip a.day.today b { text-decoration: underline; }
.weekstrip a.day i { width: 6px; height: 6px; border-radius: 50%; background: var(--lamp); visibility: hidden; }
.weekstrip a.day.on i { background: var(--lamp-ink); }
.weekstrip a.day.has i { visibility: visible; }
.tick { color: var(--ok); font-size: .85rem; }
.entry.done .row-title { text-decoration: line-through; color: var(--muted); }

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