/* ============ токены ============ */
:root {
  --bg: #0b1020;
  --panel: #131b31;
  --panel-2: #1a2440;
  --line: #26314f;
  --text: #f2f5fc;
  --muted: #9aa8c7;
  --gray: #7d8aa8;
  --accent: #4f7cff;
  --up: #34d399;
  --down: #fb7185;
  --warn: #fbbf24;
  --font-scale: 1;
  --tabs-h: 58px;
  --radius: 18px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f5fa;
  --panel: #ffffff;
  --panel-2: #eef1f8;
  --line: #dde3ef;
  --text: #0f172a;
  --muted: #55627e;
  --gray: #8a94a8;
  --accent: #2f5bea;
  --up: #059669;
  --down: #e11d48;
  --warn: #b45309;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f3f5fa;
    --panel: #ffffff;
    --panel-2: #eef1f8;
    --line: #dde3ef;
    --text: #0f172a;
    --muted: #55627e;
    --gray: #8a94a8;
    --accent: #2f5bea;
    --up: #059669;
    --down: #e11d48;
    --warn: #b45309;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: calc(16px * var(--font-scale));
  line-height: 1.35;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
body.sheet-open { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: 0.35; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
svg.fillicon { fill: currentColor; stroke: none; }

.view {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 12px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
}
.muted { color: var(--muted); }
.gray { color: var(--gray); }
.up { color: var(--up); }
.down { color: var(--down); }
.warn { color: var(--warn); }
.small { font-size: 0.8em; }
.tiny { font-size: 0.68em; }
.center { text-align: center; }
.pad { padding: 10px 4px; }
.dot { display: inline-block; width: 0.62em; height: 0.62em; border-radius: 50%; margin-right: 0.4em; vertical-align: 0.05em; flex: 0 0 auto; }
.h1 { font-size: 1.6em; margin: 6px 2px 12px; letter-spacing: -0.01em; }
.h2 { font-size: 1.05em; margin: 0 0 10px; }
.hint { color: var(--muted); font-size: 0.85em; text-align: center; margin: 8px 4px 10px; }
.hint.left { text-align: left; margin: 0 0 10px; }
.label { color: var(--muted); font-size: 0.8em; margin: 12px 2px 6px; }

/* ============ таб-бар ============ */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tab {
  position: relative; height: var(--tabs-h); border: 0; background: none; color: var(--gray);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 0.66em;
}
.tab.on { color: var(--text); }
.tab.on svg { stroke-width: 2.4; }
.tab-dot { position: absolute; top: 9px; left: calc(50% + 9px); width: 8px; height: 8px; border-radius: 50%; background: var(--up); box-shadow: 0 0 0 2px var(--bg); }

/* ============ главный экран ============ */
.view-main { padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 10px); }
.main {
  display: flex; flex-direction: column;
  min-height: calc(100dvh - var(--tabs-h) - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 20px);
}
.main-head { display: flex; align-items: center; gap: 8px; }
.day-chip { border: 0; background: var(--panel); border-radius: 999px; padding: 7px 12px; color: var(--muted); font-size: 0.85em; margin-right: auto; }
.day-chip b { color: var(--text); font-variant-numeric: tabular-nums; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--panel); display: inline-grid; place-items: center; color: var(--text); }
.icon-btn.sm { width: 34px; height: 34px; }
.sync-dot { width: 10px; height: 10px; border-radius: 50%; border: 0; padding: 0; background: var(--warn); }
.sync-dot.bad { background: var(--down); }

.clock {
  display: block; width: 100%; border: 0; background: none; padding: 0; margin: 10px 0 2px; position: relative;
  font-size: clamp(54px, 17vw, 104px); font-weight: 600; letter-spacing: -0.02em; line-height: 1.05;
  font-variant-numeric: tabular-nums; text-align: center;
}
.idle .clock { color: var(--gray); font-weight: 300; }
.clock.big { font-size: clamp(60px, 20vw, 110px); }
.clock-hint { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); color: var(--gray); }
.clock-hint svg { width: 18px; height: 18px; }
.now-line { text-align: center; color: var(--muted); font-size: 0.88em; min-height: 1.4em; margin: 2px 0 10px; }
.now-line b { color: var(--text); }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 12px; }
.ctl { height: 52px; border-radius: 16px; border: 0; background: var(--panel-2); display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; }
.ctl-stop { background: color-mix(in srgb, var(--down) 22%, var(--panel)); color: var(--text); }

.grid { display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 8px; }
.main .grid { flex: 1; grid-auto-rows: minmax(62px, 1fr); }
.grid-small { grid-auto-rows: minmax(56px, auto); }
.sb {
  position: relative; overflow: hidden; border: 0; border-radius: var(--radius);
  background: var(--c); color: var(--fg); text-align: left;
  padding: 10px 10px 14px; display: flex; flex-direction: column; justify-content: space-between; gap: 2px;
  min-height: 56px; transition: transform 0.08s ease;
}
.sb:active { transform: scale(0.97); }
.sb-name { font-weight: 700; font-size: 0.92em; line-height: 1.12; overflow-wrap: anywhere; hyphens: auto; }
.sb.long .sb-name { font-size: 0.8em; }
.sb-sub { font-size: 0.75em; opacity: 0.85; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sb-bar { position: absolute; left: 10px; right: 10px; bottom: 7px; height: 4px; border-radius: 4px; background: rgba(0, 0, 0, 0.18); overflow: hidden; }
.sb-bar i { display: block; height: 100%; background: var(--fg); opacity: 0.85; border-radius: 4px; transition: width 0.4s ease; }
.sb.run { box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--c); animation: pulse 1.8s ease-in-out infinite; }
.sb.paused { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--gray); opacity: 0.8; }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px var(--bg), 0 0 0 9px color-mix(in srgb, var(--c) 45%, transparent); } }
body.compact .sb { padding: 7px 8px 11px; min-height: 46px; }
body.compact .main .grid { grid-auto-rows: minmax(48px, 1fr); }
body.compact .card { padding: 10px; }

/* ============ общие элементы ============ */
.card { background: var(--panel); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head .h2 { margin: 0; }
.list { display: flex; flex-direction: column; }
.btn { border: 0; border-radius: 14px; background: var(--panel-2); padding: 0 16px; height: 46px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.small { height: 34px; padding: 0 12px; font-size: 0.85em; border-radius: 11px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger-ghost { background: transparent; color: var(--down); }
.btn.wide { width: 100%; }
.btn.grow, .grow { flex: 1; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.link { border: 0; background: none; color: var(--muted); padding: 2px 4px; font-size: 0.85em; display: inline-flex; align-items: center; gap: 4px; }
.link svg { width: 14px; height: 14px; }
.tag { display: inline-block; font-size: 0.68em; padding: 1px 7px; border-radius: 999px; background: var(--panel-2); color: var(--muted); font-weight: 500; vertical-align: 0.1em; }
.alert { background: color-mix(in srgb, var(--down) 16%, transparent); color: var(--text); border-radius: 12px; padding: 9px 12px; margin: 8px 0; font-size: 0.88em; }

.chips { display: flex; gap: 8px; margin: 0 0 10px; }
.chips.wrap { flex-wrap: wrap; }
.chips.scroll { overflow-x: auto; scrollbar-width: none; margin-left: -12px; margin-right: -12px; padding: 0 12px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 0 13px; height: 36px; font-size: 0.85em; display: inline-flex; align-items: center; white-space: nowrap; }
.chip.big { height: 46px; padding: 0 16px; font-size: 0.95em; font-weight: 600; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip-input { gap: 6px; color: var(--muted); }
.chip-input input { width: 58px; border: 0; background: transparent; outline: none; font-weight: 600; color: var(--text); }

.seg { display: flex; background: var(--panel); border-radius: 13px; padding: 3px; gap: 2px; margin-bottom: 10px; overflow-x: auto; }
.seg > * { flex: 1; border: 0; background: none; border-radius: 10px; height: 36px; padding: 0 8px; font-size: 0.85em; color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 4px; position: relative; }
.seg > .on { background: var(--panel-2); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); }
.seg label input[type="date"] { position: absolute; inset: 0; opacity: 0; }
.seg.mini { display: inline-flex; margin: 0; background: var(--panel-2); }
.seg.mini > * { height: 30px; font-size: 0.78em; flex: 0 0 auto; padding: 0 10px; }
.seg.mini > .on { background: var(--panel); }

input:not([type="checkbox"]):not([type="color"]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 0 12px; height: 46px; outline: none;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

/* ============ добавить ============ */
.phrase { display: flex; gap: 8px; }
.phrase input { height: 52px !important; font-size: 1.02em; border-radius: 16px !important; background: var(--panel) !important; }
.mic { width: 52px; height: 52px; border-radius: 16px; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; flex: 0 0 auto; }
.mic.listening { animation: mic 1s ease-in-out infinite; }
@keyframes mic { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent) 35%, transparent); } }
.phrase-preview { margin: 8px 0 0; }
.pp { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel); border-radius: 14px; padding: 8px 8px 8px 14px; }
.pp-bad { color: var(--muted); font-size: 0.88em; padding: 10px 14px; }
.hist { margin-top: 18px; }
.hist-top { display: flex; align-items: center; justify-content: space-between; }
.day-head { display: flex; align-items: center; gap: 10px; padding: 12px 2px 6px; border-top: 1px solid var(--line); }
.day-head:first-child { border-top: 0; padding-top: 2px; }
.day-head .link { margin-left: auto; }
.row-entry { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px; border: 0; background: none; padding: 9px 2px; text-align: left; width: 100%; }
.re-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.re-when { font-size: 0.78em; font-variant-numeric: tabular-nums; }
.re-dur { font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; }

/* ============ будильник ============ */
.cd-sphere { text-align: center; font-weight: 600; margin-top: 10px; }

/* ============ аналитика ============ */
.an-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 2px 0 12px; }
.an-title { display: flex; flex-direction: column; align-items: center; text-align: center; }
.custom-range { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.summary { text-align: left; }
.sum-main { font-size: 2.1em; font-weight: 700; letter-spacing: -0.02em; }
.sum-sub { margin-top: 2px; }
.pct { font-weight: 700; font-size: 0.9em; }
.pct.up { color: var(--up); }
.pct.down { color: var(--down); }
.chart-title { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-weight: 600; font-size: 0.92em; margin-bottom: 10px; }
.chart-title .seg { margin-left: auto; }

.day-chart { position: relative; }
.dc-area { position: relative; height: 150px; display: flex; align-items: flex-end; gap: 6px; border-bottom: 1px solid var(--line); }
.dc { flex: 1; height: 100%; position: relative; display: flex; align-items: flex-end; justify-content: center; }
.dc .stack { display: flex; flex-direction: column-reverse; width: 100%; max-width: 30px; height: 100%; justify-content: flex-start; }
.dc .stack i { display: block; width: 100%; }
.dc .stack i:last-child { border-radius: 5px 5px 0 0; }
.dc .ghost, .dc .solid { position: absolute; bottom: 0; width: 70%; max-width: 30px; border-radius: 5px 5px 0 0; }
.dc.future { opacity: 0.35; }
.dc-labels { display: flex; gap: 6px; margin-top: 4px; }
.dc-labels span { flex: 1; text-align: center; font-size: 0.7em; color: var(--gray); }
.dc-labels .today { color: var(--text); font-weight: 700; }
.day-chart.dense .dc-area, .day-chart.dense .dc-labels { gap: 2px; }
.avg-line { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--gray); pointer-events: none; }
.avg-line span { position: absolute; right: 0; top: -1.35em; font-size: 0.68em; color: var(--gray); font-style: normal; background: var(--panel); padding: 0 3px; }

.hist-chart { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.hist-chart::-webkit-scrollbar { display: none; }
.hc { flex: 1 0 40px; border: 0; background: none; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.hc-val { font-size: 0.68em; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hc-bar { position: relative; width: 100%; height: 130px; display: flex; justify-content: center; }
.hc-bar i { position: absolute; bottom: 0; width: 70%; max-width: 34px; border-radius: 6px 6px 0 0; }
.hc-bar .ghost { border: 1px dashed; border-bottom: 0; }
.hc-name { font-size: 0.66em; color: var(--muted); white-space: nowrap; }
.hc.sel .hc-name { color: var(--text); font-weight: 700; }

.sort-line { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 8px; }
.an-row { border: 0; background: none; text-align: left; padding: 11px 2px; border-top: 1px solid var(--line); width: 100%; }
.an-row:first-child { border-top: 0; }
.an-row.sel { background: var(--panel-2); border-radius: 12px; padding-left: 8px; padding-right: 8px; }
.an-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.an-name { font-weight: 600; }
.an-nums { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar { position: relative; height: 8px; border-radius: 6px; background: var(--panel-2); margin: 7px 0 5px; overflow: hidden; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; }
.bar .pace { width: 2px; background: var(--text); opacity: 0.6; border-radius: 0; z-index: 2; }
.an-sub { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 0.78em; }

/* ============ настройки ============ */
.table-wrap { overflow-x: auto; margin: 0 -14px; padding: 0 14px; -webkit-overflow-scrolling: touch; }
table.plan { border-collapse: separate; border-spacing: 0; font-size: 0.82em; min-width: 100%; }
table.plan th { color: var(--muted); font-weight: 500; padding: 4px 3px; text-align: center; white-space: nowrap; }
table.plan th.today { color: var(--text); font-weight: 700; }
table.plan td { padding: 3px; text-align: center; white-space: nowrap; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.plan .sticky { position: sticky; left: -14px; background: var(--panel); text-align: left; z-index: 1; padding-left: 0; max-width: 128px; }
table.plan input.cell { width: 46px; height: 34px; padding: 0 2px; text-align: center; border-radius: 8px; font-size: 1em; }
table.plan input.cell.flex::placeholder { color: var(--gray); }
table.plan input.cell::placeholder { color: var(--gray); opacity: 1; }
table.plan input.cell.strong { width: 54px; font-weight: 700; border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
table.plan select.flag { width: 46px; height: 34px; padding: 0 4px; border-radius: 8px; font-weight: 700; text-align: center; }
table.plan .avg { color: var(--gray); }
table.plan .calc { color: var(--muted); font-weight: 600; }
table.plan tr.sys td, table.plan tr.tot td { color: var(--muted); }
table.plan tr.tot td { font-weight: 700; }
table.plan td.bad { color: var(--down) !important; font-weight: 700; }
.link-name { border: 0; background: none; padding: 6px 0; text-align: left; display: inline-flex; align-items: center; max-width: 124px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }

.sp-row { display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--line); padding: 4px 0; }
.sp-row:first-child { border-top: 0; }
.sp-main { flex: 1; display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 8px 0; text-align: left; }
.sp-main .tag { margin-left: auto; }
.swatch { width: 22px; height: 22px; border-radius: 7px; flex: 0 0 auto; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.set-row.col { flex-direction: column; align-items: stretch; }
.set-row select { width: auto; height: 36px; }
.h2 + .set-row, .hint + .set-row { border-top: 0; }
.day-row { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 9px 0; border-top: 1px solid var(--line); text-align: left; width: 100%; }
.day-row span:first-child { flex: 1; }
.day-row svg { width: 16px; height: 16px; color: var(--gray); }
.more summary { color: var(--muted); font-size: 0.88em; padding: 8px 0; cursor: pointer; }
.auth { display: flex; flex-direction: column; gap: 8px; }

/* ============ листы ============ */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 40; animation: fade 0.15s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 640px; margin: 0 auto;
  background: var(--panel); border-radius: 22px 22px 0 0; padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 90dvh; overflow-y: auto; animation: up 0.2s ease;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.sheet-head h3 { margin: 0; font-size: 1.1em; display: flex; align-items: center; }
.sheet .chips.wrap { margin-top: 6px; }
.hm-row { display: flex; gap: 8px; align-items: flex-end; margin: 10px 0; }
.hm-row label { display: flex; align-items: center; gap: 6px; }
.hm-row label > span { color: var(--muted); font-size: 0.85em; white-space: nowrap; }
.hm-row input[type="number"] { width: 70px; text-align: center; font-weight: 700; font-size: 1.1em; }
.hm-row label.grow input { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 5px; margin: 10px 0; }
.field > span { color: var(--muted); font-size: 0.82em; }
.check { display: flex; align-items: center; gap: 10px; margin: 12px 0; font-size: 0.92em; }
.check input { width: 20px; height: 20px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.sw { width: 34px; height: 34px; border-radius: 11px; border: 0; position: relative; }
.sw.on { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--text); }
.sw-custom { overflow: hidden; display: inline-grid; place-items: center; }
.sw-custom::after { content: "+"; color: #fff; font-weight: 700; text-shadow: 0 0 3px rgba(0, 0, 0, 0.6); }
.sw-custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }
.alarm-done { text-align: center; padding: 10px 0; }
.big-emoji { font-size: 56px; }
.alarm-done h3 { margin: 6px 0; font-size: 1.4em; }

/* ============ тост ============ */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px);
  background: var(--text); color: var(--bg); border-radius: 14px; padding: 10px 10px 10px 16px;
  display: flex; align-items: center; gap: 12px; max-width: calc(100% - 24px); width: max-content;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35); font-size: 0.9em; animation: up 0.18s ease;
}
.toast[hidden] { display: none; }
.toast button { border: 0; background: none; color: var(--accent); font-weight: 700; padding: 4px 6px; }
:root[data-theme="dark"] .toast button { color: #2f5bea; }
body.sheet-open .toast { bottom: auto; top: calc(env(safe-area-inset-top) + 12px); }
