:root {
  color-scheme: light;
  --page: #f3f3f3;
  --card: #fbfbfb;
  --card-hover: #f6f6f6;
  --btn-hover: #ececec;
  --btn-press: #e3e3e3;
  --stroke: rgba(0, 0, 0, 0.08);
  --stroke-strong: rgba(0, 0, 0, 0.14);
  --text: #1b1b1b;
  --text-2: #5d5d5d;
  --muted: #8a8a8a;
  --accent: #005fb8;
  --accent-soft: rgba(0, 95, 184, 0.10);
  --on-accent: #fff;
  --iso-top: #eef1f5;
  --iso-left: #dce1e8;
  --iso-right: #c4cbd5;
  --iso-dark-top: #5b6370;
  --iso-dark-left: #454c58;
  --iso-dark-right: #373d47;
  --iso-shadow: rgba(30, 40, 60, 0.08);
  --ill-screen: #1b1f25;
  --ill-screen-1: #5aa9f7;
  --ill-screen-2: #1f63c6;
  --ill-line: #7c8592;
  --grid: #e6e6e6;
  --axis: #c8c8c8;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #0f7b0f;
  --good-mark: #0ca30c;
  --warning: #9d5d00;
  --warning-mark: #fab219;
  --serious-mark: #ec835a;
  --critical: #c42b1c;
  --critical-mark: #d03b3b;
  --track: #e5e5e5;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.04);
  --radius: 10px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #1c1c1c;
    --card: #272727;
    --card-hover: #2d2d2d;
    --btn-hover: #383838;
    --btn-press: #262626;
    --stroke: rgba(255, 255, 255, 0.07);
    --stroke-strong: rgba(255, 255, 255, 0.12);
    --text: #f3f3f3;
    --text-2: #c5c5c5;
    --muted: #9a9a9a;
    --accent: #60cdff;
    --accent-soft: rgba(96, 205, 255, 0.12);
    --on-accent: #000;
    --iso-top: #646c79;
    --iso-left: #4f5663;
    --iso-right: #414752;
    --iso-dark-top: #383d45;
    --iso-dark-left: #2e3238;
    --iso-dark-right: #24272c;
    --iso-shadow: rgba(0, 0, 0, 0.3);
    --ill-screen: #111316;
    --ill-screen-1: #5aa9f7;
    --ill-screen-2: #1f63c6;
    --ill-line: #9aa3af;
    --grid: #333333;
    --axis: #444444;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #6ccb5f;
    --warning: #fce100;
    --critical: #ff99a4;
    --track: #3a3a3a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #1c1c1c;
  --card: #272727;
  --card-hover: #2d2d2d;
  --btn-hover: #383838;
  --btn-press: #262626;
  --stroke: rgba(255, 255, 255, 0.07);
  --stroke-strong: rgba(255, 255, 255, 0.12);
  --text: #f3f3f3;
  --text-2: #c5c5c5;
  --muted: #9a9a9a;
  --accent: #60cdff;
  --accent-soft: rgba(96, 205, 255, 0.12);
  --on-accent: #000;
  --iso-top: #646c79;
  --iso-left: #4f5663;
  --iso-right: #414752;
  --iso-dark-top: #383d45;
  --iso-dark-left: #2e3238;
  --iso-dark-right: #24272c;
  --iso-shadow: rgba(0, 0, 0, 0.3);
  --ill-screen: #111316;
  --ill-screen-1: #5aa9f7;
  --ill-screen-2: #1f63c6;
  --ill-line: #9aa3af;
  --grid: #333333;
  --axis: #444444;
  --series-1: #3987e5;
  --series-2: #d95926;
  --good: #6ccb5f;
  --warning: #fce100;
  --critical: #ff99a4;
  --track: #3a3a3a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body.embedded { background: transparent; }

/* thin Fluent-style scrollbars (Chromium / WebView2) */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--axis); border-radius: 6px; border: 4px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); border-width: 3px; background-clip: content-box; }
::-webkit-scrollbar-button { display: none; }

button, input, select { font: inherit; color: inherit; }

/* column width and side gutters, shared by the page column and the full-width top bar */
:root { --gutter: 24px; --app-max: 1180px; }

.app {
  max-width: var(--app-max);
  margin: 0 auto;
  padding: 6px var(--gutter) 40px;
}

/* ---------- top bar ---------- */
/* Stays on screen while scrolling; spans the side gutters so cards scroll cleanly underneath. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--page);
  transition: box-shadow 0.2s;
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: var(--app-max);
  min-height: 56px;
  margin: 0 auto;
  padding: 4px var(--gutter);
}

/* Inside the Windows app this bar is the window title bar (WebView2 non-client region support). */
.in-app .topbar { app-region: drag; -webkit-app-region: drag; user-select: none; }
/* Windows app: the title bar stays put and only the content under it scrolls, so the scrollbar
   starts below the bar instead of running up to the window buttons (browsers keep page scrolling) */
html.in-app, html.in-app body { height: 100%; overflow: hidden; }
html.in-app body { display: flex; flex-direction: column; }
.in-app .topbar { position: relative; flex: none; }
.in-app .page-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.page-scroll:focus { outline: none; }
.in-app .topbar button, .in-app .topbar a { app-region: no-drag; -webkit-app-region: no-drag; }
/* keep the right-hand icons clear of the window buttons when the column reaches the window edge */
/* tall title bar (like Windows 11 apps): 48 px, window buttons the full height, icons centred with them */
.in-app .topbar-inner { min-height: 48px; padding-top: 0; padding-bottom: 0; }
.in-app .topbar-inner { padding-right: max(var(--gutter), calc(150px - max(0px, (100vw - var(--app-max)) / 2))); }
.win-controls { position: absolute; top: 0; right: 0; display: flex; }
.win-btn {
  width: 46px; height: 48px; border: 0; padding: 0; background: transparent; color: var(--text);
  font: 10px "Segoe Fluent Icons", "Segoe MDL2 Assets"; cursor: default;
}
.win-btn:hover { background: var(--card-hover); }
.win-btn:active { background: var(--stroke-strong); }
.win-btn.close:hover { background: #c42b1c; color: #fff; }
.win-btn.close:active { background: #c42b1cd0; color: #fff; }
.win-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.topbar.stuck { box-shadow: 0 1px 0 var(--stroke-strong), 0 6px 16px rgba(0, 0, 0, 0.08); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { flex: none; }
.brand h1 { font: 600 20px/1.2 var(--font-display); margin: 0; }
.brand .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* one line: "UPSmart   DEXP CEE-E 1500VA"; stacked again on phones (see responsive) */
.brand-text { display: flex; align-items: baseline; gap: 18px; min-width: 0; }
.topbar .spacer { flex: 1; }
.live {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-2); font-size: 12px; white-space: nowrap;
}
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on .dot { background: var(--good-mark); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good-mark) 25%, transparent); }
.live.on[data-tone="warning"] .dot { background: var(--warning-mark); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning-mark) 30%, transparent); }
.live.on[data-tone="critical"] .dot { background: var(--critical-mark); box-shadow: 0 0 0 3px color-mix(in srgb, var(--critical-mark) 30%, transparent); }
.live .dot { flex: none; transition: background 0.3s, box-shadow 0.3s; }
/* a message replaces the label for a few seconds; long ones are cut, the full text is in the tooltip */
.live .label { overflow: hidden; text-overflow: ellipsis; max-width: min(46vw, 620px); }
.live.msg .label { color: var(--text); }
.live.msg.error .label { color: var(--critical); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--text-2);
}
.icon-btn:hover { background: var(--card-hover); border-color: var(--stroke); }
.icon-btn:focus-visible, .seg button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  min-width: 0;
}
.card-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
  margin: 0 0 8px;
}
.card-title .title-note { font-weight: 400; color: var(--muted); }
.card-title .hint { margin-left: auto; font-weight: 400; color: var(--muted); font-size: 12px; }
/* period picker that looks like the hint: the text plus a small chevron */
.hint-pick { position: relative; display: inline-flex; align-items: center; }
.hint-pick select {
  appearance: none; -webkit-appearance: none; border: 0; background: transparent; color: inherit; font: inherit;
  cursor: pointer; padding: 3px 20px 3px 6px; margin: -3px -4px -3px 0; border-radius: 6px;
}
.hint-pick:hover { color: var(--text); }
.hint-pick select:hover { background: var(--btn-hover); }
.hint-pick select:active { background: var(--btn-press); }
.hint-pick select option { color: var(--text); background: var(--card); }
.hint-pick::after {
  content: ''; position: absolute; right: 4px; top: 50%; width: 5px; height: 5px; margin-top: -4.5px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); pointer-events: none;
}

/* ---------- status banner ---------- */
.banner {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; margin-bottom: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--stroke);
  background: var(--card);
  box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.banner::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--state-mark, var(--muted));
}
.banner .state-icon {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--state-mark, var(--muted)) 16%, transparent);
  color: var(--state-ink, var(--text-2));
}
.banner .state-title { font: 600 17px/1.25 var(--font-display); }
.banner .state-sub { color: var(--text-2); font-size: 13px; }
.banner .state-right { margin-left: auto; text-align: right; color: var(--text-2); font-size: 13px; }
.banner[data-state="online"] { --state-mark: var(--good-mark); --state-ink: var(--good); }
.banner[data-state="battery"] { --state-mark: var(--warning-mark); --state-ink: var(--warning); }
.banner[data-state="lowBattery"], .banner[data-state="fault"], .banner[data-state="stale"] { --state-mark: var(--critical-mark); --state-ink: var(--critical); }
.banner[data-state="offline"] { --state-mark: var(--muted); --state-ink: var(--text-2); }
.banner[data-state="battery"] .state-icon, .banner[data-state="lowBattery"] .state-icon { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
@media (prefers-reduced-motion: reduce) { .banner .state-icon { animation: none !important; } }

/* ---------- power flow diagram ---------- */
.flow-card { margin-bottom: 12px; }
.flow { width: 100%; }
.flow-svg { display: block; width: 100%; height: auto; font-family: var(--font); overflow: visible; }
/* the wide scene starts level with the card title: the bypass box sits in the empty middle of that row */
.flow-svg.wide { max-width: 1100px; margin: -24px auto 0; }
.flow-svg.compact { max-width: 420px; margin: 0 auto; }

/* thin rounded lines; the flow is short thin strokes gliding along them */
.flow-line { fill: none; stroke: color-mix(in srgb, var(--track) 78%, var(--muted)); stroke-width: 2; stroke-linecap: round; transition: stroke 0.4s; }
.flow-line.mains { stroke: color-mix(in srgb, var(--series-1) 45%, var(--track)); }
.flow-line.battery { stroke: color-mix(in srgb, var(--warning-mark) 50%, var(--track)); }
.flow-dots {
  fill: none; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 16 44;
  opacity: 0; transition: opacity 0.4s;
}
.flow-dots.on { opacity: 1; animation: flow-dots var(--flow-dur, 2.2s) linear infinite; }
.flow-dots.mains { stroke: var(--series-1); }
.flow-dots.battery { stroke: var(--warning-mark); }
@keyframes flow-dots { to { stroke-dashoffset: -60; } }
.flow-joint { fill: var(--track); transition: fill 0.4s; }
.flow-joint.on { fill: var(--series-1); }
.flow-joint.on.battery { fill: var(--warning-mark); }

.flow-label { fill: var(--muted); font-size: 13px; }
.flow-value { fill: var(--text); font-size: 20px; font-weight: 600; font-family: var(--font-display); }
.flow-sub { fill: var(--text-2); font-size: 13px; }
.flow-svg.compact .flow-label, .flow-svg.compact .flow-sub { font-size: 12px; }
.flow-svg.compact .flow-value { font-size: 17px; }
.flow-temp-icon path { fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.flow-node.dead .ill { opacity: 0.4; }
.flow-node.dead .flow-sub { fill: var(--critical); }

/* isometric devices: three shaded faces; the stroke in the face colour softens the edges */
.iso-t, .iso-l, .iso-r { stroke-width: 0.8; stroke-linejoin: round; }
.iso-t { fill: var(--iso-top); stroke: var(--iso-top); }
.iso-l { fill: var(--iso-left); stroke: var(--iso-left); }
.iso-r { fill: var(--iso-right); stroke: var(--iso-right); }
.iso-t.dark { fill: var(--iso-dark-top); stroke: var(--iso-dark-top); }
.iso-l.dark { fill: var(--iso-dark-left); stroke: var(--iso-dark-left); }
.iso-r.dark { fill: var(--iso-dark-right); stroke: var(--iso-dark-right); }
.iso-t.pole { fill: #d4d9e0; stroke: #d4d9e0; }
.iso-l.pole { fill: #b3bac4; stroke: #b3bac4; }
.iso-r.pole { fill: #9aa2ad; stroke: #9aa2ad; }
.iso-t.pole.plus { fill: #e8776a; stroke: #e8776a; }
.iso-l.pole.plus { fill: #cc5b4f; stroke: #cc5b4f; }
.iso-r.pole.plus { fill: #ad4a40; stroke: #ad4a40; }
.iso-shadow { fill: var(--iso-shadow); }
.iso-slot, .iso-panel { fill: var(--iso-dark-left); }
.iso-display { fill: var(--ill-screen); transition: fill 0.4s; }
.flow-dev.on.battery .iso-display { fill: var(--warning-mark); }
.iso-icon path { fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: stroke 0.4s; }
.flow-dev.on .iso-icon path { stroke: var(--series-1); }
.flow-dev.on.battery .iso-icon path { stroke: var(--warning-mark); }

.ill-screen { fill: var(--ill-screen); transition: fill 0.4s; }
.ill-screen.on { fill: url(#flow-screen-on); }
.flow-svg .stop-1 { stop-color: var(--ill-screen-1); }
.flow-svg .stop-2 { stop-color: var(--ill-screen-2); }
.ill-screen-content { opacity: 0; fill: rgba(255, 255, 255, 0.85); transition: opacity 0.4s; }
.ill-screen-content.on { opacity: 1; }
.ill-chart { fill: none; stroke: rgba(255, 255, 255, 0.9); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ill-led { fill: var(--iso-right); transition: fill 0.4s; }
.ill-led.green { fill: var(--good-mark); }
.flow-dev.on .ill-led { fill: var(--series-1); }
.flow-dev.on.battery .ill-led { fill: var(--warning-mark); }
/* charge: flat battery icon around the percentage under «Батарея» */
.bat-body { fill: none; stroke: var(--text); stroke-width: 1.5; }
.bat-nub { fill: var(--text); }
.bat-fill { fill: var(--good-mark); fill-opacity: 0.35; }
.bat-fill[data-level="warning"] { fill: var(--warning-mark); }
.bat-fill[data-level="critical"] { fill: var(--critical-mark); }
.bat-fill.charging { animation: bat-charge 2.4s ease-in-out infinite; }
@keyframes bat-charge { 50% { fill-opacity: 0.6; } }
.ill-pylon { fill: none; stroke: var(--ill-line); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ill-pylon.back { opacity: 0.45; }
.ill-insulator { fill: none; stroke: var(--ill-line); stroke-width: 2.6; stroke-linecap: round; }
.ill-wire { fill: none; stroke: url(#flow-wire-fade); stroke-width: 1.2; }
.flow-svg .wire-stop-1 { stop-color: var(--ill-line); stop-opacity: 0.8; }
.flow-svg .wire-stop-2 { stop-color: var(--ill-line); stop-opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .flow-dots.on, .bat-fill.charging { animation: none; }
}

/* ---------- top grid ---------- */
.grid-top {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));   /* halves, like the tiles below */
  grid-template-rows: auto auto 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
/* the power and battery cards share the rows (title / value / chart), so side by side their parts line up */
.grid-top > .spark-card { display: grid; grid-row: span 3; grid-template-rows: subgrid; row-gap: 0; }
.hero-value {
  font: 600 56px/1 var(--font-display);
  letter-spacing: -0.02em;
  display: flex; align-items: baseline; gap: 8px;
}
.hero-value { font-variant-numeric: tabular-nums; }
/* the number always takes at least three digits of room (digits are equally wide), so what stands to the right of
   it — the load and charge bars — does not move when the value changes */
.hero-value > span:first-child { min-width: 3ch; text-align: right; }
.hero-value .unit { font-size: 22px; font-weight: 500; color: var(--text-2); letter-spacing: 0; }
.hero-row { display: flex; align-items: flex-end; gap: 16px; }
/* power and battery cards: the value with its bar(s) on top, the live chart below across the card, taking the
   height the card has left (cards in one row are equally high) */
.spark-card { display: flex; flex-direction: column; }
.spark-card .hero-row { display: flex; align-items: center; gap: 24px; }
.spark-card .hero-side { flex: 1 1 auto; min-width: 0; }
.spark-card .hero-side .meter { margin-top: 0; }
.spark-card .hero-side .kv { margin-top: 8px; }
.spark-card .card-chart { flex: 1 1 auto; margin-top: 12px; }
/* voltage card: input, output and frequency side by side, each with its legend key above the number */
.voltage-card { margin-bottom: 12px; }
.volt-row { gap: 48px; }
.volt-val { display: flex; flex-direction: column; gap: 4px; }
.volt-key { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.volt-key .swatch { width: 14px; height: 2px; border-radius: 1px; }
/* a chart that fills its box must not size it (the svg would feed its height back) */
.chart-fill svg { position: absolute; inset: 0; }
/* the charge chart takes the colour of the charge bar */
.battery-card:has(#soc-meter[data-level="warning"]) { --spark-color: var(--warning-mark); }
.battery-card:has(#soc-meter[data-level="critical"]) { --spark-color: var(--critical-mark); }

.meter { margin-top: 14px; }
.meter-track {
  position: relative; height: 22px; border-radius: 11px; background: var(--track); overflow: hidden;
}
.meter-fill {
  position: absolute; left: 0; top: 0; height: 100%; border-radius: 11px; background: var(--series-1);
  width: 0; transition: width 0.6s ease, background-color 0.3s;
}
/* caption inside the bar: dark over the track, white over the fill (a clipped copy that follows --pct) */
.meter-label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; pointer-events: none;
}
.meter-label.on-fill { color: #fff; clip-path: inset(0 calc(100% - var(--pct, 0%)) 0 0); transition: clip-path 0.6s ease; }
.meter-track[data-level="warning"] .meter-label.on-fill { color: #1b1b1b; }
.meter-fill[data-level="warning"] { background: var(--warning-mark); }
.meter-fill[data-level="critical"] { background: var(--critical-mark); }
.meter-fill[data-level="good"] { background: var(--good-mark); }
.meter-scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 4px; font-variant-numeric: tabular-nums; }

.battery-note { color: var(--text-2); font-size: 12px; margin-top: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin-top: 12px; color: var(--text-2); }
.kv b { color: var(--text); font-weight: 600; text-align: right; white-space: nowrap; }

/* ---------- stat tiles ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.tile .label { color: var(--text-2); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.tile .value { font: 600 26px/1.15 var(--font-display); margin-top: 6px; white-space: nowrap; }
.tile .value .unit { font-size: 14px; font-weight: 500; color: var(--text-2); margin-left: 3px; }
.tile .foot { color: var(--muted); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile svg { color: var(--muted); }

/* ---------- UPS controls (top bar) ---------- */
.icon-btn.off { opacity: 0.45; }
.icon-btn.off:hover { background: transparent; border-color: transparent; }
.icon-btn.active { color: var(--warning-mark); background: color-mix(in srgb, var(--warning-mark) 14%, transparent); animation: ctl-pulse 1.6s ease-in-out infinite; }
@keyframes ctl-pulse { 50% { background: color-mix(in srgb, var(--warning-mark) 28%, transparent); } }
@media (prefers-reduced-motion: reduce) { .icon-btn.active { animation: none; } }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- section / filters ---------- */
.section-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 8px 0 12px;
}
.section-head h2 { font: 600 16px/1.2 var(--font-display); margin: 0; }
.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--card); border: 1px solid var(--stroke); border-radius: 8px;
}
.seg button {
  border: 0; background: transparent; padding: 4px 12px; border-radius: 6px; cursor: pointer;
  color: var(--text-2); font-size: 13px;
}
.seg button:hover { background: var(--card-hover); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.charts .wide { grid-column: 1 / -1; }
.chart-box { position: relative; transition: opacity 0.2s; }
.chart-box.loading { opacity: 0.5; }
.chart-box svg { display: block; width: 100%; overflow: visible; }
.chart-empty { color: var(--muted); font-size: 13px; padding: 40px 0; text-align: center; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin: -2px 0 6px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 14px; height: 2px; border-radius: 1px; }
.legend .swatch.rect { width: 10px; height: 10px; border-radius: 2px; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--card); border: 1px solid var(--stroke-strong); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
  padding: 8px 10px; font-size: 12px; min-width: 120px;
  opacity: 0; transition: opacity 0.1s;
}
.tooltip.show { opacity: 1; }
.tooltip .t-head { color: var(--muted); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; }
.tooltip .t-row .k { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tooltip .t-row b { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.tooltip .t-row span { color: var(--text-2); }

.link-btn {
  border: 0; background: none; padding: 2px 0; color: var(--accent); cursor: pointer; font-size: 12px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.table-toggle, #journal-open { margin-top: 6px; }
.data-table { max-height: 220px; overflow: auto; margin-top: 6px; border-top: 1px solid var(--stroke); }
.data-table table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--stroke); }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--card); }

/* ---------- journal ---------- */
/* "15.11.2026 1:13:10:  ⓘ  text" — the time column is shared by all rows (subgrid) so icons line up */
.events {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: max-content 16px minmax(0, 1fr); column-gap: 10px;
}
.events li {
  /* position: relative keeps the absolutely positioned .ev-sev inside the scroll box;
     without it those labels escape to the dialog/page and stretch it by thousands of px */
  position: relative;
  display: grid; grid-template-columns: subgrid; grid-column: 1 / -1; align-items: start;
  padding: 4px 0; line-height: 1.45; border-bottom: 1px solid var(--stroke);   /* same spacing as the data tables */
}
.events li:last-child { border-bottom: 0; }
.events .ev-time { color: var(--text-2); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; padding-top: 1px; }
.events .ev-icon { margin-top: 2px; }
.events .ev-icon svg { display: block; }   /* no baseline gap under the icon: it must not make the row taller */
.events .ev-empty { grid-column: 1 / -1; color: var(--muted); padding: 12px 0; }

/* height is set from JS to exactly the first 10 rows; everything else scrolls */
.journal-box {
  max-height: 400px; overflow: auto;
  border: 1px solid var(--stroke); border-radius: 8px; background: transparent; padding: 0 14px;
}

.journal-dlg { width: min(980px, calc(100vw - 32px)); height: min(82vh, 920px); overflow: hidden; }
.journal-dlg[open] { display: flex; flex-direction: column; }
/* title | count in the middle of the dialog | close; equal side columns keep the count truly centred */
.journal-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 12px; border-bottom: 1px solid var(--stroke);
}
.journal-head h3 { margin: 0 0 0 10px; font: 600 18px/1.3 var(--font-display); }
.journal-head .hint { color: var(--muted); font-size: 13px; white-space: nowrap; }
.journal-head .icon-btn { justify-self: end; }
/* min-height: 0 lets the list shrink inside the flex column, so only the list scrolls (not the dialog) */
.journal-full { flex: 1; min-height: 0; overflow: auto; padding: 4px 22px 12px; }
/* «Удалённый доступ» tab: the error line sits in the pane and appears only when there is one */
#rs-error { padding: 8px 0 0; }
#rs-error:empty { display: none; }
.journal-foot { flex: none; padding: 10px 22px 12px; border-top: 1px solid var(--stroke); }
.events li[data-sev="info"] .ev-icon { color: var(--muted); }
.events li[data-sev="warning"] .ev-icon { color: var(--warning-mark); }
.events li[data-sev="critical"] .ev-icon { color: var(--critical-mark); }
.events .ev-sev { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.footer { color: var(--muted); font-size: 12px; margin-top: 18px; display: flex; gap: 16px; flex-wrap: wrap; }
.footer code { font-size: 11px; }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--stroke-strong); border-radius: 12px; padding: 0;
  background: var(--card); color: var(--text); width: min(460px, calc(100vw - 32px));
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog.wide { width: min(660px, calc(100vw - 32px)); }
.lines { line-height: 1.6; }
.dlg-body { padding: 20px 22px 8px; }
.dlg-body h3, .dlg-head h3 { margin: 0 0 4px; font: 600 18px/1.3 var(--font-display); }
/* Dialogs with a fixed header (title + ✕) and footer: only .dlg-body scrolls.
   min-height: 0 lets the body shrink inside the flex column instead of the whole dialog scrolling. */
.panel-dlg { overflow: hidden; }
/* page behind an open dialog: no scrolling, no scrollbar (padding keeps the width), see syncModal() */
html.modal-open { overflow: hidden; padding-right: var(--scrollbar-gap, 0px); }
.dlg-body, .journal-full { overscroll-behavior: contain; }
.panel-dlg[open] { display: flex; flex-direction: column; }
.panel-dlg > form { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.dlg-head {
  display: flex; align-items: center; gap: 12px; flex: none;
  padding: 12px 12px 12px 22px; border-bottom: 1px solid var(--stroke);
}
.dlg-head h3 { margin: 0; }
.dlg-head .icon-btn { margin-left: auto; }
.panel-dlg .dlg-body { flex: 0 1 auto; min-height: 0; max-height: none; overflow: auto; padding-top: 14px; }
.panel-dlg .dlg-error, .panel-dlg .dlg-actions { flex: none; }
.panel-dlg .dlg-actions { border-top: 1px solid var(--stroke); padding-top: 14px; }
.dlg-body p { margin: 0 0 10px; color: var(--text-2); font-size: 13px; }
/* compact rows: 30 px fields, 4 px apart */
/* number fields: room for 4–5 characters plus the ▲▼ on the left */
/* every row as high as a field, so rows with a switch are spaced like the rest */
.field { display: grid; grid-template-columns: 1fr 88px; align-items: center; gap: 10px; margin-bottom: 4px; min-height: 30px; }
.field label { color: var(--text-2); }
.field input {
  width: 100%; padding: 4px 10px; border-radius: 6px; border: 1px solid var(--stroke-strong);
  background: var(--page); text-align: right;
}
/* no native ▲▼ spinners: Chromium keeps their room even while hidden, leaving a gap right of the number.
   app.js puts small ▲▼ into the empty left part of the field instead (.num-steps). */
.field .num input { padding-left: 26px; }   /* room for the ▲▼ on the left */
.num { position: relative; display: block; min-width: 0; }
.num-steps {
  position: absolute; left: 3px; top: 3px; bottom: 3px; width: 18px;
  display: flex; flex-direction: column; gap: 1px; opacity: 0; transition: opacity .15s;
}
.field:hover .num-steps, .num:focus-within .num-steps { opacity: 1; }
.num:has(input:disabled) .num-steps { display: none; }
.num-steps button {
  flex: 1; min-height: 0; display: grid; place-items: center; padding: 0; border: 0; border-radius: 3px;
  background: transparent; color: var(--text-2); cursor: pointer;
}
.num-steps button:hover { background: var(--btn-hover); color: var(--text); }
.num-steps button:active { background: var(--btn-press); }
.num-steps svg path { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
/* focus as in Windows 11: thin neutral frame, a straight 2 px accent line along the bottom, clipped by the rounding */
.field input:focus, .field select:focus {
  outline: none; box-shadow: none; border-bottom-color: transparent;
  background-image: linear-gradient(var(--accent), var(--accent));
  background-origin: border-box; background-position: 0 100%; background-size: 100% 2px; background-repeat: no-repeat;
}
/* settings: section tabs on the left, the chosen section on the right; the dialog keeps its size between tabs */
#settings { width: min(760px, calc(100vw - 32px)); }
.field:has(#f-name) { grid-template-columns: 1fr 220px; }   /* the model name is longer than the numbers */
/* drop-downs are as wide as their longest option, no empty tail */
.field:has(select) { grid-template-columns: 1fr auto; }
#settings[open] { height: min(600px, calc(100vh - 32px)); }
.settings-split { flex: 1 1 auto; min-height: 0; display: flex; }
.settings-nav {
  flex: none; min-width: 180px; display: flex; flex-direction: column; gap: 2px;
  padding: 10px 8px; border-right: 1px solid var(--stroke);
}
/* tab names on one line: the column grows to the longest one (e.g. «Удалённый доступ» in Kazakh) */
.settings-nav [role="tab"] {
  position: relative; display: flex; align-items: center; gap: 10px; width: 100%; white-space: nowrap;
  padding: 8px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--text);
  text-align: left; cursor: pointer;
}
.settings-nav [role="tab"] svg { flex: none; color: var(--text-2); }
.settings-nav [role="tab"]:hover { background: var(--btn-hover); }
.settings-nav [role="tab"]:active { background: var(--btn-press); }
.settings-nav [role="tab"][aria-selected="true"] { background: var(--btn-hover); font-weight: 600; }
.settings-nav [role="tab"][aria-selected="true"] svg { color: var(--accent); }
/* the accent pill of the chosen tab, as in Windows Settings */
.settings-nav [role="tab"][aria-selected="true"]::before {
  content: ''; position: absolute; left: 0; top: 50%; width: 3px; height: 16px; margin-top: -8px;
  border-radius: 2px; background: var(--accent);
}
.settings-nav [role="tab"]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#settings .settings-pane { flex: 1 1 auto; min-width: 0; overflow: auto; }
.settings-pane > .dlg-section:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.settings-readonly { padding: 0 22px; }
/* ⓘ next to a heading: the hint pops up on hover or keyboard focus, one sentence per line */
.info { position: relative; display: inline-flex; vertical-align: -3px; margin-left: 4px; color: var(--muted); cursor: help; border-radius: 50%; }
.info:hover, .info:focus-visible { color: var(--accent); }
.info:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.info-tip {
  position: fixed; left: 0; top: 0; z-index: 5; display: none;   /* placed by app.js, so the dialog never clips it */
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--stroke-strong); background: var(--card);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); color: var(--text); font: 400 13px/1.6 var(--font); white-space: nowrap;
}
.info:hover .info-tip, .info:focus-visible .info-tip { display: block; }
/* ⓘ beside a field's label: outside the <label>, so a click does not toggle the switch */
.label-info { display: inline-flex; align-items: center; gap: 2px; min-width: 0; }
.dlg-section { margin: 12px 0 6px; font: 600 14px/1.3 var(--font-display); padding-top: 12px; border-top: 1px solid var(--stroke); }
.dlg-note { color: var(--text-2); font-size: 13px; margin: 8px 0 0 !important; }
/* battery configuration that does not match what the UPS measures */
.pack-warn {
  display: flex; align-items: flex-start; gap: 12px; margin: 6px 0 4px; padding: 8px 12px; border-radius: 8px;
  background: color-mix(in srgb, var(--warning-mark) 14%, transparent); color: var(--text); font-size: 13px; line-height: 1.6;
}
.pack-warn span { flex: 1; }
.pack-warn .link-btn { flex: none; }
/* Toggle switch: the native checkbox restyled, so labels, keyboard (Space) and forms work as before */
.field.check input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; position: relative; flex: none;
  width: 40px; height: 20px; margin: 0; padding: 0; justify-self: end; cursor: pointer;
  border: 1px solid var(--text-2); border-radius: 10px; background: transparent; box-shadow: none;
  transition: background-color .15s, border-color .15s;
}
.field.check input[type="checkbox"]::before {
  content: ""; position: absolute; top: 50%; left: 4px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--text-2); transform: translateY(-50%);
  transition: left .15s, width .1s, height .1s, background-color .15s;
}
.field.check input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.field.check input[type="checkbox"]:checked::before { left: 22px; background: var(--on-accent); }
:root.kbd-nav .field.check input[type="checkbox"]:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }   /* keyboard only */
.field.check input[type="checkbox"]:disabled { opacity: .45; cursor: default; }
.field.check label { cursor: pointer; }
/* inactive options (e.g. auto-shutdown switched off): the whole row fades */
.field:has(:is(input, select):disabled) label { color: var(--muted); cursor: default; }
.field input:disabled, .field select:disabled { opacity: 0.5; cursor: default; }
.field select {
  width: auto; min-width: 88px; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--stroke-strong); background: var(--page);
}
.dlg-body { max-height: calc(100vh - 160px); overflow: auto; }
.btn.danger { background: var(--critical-mark); border-color: var(--critical-mark); color: #fff; white-space: nowrap; flex: none; }
.btn.danger:not(:disabled):hover { background: var(--critical-mark); filter: brightness(1.08); }
.btn.danger:not(:disabled):active { background: var(--critical-mark); filter: brightness(0.92); }
.banner .countdown { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.banner[data-shutdown="countdown"] { --state-mark: var(--critical-mark); --state-ink: var(--critical); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 22px 18px; }
/* confirmation: as wide as its longest sentence (one per line), never narrower than a small dialog */
#confirm { width: fit-content; min-width: min(380px, calc(100vw - 32px)); max-width: calc(100vw - 32px); }
#confirm .dlg-body { padding-bottom: 4px; }
#confirm h3 { margin-bottom: 8px; }
#confirm .lines { font-size: 14px; margin: 0; }
.btn {
  padding: 6px 16px; border-radius: 6px; border: 1px solid var(--stroke-strong);
  background: var(--card-hover); cursor: pointer;
}
.btn:not(:disabled):hover { background: var(--btn-hover); }
.btn:not(:disabled):active { background: var(--btn-press); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:not(:disabled):hover { background: var(--accent); filter: brightness(1.08); }
.btn.primary:not(:disabled):active { background: var(--accent); filter: brightness(0.92); }
:root[data-theme="dark"] .btn.primary { color: #000; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #000; } }
.dlg-error { color: var(--critical); font-size: 13px; min-height: 18px; padding: 0 22px; }

/* ---------- login page ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: min(380px, 100%); padding: 28px 26px; text-align: center; }
.login-box h1 { font: 600 22px/1.2 var(--font-display); margin: 12px 0 6px; }
.login-box p { color: var(--text-2); margin: 0 0 18px; }
.login-box input {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--stroke-strong);
  background: var(--page); font-size: 16px; margin-bottom: 12px;
}
.login-box input:focus {
  outline: none; border-bottom-color: transparent;
  background-image: linear-gradient(var(--accent), var(--accent));
  background-origin: border-box; background-position: 0 100%; background-size: 100% 2px; background-repeat: no-repeat;
}
.login-box .btn { width: 100%; padding: 10px; font-size: 15px; }
.login-error { color: var(--critical); min-height: 20px; margin-top: 10px; font-size: 13px; }

/* ---------- remote access dialog ---------- */
.remote-state { border: 1px solid var(--stroke); border-radius: 10px; padding: 14px 16px; margin: 4px 0 12px; background: var(--page); }
.remote-state .rs-title { font-weight: 600; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.remote-state .rs-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.remote-state[data-state="running"] .rs-dot { background: var(--good-mark); }
.remote-state[data-state="needsLogin"] .rs-dot, .remote-state[data-state="needsFunnel"] .rs-dot, .remote-state[data-state="starting"] .rs-dot { background: var(--warning-mark); }
.remote-state[data-state="error"] .rs-dot { background: var(--critical-mark); }
.remote-state p { margin: 4px 0 10px !important; }
.remote-url { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.remote-url a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); font-weight: 600; }
.remote-qr { display: block; width: 168px; height: 168px; margin: 8px auto 0; border-radius: 8px; background: #fff; padding: 4px; }
.btn.link { display: inline-block; text-decoration: none; color: inherit; }
.btn.primary.link { color: #fff; }
.remote-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.ghost-danger { background: transparent; border-color: transparent; color: var(--critical); }
.btn.ghost-danger:not(:disabled):hover { background: color-mix(in srgb, var(--critical) 10%, transparent); }

/* Top bar icons closer together on desktop (≈15 px between glyphs); phones keep larger touch targets. */
@media (min-width: 761px) {
  .topbar-inner .icon-btn { width: 32px; height: 32px; }
  .topbar-inner .icon-btn + .icon-btn { margin-left: -11px; }
}
/* In the Windows app, focus can land on a button when the window is activated — show the ring only for Tab navigation. */
/* focus rings only during keyboard navigation (app.js toggles .kbd-nav on Tab / pointer) */
:root:not(.kbd-nav) :focus-visible { outline: none; }

/* ---------- layout wrappers ---------- */
/* Normal width: the wrappers are transparent and the blocks keep their usual order. */
.overview { display: contents; }
.lower { display: flex; flex-direction: column; }
.lower-side, .lower-main { display: contents; }
.lower .energy-card { order: 2; margin-bottom: 20px; }
.lower .section-head { order: 3; }
.lower .charts { order: 4; }
.lower .events-card { order: 5; }

/* Wide screens (maximised window): two columns that use the whole width, no empty margins. */
@media (min-width: 1500px) {
  :root { --gutter: 32px; --app-max: 2600px; }
  .overview {
    display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    gap: 12px; margin-bottom: 12px;
  }
  .overview .flow-card { margin-bottom: 0; }
  .overview .grid-top { grid-template-columns: 1fr; grid-template-rows: repeat(2, auto auto 1fr); margin-bottom: 0; grid-row: span 2; }
  .overview .voltage-card { margin-bottom: 0; }   /* under the power-flow diagram, left column */
  .lower { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 12px; align-items: stretch; margin-bottom: 20px; }
  .lower-main .charts { margin-bottom: 0; }
  .lower-main { display: block; grid-column: 1; grid-row: 1; }
  .lower-side { display: flex; flex-direction: column; gap: 12px; grid-column: 2; grid-row: 1; }
  .lower-side > * { margin-bottom: 0 !important; }
  /* both columns end on one line: the journal grows down to the bottom of the charts, showing more rows */
  .lower-side .events-card { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
  .lower-side .events-card .journal-box { flex: 1 1 0; min-height: 220px; max-height: none !important; }
  .lower-side .events-card .link-btn { align-self: flex-start; }
  .lower-main .section-head { margin-top: 0; }
}

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  :root { --gutter: 16px; }
  .app { padding-bottom: 32px; }
  .grid-top { grid-template-columns: 1fr; grid-template-rows: none; }
  .charts { grid-template-columns: 1fr; }
  .brand-text { flex-direction: column; align-items: flex-start; gap: 0; overflow: hidden; }
  /* phone top bar: the name block takes what the icons leave and truncates, instead of running under them */
  .topbar-inner { gap: 4px; }
  .brand { flex: 1 1 auto; margin-right: 4px; }
  .brand h1 { font-size: 18px; }
  .brand-text > * { max-width: 100%; }
  .brand h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-inner .icon-btn { width: 34px; }
  .brand .sub { font-size: 12px; }
  .seg { flex-wrap: wrap; }
  .seg button { padding: 4px 10px; }
  .hero-value { font-size: 48px; }
  .volt-row { gap: 20px; }
  .volt-row .hero-value { font-size: 34px; }
  .banner .state-right { display: none; }
  .banner { flex-wrap: wrap; }
  .banner .btn.danger { width: 100%; }
  /* phone: the tabs go on top, side by side */
  .settings-split { flex-direction: column; }
  .settings-nav { width: auto; min-width: 0; flex-direction: row; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--stroke); overflow-x: auto; }
  .settings-nav [role="tab"] { flex: 1 0 auto; width: auto; justify-content: center; }
  .settings-nav [role="tab"][aria-selected="true"]::before { left: 50%; top: auto; bottom: 0; width: 16px; height: 3px; margin: 0 0 0 -8px; }
  .live .label { display: none; }
  /* journal on a phone: date and time on the first line, icon + event on the second */
  .events { grid-template-columns: 16px minmax(0, 1fr); column-gap: 8px; }
  .events li { row-gap: 1px; padding: 6px 0; }
  .events .ev-time { grid-column: 1 / -1; font-size: 12px; }
  .events .ev-colon { display: none; }
}

/* very narrow window on this PC (UPS buttons shown): keep the logo, drop the name so the icons fit */
@media (max-width: 350px) {
  .topbar:has(#ctl-test:not([hidden])) .brand-text { display: none; }
}

/* A page in another language stays hidden until i18n.js has translated it (see the script in <head>). */
.i18n-pending body { visibility: hidden; }

/* Language picker: looks like the drop-downs around it, but its list shows a flag before each language
   (a native <select> cannot show pictures). The list is a popover, so the scrolling pane never clips it. */
.field:has(.lang-btn) { grid-template-columns: 1fr auto; }
.lang-btn {
  display: inline-flex; align-items: center; gap: 8px; justify-self: end; min-width: 88px;
  padding: 4px 8px 4px 9px; border-radius: 6px; border: 1px solid var(--stroke-strong); background: var(--page);
  color: var(--text); text-align: left; white-space: nowrap; cursor: default;
}
.lang-btn:focus {
  outline: none; border-bottom-color: transparent;
  background-image: linear-gradient(var(--accent), var(--accent));
  background-origin: border-box; background-position: 0 100%; background-size: 100% 2px; background-repeat: no-repeat;
}
.lang-cur { display: inline-flex; align-items: center; gap: 8px; }
.lang-chev { flex: none; margin-left: 2px; }
.lang-chev path { fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.lang-icon { display: inline-grid; place-items: center; flex: none; width: 21px; height: 14px; color: var(--text-2); }
.lang-icon img {
  display: block; width: 21px; height: 14px; border-radius: 2px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--text) 16%, transparent);   /* the white of a flag on a light page */
}
.lang-list {
  inset: auto; margin: 0; padding: 4px; list-style: none; overflow: visible;
  border: 1px solid var(--stroke-strong); border-radius: 8px; background: var(--card); color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.lang-list li {
  position: relative; display: flex; align-items: center; gap: 8px; padding: 5px 12px 5px 10px; border-radius: 4px;
  white-space: nowrap; cursor: default;
}
.lang-list li:hover, .lang-list li:focus { background: var(--btn-hover); outline: none; }
.lang-list li[aria-selected="true"] { background: var(--btn-hover); }
/* the accent pill of the chosen item, as in Windows menus */
.lang-list li[aria-selected="true"]::before {
  content: ''; position: absolute; left: 0; top: 50%; width: 3px; height: 16px; margin-top: -8px;
  border-radius: 2px; background: var(--accent);
}
