/* Components added for the MRD-faithful rebuild. Uses the brand tokens defined in
   brand.css; falls back to sane values so it works even if a token is missing. */

/* charts */
.chart { min-height: 280px; width: 100%; position: relative; }
/* Reset-zoom pill, injected by the echarts controller and shown only while the
   chart is actually zoomed. */
.chart-reset {
  position: absolute; top: 2px; right: 6px; z-index: 5;
  font: inherit; font-size: 11px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-elev);
  color: var(--text-muted); cursor: pointer;
}
.chart-reset:hover { color: var(--text); border-color: var(--accent); }
.chart-reset[hidden] { display: none; }
.chart-lg { height: 380px; }
.chart-error { display: flex; align-items: center; justify-content: center; height: 100%;
  color: var(--text-muted, #9fb0c3); font-size: var(--fs-1, 12px); }

/* generic layout helpers */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3, 12px); }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .cols-2, .cols-3 { grid-template-columns: 1fr; } }

/* topbar pills */
.tb-ico { opacity: .65; font-size: 13px; }
.tb-pill select, .chip-select { background: transparent; border: 0; color: inherit; font: inherit; cursor: pointer; }
.chip-select { padding: 4px 8px; border: 1px solid var(--border, #2a3848); border-radius: 8px; background: var(--card, #141c28); color: var(--text, #e7eef6); }

/* sidebar role-gating */
.nav-item.locked { opacity: .45; cursor: not-allowed; }
.nav-item .nav-lock { margin-left: auto; opacity: .7; display: inline-flex; }
.ico-sm { width: 14px; height: 14px; }

/* decision tile */
.decision { border-radius: 12px; padding: var(--s-4, 16px); border: 1px solid var(--border, #2a3848); }
.decision.is-clean { background: rgba(200, 69, 59, .12); border-color: rgba(200, 69, 59, .4); }
.decision.is-wait { background: rgba(63, 179, 127, .10); border-color: rgba(63, 179, 127, .35); }
.decision-verb { font-family: var(--font-display, inherit); font-weight: 800; font-size: 20px; letter-spacing: -.01em; }
.decision-why { color: var(--text-muted, #9fb0c3); font-size: var(--fs-1, 12px); margin-top: 4px; }

/* map */
.map-wrap { position: relative; }
.map-canvas { border-radius: 10px; overflow: hidden; }
.map-note { position: absolute; z-index: 5; top: 10px; left: 10px; font-size: 11px;
  background: rgba(12, 18, 27, .82); color: #e7eef6; padding: 5px 10px; border-radius: 8px; }
.map-grid { grid-template-columns: 1fr 320px; gap: var(--s-5, 20px); }
@media (max-width: 900px) { .map-grid { grid-template-columns: 1fr; } }

/* Upload page: the mirror of map-grid. The form needs little room; the
   file-format reference is a two-column table that was being squeezed into the
   narrow side and wrapping its labels. */
.upload-grid { grid-template-columns: 340px 1fr; gap: var(--s-5, 20px); align-items: start; }
@media (max-width: 900px) { .upload-grid { grid-template-columns: 1fr; } }

/* Template download shelf on the upload page. Each box is one downloadable file:
   what it is, what it is for, which version. */
.tpl-shelf { display: flex; flex-direction: column; gap: 10px; margin-top: var(--s-3); }
.tpl-box {
  display: flex; gap: 12px; align-items: flex-start; text-decoration: none; color: inherit;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r-3);
  background: var(--bg-soft); transition: border-color .15s, background .15s;
}
.tpl-box:hover { border-color: var(--accent); background: var(--accent-tint); text-decoration: none; }
.tpl-ico { flex: none; display: inline-flex; color: var(--accent-bright, var(--accent)); margin-top: 2px; }
.tpl-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tpl-name { font-weight: 700; font-size: var(--fs-2); }
.tpl-desc { color: var(--text-muted); font-size: var(--fs-1); line-height: 1.45; }
.tpl-meta { color: var(--text-faint, var(--text-muted)); font-size: 11px; }

/* Key/value reference table: the label column sizes to its content and never
   wraps, so "Row 4+" and "Required" stay on one line. */
.table.keyed td:first-child {
  width: 7.5rem; white-space: nowrap; vertical-align: top;
  font-weight: 600; color: var(--text-muted);
}

/* station list */
.sensor-list { display: flex; flex-direction: column; gap: 6px; margin-top: var(--s-3, 12px); }
.sensor-row { display: flex; align-items: center; gap: 10px; padding: 7px 9px; border-radius: 8px; background: var(--panel, rgba(255,255,255,.03)); }
.sensor-row .sr-name { flex: 1; font-size: var(--fs-1, 12px); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* cleaning verdicts */
.verdict-delta { font-family: var(--font-display, inherit); font-weight: 800; font-size: 28px; letter-spacing: -.02em; margin-top: 6px; }

/* sensor flag bars */
.flagbar-row { display: flex; align-items: center; gap: 10px; }
.flagbar-label { width: 70px; font-size: var(--fs-1, 12px); color: var(--text-muted, #9fb0c3); }
.flagbar-track { flex: 1; height: 8px; border-radius: 999px; background: var(--panel, rgba(255,255,255,.06)); overflow: hidden; }
/* The fill is a <span>, i.e. an inline box by default — and width does not
   apply to inline boxes, so every bar rendered 0px wide however large its
   percentage. It has to be a block for the width to mean anything. */
.flagbar-fill { display: block; height: 100%; border-radius: 999px; min-width: 2px; }
.flagbar-pct { width: 42px; text-align: right; font-size: var(--fs-1, 12px); }
.flag-ok { background: #3FB37F; } .flag-night { background: #5B6B7E; }
.flag-wet { background: #4F9BE8; } .flag-abnormal { background: #C8453B; }
.flag-over_100 { background: #E8893B; }

/* The station list is a list of links, so without this every name inherits the
   link colour — which made all of them read as "over threshold" (Damon). Colour
   carries meaning here: alert red only for a station over the contract. */
a.sensor-row, a.sensor-row:hover { color: var(--text); text-decoration: none; }
.sensor-row .sr-loss { color: var(--text-muted); }
.sensor-row.is-over .sr-name, .sensor-row.is-over .sr-loss { color: var(--alert); }

/* Stale stations keep their last value but must read as history, not "now". */
.sensor-row.is-stale { opacity: .62; }
.sensor-row.is-stale .stale-note { color: var(--warn, #E8A33B); }
.sensor-row .sensor-val.stale-val { color: var(--warn, #E8A33B); font-style: italic; }

/* About page: the glossary is the working half of the page, so it takes 3/5 and
   the description 2/5. Collapses to one column on narrow screens, where a 2/5
   column would be unreadable. */
.about-grid { grid-template-columns: 2fr 3fr; align-items: start; }
@media (max-width: 1000px) { .about-grid { grid-template-columns: 1fr; } }

/* Glossary: a long list that must not stretch the page. Scrolls in place —
   find-in-page still reaches terms scrolled out of view, because they are in the
   DOM and rendered, just clipped. */
.glossary-scroll { max-height: min(60vh, 520px); overflow-y: auto; margin-top: var(--s-3); }
.glossary-scroll .table td:first-child { width: 10rem; white-space: normal; }
@media (max-width: 1000px) { .glossary-scroll { max-height: min(70vh, 620px); } }

/* settings + admin */
.settings-grid { display: grid; grid-template-columns: 210px 1fr; gap: var(--s-5, 20px); align-items: start; }
.settings-tabs { display: flex; flex-direction: column; gap: 4px; }
.settings-content { display: flex; flex-direction: column; gap: var(--s-5, 20px); min-width: 0; }
@media (max-width: 820px) { .settings-grid { grid-template-columns: 1fr; } }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s-4, 16px); margin-top: var(--s-3, 12px); }
.form-grid .field { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-1, 12px); color: var(--text-muted, #9fb0c3); }
.form-grid input { padding: 8px 10px; border: 1px solid var(--border, #2a3848); border-radius: 8px;
  background: var(--card, #141c28); color: var(--text, #e7eef6); font: inherit; }
.toggle-row { display: flex; align-items: center; gap: 8px; }

/* Radio choices that carry an explanation, not just a label (Settings →
   averaging window). The selected one is tinted so the current state reads at
   a glance. */
.opt-list { display: flex; flex-direction: column; gap: 10px; margin-top: var(--s-3); }
.opt { display: flex; gap: 10px; align-items: flex-start; cursor: pointer;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r-3);
  background: var(--bg-soft); }
.opt:hover { border-color: var(--accent); }
/* Highlight follows the RADIO, so it moves on click rather than waiting for the
   save to come back from the server (Damon). */
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-tint); }
.opt input[type="radio"] { margin-top: 3px; flex: none; accent-color: var(--accent); }
.opt-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.opt-name { font-weight: 700; font-size: var(--fs-2); }
.opt-desc { color: var(--text-muted); font-size: var(--fs-1); line-height: 1.45; }

/* Permission matrix: a filled mark instead of a disabled checkbox, which the
   browser paints as a near-invisible grey ghost in both themes. */
.perm { display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px; font-size: 13px; font-weight: 700; }
.perm.yes { background: var(--accent-deep); color: #fff; }
.perm.no  { background: var(--bg-soft); color: var(--text-faint, var(--text-muted));
  border: 1px solid var(--border); }

/* Destructive row actions sit right-aligned and stay quiet until hovered. */
.row-actions { text-align: right; white-space: nowrap; }
.row-actions form { display: inline; }
.btn.danger { color: var(--alert); border-color: transparent; }
.btn.danger:hover { border-color: var(--alert); background: rgba(200, 69, 59, .12); }

/* A card that states what a screen does NOT do — read as guidance, not alarm. */
.card.is-notice { border-left: 3px solid var(--accent); background: var(--bg-soft); }

/* placeholder affordances */
.placeholder-pill { display: inline-block; font-size: 10px; padding: 2px 9px; border-radius: 999px;
  background: var(--panel, rgba(255,255,255,.06)); color: var(--text-muted, #9fb0c3); cursor: help;
  text-transform: uppercase; letter-spacing: .06em; }
.placeholder-toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: #1c252d; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 8px 30px rgba(0,0,0,.4); opacity: 0; transition: opacity .2s; z-index: 200; }
.placeholder-toast.show { opacity: 1; }

.badge.muted { background: var(--panel, rgba(255,255,255,.06)); color: var(--text-muted, #9fb0c3); }

/* login role buttons */
.login-roles { display: flex; flex-direction: column; gap: 8px; }

/* native <select> dropdown options — readable in dark chrome (was white-on-white) */
select option { background: #1C252D; color: #EAEEF6; }
:root[data-chrome="light"] select option { background: #ffffff; color: #19222b; }

/* overview stats column */
.ov-stats { align-content: start; }

/* topbar custom date-range popover (UI-03 / SR-009) */
.range-pill { gap: 6px; }
.range-pill select[disabled] { opacity: .55; }
.range-panel {
  position: absolute; right: 0; top: 44px; z-index: 60; width: 240px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--r-3); box-shadow: var(--shadow-3);
  padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-3);
}
.range-panel[hidden] { display: none; }          /* flex would override [hidden] */
.range-panel .field { display: flex; flex-direction: column; gap: 4px;
  font-size: var(--fs-1); color: var(--text-muted); }
.range-panel input[type="date"] {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}

/* ---------------------------------------------------------------------------
   Review fixes: theming of native controls + responsive overflow
   --------------------------------------------------------------------------- */

/* #2/#13 — native date & select widgets follow the theme. Without color-scheme
   the browser paints its own picker chrome (invisible calendar icon in dark,
   a dark bar in light). */
:root[data-theme="dark"]  input[type="date"],
:root[data-theme="dark"]  input[type="datetime-local"],
:root[data-theme="dark"]  select { color-scheme: dark; }
:root[data-theme="light"] input[type="date"],
:root[data-theme="light"] input[type="datetime-local"],
:root[data-theme="light"] select { color-scheme: light; }

/* #13 — station/side pickers used an undefined --card token, so they stayed
   dark in light mode. Use real surface tokens. */
.chip-select {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
}
.form-grid input, .range-panel input[type="date"] {
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--border);
}

/* #6/#11 — nothing may overflow its card on narrow / half-screen viewports. */
.card, .kpi, .settings-content, .main { min-width: 0; }
.card > .table, .settings-content .table { display: block; overflow-x: auto; width: 100%; }
.table { table-layout: auto; }
/* `anywhere` breaks ordinary prose mid-word, which is what made the glossary
   look broken (Damon). Break only where a word genuinely cannot fit — long
   identifiers, file names — and leave sentences alone. */
.table td, .table th { overflow-wrap: break-word; word-break: normal; hyphens: none; }
.table td .mono, .table th .mono { overflow-wrap: anywhere; }
.kpi .kpi-value { overflow-wrap: break-word; }
.grid { min-width: 0; }
.grid > * { min-width: 0; }
@media (max-width: 1200px) {
  .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ov-top { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .grid-kpi { grid-template-columns: 1fr; }
}

/* #12 — honest empty state when a view has no data to draw. */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s-2); text-align: center; padding: var(--s-8) var(--s-5);
  border: 1px dashed var(--border); border-radius: var(--r-3);
  background: var(--bg-soft); color: var(--text-muted);
}
.empty-state .empty-title { font-family: var(--font-display); font-weight: 700;
  font-size: var(--fs-5); color: var(--text); }
.empty-state .ico { width: 28px; height: 28px; opacity: .6; }

/* #8 — map pins carry a permanent name/value label; popup adds detail on click */
.map-pin { display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.map-pin-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; }
.map-pin-label {
  margin-top: 3px; display: flex; flex-direction: column; align-items: center; line-height: 1.15;
  background: rgba(12, 18, 27, .82); color: #EAEEF6;
  padding: 2px 7px; border-radius: 6px; white-space: nowrap;
  font-size: 10px; font-family: var(--font-body);
}
.map-pin-label b { font-size: 10px; font-weight: 700; }
.map-pin-label span { opacity: .85; font-family: var(--font-mono); }
.map-pin:hover .map-pin-label { background: rgba(12, 18, 27, .95); }
.sensor-row.active { outline: 2px solid var(--accent); background: var(--accent-tint); }

/* #14 — logo/title are links now; keep them looking like chrome, not body links */
a.logo-block, a.topbar-title { text-decoration: none; color: inherit; }
a.logo-block:hover, a.topbar-title:hover { text-decoration: none; opacity: .9; }
