/* ============================================================
   CNSVCS — theme.css
   Dark (default) and light themes for the portal, admin, estimates
   and login pages. Load after the other stylesheets. js/theme-init.js sets
   <html data-theme="dark|light"> before first paint.
   ============================================================ */

/* ── Tokens shared by both themes (dark values) ── */
:root {
  color-scheme: dark;

  /* Dark palette (same values as main.css, repeated so pages that don't load
     main.css — admin, estimates — get every token from this file) */
  --color-bg-primary:      #080A0C;
  --color-bg-secondary:    #0E1114;
  --color-bg-tertiary:     #141820;
  --color-surface:         #1A1F28;
  --color-bg-footer:       #050608;
  --color-card:            #0E1114;
  --color-input-bg:        #111416;
  --color-border-subtle:   rgba(255, 255, 255, 0.06);
  --color-border-default:  rgba(255, 255, 255, 0.10);
  --color-border-emphasis: rgba(255, 255, 255, 0.18);
  --color-border:          rgba(255, 255, 255, 0.10);
  --color-accent:          #C8A96E;
  --color-accent-strong:   #A88E5A;
  --color-accent-dim:      rgba(200, 169, 110, 0.15);
  --color-accent-glow:     rgba(200, 169, 110, 0.08);
  --color-text-primary:    #F0EDE8;
  --color-text-secondary:  #8A9099;
  --color-text-inverse:    #080A0C;

  /* RGB channels for translucent overlays: rgba(var(--fg-rgb), .05) */
  --fg-rgb:     255, 255, 255;
  --accent-rgb: 200, 169, 110;
  --bg-rgb:     8, 10, 12;          /* page background, for translucent bars */

  /* Status text (also used for status borders/dots) */
  --color-danger-text:  #F87171;
  --color-success-text: #4ADE80;
  --color-warning-text: #FB923C;
  --color-info-text:    #60A5FA;
  --color-accent-text:  #C8A96E;

  /* Was #4A5260 (2.5:1 on the page background); now 5.3:1 */
  --color-text-muted: #7C8593;

  /* Referenced by the portal but never defined */
  --font-body: var(--font-heading);
  --font-sans: var(--font-heading);
  --font-ui:   var(--font-heading);
  --space-7:   28px;
  --text-muted: var(--color-text-muted);
}

/* ── Light theme ── */
:root[data-theme="light"] {
  color-scheme: light;

  --fg-rgb:     20, 24, 32;
  --accent-rgb: 148, 114, 58;
  --bg-rgb:     247, 245, 240;

  --color-bg-primary:   #F7F5F0;
  --color-bg-secondary: #FFFFFF;
  --color-bg-tertiary:  #EFECE5;
  --color-surface:      #FFFFFF;
  --color-bg-footer:    #EDEAE3;
  --color-card:         #FFFFFF;
  --color-input-bg:     #FFFFFF;

  --color-border-subtle:   rgba(20, 24, 32, 0.08);
  --color-border-default:  rgba(20, 24, 32, 0.12);
  --color-border-emphasis: rgba(20, 24, 32, 0.22);
  --color-border:          rgba(20, 24, 32, 0.12);

  --color-accent:      #94723A;
  --color-accent-dim:  rgba(148, 114, 58, 0.14);
  --color-accent-glow: rgba(148, 114, 58, 0.08);
  --color-accent-text: #80612A;
  --color-accent-strong: #7A5C24;

  --color-text-primary:   #16191F;
  --color-text-secondary: #4B5361;
  --color-text-muted:     #636B78;
  --color-text-inverse:   #080A0C;

  --color-danger-text:  #B42318;
  --color-success-text: #147A3D;
  --color-warning-text: #B54708;
  --color-info-text:    #1D5FC9;
}

/* Hand-off between themes without animating every element */
:root.theme-switching *,
:root.theme-switching *::before,
:root.theme-switching *::after {
  transition: none !important;
}

/* Light theme: separate panels with hairlines/shadows instead of tone alone */
:root[data-theme="light"] .portal-sidebar { box-shadow: 1px 0 0 var(--color-border-subtle); }
:root[data-theme="light"] .portal-card,
:root[data-theme="light"] .kpi-card { box-shadow: 0 1px 2px rgba(20, 24, 32, 0.05); }

/* Home hero: the top-right blob fades through a near-black stop, which is a
   grey smudge on paper; use a soft gold glow instead */
:root[data-theme="light"] .hero__bg::before {
  background: radial-gradient(ellipse at center,
    rgba(var(--accent-rgb), 0.10) 0%, rgba(var(--accent-rgb), 0.04) 45%, transparent 70%);
}

/* Primary button hover: main.css lightens to #D4B97E, which jumps too far from
   the darker light-mode gold; a small step keeps it a hover, not a new color */
:root[data-theme="light"] .btn--primary:hover { background: #A4824A; border-color: #A4824A; }

/* ── Theme toggle (portal top bar) ── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md, 8px);
  border: 1px solid var(--color-border-default);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--color-text-primary); border-color: var(--color-border-emphasis); }
.theme-toggle:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .theme-toggle__sun { display: none; }
:root[data-theme="light"] .theme-toggle .theme-toggle__sun { display: block; }
:root[data-theme="light"] .theme-toggle .theme-toggle__moon { display: none; }

/* Login, password reset, vendor sign-up: toggle in the top-right corner */
.theme-toggle--corner { position: absolute; top: 20px; right: 20px; z-index: 2; }
.theme-toggle--fixed  { position: fixed; }
.nav__theme-toggle { width: 34px; height: 34px; }

/* Admin and estimates: the toggle sits with the other header buttons */
.adm-topbar-actions .theme-toggle,
.header__actions .theme-toggle { width: 34px; height: 34px; }
