/* GluMonitor PWA — тёмная тема по макету (docs/05-ui.md) */
:root {
  --bg: #0B0F14; --card: #151B23; --card2: #1C2430; --line: #2C3644; --inset: #10151C;
  --text: #E9EEF4; --text2: #C9D1D9; --muted: #8B97A6; --faint: #6F7B8A;
  --ok: #3DD68C; --ok-t: #7FE3B0; --low: #FF6B6B; --low-t: #FF8A8A; --high: #FFB020; --high-t: #FFC24D;
  --rapid: #5B9BFF; --rapid-t: #8FB6FF; --long: #B197FC; --long-t: #C9B8FF; --food: #FF9F43; --food-t: #FFB877;
  --q: #FFD43B; --link: #8FB6FF;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  --nav-h: 58px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
  overscroll-behavior: none; -webkit-user-select: none; user-select: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; padding: 0; }
a { color: var(--link); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.boot { height: 100vh; display: grid; place-items: center; color: var(--faint); font-weight: 600; letter-spacing: .02em; }

/* ---- Каркас ---- */
.screen { min-height: 100vh; padding: calc(var(--safe-t) + 12px) calc(16px + var(--safe-r)) calc(var(--nav-h) + var(--safe-b) + 24px) calc(16px + var(--safe-l)); max-width: 560px; margin: 0 auto; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--nav-h) + var(--safe-b));
  padding: 6px 12px var(--safe-b); display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(11,15,20,.94); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); border-top: 1px solid rgba(255,255,255,.06);
}
.nav a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); text-decoration: none; font-size: 11px; padding-top: 4px; }
.nav a[aria-current="page"] { color: var(--text); }
.nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.badge { position: absolute; top: -1px; left: 56%; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--q); color: #1A1500; font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.pill { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px; border-radius: 15px; background: var(--card); font-size: 12px; color: #B7C1CD; text-decoration: none; white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.warn { background: var(--high); } .dot.bad { background: var(--low); } .dot.off { background: var(--faint); }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.sync.warn { color: var(--high-t); }
.card { padding: 10px 12px; border-radius: 16px; background: var(--card); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
.muted { color: var(--muted); } .faint { color: var(--faint); }
.small { font-size: 12px; } .tiny { font-size: 11px; }
h1 { font-size: 22px; font-weight: 650; margin: 0; }
h2 { font-size: 13px; font-weight: 600; margin: 22px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---- Главный экран ---- */
.who { font-size: 13px; color: var(--muted); margin-top: 14px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; margin-top: 10px; }
.hero-v { display: flex; align-items: flex-end; gap: 10px; }
.big { font-size: 84px; line-height: .9; font-weight: 600; letter-spacing: -.03em; }
.big.low { color: var(--low-t); } .big.high { color: var(--high-t); } .big.stale { color: var(--faint); }
.arrow { width: 34px; height: 34px; border-radius: 50%; background: var(--card2); display: flex; align-items: center; justify-content: center; }
.arrow svg { width: 18px; height: 18px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.unit { font-size: 13px; color: var(--muted); }
.sub { margin-top: 10px; font-size: 13px; color: var(--muted); }
.tags { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; padding-bottom: 2px; }
.tag { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 13px; background: var(--card); color: var(--text2); font-size: 12px; white-space: nowrap; }
.tag.ok { background: rgba(61,214,140,.12); color: var(--ok-t); font-weight: 500; }
.tag.low { background: rgba(255,107,107,.14); color: var(--low-t); font-weight: 500; }
.tag.high { background: rgba(255,176,32,.14); color: var(--high-t); font-weight: 500; }
.tag.off { color: var(--muted); }
.iob { margin-top: 16px; }
.iob .h { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.iob .v { margin-top: 4px; font-size: 22px; font-weight: 600; }
.iob .v small { font-size: 13px; font-weight: 400; color: var(--muted); }
.iob .s { font-size: 11px; color: var(--muted); }
.toolbar { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 6px; gap: 8px; }
.seg { display: flex; gap: 4px; padding: 3px; border-radius: 12px; background: var(--card); }
.seg button { height: 34px; min-width: 46px; padding: 0 10px; border-radius: 9px; font-size: 13px; font-weight: 500; color: #B7C1CD; }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.btn2 { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 12px; border-radius: 12px; background: var(--card); color: var(--text2); font-size: 13px; }
.btn2 svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.chart-wrap { position: relative; height: 250px; }
.hint { margin-top: 8px; font-size: 11px; line-height: 15px; color: var(--faint); }
.stat .l { font-size: 11px; color: var(--muted); } .stat .v { font-size: 18px; font-weight: 600; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); border-radius: 16px; background: var(--inset); border: 1px dashed var(--line); margin-top: 12px; }

/* ---- График ---- */
.chart { position: relative; overflow: visible; }
.chart > svg { position: absolute; left: 0; top: 0; display: block; overflow: visible; }
.chart > svg.chart-base { overflow: hidden; } /* линия не вылезает за края */
.chart-html { position: absolute; inset: 0; pointer-events: none; }
.chart-touch { position: absolute; inset: 0; touch-action: none; cursor: crosshair; -webkit-touch-callout: none; }
.ylab { position: absolute; right: 2px; font-size: 10px; line-height: 12px; color: #7E8A99; }
.tlab { position: absolute; width: 48px; white-space: nowrap; text-align: center; font-size: 10px; line-height: 14px; color: var(--muted); }
.mk { position: absolute; height: 22px; display: flex; align-items: center; gap: 4px; }
.mk-i { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid; background: var(--bg); display: flex; align-items: center; justify-content: center; flex: none; }
.mk-l { font-size: 10px; font-weight: 600; white-space: nowrap; text-shadow: 0 1px 2px #000; }
.mk.pending .mk-i, .mq.pending span { border-style: dashed; opacity: .75; }
.mq { position: absolute; width: 24px; height: 24px; }
.mq span { position: absolute; inset: 0; border-radius: 50%; background: var(--q); color: #1A1500; font-size: 15px; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 1.5px solid var(--q); }
.mq b { position: absolute; left: 16px; top: -6px; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px; background: var(--text); color: var(--bg); font-size: 9px; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 1.5px solid var(--bg); }
.mq.unread b { background: var(--low); color: #fff; }
.chart-tip { position: absolute; width: 120px; padding: 7px 10px; border-radius: 12px; background: var(--card2); border: 1px solid rgba(255,255,255,.12); box-shadow: 0 8px 24px rgba(0,0,0,.45); pointer-events: none; z-index: 2; }
.tip-t { font-size: 11px; color: var(--muted); } .tip-v { font-size: 20px; font-weight: 600; } .tip-u { font-size: 10px; color: var(--muted); }
.peak { position: absolute; width: 30px; display: flex; flex-direction: column; align-items: center; }
.peak span { font-size: 9px; line-height: 10px; color: var(--rapid-t); }
.peak i { width: 7px; height: 7px; border-radius: 50%; background: var(--rapid); border: 1.5px solid var(--bg); margin-top: 1px; }
.lane-lab { position: absolute; font-size: 9px; letter-spacing: .04em; text-transform: uppercase; }

/* ---- Пузырьки, шторка, тост ---- */
#layer { position: fixed; inset: 0; z-index: 30; pointer-events: none; }
#layer > * { pointer-events: auto; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); animation: fade .15s ease-out; }
.bubbles { position: fixed; inset: 0; }
.bubbles .title { position: absolute; transform: translateX(-50%); height: 26px; padding: 0 12px; border-radius: 13px; background: var(--q); color: #1A1500; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; white-space: nowrap; }
.bub { position: absolute; width: 60px; display: flex; flex-direction: column; align-items: center; gap: 3px; transform: translate(-50%, -50%); animation: pop .18s cubic-bezier(.2,.9,.3,1.3) both; }
.bub button { width: 54px; height: 54px; border-radius: 50%; border: 2px solid; background: var(--card); display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 22px rgba(0,0,0,.55); }
.bub button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bub span { font-size: 11px; font-weight: 500; text-shadow: 0 1px 3px #000; }
.bub .q { font-size: 24px; font-weight: 700; line-height: 1; }
.cancel { position: fixed; left: 16px; right: 16px; bottom: calc(var(--safe-b) + 16px); height: 48px; border-radius: 14px; border: 1px solid rgba(255,255,255,.12) !important; background: var(--card); color: var(--text2); font-size: 15px; max-width: 528px; margin: 0 auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto; max-height: 92vh; overflow: auto;
  padding: 10px calc(20px + var(--safe-r)) calc(var(--safe-b) + 20px) calc(20px + var(--safe-l));
  border-radius: 26px 26px 0 0; background: var(--card); display: flex; flex-direction: column; gap: 16px; animation: up .22s cubic-bezier(.2,.8,.2,1);
}
.grab { align-self: center; width: 40px; height: 5px; border-radius: 3px; background: var(--line); flex: none; }
.sheet .head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.sheet .head b { font-size: 20px; font-weight: 600; }
.switch2 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--bg); }
.switch2 button { height: 44px; border-radius: 11px; font-size: 15px; font-weight: 500; color: #B7C1CD; }
.switch2 button.on-rapid { background: var(--rapid); color: #06101F; }
.switch2 button.on-long { background: var(--long); color: #140A2B; }
.stepper { display: flex; align-items: center; justify-content: space-between; }
.stepper button { width: 56px; height: 56px; border-radius: 50%; background: var(--card2); font-size: 26px; }
.stepper .val { display: flex; align-items: baseline; gap: 6px; }
.stepper .val input { width: 120px; text-align: center; font-size: 52px; font-weight: 600; letter-spacing: -.02em; background: none; border: none; color: var(--text); padding: 0; font-variant-numeric: tabular-nums; }
.stepper .val span { font-size: 16px; color: var(--muted); }
.center { text-align: center; }
textarea, input[type=text], input[type=number] { width: 100%; padding: 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 16px; resize: none; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { height: 50px; border-radius: 15px; font-size: 15px; font-weight: 600; background: var(--text); color: var(--bg); display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text2); font-weight: 500; }
.btn.danger { background: transparent; border: 1px solid rgba(255,107,107,.35); color: var(--low-t); font-weight: 500; }
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }
#toast { position: fixed; z-index: 40; left: 16px; right: 16px; top: calc(var(--safe-t) + 14px); max-width: 528px; margin: 0 auto; padding: 12px 14px; border-radius: 14px; background: var(--text); color: var(--bg); font-size: 14px; font-weight: 500; box-shadow: 0 10px 30px rgba(0,0,0,.5); animation: drop .2s ease-out; }
@keyframes fade { from { opacity: 0 } }
@keyframes up { from { transform: translateY(40px); opacity: 0 } }
@keyframes drop { from { transform: translateY(-12px); opacity: 0 } }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.4); opacity: 0 } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

/* ---- Списки, настройки ---- */
.list { border-radius: 16px; background: var(--card); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 14px; border-top: 1px solid rgba(255,255,255,.05); text-decoration: none; color: inherit; width: 100%; text-align: left; }
.item:first-child { border-top: none; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-size: 15px; } .item .d { font-size: 12px; color: var(--muted); }
.item .r { color: var(--muted); font-size: 14px; white-space: nowrap; }
.chev { width: 8px; height: 14px; fill: none; stroke: var(--faint); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.toggle { position: relative; width: 51px; height: 31px; border-radius: 16px; background: var(--line); flex: none; transition: background .15s; }
.toggle::after { content: ''; position: absolute; left: 2px; top: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle[aria-checked="true"] { background: var(--ok); }
.toggle[aria-checked="true"]::after { transform: translateX(20px); }
.mini-step { display: inline-flex; align-items: center; gap: 6px; }
.mini-step button { width: 32px; height: 32px; border-radius: 10px; background: var(--card2); font-size: 18px; }
.mini-step b { min-width: 44px; text-align: center; font-weight: 600; }
.progress { height: 8px; border-radius: 4px; background: var(--card2); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.progress.warn i { background: var(--high); }
.note { padding: 12px 14px; border-radius: 14px; background: var(--inset); border: 1px solid var(--card2); font-size: 13px; color: var(--text2); line-height: 1.45; }
.note b { color: var(--text); }
.backbar { display: flex; align-items: center; gap: 4px; margin: 0 -8px; }
.back { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; }
.back svg { width: 18px; height: 18px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Обсуждение ---- */
.thread-card { margin-top: 12px; padding: 12px 0 10px; border-radius: 20px; background: var(--inset); border: 1px solid var(--card2); }
.thread-card .hd { display: flex; align-items: center; gap: 8px; padding: 0 12px 10px; }
.qmark { width: 26px; height: 26px; border-radius: 50%; background: var(--q); color: #1A1500; font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.qmark.other { background: var(--card2); color: var(--text2); }
.thread-chart { height: 200px; margin: 0 4px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px 0; }
.chip { height: 26px; padding: 0 10px; border-radius: 13px; font-size: 12px; display: inline-flex; align-items: center; background: var(--card2); color: var(--text2); }
.chip.rapid { background: rgba(91,155,255,.14); color: var(--rapid-t); } .chip.long { background: rgba(177,151,252,.14); color: var(--long-t); }
.chip.food { background: rgba(255,159,67,.14); color: var(--food-t); } .chip.activity { background: rgba(61,214,140,.14); color: var(--ok-t); }
.msgs { display: flex; flex-direction: column; gap: 10px; padding: 16px 0 8px; }
.msg { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }
.msg.mine { align-items: flex-end; }
.msg .b { max-width: 82%; padding: 10px 13px; border-radius: 18px; background: var(--card); font-size: 15px; line-height: 20px; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.msg.mine .b { background: #2A3646; }
.msg .m { font-size: 11px; color: var(--faint); padding: 0 6px; }
.reply { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; padding: 10px calc(12px + var(--safe-r)) calc(var(--safe-b) + 10px) calc(12px + var(--safe-l)); background: var(--bg); border-top: 1px solid rgba(255,255,255,.06); display: flex; gap: 8px; align-items: flex-end; max-width: 560px; margin: 0 auto; }
.reply textarea { border-radius: 22px; padding: 11px 16px; min-height: 44px; max-height: 140px; background: var(--card); }
.send { width: 44px; height: 44px; border-radius: 50%; background: var(--text); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.send svg { width: 18px; height: 18px; fill: none; stroke: var(--bg); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.screen.with-reply { padding-bottom: calc(var(--safe-b) + 90px); }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--low); flex: none; }

/* ---- Вход ---- */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; gap: 18px; padding: calc(var(--safe-t) + 24px) 24px calc(var(--safe-b) + 24px); max-width: 420px; margin: 0 auto; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; }
.code-input { font-size: 28px !important; letter-spacing: .18em; text-align: center; text-transform: uppercase; font-weight: 600; padding: 14px !important; }
.err { color: var(--low-t); font-size: 14px; }

/* ---- Отчёты ---- */
.tirbar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--card2); }
.tirbar i { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.agp { position: relative; }
.agp svg { display: block; width: 100%; height: auto; overflow: visible; }

/* ---- Альбом ---- */
.land { position: fixed; inset: 0; z-index: 15; background: var(--bg); display: flex; flex-direction: column; padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 12px); }
.land .top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.land .now { display: flex; align-items: baseline; gap: 6px; }
.land .now b { font-size: 34px; font-weight: 600; letter-spacing: -.02em; }
.land .layers { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.layer-btn { height: 30px; padding: 0 10px; border-radius: 15px; font-size: 12px; background: var(--card); color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.layer-btn[aria-pressed="true"] { color: var(--text); background: var(--card2); box-shadow: inset 0 0 0 1px var(--line); }
.layer-btn i { width: 14px; height: 0; border-top: 2px solid; display: inline-block; }
.land .plot { flex: 1; position: relative; margin-top: 8px; min-height: 160px; }
.land-close { width: 36px; height: 36px; border-radius: 10px; background: var(--card); display: inline-flex; align-items: center; justify-content: center; }
.land-close svg { width: 14px; height: 14px; stroke: var(--text2); stroke-width: 2; stroke-linecap: round; fill: none; }
@media (orientation: landscape) and (max-height: 520px) {
  .nav { display: none; }
}
.tlab.mid { color: var(--text2); font-weight: 600; }

/* ---- Период ---- */
.period-bar { display: flex; align-items: center; gap: 6px; margin: 14px 0 6px; }
.period-bar .lbl { flex: 1; min-width: 0; height: 40px; padding: 0 10px; border-radius: 12px; background: var(--card); display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 12.5px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.period-bar .lbl span { overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; background: var(--card); display: inline-flex; align-items: center; justify-content: center; flex: none; color: var(--text2); }
.icon-btn:disabled { opacity: .35; }
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-now { height: 40px; padding: 0 10px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 13px; font-weight: 600; flex: none; }
.presets { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
.presets button { height: 44px; border-radius: 12px; background: var(--card2); font-size: 14px; }
.presets button[aria-pressed="true"] { background: var(--text); color: var(--bg); font-weight: 600; }
.dt { width: 100%; padding: 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 16px; min-height: 48px; }
.chart-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; pointer-events: none; }
