/* ============================================================
   INBOX / CONTROL LEDGER
   Editorial instrumentation, not glassmorphism.
   ============================================================ */

@font-face {
  font-family: "Vazirmatn";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/vazirmatn-arabic.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-0891, U+0897-08E1,
    U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF,
    U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC7,
    U+10EC9-10EEE, U+10EF0-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22,
    U+1EE24, U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42,
    U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54, U+1EE57,
    U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64, U+1EE67-1EE6A,
    U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E, U+1EE80-1EE89,
    U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9, U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}

@font-face {
  font-family: "Vazirmatn";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/vazirmatn-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/plex-mono-400.woff2") format("woff2");
}

@font-face {
  font-family: "Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/plex-mono-500.woff2") format("woff2");
}

@font-face {
  font-family: "Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/plex-mono-600.woff2") format("woff2");
}

:root {
  color-scheme: dark;
  --bg: #0b0b0a;
  --panel: #131311;
  --panel-2: #191916;
  --panel-3: #20201b;
  --ink: #ece9df;
  --muted: #b0aa9c;
  --faint: #8a8578;
  --line: #2e2d28;
  --line-2: #454137;
  --accent: #ff5a36;
  --accent-ink: #0b0b0a;
  --accent-soft: rgba(255, 90, 54, 0.09);
  --lime: #b9d96e;
  --blue: #83a9ff;
  --red: #ff6f61;
  --amber: #e7b34a;
  --grid: rgba(236, 233, 223, 0.028);
  --font-fa: "Vazirmatn", "Tahoma", sans-serif;
  --font-mono: "Plex Mono", "SFMono-Regular", ui-monospace, Menlo, monospace;
  --radius: 2px;
  --shadow: 0 20px 44px rgba(0, 0, 0, 0.34);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f1ede3;
  --panel: #faf7ee;
  --panel-2: #f2ede1;
  --panel-3: #e9e3d5;
  --ink: #171612;
  --muted: #5f5b50;
  --faint: #6f695c;
  --line: #d7d0c0;
  --line-2: #b9b09c;
  --accent: #b83a17;
  --accent-ink: #fdf9f0;
  --accent-soft: rgba(207, 67, 29, 0.09);
  --lime: #4d7218;
  --blue: #1f4fbe;
  --red: #b3261e;
  --amber: #9a6707;
  --grid: rgba(23, 22, 18, 0.035);
  --shadow: 0 18px 40px rgba(60, 51, 33, 0.12);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 100% 32px, 32px 100%;
  color: var(--ink);
  font-family: var(--font-fa);
  font-size: 13px;
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::selection { background: var(--accent); color: var(--accent-ink); }

button, input { font: inherit; color: inherit; }
h1, h2, p, dl, dd, dt, ul { margin: 0; }
ul { padding: 0; list-style: none; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.ico {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: square;
  stroke-linejoin: miter;
  flex: 0 0 auto;
}

.hidden { display: none !important; }

.mono,
.hero-value,
.cell-value,
.delta-chip,
.health-badge,
.pill-soft,
.bars,
.week-value,
.break-value,
.switch,
.nav-index,
.meter-head strong,
.chart-tooltip strong,
.info-row dd,
#infoVersion {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums slashed-zero;
  direction: ltr;
  unicode-bidi: isolate;
}

.micro {
  font-size: 9px;
  line-height: 1.5;
  color: var(--faint);
  font-weight: 500;
}

.micro.latin {
  font-family: var(--font-mono);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------- shell ------------------------------- */

.app {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding:
    calc(14px + env(safe-area-inset-top, 0px))
    16px
    calc(104px + env(safe-area-inset-bottom, 0px));
}

/* ------------------------------- masthead ------------------------------- */

.masthead { margin-bottom: 14px; }

.masthead-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

#metaDate {
  font-family: var(--font-fa);
  font-size: 9.5px;
  letter-spacing: 0;
  color: var(--muted);
}

.masthead-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--accent);
  font-family: var(--font-fa);
  font-size: 21px;
  font-weight: 800;
  line-height: 1;
  flex: 0 0 auto;
}

.brand-mark svg { width: 22px; height: 22px; }

.brand-copy { min-width: 0; }

.brand-copy h1 {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.4;
}

.brand-copy p {
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46vw;
}

.masthead-actions { display: flex; align-items: center; gap: 9px; flex: 0 0 auto; }

.preview-badge {
  padding: 2px 6px;
  border: 1px solid var(--amber);
  border-radius: var(--radius);
  color: var(--amber);
  font-size: 8.5px;
  font-weight: 600;
  white-space: nowrap;
}

.status-plain {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 500;
  white-space: nowrap;
}

.status-square {
  width: 7px;
  height: 7px;
  border: 1px solid var(--faint);
  background: transparent;
  flex: 0 0 auto;
}

.status-square.accent { border-color: var(--accent); background: var(--accent); }

.status-plain.is-live { color: var(--lime); }
.status-plain.is-live .status-square { border-color: var(--lime); background: var(--lime); }
.status-plain.is-off { color: var(--amber); }
.status-plain.is-off .status-square { border-color: var(--amber); background: var(--amber); }
.status-plain.is-danger { color: var(--red); }
.status-plain.is-danger .status-square { border-color: var(--red); background: var(--red); }

.square-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.square-btn:hover { border-color: var(--accent); color: var(--accent); }
.square-btn:active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.square-btn:disabled { opacity: 0.5; cursor: default; }
.square-btn.is-busy .ico { animation: spin 0.9s linear infinite; }

.rule-double {
  height: 5px;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--line-2);
}

/* ------------------------------- views ------------------------------- */

.view { display: none; }
.view.is-active { display: block; animation: view-in 0.3s ease both; }
.view > * + * { margin-top: 12px; }

/* ------------------------------- panel ------------------------------- */

.panel {
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: none;
  overflow: hidden;
  position: relative;
}

.panel-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 13px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.panel-index {
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--accent);
  direction: ltr;
  unicode-bidi: isolate;
  flex: 0 0 auto;
}

.panel-title { font-size: 11.5px; font-weight: 700; }
.panel-meta { margin-inline-start: auto; color: var(--faint); font-size: 9px; white-space: nowrap; }

.panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 13px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 9px;
  line-height: 1.6;
}

/* ------------------------------- hero ------------------------------- */

.hero-body {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 14px 8px;
}

.hero-primary { min-width: 0; flex: 1 1 auto; }

.hero-value {
  font-size: clamp(48px, 14vw, 66px);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.06em;
  color: var(--ink);
  text-align: right;
}

.hero-label { color: var(--muted); font-size: 10.5px; margin-top: 5px; }

.delta-chip {
  display: inline-block;
  margin-top: 9px;
  border: 0;
  background: none;
  padding: 0;
  color: var(--faint);
  font-size: 9.5px;
  font-weight: 500;
  white-space: nowrap;
}

.delta-chip.is-up { color: var(--lime); }
.delta-chip.is-down { color: var(--red); }
.delta-chip.is-flat { color: var(--faint); }

.hero-secondary {
  flex: 0 0 38%;
  max-width: 190px;
  display: grid;
  align-content: center;
  border-inline-start: 1px solid var(--line);
  padding-inline-start: 14px;
}

.hero-stat { padding: 6px 0; border-bottom: 1px solid var(--line); }
.hero-stat:last-child { border-bottom: 0; }
.hero-stat span { display: block; color: var(--faint); font-size: 9px; line-height: 1.5; }
.hero-stat strong {
  display: block;
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 500;
  line-height: 1.4;
  direction: ltr;
  text-align: right;
  unicode-bidi: isolate;
}

.spark {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 42px;
  margin: 4px 14px 10px;
  border-bottom: 1px solid var(--line-2);
  direction: ltr;
}

.spark span {
  flex: 1;
  height: var(--h, 4%);
  min-height: 3px;
  background: var(--accent);
  opacity: 0.55;
  transition: height 0.45s ease;
}

.spark span.is-today { opacity: 1; }

html[data-theme="light"] .spark span { opacity: 0.72; }

/* ------------------------------- ledger grid ------------------------------- */

.ledger-grid {
  display: grid;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  overflow: hidden;
}

.kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.cell {
  position: relative;
  background: var(--panel);
  padding: 12px;
  min-height: 104px;
}

.cell-index {
  position: absolute;
  top: 9px;
  left: 10px;
  font-family: var(--font-mono);
  font-size: 8px;
  color: var(--faint);
  direction: ltr;
  unicode-bidi: isolate;
}

.cell-label {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
  margin-bottom: 7px;
  padding-right: 2px;
}

.cell-value {
  display: block;
  font-size: 25px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.05em;
  text-align: right;
}

.cell-note {
  display: block;
  color: var(--faint);
  font-size: 9px;
  line-height: 1.6;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------- section head ------------------------------- */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px 0;
}

.section-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.section-title h2 { font-size: 13.5px; font-weight: 700; letter-spacing: -0.2px; line-height: 1.5; }

.section-note {
  padding: 0 13px;
  margin: 2px 0 12px;
  color: var(--faint);
  font-size: 10px;
  line-height: 1.6;
}

/* ------------------------------- segmented ------------------------------- */

.segmented {
  display: inline-flex;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  overflow: hidden;
  flex: 0 0 auto;
}

.segmented button {
  border: 0;
  border-inline-start: 1px solid var(--line-2);
  background: transparent;
  color: var(--muted);
  font-size: 9px;
  font-weight: 600;
  min-height: 34px;
  padding: 4px 9px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.segmented button:first-child { border-inline-start: 0; }
.segmented button[aria-selected="true"] { background: var(--ink); color: var(--bg); }
.segmented button:hover:not([aria-selected="true"]) { color: var(--ink); }

/* ------------------------------- chart ------------------------------- */

.chart-wrap {
  position: relative;
  min-height: 190px;
  margin: 0 8px 8px;
  direction: ltr;
}

.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }

.chart-grid-line { stroke: var(--line); stroke-width: 1; }
.chart-axis-text {
  fill: var(--faint);
  font-size: 9px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.chart-line { fill: none; stroke-width: 1.9; stroke-linecap: square; stroke-linejoin: miter; }
.chart-dot { stroke: var(--panel); stroke-width: 2; }
.chart-cursor { stroke: var(--line-2); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-hit { fill: transparent; cursor: crosshair; }

.chart-tooltip {
  position: absolute;
  z-index: 4;
  min-width: 84px;
  padding: 5px 8px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--panel-2);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 9px;
  line-height: 1.6;
  text-align: center;
  pointer-events: none;
  transform: translate(-50%, -112%);
  opacity: 0;
  transition: opacity 0.1s ease;
}

.chart-tooltip.is-visible { opacity: 1; }
.chart-tooltip strong { display: block; font-size: 12px; font-weight: 500; }
.chart-tooltip span { color: var(--muted); font-family: var(--font-fa); }

.chart-empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--faint);
  font-size: 10px;
  border: 1px dashed var(--line-2);
  border-radius: var(--radius);
}

/* ------------------------------- meters ------------------------------- */

.meter-list { display: grid; gap: 12px; padding: 0 13px 14px; }

.meter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 9.5px;
  margin-bottom: 5px;
}

.meter-head strong { color: var(--ink); font-size: 10.5px; font-weight: 500; }

.meter-track {
  height: 6px;
  border: 1px solid var(--line-2);
  background: transparent;
  overflow: hidden;
}

.meter-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.55s ease;
}

.meter-fill.tint-green { background: var(--lime); }
.meter-fill.tint-violet { background: var(--amber); }
.meter-fill.tint-blue { background: var(--blue); }

.mini-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-width: 1px 0 0;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
}

.cell.mini { min-height: 62px; padding: 10px 12px; }
.cell.mini .cell-label { margin-bottom: 4px; }
.cell.mini strong {
  display: block;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 500;
  direction: ltr;
  text-align: right;
  unicode-bidi: isolate;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------- health badge ------------------------------- */

.health-badge {
  padding: 2px 6px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 8px;
  font-weight: 500;
  white-space: nowrap;
}

.health-badge.is-good { color: var(--lime); border-color: var(--lime); }
.health-badge.is-warn { color: var(--amber); border-color: var(--amber); }
.health-badge.is-bad { color: var(--red); border-color: var(--red); }

/* ------------------------------- stats ------------------------------- */

.stat-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.pill-soft {
  padding: 2px 6px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 8px;
  white-space: nowrap;
}

.bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 118px;
  margin: 0 13px;
  padding-top: 6px;
  border-bottom: 1px solid var(--line-2);
  direction: ltr;
}

.bars .bar {
  flex: 1;
  min-width: 2px;
  height: var(--h, 3%);
  min-height: 2px;
  background: var(--accent);
  opacity: 0.34;
  transition: height 0.45s ease, opacity 0.15s ease;
}

.bars .bar.is-peak { opacity: 1; }
.bars .bar.is-zero { background: var(--line-2); opacity: 0.55; }

.axis-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 13px 11px;
  color: var(--faint);
  font-size: 8px;
  direction: ltr;
}

.week-bars {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
  align-items: end;
  padding: 0 13px 14px;
  min-height: 128px;
  direction: ltr;
}

.week-col { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.week-value { font-size: 8px; color: var(--muted); }
.week-track {
  width: 100%;
  height: 76px;
  display: flex;
  align-items: flex-end;
  border: 1px solid var(--line);
  background: transparent;
  overflow: hidden;
}
.week-fill {
  width: 100%;
  height: var(--h, 0%);
  min-height: 2px;
  background: var(--lime);
  opacity: 0.62;
  transition: height 0.5s ease;
}
.week-col.is-today .week-fill { background: var(--accent); opacity: 1; }
.week-label { font-size: 8px; color: var(--faint); white-space: nowrap; }
.week-col.is-today .week-label { color: var(--accent); font-weight: 700; }

.breakdown { padding: 0 13px 10px; }

.break-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}

.break-row:last-child { border-bottom: 0; }
.break-label { color: var(--muted); font-size: 10.5px; min-width: 0; }
.break-value { font-size: 10.5px; color: var(--ink); }
.break-bar { grid-column: 1 / -1; height: 2px; background: var(--line); overflow: hidden; }
.break-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.5s ease; }
.break-bar.tone-violet span { background: var(--amber); }
.break-bar.tone-blue span { background: var(--blue); }
.break-bar.tone-amber span { background: var(--amber); }
.break-bar.tone-danger span { background: var(--red); }

/* ------------------------------- notice ------------------------------- */

.notice {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 9.5px;
  line-height: 1.8;
}

.notice-mark { width: 7px; height: 7px; margin-top: 4px; background: var(--accent); flex: 0 0 auto; }
.notice.is-warn { border-inline-start-color: var(--amber); color: var(--amber); }
.notice.is-warn .notice-mark { background: var(--amber); }
.notice.is-danger { border-inline-start-color: var(--red); color: var(--red); }
.notice.is-danger .notice-mark { background: var(--red); }

/* ------------------------------- modes ------------------------------- */

.mode-grid { display: grid; gap: 0; border-top: 1px solid var(--line); }

.mode { position: relative; display: block; cursor: pointer; }
.mode input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.mode-box {
  display: grid;
  grid-template-columns: 22px 1fr 14px;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  border-inline-start: 2px solid transparent;
  background: transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.mode:last-child .mode-box { border-bottom: 0; }
.mode:hover .mode-box { background: var(--panel-2); }

.mode-index {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--faint);
  direction: ltr;
  unicode-bidi: isolate;
}

.mode-copy { min-width: 0; }
.mode-copy strong { display: block; font-size: 11.5px; font-weight: 700; }
.mode-copy span { display: block; color: var(--muted); font-size: 9.5px; line-height: 1.75; margin-top: 1px; }

.mode-tick {
  width: 12px;
  height: 12px;
  border: 1px solid var(--line-2);
  background: transparent;
}

.mode input:checked + .mode-box {
  background: var(--panel-3);
  border-inline-start-color: var(--accent);
}

.mode input:checked + .mode-box .mode-index { color: var(--accent); }
.mode input:checked + .mode-box .mode-tick { border-color: var(--accent); background: var(--accent); }
.mode input:focus-visible + .mode-box { outline: 1px solid var(--accent); outline-offset: -1px; }
.mode-grid.is-saving { opacity: 0.55; pointer-events: none; }

/* ------------------------------- transport ------------------------------- */

.transport-grid { border-top: 1px solid var(--line); }

.transport-card {
  display: grid;
  grid-template-columns: 22px 1fr 14px;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 13px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-inline-start: 2px solid transparent;
  background: transparent;
  color: var(--ink);
  text-align: right;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.transport-card:last-child { border-bottom: 0; }
.transport-card:hover { background: var(--panel-2); }
.transport-card[aria-checked="true"] {
  background: var(--panel-3);
  border-inline-start-color: var(--accent);
}
.transport-card[aria-checked="true"] .transport-index { color: var(--accent); }
.transport-card[aria-checked="true"] .transport-tick { border-color: var(--accent); background: var(--accent); }
.transport-card:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }
.transport-card:disabled { opacity: 0.5; cursor: default; }

.transport-index {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--faint);
  direction: ltr;
  unicode-bidi: isolate;
}

.transport-copy { min-width: 0; }
.transport-copy strong { display: block; font-size: 11.5px; font-weight: 700; }
.transport-copy span { display: block; color: var(--muted); font-size: 9.5px; line-height: 1.75; margin-top: 1px; }

.transport-tick { width: 12px; height: 12px; border: 1px solid var(--line-2); background: transparent; }

.inline-note { padding: 0 13px 12px; color: var(--faint); font-size: 9px; line-height: 1.8; }

/* ------------------------------- switches ------------------------------- */

.switch-list { border-top: 1px solid var(--line); }

.switch-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
}

.switch-row:last-child { border-bottom: 0; }
.switch-copy { min-width: 0; }
.switch-copy strong { display: block; font-size: 11px; font-weight: 700; }
.switch-copy span { display: block; color: var(--muted); font-size: 9.5px; line-height: 1.8; margin-top: 1px; }
.switch-row.is-danger .switch-copy strong { color: var(--red); }

.switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex: 0 0 auto;
  margin-top: 2px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.switch::before {
  content: "";
  position: absolute;
  inset: -10px -4px;
}

.switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: var(--faint);
  transition: transform 0.18s ease, background 0.15s ease;
}

.switch[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.switch[aria-checked="true"] span { transform: translateX(20px); background: var(--accent); }
.switch-row.is-danger .switch[aria-checked="true"] { border-color: var(--red); background: rgba(255, 111, 97, 0.1); }
.switch-row.is-danger .switch[aria-checked="true"] span { background: var(--red); }
.switch:hover { border-color: var(--ink); }
.switch:disabled { opacity: 0.45; cursor: default; }

/* ------------------------------- safety / privacy ------------------------------- */

.safety-panel, .privacy-panel { padding: 13px; }

.safety-head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.safety-head .ico { color: var(--accent); }
.safety-head h2 { font-size: 12px; font-weight: 700; }

.safety-list { display: grid; gap: 5px; }
.safety-list li {
  position: relative;
  padding-right: 14px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.85;
}
.safety-list li::before {
  content: "";
  position: absolute;
  top: 8px;
  right: 0;
  width: 5px;
  height: 1px;
  background: var(--accent);
}

.privacy-panel p { color: var(--muted); font-size: 9.5px; line-height: 1.95; }
.privacy-panel .privacy-foot { color: var(--faint); margin-top: 7px; }

/* ------------------------------- settings ------------------------------- */

.info-list { border-top: 1px solid var(--line); }

.info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 13px;
  border-bottom: 1px solid var(--line);
}

.info-row:last-child { border-bottom: 0; }
.info-row dt { color: var(--muted); font-size: 10px; flex: 0 0 auto; }
.info-row dd {
  font-size: 10px;
  color: var(--ink);
  text-align: left;
  direction: rtl;
  unicode-bidi: plaintext;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ------------------------------- dock ------------------------------- */

.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  border-top: 1px solid var(--line-2);
  background: var(--bg);
  box-shadow: 0 -12px 28px rgba(0, 0, 0, 0.18);
}

html[data-theme="light"] .dock { box-shadow: 0 -12px 28px rgba(60, 51, 33, 0.08); }

.nav-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 58px;
  padding: 6px 4px 7px;
  border: 0;
  border-inline-start: 1px solid var(--line);
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.nav-item:first-child { border-inline-start: 0; }
.nav-item .ico { width: 16px; height: 16px; }
.nav-label { font-size: 10px; font-weight: 600; line-height: 1.4; }
.nav-index {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 7px;
  color: var(--faint);
  opacity: 0.7;
}

.nav-item.is-active { color: var(--accent); background: transparent; }
.nav-item.is-active::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 12%;
  right: 12%;
  height: 2px;
  background: var(--accent);
}
.nav-item.is-active .nav-index { color: var(--accent); opacity: 1; }
.nav-item:hover { color: var(--ink); }

/* ------------------------------- loading / error ------------------------------- */

.loading { display: grid; gap: 10px; }

.skeleton {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--grid), transparent);
  animation: shimmer 1.6s infinite;
}

.sk-hero { height: 190px; }
.skeleton-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sk-kpi { height: 108px; }
.sk-card { height: 210px; }

.error-state { padding: 28px 20px; text-align: center; }
.error-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 10px;
  display: grid;
  place-items: center;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  color: var(--red);
}
.error-state h2 { font-size: 13px; font-weight: 700; }
.error-state p { color: var(--muted); font-size: 10px; line-height: 1.9; margin-top: 5px; }

.btn-primary {
  margin-top: 14px;
  min-height: 44px;
  padding: 9px 20px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s ease;
}
.btn-primary:hover { filter: brightness(1.08); }

/* ------------------------------- login ------------------------------- */

.login-state {
  max-width: 460px;
  margin: 6vh auto 0;
}

.login-panel { box-shadow: var(--shadow); }

.login-body { padding: 16px; }
.login-body h2 { font-size: 15px; font-weight: 800; letter-spacing: -0.3px; }
.login-body p { color: var(--muted); font-size: 10.5px; line-height: 1.9; margin-top: 7px; }
.login-body p code {
  font-family: var(--font-mono);
  direction: ltr;
  unicode-bidi: isolate;
  color: var(--accent);
  font-size: 9.5px;
}

.login-body form { margin-top: 16px; }
.login-body label {
  display: block;
  color: var(--muted);
  font-size: 9.5px;
  margin-bottom: 5px;
}

.login-body input {
  width: 100%;
  height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.login-body input:focus {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.login-body input:disabled { opacity: 0.55; }
.login-body .btn-primary { width: 100%; margin-top: 10px; }
.login-body .btn-primary:disabled { opacity: 0.55; cursor: default; }

.login-error {
  color: var(--red) !important;
  font-size: 10px !important;
  line-height: 1.8;
  border-inline-start: 2px solid var(--red);
  padding-inline-start: 8px;
  margin-top: 12px !important;
}

.login-note {
  color: var(--faint) !important;
  font-size: 9.5px !important;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 16px !important;
}

.text-btn {
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 9px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}

.text-btn:hover { text-decoration: underline; }

/* ------------------------------- toast ------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 8px);
  z-index: 50;
  max-width: calc(100% - 32px);
  padding: 8px 12px;
  border: 1px solid var(--line-2);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--ink);
  font-size: 10px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  text-align: center;
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { border-inline-start-color: var(--red); }

/* ------------------------------- motion ------------------------------- */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 100% { transform: translateX(100%); } }
@keyframes view-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

/* ------------------------------- responsive ------------------------------- */

@media (min-width: 560px) {
  .app { padding-left: 24px; padding-right: 24px; }
  .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .hero-value { font-size: 72px; }
  .dock { padding-left: max(0px, calc((100% - 720px) / 2)); padding-right: max(0px, calc((100% - 720px) / 2)); }
}

@media (max-width: 470px) {
  .preview-badge { display: none; }
  .masthead-actions { gap: 7px; }
  .masthead-main { gap: 9px; }
  .brand-copy p { max-width: 42vw; }
  .masthead-actions .status-plain span:last-child { display: none; }
}

@media (max-width: 370px) {
  .app { padding-left: 11px; padding-right: 11px; }
  .hero-body { gap: 10px; }
  .hero-secondary { flex-basis: 40%; padding-inline-start: 10px; }
  .hero-value { font-size: 44px; }
  .cell { padding: 10px; }
  .brand-mark { width: 36px; height: 36px; font-size: 19px; }
  .panel-meta { font-size: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-contrast: more) {
  :root { --line: #4a473e; --line-2: #6b675b; --muted: #c3bdad; }
  html[data-theme="light"] { --line: #b3aa96; --line-2: #8d8471; --muted: #3f3b32; }
}
