/* Shared appearance layer. Loaded after each workspace's component styles.
   Images, receipt pages and outgoing email keep their original colours.

   B53 (Ahmed, 9 Nov 2026): dark mode uses neutral charcoal surfaces,
   softer off-white text and a muted slate-blue primary. Header, ground,
   panel and field each use the matching semantic role. Secondary controls
   keep visible borders and keyboard focus in both appearances. */
:root {
  color-scheme: light;
  --sag-app:#E1E7EA;
  --sag-surface:#FBFCFC;
  --sag-hover:#F0F4F5;
  --sag-selected:#E3EBEE;
  --sag-text:#11191D;
  --sag-text-2:#2C4550;
  --sag-text-3:#56666C;
  --sag-icon:#6F8187;
  --sag-line:#D3DCDF;
  --sag-line-strong:#7E9199;
  --sag-primary:#1B3038;
  --sag-on-primary:#FFFFFF;
  --sag-focus:#1B3038;
  --sag-ok:#1F7A53; --sag-ok-fg:#14563B; --sag-ok-bg:#DFF0E6;
  --sag-wait:#A57712; --sag-wait-fg:#6B510C; --sag-wait-bg:#FAEDC6;
  --sag-risk:#B4472A; --sag-risk-fg:#8A331C; --sag-risk-bg:#F7DFD6;
  --sag-idle:#76878D; --sag-idle-fg:#4E5F65; --sag-idle-bg:#E9EEF0;
  --sag-slate:#3F5878; --sag-slate-fg:#2F4560; --sag-slate-bg:#E1E9F3;
  --sag-pay-company:#3F5878; --sag-pay-company-fg:#2F4560; --sag-pay-company-bg:#E6EDF6;
  --sag-pay-petty:#A57F1A; --sag-pay-petty-fg:#6B5410; --sag-pay-petty-bg:#F8EFD6;
  --sag-shadow-1:0 1px 2px rgba(17,32,40,.06), 0 3px 10px -4px rgba(17,32,40,.10), 0 0 0 1px var(--theme-edge);
  --sag-shadow-2:0 18px 40px -12px rgba(17,32,40,.30), 0 0 0 1px var(--theme-edge);
  --sag-ring:0 0 0 2px var(--sag-surface), 0 0 0 5px rgba(27,48,56,.35);
  --theme-field:#FFFFFF;
  --theme-edge:#D0D9DD;
  --theme-primary-hover:#284652;
  --theme-chart:#1B3038;
  --theme-wheel-fill:#C6D5DB;
  --theme-wheel-fill-on:#AFC4CC;
  --theme-ok-line:#9CCBB1;
  --theme-wait-line:#E1C06C;
  --theme-risk-line:#E0A693;
  --theme-topbar:#1B3038;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --sag-app:#1B2026;
  --sag-surface:#252C34;
  --sag-hover:#303A44;
  --sag-selected:#354450;
  --sag-text:#E1E6EB;
  --sag-text-2:#BFC9D2;
  --sag-text-3:#A5B2BE;
  --sag-icon:#99AAB7;
  --sag-line:#3B4652;
  --sag-line-strong:#728497;
  /* Muted slate blue keeps the primary distinct without a bright white fill. */
  --sag-primary:#AAC7D8;
  --sag-on-primary:#18232B;
  --sag-focus:#AAC7D8;
  --sag-ok:#4FB585; --sag-ok-fg:#8FD3B0; --sag-ok-bg:#15332A;
  --sag-wait:#E0B23F; --sag-wait-fg:#F2CF6B; --sag-wait-bg:#352C12;
  --sag-risk:#E07A5C; --sag-risk-fg:#F0A58E; --sag-risk-bg:#3E2119;
  --sag-idle:#99AAB7; --sag-idle-fg:#B8C6CC; --sag-idle-bg:#1F2C33;
  --sag-slate:#8EA7C7; --sag-slate-fg:#C3D2E6; --sag-slate-bg:#1B2939;
  --sag-pay-company:#8EA7C7; --sag-pay-company-fg:#C3D2E6; --sag-pay-company-bg:#172433;
  --sag-pay-petty:#D9B64A; --sag-pay-petty-fg:#EBD48A; --sag-pay-petty-bg:#2C2614;
  --sag-shadow-1:0 1px 2px rgba(0,0,0,.4), 0 0 0 1px var(--theme-edge);
  --sag-shadow-2:0 20px 44px -12px rgba(0,0,0,.7), 0 0 0 1px var(--theme-edge);
  --sag-ring:0 0 0 2px var(--sag-surface), 0 0 0 5px rgba(170,199,216,.45);
  --sag-ring-inset:inset 0 0 0 2px var(--sag-primary);
  --theme-field:#20272E;
  --theme-edge:#465360;
  --theme-primary-hover:#BED7E5;
  /* Charts follow the same muted slate-blue accent. */
  --theme-chart:#90B4C9;
  --theme-wheel-fill:#354450;
  --theme-wheel-fill-on:#486073;
  --theme-ok-line:#3D7A5C;
  --theme-wait-line:#8A7337;
  --theme-risk-line:#8E5646;
  --theme-topbar:#222A32;
}
/* Older workspace aliases resolve to these same roles, without changing the
   brand constants used by printed documents and outgoing messages. */
:root, :root[data-theme="dark"] {
  --line:var(--sag-line); --line-2:var(--sag-hover);
  --muted:var(--sag-text-3); --green:var(--sag-primary);
  --gold:var(--sag-primary); --red:var(--sag-risk-fg);
  --ink:var(--sag-text); --ink-2:var(--sag-text-2);
  --paper:var(--sag-app); --surface:var(--sag-surface);
  --cream:var(--sag-selected); --line-strong:var(--sag-line-strong);
  --sage-line:var(--theme-ok-line); --sky:var(--sag-text-2);
  --sag-bg:var(--sag-app); --sag-field:var(--theme-field);
  --sag-field-2:var(--sag-hover);
  --sag-ink-2:var(--sag-text-2); --sag-ink-3:var(--sag-text-3);
  --navy-950:var(--sag-text); --navy-900:var(--sag-primary);
  --navy-800:var(--sag-primary); --navy-700:var(--sag-text-2);
  --green-soft:var(--sag-ok-bg); --blue:var(--sag-slate-fg);
  --blue-soft:var(--sag-slate-bg); --amber:var(--sag-wait-fg);
  --amber-soft:var(--sag-wait-bg); --red-soft:var(--sag-risk-bg);
}
html { background:var(--sag-app); }
body { color:var(--sag-text); background-color:var(--sag-app); }
:where(input[type="date"], input[type="month"], input[type="time"]) {
  background-color:var(--theme-field); color:var(--sag-text);
}
:where(input, textarea)::placeholder { color:var(--sag-text-3); opacity:1; }
/* B56: one dropdown standard for Lists, Email Template and Document Control.
   The actual select remains in charge of forms, labels, keyboard and events.
   Unsupported browsers retain their native picker. */
html select:not([multiple]):not([size]) {
  box-sizing:border-box; min-height:34px; max-width:100%;
  padding:6px 10px; border:1px solid var(--sag-line-strong); border-radius:8px;
  background-color:var(--sag-field); background-image:none; color:var(--sag-text);
  font:500 13px/1.25 var(--sag-font); cursor:pointer; text-overflow:ellipsis;
  box-shadow:none;
}
html select:not([multiple]):not([size]):hover:not(:disabled) { border-color:var(--sag-text-2); }
html select:not([multiple]):not([size]):focus-visible {
  outline:2px solid var(--sag-focus); outline-offset:2px; box-shadow:none;
}
html select:not([multiple]):not([size]):disabled { cursor:default; opacity:.6; }
@supports (appearance:base-select) {
  html select:not([multiple]):not([size]),
  html select:not([multiple]):not([size])::picker(select) { appearance:base-select; }
  html select:not([multiple]):not([size]) { align-items:center; align-content:center; gap:10px; }
  html select:not([multiple]):not([size])::picker-icon {
    content:''; width:7px; height:7px; flex:none; margin-inline-start:auto; margin-inline-end:2px;
    border:solid var(--sag-text-2); border-width:0 1.5px 1.5px 0; rotate:45deg; translate:0 -2px;
  }
  html select:not([multiple]):not([size]):open::picker-icon { rotate:225deg; translate:0 2px; }
  html select:not([multiple]):not([size])::picker(select) {
    box-sizing:border-box; margin:5px 0; padding:5px;
    border:1px solid var(--sag-line-strong); border-radius:10px;
    background:var(--sag-surface); color:var(--sag-text); box-shadow:var(--sag-shadow-2);
    max-height:min(360px,60dvh); max-width:calc(100vw - 24px); overflow:auto;
    overscroll-behavior:contain; scrollbar-width:thin; scrollbar-color:var(--sag-line-strong) transparent;
  }
  html select:not([multiple]):not([size]) option {
    display:flex; align-items:center; gap:12px; min-height:32px; padding:7px 10px;
    border-radius:6px; background:transparent; color:var(--sag-text);
    font:500 13px/1.4 var(--sag-font); cursor:pointer; white-space:normal; overflow-wrap:anywhere;
  }
  html select:not([multiple]):not([size]) option:checked { background:var(--sag-selected); font-weight:650; }
  html select:not([multiple]):not([size]) option:is(:hover,:focus-visible) {
    background:var(--sag-hover); outline:none;
  }
  html select:not([multiple]):not([size]) option::checkmark { order:1; margin-inline-start:auto; color:var(--sag-primary); }
  html select:not([multiple]):not([size]) option:disabled { color:var(--sag-text-3); cursor:default; }
  html select:not([multiple]):not([size]) optgroup { padding:4px 0; font:600 12px/1.4 var(--sag-font); color:var(--sag-text-3); }
}
@media (pointer:coarse) {
  html select:not([multiple]):not([size]) { min-height:44px; font-size:16px; }
  html select:not([multiple]):not([size]) option { min-height:44px; font-size:14px; }
}
body:has(#app), body:has(.workspace-shell), body:has(#app-scroll) {
  background-image:none;
  background-attachment:fixed;
}

/* ── The top bar: the brand's panel colour ──
   In light mode the bar is a dark island, so its own roles are set here and
   the page's older aliases are pointed at them again inside it (an alias set
   on :root keeps the :root value, so it has to be restated where the roles
   change). In dark mode it is a step above the ground. */
:root:not([data-theme="dark"]) .topbar {
  color-scheme:dark;
  --sag-app:#1B3038; --sag-surface:#24404A; --sag-hover:#2B4A55; --sag-selected:#335662;
  --sag-text:#F4F8F9; --sag-text-2:#CFDDE2; --sag-text-3:#A9BEC5; --sag-icon:#9DB4BC;
  --sag-line:#34525D; --sag-line-strong:#6F8D98; --theme-edge:#34525D;
  --sag-primary:#F4F8F9; --sag-on-primary:#1B3038; --theme-primary-hover:#FFFFFF;
  --sag-shadow-1:0 0 0 1px #34525D;
  --sag-ring:0 0 0 2px #1B3038, 0 0 0 5px rgba(249,201,57,.55);
}
.topbar {
  --paper:var(--sag-app); --paper-2:var(--sag-surface); --surface:var(--sag-surface); --surface-2:var(--sag-hover);
  --ink:var(--sag-text); --ink-2:var(--sag-text-2); --muted:var(--sag-text-3);
  --line:var(--sag-line); --line-2:var(--sag-hover);
  --gold:var(--sag-primary); --gold-soft:var(--sag-selected); --shadow-1:var(--sag-shadow-1);
  color:var(--sag-text);
  border-bottom-color:var(--theme-edge);
  box-shadow:0 2px 12px -6px rgba(10,20,26,.45);
}
.topbar::before { background:var(--theme-topbar); }
/* What is on: the selected tab and language are the primary, filled. */
.topbar :is(.nav, .lang, .tb-dock) { background:var(--sag-surface); box-shadow:inset 0 0 0 1px var(--sag-line); }
.topbar :is(.nav, .lang) button { color:var(--sag-text-2); }
.topbar :is(.nav, .lang) button:hover { color:var(--sag-text); }
.topbar :is(.nav, .lang) button.on {
  background:var(--sag-primary); color:var(--sag-on-primary); box-shadow:0 1px 3px rgba(0,0,0,.25);
}
/* The tabs' sliding pill (lists-density.css) draws the selected tab's ground. */
.topbar #nav > .tab-pill { background:var(--sag-primary); box-shadow:0 1px 3px rgba(0,0,0,.25); }
.topbar .icon-btn { color:var(--sag-text-2); }
.topbar .icon-btn:hover { background:var(--sag-hover); color:var(--sag-text); }

/* ── Buttons ──
   The primary is the one solid thing in a row of buttons; a secondary has an
   edge in both themes; every button answers a hover and a press. Sizes are
   untouched (UI_RULES §11). */
.btn { transition:background .14s var(--sag-ease), box-shadow .14s var(--sag-ease), transform .08s var(--sag-ease); }
.btn:active:not(:disabled) { transform:translateY(1px); }
.btn-gold, .btn-ink {
  background:var(--sag-primary); color:var(--sag-on-primary);
  box-shadow:0 1px 2px rgba(17,32,40,.22), inset 0 1px 0 rgba(255,255,255,.10);
}
.btn-gold:hover:not(:disabled), .btn-ink:hover:not(:disabled) {
  background:var(--theme-primary-hover); box-shadow:0 4px 10px -3px rgba(17,32,40,.35), inset 0 1px 0 rgba(255,255,255,.10);
}
.btn-ghost { background:var(--sag-surface); color:var(--sag-text); box-shadow:var(--sag-shadow-1); }
.btn-ghost:hover:not(:disabled) { background:var(--sag-hover); box-shadow:0 1px 2px rgba(17,32,40,.08), 0 0 0 1px var(--sag-line-strong); }
.btn-clay:hover:not(:disabled) { background:var(--sag-risk-bg); box-shadow:0 0 0 1px var(--theme-risk-line); }
.btn:focus-visible { box-shadow:var(--sag-ring); }
.icon-btn:hover { background:var(--sag-hover); color:var(--sag-text); }

/* B53: secondary actions need a visible face and boundary on dark panels. */
:root[data-theme="dark"] :is(.btn-ghost,.account-action:not(.primary),.account-copy,.account-line-btn:not(.primary),.access-trigger,.document-duty:not([aria-pressed="true"])) {
  background:var(--sag-hover); border-color:var(--sag-line-strong); box-shadow:none;
}
:root[data-theme="dark"] :is(.btn-ghost,.account-action:not(.primary),.account-copy,.account-line-btn:not(.primary),.access-trigger,.document-duty:not([aria-pressed="true"])):hover:not(:disabled) {
  background:var(--sag-selected); border-color:var(--sag-text-3);
}
.account-language button.on { background:var(--sag-primary); color:var(--sag-on-primary); box-shadow:none; }
.account-language button:focus-visible { outline:2px solid var(--sag-primary); outline-offset:2px; box-shadow:var(--sag-ring); }
:root[data-theme="dark"] :is(.btn-ghost,.account-action,.account-copy,.account-line-btn,.access-trigger,.document-duty):focus-visible {
  outline:2px solid var(--sag-primary); outline-offset:2px; box-shadow:var(--sag-ring);
}
:root[data-theme="dark"] :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),textarea,select) {
  border-color:var(--sag-line-strong);
}

/* ── The theme switch ──
   A sun and a moon on one track, with the knob -- the primary, filled, like
   the selected tab -- under the one in use. */
button.sag-theme-toggle {
  display:inline-flex; align-items:center; flex:0 0 auto;
  width:auto; height:32px; padding:3px; border-radius:999px;
  border:1px solid var(--sag-line); background:var(--sag-surface);
  color:var(--sag-icon); cursor:pointer;
  transition:border-color .16s var(--sag-ease), background .16s var(--sag-ease);
}
button.sag-theme-toggle:hover { border-color:var(--sag-line-strong); }
button.sag-theme-toggle:focus-visible { box-shadow:var(--sag-ring); }
.sag-theme-track { position:relative; display:inline-flex; align-items:center; gap:2px; height:100%; }
.sag-theme-icon {
  position:relative; z-index:1; display:grid; place-items:center; width:26px; height:100%;
  color:var(--sag-text-3); transition:color .2s var(--sag-ease);
}
.sag-theme-icon svg { width:15px; height:15px; flex:none; pointer-events:none; }
.sag-theme-knob {
  position:absolute; left:0; top:0; width:26px; height:100%; border-radius:999px;
  background:var(--sag-primary); box-shadow:0 1px 3px rgba(0,0,0,.25);
  transition:transform .26s var(--sag-ease);
}
:root[data-theme="dark"] .sag-theme-knob { transform:translateX(28px); }
:root:not([data-theme="dark"]) .sag-theme-icon.is-sun,
:root[data-theme="dark"] .sag-theme-icon.is-moon { color:var(--sag-on-primary); }
.sag-topbar .sag-theme-toggle { order:1; margin-left:auto; }
.sag-topbar .email-verified-user { order:2; margin-left:0; }
/* Keep the existing photograph and orbit, with a calmer glass surface that
   follows the selected theme. */
.gate {
  --lg-bg:var(--sag-surface); --lg-field:var(--sag-hover);
  --lg-field-2:var(--sag-selected); --lg-ink:var(--sag-text);
  --lg-ink-2:var(--sag-text-2); --lg-ink-3:var(--sag-text-3);
  --lg-line:var(--sag-line); --lg-gold:var(--sag-text-2);
  --lg-gold-2:var(--sag-line-strong);
  --ws-ink:var(--sag-text); --ws-ink-2:var(--sag-text-2);
  --ws-ink-3:var(--sag-text-3); --ws-line:var(--sag-line);
  --ws-glass:color-mix(in srgb,var(--sag-surface) 84%,transparent);
  --ws-glass-2:var(--sag-selected); --ws-cream:var(--sag-surface);
}
:root[data-theme="light"] .gate::before {
  background:linear-gradient(90deg,rgba(225,231,234,.99),rgba(225,231,234,.96) 36%,rgba(225,231,234,.78) 72%,rgba(225,231,234,.62));
}
:root[data-theme="light"] .login-art::before { opacity:.15; }
:root[data-theme="dark"] .gate::before {
  background:linear-gradient(90deg,rgba(11,19,23,.98),rgba(11,19,23,.93) 36%,rgba(11,19,23,.74) 72%,rgba(11,19,23,.58));
}
.workspace-top .sag-theme-toggle { align-self:center; }
.gate .ws-ico { background:var(--sag-surface); }
.gate .ws-node.gold .ws-ico svg, .gate .ws-node.cream .ws-ico svg { color:#243E49; }
:root[data-theme="light"] .ws-motto span { text-shadow:none; }
.workspace-title em {
  background:none; color:var(--sag-text-2); -webkit-text-fill-color:currentColor;
}
.bgt {
  --bg-ink:var(--theme-chart); --bg-ink-soft:var(--sag-icon);
  --bg-wash:var(--sag-selected); --bg-grid:var(--sag-line);
  --bg-good:var(--sag-ok); --bg-good-soft:var(--theme-ok-line);
  --bg-good-wash:var(--sag-ok-bg); --bg-low:var(--sag-wait);
  --bg-low-soft:var(--theme-wait-line); --bg-low-wash:var(--sag-wait-bg);
  --bg-over:var(--sag-risk); --bg-over-soft:var(--theme-risk-line);
  --bg-over-wash:var(--sag-risk-bg);
}
/* The months wheel's lines: their fills were fixed light tints, so in dark the
   month's words sat on a pale blob. The words stay readable on every fill. */
.bgt-wm-line { background:var(--sag-surface); }
.bgt-wm-line i { background:var(--theme-wheel-fill); }
.bgt-wm.on .bgt-wm-line i { background:var(--theme-wheel-fill-on); }
.bgt-wm.went-over .bgt-wm-line i { background:var(--sag-risk-bg); }
.bgt-wm.went-over .bgt-wm-line { box-shadow:inset 0 0 0 1px var(--theme-risk-line); }
/* The older Document Control pilot uses the same palette as the main workspace. */
.app-shell .sidebar { background:var(--sag-app); color:var(--sag-text); }
.app-shell :is(.nav-item,.collection-button,.back-link,.brand-block span,.local-card span:not(.pulse-dot)) {
  color:var(--sag-text-2);
}
.app-shell :is(.nav-item,.collection-button,.back-link):hover {
  background:var(--sag-hover); color:var(--sag-text);
}
.app-shell .nav-item.is-active { background:var(--sag-selected); color:var(--sag-text); }
.app-shell .nav-item.is-active > span { color:var(--sag-text); }
.app-shell .hero-copy { background:var(--sag-surface); color:var(--sag-text); }
.app-shell .hero-copy p { color:var(--sag-text-2); }
.app-shell .hero-copy .text-button { color:var(--sag-text-2); }
.app-shell .primary-button { background:var(--sag-primary); color:var(--sag-on-primary); }
.app-shell .primary-button:hover { background:var(--theme-primary-hover); }
body:has(.app-shell) .toast.error { background:var(--sag-risk-bg); color:var(--sag-risk-fg); }
/* Generated documents stay a faithful paper preview in either appearance. */
#preview-wrap, .attach-doc { color-scheme:light; }
@media (pointer:coarse) {
  /* Wider than the bar's other 44px icon buttons (density/account.css), or the moon is cut off. */
  button.sag-theme-toggle, .topbar button.sag-theme-toggle { width:auto; height:44px; padding:4px; }
  .sag-theme-icon, .sag-theme-knob { width:34px; }
  :root[data-theme="dark"] .sag-theme-knob { transform:translateX(36px); }
}
@media (max-width:600px) {
  .login-brand { gap:8px; }
  .login-brand span { max-width:calc(100vw - 248px); font-size:12px; line-height:1.3; }
  .login-brand img { flex:0 0 36px; }
  .login-nav { display:none; }
}
@media print {
  .sag-theme-toggle { display:none !important; }
}
