/* ============================================================
   Willow Brooks HMS v2 — Design System
   Principles distilled from taste-skill, impeccable, emil-design-eng:
   - One accent locked (gold). Sage is the brand primary. Calm neutrals.
   - One radius scale. Tinted shadows, never pure black.
   - Serif (Playfair) for headings ONLY — brand-justified. Inter for everything else.
   - Mono numerals for all data/money/counts (density 6, "daily app/cockpit").
   - Motion subtle + motivated; full prefers-reduced-motion support.
   - No AI-purple, no glow, no pure #000/#fff, no cards-in-cards.
   ============================================================ */

:root {
  /* ---- Brand ---- */
  --sage:        #506048;   /* brand primary */
  --sage-700:    #3f4c39;
  --sage-900:    #2b3527;
  --sage-050:    #eef2ea;   /* tint surfaces */
  --gold:        #c9a452;   /* THE accent — locked, used identically everywhere */
  --gold-600:    #b8923f;
  --gold-050:    #f7f0dd;

  /* ---- Neutrals (warm, calm — not pure black/white) ---- */
  --ink:         #232a24;   /* primary text (warm near-black) */
  --ink-2:       #56605a;   /* secondary text */
  --ink-3:       #8a938c;   /* tertiary / muted */
  --line:        #e4e2d8;   /* hairlines */
  --line-2:      #efeee7;   /* faint dividers */
  --paper:       #faf8f3;   /* app background (cream) */
  --surface:     #ffffff;   /* cards / panels */
  --surface-2:   #f6f4ec;   /* inset / hover */

  /* ---- Semantic status ---- */
  --ok:          #3f7d4e;  --ok-bg:   #e6f1e7;
  --warn:        #9a6b1e;  --warn-bg: #f7ecd4;
  --bad:         #a23b34;  --bad-bg:  #f7e3e1;
  --info:        #2f5d86;  --info-bg: #e2ecf4;

  /* ---- Type ---- */
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body:    'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:    'JetBrains Mono', 'SF Mono', ui-monospace, Menlo, monospace;

  /* type scale (1.2 minor third, body 14px base for density) */
  --t-xs:   11px;
  --t-sm:   12.5px;
  --t-base: 14px;
  --t-md:   16px;
  --t-lg:   19px;
  --t-xl:   24px;
  --t-2xl:  31px;
  --t-3xl:  40px;

  /* ---- Spacing (4px base) ---- */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  /* ---- Radius (ONE scale) ---- */
  --r-sm: 6px;   --r-md: 10px;  --r-lg: 14px;  --r-pill: 999px;

  /* ---- Elevation (tinted to sage, never pure black) ---- */
  --sh-1: 0 1px 2px rgba(43,53,39,.06), 0 1px 1px rgba(43,53,39,.04);
  --sh-2: 0 2px 8px rgba(43,53,39,.07), 0 1px 2px rgba(43,53,39,.05);
  --sh-3: 0 8px 28px rgba(43,53,39,.10), 0 2px 6px rgba(43,53,39,.06);
  --sh-pop: 0 16px 48px rgba(43,53,39,.18);

  /* ---- Motion ---- */
  --ease: cubic-bezier(.2,.8,.2,1);
  --dur:  .18s;

  /* ---- Layout ---- */
  --sb-w: 236px;
  --sb-w-collapsed: 64px;
  --topbar-h: 60px;
}

/* Dark mode — calm, brand stays recognisable, hierarchy parity */
@media (prefers-color-scheme: dark) {
  :root.theme-auto {
    --ink: #e8e6dd; --ink-2: #a9b0a6; --ink-3: #7c847b;
    --line: #2c332b; --line-2: #232a23;
    --paper: #171c16; --surface: #1e241d; --surface-2: #232a22;
    --sage-050: #232c20;
    --ok-bg:#1d2c20; --warn-bg:#2e2615; --bad-bg:#2e1d1a; --info-bg:#16242f;
    --sh-1: 0 1px 2px rgba(0,0,0,.3);
    --sh-2: 0 2px 8px rgba(0,0,0,.34);
    --sh-3: 0 8px 28px rgba(0,0,0,.42);
  }
}

/* ============================================================
   RESET + BASE
   ============================================================ */
*,*::before,*::after { box-sizing: border-box; }
html,body { margin:0; padding:0; }
body {
  font-family: var(--font-body);
  font-size: var(--t-base);
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1,h2,h3,h4 { font-family: var(--font-display); font-weight:600; color: var(--ink); margin:0; letter-spacing:.005em; }
h1 { font-size: var(--t-2xl); }
h2 { font-size: var(--t-xl); }
h3 { font-size: var(--t-lg); }
a { color: var(--sage); text-decoration: none; }
button { font-family: inherit; }
/* tabular numerals everywhere numbers matter */
.num, td.num, .mono, .money { font-family: var(--font-mono); font-feature-settings:"tnum" 1; }

::-webkit-scrollbar { width:10px; height:10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: var(--r-pill); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

/* ============================================================
   PRIMITIVES
   ============================================================ */

/* Buttons — one shape system, tactile :active, AA contrast */
.btn {
  display:inline-flex; align-items:center; gap:var(--s-2); justify-content:center;
  padding: 9px 16px; border-radius: var(--r-sm);
  font-size: var(--t-sm); font-weight:600; line-height:1;
  border:1px solid transparent; cursor:pointer; white-space:nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform .08s var(--ease), box-shadow var(--dur) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline:2px solid var(--gold); outline-offset:2px; }
.btn-primary   { background: var(--sage); color:#fff; }
.btn-primary:hover { background: var(--sage-700); }
.btn-gold      { background: var(--gold); color:#241f12; }
.btn-gold:hover { background: var(--gold-600); }
.btn-ghost     { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn-danger    { background: var(--bad-bg); color: var(--bad); }
.btn-danger:hover { background: var(--bad); color:#fff; }
.btn-sm { padding: 6px 11px; font-size: var(--t-xs); }
.btn-icon { padding: 8px; width:34px; height:34px; }

/* Status pills */
.pill {
  display:inline-flex; align-items:center; gap:6px;
  padding: 3px 10px; border-radius: var(--r-pill);
  font-size: var(--t-xs); font-weight:600; letter-spacing:.02em; white-space:nowrap;
}
.pill.ok   { background: var(--ok-bg);   color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad  { background: var(--bad-bg);  color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.neutral { background: var(--surface-2); color: var(--ink-2); }
.pill .dot { width:6px; height:6px; border-radius:50%; background: currentColor; }

/* Card — used only when elevation = real hierarchy */
.card {
  background: var(--surface);
  border:1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card-pad { padding: var(--s-6); }

/* KPI cell — no nested card boxes; numbers breathe */
.kpi { display:flex; flex-direction:column; gap:var(--s-1); padding: var(--s-5) var(--s-6); }
.kpi .label { font-size: var(--t-xs); letter-spacing:.08em; text-transform:uppercase; color: var(--ink-3); font-weight:600; }
.kpi .value { font-family: var(--font-mono); font-size: var(--t-2xl); font-weight:600; color: var(--ink); line-height:1.05; font-feature-settings:"tnum" 1; }
.kpi .delta { font-size: var(--t-xs); color: var(--ink-2); }
.kpi-grid { display:grid; grid-template-columns: repeat(auto-fit,minmax(150px,1fr)); }
.kpi-grid .kpi + .kpi { border-left:1px solid var(--line-2); }

/* Data table — hairline rows, sticky head, mono numerals, zebra-free */
.tbl { width:100%; border-collapse:collapse; font-size: var(--t-sm); }
.tbl thead th {
  position:sticky; top:0; z-index:1;
  text-align:left; font-size: var(--t-xs); letter-spacing:.06em; text-transform:uppercase;
  color: var(--ink-3); font-weight:600; background: var(--surface-2);
  padding: 10px 12px; border-bottom:1px solid var(--line);
}
.tbl tbody td { padding: 11px 12px; border-bottom:1px solid var(--line-2); color: var(--ink); vertical-align:middle; }
.tbl tbody tr:hover td { background: var(--sage-050); }
.tbl td.num, .tbl th.num { text-align:right; font-family: var(--font-mono); font-feature-settings:"tnum" 1; }
.tbl .empty { text-align:center; color: var(--ink-3); padding: var(--s-10); font-style:italic; }

/* Forms — label above, AA contrast, gold focus ring */
.field { display:flex; flex-direction:column; gap:6px; margin-bottom: var(--s-4); }
.field label { font-size: var(--t-xs); font-weight:600; color: var(--ink-2); letter-spacing:.02em; }
.input, select.input, textarea.input {
  width:100%; padding: 10px 12px; font-size: var(--t-sm); font-family:inherit;
  color: var(--ink); background: var(--surface);
  border:1px solid var(--line); border-radius: var(--r-sm);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input:focus, select.input:focus, textarea.input:focus {
  outline:none; border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-050);
}
.input::placeholder { color: var(--ink-3); }
.grid-2 { display:grid; grid-template-columns:1fr 1fr; gap: var(--s-4); }
.grid-3 { display:grid; grid-template-columns:1fr 1fr 1fr; gap: var(--s-4); }
@media (max-width:640px){ .grid-2,.grid-3 { grid-template-columns:1fr; } }

/* Section header */
.section-head { display:flex; align-items:center; justify-content:space-between; gap:var(--s-4); margin-bottom: var(--s-5); flex-wrap:wrap; }
.section-head h2 { display:flex; align-items:center; gap:var(--s-3); }
.section-head .sub { font-size: var(--t-sm); color: var(--ink-3); }

/* Toast */
#toastHost { position:fixed; right:20px; bottom:20px; display:flex; flex-direction:column; gap:8px; z-index:9999; pointer-events:none; }
.toast {
  pointer-events:auto; cursor:pointer; min-width:220px; max-width:380px;
  padding: 12px 16px; border-radius: var(--r-md); font-size: var(--t-sm); font-weight:500;
  box-shadow: var(--sh-pop); display:flex; gap:10px; align-items:center;
  opacity:0; transform: translateY(8px); transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.toast.show { opacity:1; transform: translateY(0); }
.toast.ok   { background: var(--sage); color:#fff; }
.toast.bad  { background: var(--bad);  color:#fff; }
.toast.info { background: var(--info); color:#fff; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration:.001ms !important; transition-duration:.001ms !important; }
}
