/* ============================================================
   theme-glass.css — shared visual re-skin for the whole MPFC suite
   (shell, MPFC, WD Logistics, Sales, Finished Goods, and the shared
   login overlay). Loaded LAST by every app's own <head>, after that
   app's own stylesheet, so these rules win the cascade without
   editing hundreds of component rules in four independently-built
   codebases. Solid, opaque colors — no glass/blur.

   BUG FIXED HERE: the previous version gave light and dark mode the
   exact same color values, so the theme toggle button visibly did
   nothing. Light and dark are now genuinely distinct palettes; only
   the sidebar/topbar (brand chrome) stays constant dark navy across
   both, which is a deliberate, common dashboard convention (e.g.
   GitHub, Slack), not an oversight.

   Two different theme mechanisms exist across the four apps, and
   the selectors below target each precisely so a fix for one can't
   silently leak into the other:
     - MPFC / Sales: attribute-based — <html data-theme="light|dark">
     - WD Logistics / Finished Goods: class-based — <body class="dark-mode">
       (light = ABSENCE of that class; scoped via "html:not([data-theme])"
       so this never accidentally matches the attribute-based apps, which
       always carry a data-theme value once loaded).
   ============================================================ */

:root{
  /* PALETTE: Refined Teal. The previous chrome was a blue from the same
     family the charts open with (#2A78D6 is series 1), so the interface
     read as one more series and the charts felt loud. Teal sits clear of
     that blue, so the chrome stops competing with the data while the
     interface still carries a colour of its own. Neutrals here are cooler
     and cleaner than the original teal build, and the text steps are
     darker for higher contrast.
     --gl-accent is the LIGHT-theme accent (carries white button text);
     --gl-accent-dim is the DARK-theme one (light enough to read on a
     near-black ground). Each is the only usable one on its own surface,
     which is why the theme blocks below swap which one --teal points at. */
  --gl-accent:#0e7c8b; --gl-accent-2:#0a616d; --gl-accent-dim:#35a3b5;
  --gl-navy:#0b2229; --gl-navy-2:#0f2c35; /* sidebar/topbar — constant in both themes */
  --gl-shadow-dark:0 6px 20px rgba(0,0,0,.38), 0 1px 2px rgba(0,0,0,.22);
  --gl-shadow-light:0 2px 10px rgba(16,32,43,.09), 0 1px 2px rgba(16,32,43,.06);

  /* Dark is also the pre-theme-resolved fallback (matches each app's own
     default), so plain :root carries the dark values. */
  --gl-page:#0b1418; --gl-surface:#121e24; --gl-surface-2:#17272e;
  --gl-text:#e9f1f3; --gl-muted:#93a6ad; --gl-line:rgba(255,255,255,.12);
  --gl-shadow:var(--gl-shadow-dark);

  --ink:var(--gl-page); --panel:var(--gl-surface); --panel-2:var(--gl-surface-2); --panel-3:#1e323b;
  --line:var(--gl-line); --text:var(--gl-text); --muted:var(--gl-muted);
  --side:var(--gl-navy); --side-2:var(--gl-navy-2); --side-line:rgba(255,255,255,.10);
  --teal:var(--gl-accent-dim); --teal-2:var(--gl-accent-2); --teal-dim:var(--gl-accent-dim);
  --head-a:var(--gl-navy); --head-b:var(--gl-navy-2); --brand:var(--gl-accent);
  --navy:var(--gl-navy); --navy2:var(--gl-navy-2); --bg:var(--gl-page); --card:var(--gl-surface);
  --blue:var(--gl-accent); --blue-d:var(--gl-accent-2);
  --gradient-accent:linear-gradient(135deg,var(--gl-accent) 0%, var(--gl-accent-2) 100%);
}

/* ---- LIGHT ---- */
:root[data-theme="light"], [data-theme="light"],
html:not([data-theme]) body:not(.dark-mode){
  --gl-page:#f2f5f6; --gl-surface:#ffffff; --gl-surface-2:#e9eef0;
  --gl-text:#14232a; --gl-muted:#5c6d75; --gl-line:#d9e2e5;
  --gl-shadow:var(--gl-shadow-light);
  --ink:var(--gl-page); --panel:var(--gl-surface); --panel-2:var(--gl-surface-2); --panel-3:#dfe7ea;
  --line:var(--gl-line); --text:var(--gl-text); --muted:var(--gl-muted);
  --bg:var(--gl-page); --card:var(--gl-surface); --teal:var(--gl-accent);
}

/* ---- DARK ---- */
:root[data-theme="dark"], [data-theme="dark"],
html:not([data-theme]) body.dark-mode{
  --gl-page:#0b1418; --gl-surface:#121e24; --gl-surface-2:#17272e;
  --gl-text:#e9f1f3; --gl-muted:#93a6ad; --gl-line:rgba(255,255,255,.12);
  --gl-shadow:var(--gl-shadow-dark);
  --ink:var(--gl-page); --panel:var(--gl-surface); --panel-2:var(--gl-surface-2); --panel-3:#1e323b;
  --line:var(--gl-line); --text:var(--gl-text); --muted:var(--gl-muted);
  --bg:var(--gl-page); --card:var(--gl-surface); --teal:var(--gl-accent-dim);
}

html, body{ background:var(--bg) !important; color:var(--text); }

/* ---- chrome: sidebar / top navigation — constant dark navy, both themes ---- */
.sidebar, .suite-topbar, .side{
  background:var(--gl-navy) !important;
  border-color:rgba(255,255,255,.08) !important;
}

/* ---- chrome: top bars / filter bars / header rows — follow the theme ---- */
.topbar, .top-header, .filterbar, .filter-bar, .page-header{
  background:var(--panel) !important;
  border-color:var(--line) !important;
}

/* ---- chrome: cards, KPI tiles, panels — follow the theme ---- */
.card, .kpi, .statgrid .s, .insightbox, .uploadbox, .snapshot-banner,
.carrier-lane-block, .ac-card{
  background:var(--panel) !important;
  border:1px solid var(--line) !important;
  box-shadow:var(--gl-shadow) !important;
  color:var(--text);
}
.card h3, .kpi .lbl{ color:var(--muted) !important; }

/* ---- chrome: modals + the shared login overlay ---- */
.modal, .modal-overlay .modal, .ac-overlay .ac-card{
  background:var(--panel-2) !important;
  border:1px solid var(--line) !important;
  box-shadow:0 20px 50px rgba(0,0,0,.35) !important;
  color:var(--text);
}
.modal-overlay, .ac-overlay{ background:rgba(4,10,14,.55) !important; }

/* ---- tables ---- */
.tablewrap, table{ background:transparent; }
thead th{ background:var(--panel-2) !important; color:var(--muted) !important; }
tbody tr:hover{ background:rgba(15,109,125,.08) !important; }
td, th{ color:var(--text); border-color:var(--line) !important; }

/* ---- inputs ---- */
input, select, textarea{ background:var(--panel-2) !important; color:var(--text) !important; border-color:var(--line) !important; }
/* A <select> with no width sizes itself to its LONGEST option, so one verbose
   entry ("Kiwiplan Sales Summary (no data imported yet)") makes the control
   wider than a phone screen and puts the whole page into horizontal scroll.
   max-width caps it at its container; the option list still opens at full
   width when tapped. */
input, select, textarea{ max-width:100%; min-width:0; }

/* ---- buttons — INK, and the ink flips with the theme ----
   A near-black button reads as "the primary action" on a light page, but
   disappears into a near-black page. So dark mode inverts it: a light
   button carrying dark text. --btn-bg/--btn-fg are set per theme block
   below; the base values here are the dark ones, matching the pre-theme
   fallback the rest of this file uses. */
:root{ --btn-bg:var(--gl-accent-dim); --btn-fg:#04191d; }
:root[data-theme="light"], [data-theme="light"],
html:not([data-theme]) body:not(.dark-mode){ --btn-bg:var(--gl-accent); --btn-fg:#ffffff; }
:root[data-theme="dark"], [data-theme="dark"],
html:not([data-theme]) body.dark-mode{ --btn-bg:var(--gl-accent-dim); --btn-fg:#04191d; }

.btn:not(.secondary):not(.danger){ background:var(--btn-bg) !important; color:var(--btn-fg) !important; }
.btn:not(.secondary):not(.danger):hover{ filter:brightness(1.12); }
.navlist a.active, .suite-tabs button.active{ background:var(--btn-bg) !important; color:var(--btn-fg) !important; }

/* ---- large accent-filled bars carry WHITE text, so they must use the DARK
   accent in BOTH themes ----
   MPFC's sticky year bar fills itself with linear-gradient(--teal, --teal-2),
   and --teal points at the light accent (#3D97CF) under the dark theme —
   white on that is 3.2:1, below the 4.5:1 an interface owes body text.
   Pinning the fill to --gl-accent/--gl-accent-2 puts it at 6.6:1 and, as a
   bonus, keeps the bar looking the same in both themes like every other
   piece of brand chrome here. */
#yearBar{
  background:linear-gradient(90deg, var(--gl-accent), var(--gl-accent-2)) !important;
  color:#fff !important;
}

/* ---- RTL: keep machine-formatted values left-to-right ----
   Date, time and number inputs render their segments in the container's
   direction. Under dir="rtl" that reorders a date's own parts on screen —
   Safari shows 29/08/2026 as "2026/29/08" — so the field reads as a
   different date than it holds. Pinning these controls to LTR keeps the
   segment order the user typed; the label beside them stays RTL, and the
   field is still laid out on the correct (right) side of the form because
   only the text direction inside the control is overridden.
   Same reasoning for the monospace/tabular numeric cells: a bare number is
   direction-neutral, but a value carrying Latin punctuation (1,234.5 / +12%
   / 2026-08-29) gets its trailing sign or unit flipped to the wrong end. */
html[dir="rtl"] input[type="date"],
html[dir="rtl"] input[type="datetime-local"],
html[dir="rtl"] input[type="month"],
html[dir="rtl"] input[type="time"],
html[dir="rtl"] input[type="week"],
html[dir="rtl"] input[type="number"],
html[dir="rtl"] input[type="tel"]{
  direction:ltr;
  text-align:start;
}
/* Table cells were authored with a physical `text-align:left` (WD and FG;
   Sales/MPFC patched only some of their tables). Under dir="rtl" that pushes
   every column's content to the far (left) side of its cell, so the first
   column floats away from the right card edge and the whole table reads as
   "not filling the width". Align to the reading edge instead — this matches
   what Sales' own .data-table RTL rule and MPFC's dynamic CSS already do. */
html[dir="rtl"] th,
html[dir="rtl"] td{
  text-align:right;
}
html[dir="rtl"] td.num,
html[dir="rtl"] th.num,
html[dir="rtl"] .num,
html[dir="rtl"] .kpi .val,
html[dir="rtl"] .kpi-value{
  direction:ltr;
  unicode-bidi:isolate;
}

/* ---- Suite filter bar (shared component: suite-filterbar.js) ---- */
.sfb{margin:10px 0}
.sfb-row{display:flex;gap:10px;flex-wrap:wrap;align-items:flex-end}
.sfb-f{display:flex;flex-direction:column;gap:3px;font-size:11.5px;color:var(--muted);min-width:0}
.sfb-f span{padding-inline-start:2px}
.sfb-f select,.sfb-f input{min-width:120px;max-width:190px;padding:6px 9px;border-radius:8px;font:inherit;font-size:12.5px}
.sfb-f input[type="search"]{min-width:170px}
.sfb-spacer{flex:1}
.sfb-btn,.sfb-preset{padding:6px 12px;border-radius:8px;border:1px solid var(--line);
  background:var(--panel-2);color:var(--text);font:inherit;font-size:12px;cursor:pointer}
.sfb-btn:hover{border-color:var(--gl-accent)}
.sfb-chips{display:flex;gap:6px;flex-wrap:wrap;margin-top:8px}
.sfb-chips:empty{display:none}
.sfb-chip{display:inline-flex;align-items:center;gap:7px;font-size:11.5px;
  background:var(--accent-soft,rgba(15,109,125,.10));color:var(--text);
  border:1px solid var(--gl-accent);border-radius:20px;padding:3px 11px}
.sfb-chip b{cursor:pointer;font-weight:700;color:var(--gl-accent)}
.sfb-chip b:hover{color:var(--gl-accent-2)}
.sfb-chip.sfb-clear{background:transparent;border-style:dashed;color:var(--muted);cursor:pointer}
.sfb-chip.sfb-clear:hover{color:var(--text)}

/* ---- Data-freshness badge (shared component: suite-freshness.js) ---- */
.sfr{display:inline-block;font-size:11px;font-weight:600;border-radius:20px;
  padding:1px 9px;margin-inline-start:8px;white-space:nowrap;vertical-align:1px}
.sfr-fresh{background:rgba(26,127,75,.14);color:#1a7f4b}
.sfr-warn{background:rgba(176,106,0,.16);color:#b06a00}
.sfr-stale{background:rgba(179,54,42,.16);color:#b3362a}
.sfr-never{background:rgba(120,130,140,.16);color:var(--muted)}
html[dir="rtl"] .sfr{unicode-bidi:isolate}
