/* HeatLog — тёмный минималистичный интерфейс с неоновыми акцентами режимов */
:root {
  color-scheme: dark;
  --bg: #05070a;
  --surface: #0c1016;
  --surface-2: #141a23;
  --line: #222b37;
  --text: #e9eef5;
  --text-2: #a7b2bf;
  --muted: #6f7b89;
  --std: #2ee6ff;      /* Standard — холодный неон */
  --boost: #ff6b2c;    /* Boost — горячий неон */
  --ok: #3ddc84;
  --warn: #ffc53d;
  --bad: #ff4d5e;
  --radius: 20px;
  --accent: var(--std);
  --bat-color: var(--muted);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(120% 60% at 50% -10%, #0e1a22 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
b { font-weight: 650; }
small, .small { font-size: 13px; }
.muted { color: var(--text-2); }
.empty { color: var(--muted); margin: 6px 0 0; }
:focus-visible { outline: 2px solid var(--std); outline-offset: 2px; }

/* ---------- раскладка ---------- */
.dash, .login {
  max-width: 480px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.top { display: flex; align-items: center; gap: 10px; padding: 6px 0 14px; }
.logo { font-weight: 800; font-size: 20px; letter-spacing: .02em; margin-right: auto; }
.logo span { color: var(--std); text-shadow: 0 0 14px color-mix(in oklab, var(--std) 70%, transparent); }
.logo-big { font-size: 40px; margin: 12vh 0 4px; text-align: center; }
.me-btn { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 4px 4px 12px; cursor: pointer; max-width: 55%; }
.me-btn #meName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; color: var(--text-2); }
.ava { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); font-size: 18px; flex: none; }
.sync-badge { font-size: 12px; color: var(--warn); border: 1px solid color-mix(in oklab, var(--warn) 40%, transparent); border-radius: 999px; padding: 2px 8px; }

.card {
  background: linear-gradient(180deg, color-mix(in oklab, var(--surface) 92%, white 2%), var(--surface));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.card-title { font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-2); margin: 0 0 8px; }
.card-head .card-title { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 .card { margin-bottom: 12px; min-width: 0; }
@media (max-width: 360px) { .grid2 { grid-template-columns: 1fr; gap: 0; } }

.big-num { font-size: 30px; font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; }
.big-num.ago { font-size: 22px; }
.meta-row { display: flex; align-items: center; gap: 8px; margin: 10px 0 6px; flex-wrap: wrap; }
.dur { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.disclaimer { text-align: center; color: var(--muted); font-size: 12px; margin: 18px 0 6px; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px;
  font-weight: 600; cursor: pointer; transition: transform .1s, background .2s, border-color .2s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--std); border-color: var(--std); color: #001a20; box-shadow: 0 0 22px -8px var(--std); }
.btn.danger { background: transparent; border-color: color-mix(in oklab, var(--bad) 55%, transparent); color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.wide { width: 100%; }
.icon-btn { background: transparent; border: 0; width: 40px; height: 40px; border-radius: 12px; cursor: pointer; font-size: 18px; flex: none; }
.icon-btn:hover { background: var(--surface-2); }

.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; }
.seg.wide { display: flex; width: 100%; margin-bottom: 14px; }
.seg button { flex: 1; white-space: nowrap; background: transparent; border: 0; border-radius: 9px; padding: 8px 10px; cursor: pointer; color: var(--text-2); font-weight: 600; }
.seg.small button { padding: 4px 10px; font-size: 13px; }
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: 0 0 0 1px var(--line); }

.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--text-2); position: relative; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle .track { width: 38px; height: 22px; border-radius: 11px; background: var(--line); position: relative; transition: background .2s; flex: none; }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--text-2); transition: transform .2s, background .2s; }
.toggle input:checked + .track { background: color-mix(in oklab, var(--std) 35%, var(--surface-2)); }
.toggle input:checked + .track::after { transform: translateX(16px); background: var(--std); }
.toggle input:focus-visible + .track { outline: 2px solid var(--std); outline-offset: 2px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; font-weight: 600; }
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--std); box-shadow: 0 0 8px var(--std); }
.chip[data-mode="Boost"] i { background: var(--boost); box-shadow: 0 0 8px var(--boost); }
.tag { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--warn); border: 1px solid color-mix(in oklab, var(--warn) 45%, transparent); border-radius: 6px; padding: 2px 6px; }

/* ---------- карточка устройства ---------- */
.device[data-mode="Boost"] { --accent: var(--boost); }
.device[data-bat="ok"] { --bat-color: var(--ok); }
.device[data-bat="mid"] { --bat-color: var(--warn); }
.device[data-bat="low"] { --bat-color: var(--bad); }
.device-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.device-title { min-width: 0; }
.device-name { background: none; border: 0; padding: 0; font-size: 20px; font-weight: 700; cursor: pointer; text-align: left; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.device-name::after { content: " ✎"; font-size: 14px; color: var(--muted); }
.device-sub { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); margin-top: 2px; flex-wrap: wrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.device[data-status="online"] .status-dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.device[data-status="online"] #devStatus { color: var(--ok); }
.device[data-status="connecting"] .status-dot, .device[data-status="reconnecting"] .status-dot { background: var(--warn); animation: blink 1s infinite; }
.battery { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; flex: none; }
.battery-body { width: 30px; height: 15px; border: 2px solid var(--text-2); border-radius: 4px; padding: 1px; position: relative; }
.battery-body::after { content: ""; position: absolute; right: -5px; top: 3px; width: 3px; height: 5px; background: var(--text-2); border-radius: 0 2px 2px 0; }
.battery-fill { display: block; height: 100%; width: 0; background: var(--bat-color); border-radius: 1px; transition: width .6s; }

.ring-wrap { position: relative; width: min(240px, 70vw); aspect-ratio: 1; margin: 14px auto 10px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 10; }
.ring-bar {
  fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 100; stroke-dashoffset: 100;
  transition: stroke-dashoffset .9s linear, stroke .4s;
  filter: drop-shadow(0 0 6px var(--accent));
}
.device[data-phase="idle"] .ring-bar { stroke: var(--bat-color); filter: drop-shadow(0 0 4px var(--bat-color)); }
.device[data-phase="heating"] .ring-bar { animation: glow 1.2s ease-in-out infinite; }
.device[data-phase="ending"] .ring-bar { animation: glow .6s ease-in-out infinite; }
.device[data-status="offline"][data-phase="idle"] .ring-bar { opacity: .45; }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-value { font-size: clamp(36px, 12vw, 50px); font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.device:not([data-phase="idle"]) .ring-value { text-shadow: 0 0 22px color-mix(in oklab, var(--accent) 60%, transparent); }
.ring-label { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--text-2); }

.modes { display: flex; gap: 10px; }
.mode {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg);
  font-weight: 700; cursor: pointer; color: var(--text-2); transition: border-color .2s, box-shadow .2s, color .2s;
}
.mode small { font-weight: 500; color: var(--muted); }
.mode.on { color: var(--text); }
.mode.on[data-mode="Standard"] { border-color: var(--std); box-shadow: inset 0 0 0 1px var(--std), 0 0 22px -8px var(--std); }
.mode.on[data-mode="Boost"] { border-color: var(--boost); box-shadow: inset 0 0 0 1px var(--boost), 0 0 22px -8px var(--boost); }
.mode:disabled { cursor: not-allowed; opacity: .7; }
.hint { color: var(--text-2); font-size: 14px; margin: 12px 0 10px; min-height: 1.4em; }
.device-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.device-actions .btn { flex: 1 1 140px; }

.mock { border-style: dashed; border-color: color-mix(in oklab, var(--warn) 35%, var(--line)); }
.mock-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; }
.field-inline { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-2); }
select, input:not([type="checkbox"]) {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; color: var(--text);
}
input:focus, select:focus { border-color: var(--std); outline: none; box-shadow: 0 0 0 3px color-mix(in oklab, var(--std) 25%, transparent); }

/* ---------- счётчик ---------- */
.today { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.today .of { color: var(--text-2); font-size: 14px; }
.limit { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 10px 0 6px; }
.limit span { display: block; height: 100%; background: var(--std); border-radius: 4px; transition: width .6s; }
.limit.over span { background: var(--warn); }
.warn-text { color: var(--warn); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.split b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.split small { color: var(--text-2); }

/* ---------- график ---------- */
.chart { position: relative; padding-top: 10px; }
.grid-line { position: absolute; top: 10px; left: 0; right: 0; border-top: 1px dashed var(--line); }
.grid-line span { position: absolute; top: -9px; right: 0; font-size: 11px; color: var(--muted); background: var(--surface); padding-left: 4px; line-height: 16px; }
.bars { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; align-items: end; height: 110px; }
.bar { position: relative; height: 100%; display: flex; align-items: flex-end; background: none; border: 0; padding: 0; cursor: pointer; border-radius: 4px 4px 0 0; }
.bar span { display: block; width: 100%; height: max(var(--h), 3px); background: color-mix(in oklab, var(--std) 55%, var(--surface)); border-radius: 4px 4px 0 0; transition: height .5s; }
.bar.zero span { height: 2px; background: var(--line); border-radius: 1px; }
.bar.now span { background: var(--std); box-shadow: 0 0 10px -2px var(--std); }
.bar.now.zero span { background: var(--std); }
.bar:hover span, .bar:focus span { filter: brightness(1.25); }
.bar:hover::after, .bar:focus::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  font-size: 12px; padding: 4px 8px; border-radius: 8px; z-index: 3; pointer-events: none;
}
.bar:nth-child(-n+5)::after { left: 0; transform: none; }
.bar:nth-last-child(-n+5)::after { left: auto; right: 0; transform: none; }
.bar:focus { outline: none; }
.x-axis { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; font-size: 11px; color: var(--muted); margin-top: 6px; }
.x-axis span { text-align: center; }

/* ---------- друзья ---------- */
.friends { list-style: none; margin: 4px 0 0; padding: 0; }
.friend { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.friend:last-child { border-bottom: 0; }
.f-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.f-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.f-main small { color: var(--text-2); }
.hidden-stats .f-main small { color: var(--muted); }
.f-count { text-align: right; display: flex; flex-direction: column; }
.f-count b { font-size: 18px; font-variant-numeric: tabular-nums; }
.f-count small { color: var(--muted); font-size: 11px; }
.req { display: flex; align-items: center; gap: 10px; padding: 10px; margin: 6px 0; border-radius: 14px; background: color-mix(in oklab, var(--std) 8%, var(--surface-2)); border: 1px solid color-mix(in oklab, var(--std) 30%, var(--line)); }
.grow { flex: 1; min-width: 0; }
.add-friend { display: flex; gap: 8px; margin-top: 12px; }
.add-friend .btn { flex: none; }

/* ---------- вход ---------- */
.login .muted { text-align: center; margin-bottom: 20px; }
.login form label, .sheet form label:not(.toggle) { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--text-2); margin-bottom: 12px; }
.login form:not([data-mode="register"]) .reg-only { display: none; }
.form-error { color: var(--bad); font-size: 14px; min-height: 1.2em; margin: 10px 0 0; }

/* ---------- диалоги ---------- */
dialog.sheet {
  width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
}
dialog::backdrop { background: rgba(0, 0, 0, .65); backdrop-filter: blur(4px); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet .toggle { margin: 4px 0 14px; }
.sheet-foot { display: grid; gap: 10px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.steps { padding-left: 20px; color: var(--text-2); font-size: 14px; margin: 0 0 12px; }
.steps li { margin-bottom: 6px; }
.qr-box { position: relative; aspect-ratio: 1; max-width: 300px; margin: 0 auto 12px; border-radius: 16px; overflow: hidden; background: #000; }
.qr-box video { width: 100%; height: 100%; object-fit: cover; }
.qr-frame { position: absolute; inset: 18%; border: 2px solid var(--std); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35), 0 0 18px var(--std); }
.manual { display: flex; gap: 8px; margin: 12px 0; }
.manual .btn { flex: none; }
.qr-result { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); font-size: 14px; margin-bottom: 12px; word-break: break-all; }

/* ---------- уведомление ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  max-width: min(440px, calc(100vw - 32px)); padding: 12px 16px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text); font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5); opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="warn"] { border-color: color-mix(in oklab, var(--warn) 50%, transparent); }
.toast[data-kind="error"] { border-color: color-mix(in oklab, var(--bad) 60%, transparent); }

@keyframes blink { 50% { opacity: .3; } }
@keyframes glow { 50% { filter: drop-shadow(0 0 14px var(--accent)); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
