/* ──────────────────────────────────────────────────────────────────
   HT OS Design System v1
   Home Therapist brand (Pantone 660 / 299 / 333 + gold), Radio Canada Big,
   4px grid, WCAG AA, touch-first (44px min), dark-mode ready.

   Prefix: .ds-*  — does not collide with existing .htos-* classes.
   ────────────────────────────────────────────────────────────────── */

/* ────── Tokens ────── */
:root {
  color-scheme: light dark;

  /* Brand — from Home Therapist_Guidelines.pdf */
  --brand-royal: #3D7CC9;      /* Pantone 660 C — primary */
  --brand-royal-ink: #1E4F8A;  /* darker, for text-on-light + hover */
  --brand-royal-soft: #E6EEF9;
  --brand-sky: #00A0DF;        /* Pantone 299 C — secondary */
  --brand-sky-ink: #006A96;
  --brand-sky-soft: #E0F4FC;
  --brand-mint: #2ED9C3;       /* Pantone 333 C — accent */
  --brand-mint-ink: #158F7D;
  --brand-mint-soft: #E1F9F4;
  --brand-gold-a: #D4A94A;
  --brand-gold-b: #F4D97B;
  --brand-gold-grad: linear-gradient(135deg, var(--brand-gold-a) 0%, var(--brand-gold-b) 100%);

  /* Semantic */
  --accent: var(--brand-royal);
  --accent-ink: var(--brand-royal-ink);
  --accent-soft: var(--brand-royal-soft);
  --success: #16A870;
  --success-soft: #E1F5EC;
  --warn: #E08A1E;
  --warn-soft: #FCEFD9;
  --danger: #DC2E2E;
  --danger-soft: #FBE3E3;
  --info: var(--brand-sky);
  --info-soft: var(--brand-sky-soft);

  /* Neutrals — light */
  --bg: #F6F8FB;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --surface-3: #E7ECF3;
  --surface-overlay: rgba(255, 255, 255, 0.85);
  --border: #DFE5EE;
  --border-subtle: #ECEFF4;
  --ink: #0E1B33;
  --ink-2: #3C4A64;
  --ink-3: #64728A;
  --muted: #8A94A7;

  /* Type */
  --font-sans: 'Radio Canada Big', -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Type scale (1.125 ratio from 14px base — readable, dense enough for tools) */
  --text-xs:   0.75rem;     /* 12 — meta, captions */
  --text-sm:   0.8125rem;   /* 13 — table cells, dense UI */
  --text-base: 0.9375rem;   /* 15 — body default, up from old 14 */
  --text-md:   1rem;        /* 16 — comfortable reading */
  --text-lg:   1.125rem;    /* 18 — card titles */
  --text-xl:   1.375rem;    /* 22 — section headers */
  --text-2xl:  1.75rem;     /* 28 — page titles */
  --text-3xl:  2.25rem;     /* 36 — hero */
  --text-4xl:  3rem;        /* 48 — marketing */

  --lh-tight:  1.15;
  --lh-snug:   1.3;
  --lh-normal: 1.5;
  --lh-loose:  1.65;

  --tracking-tight: -0.02em;
  --tracking-snug:  -0.01em;
  --tracking-wide:   0.04em;

  /* Spacing (4px grid) */
  --s-0:  0;
  --s-1:  4px;
  --s-2:  8px;
  --s-3:  12px;
  --s-4:  16px;
  --s-5:  20px;
  --s-6:  24px;
  --s-7:  28px;
  --s-8:  32px;
  --s-10: 40px;
  --s-12: 48px;
  --s-16: 64px;
  --s-20: 80px;
  --s-24: 96px;

  /* Radius */
  --r-xs:  4px;
  --r-sm:  6px;
  --r:     10px;   /* default */
  --r-md:  12px;
  --r-lg:  16px;
  --r-xl:  22px;
  --r-full: 9999px;

  /* Elevation — tuned for light bg, very soft */
  --sh-xs: 0 1px 2px rgba(14, 27, 51, 0.04);
  --sh-sm: 0 1px 3px rgba(14, 27, 51, 0.05), 0 1px 2px rgba(14, 27, 51, 0.04);
  --sh:    0 4px 8px -2px rgba(14, 27, 51, 0.06), 0 2px 4px -2px rgba(14, 27, 51, 0.04);
  --sh-md: 0 10px 20px -6px rgba(14, 27, 51, 0.08), 0 4px 8px -4px rgba(14, 27, 51, 0.04);
  --sh-lg: 0 20px 32px -10px rgba(14, 27, 51, 0.12), 0 8px 14px -8px rgba(14, 27, 51, 0.06);
  --sh-xl: 0 32px 56px -16px rgba(14, 27, 51, 0.18), 0 12px 20px -12px rgba(14, 27, 51, 0.08);

  /* Focus ring — Apple-style 3px outside, brand color */
  --ring:       0 0 0 3px rgba(61, 124, 201, 0.30);
  --ring-danger:0 0 0 3px rgba(220, 46, 46, 0.30);

  /* Motion */
  --dur-fast: 140ms;
  --dur:      220ms;
  --dur-slow: 420ms;
  --ease:     cubic-bezier(0.2, 0.7, 0.2, 1);            /* default */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);             /* decel */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);      /* tiny bounce */

  /* Layout widths */
  --container-sm: 640px;
  --container:    1024px;
  --container-lg: 1280px;
  --container-xl: 1440px;

  /* Z stack */
  --z-sticky:   80;
  --z-dropdown: 120;
  --z-dialog:   400;
  --z-toast:    500;

  /* ── Bridges to legacy shell.css tokens ──
     shell.css defined its own --panel/--line/--ok/etc with hardcoded
     hex values. Since design-system.css loads AFTER shell.css, these
     redefinitions win. Mapping them onto modern semantic tokens means
     the legacy .htos-* surfaces (appbar, login overlay, modals, etc.)
     follow dark mode automatically — no per-rule rewrite needed. */
  --panel: var(--surface);
  --panel-2: var(--surface-2);
  --card2: var(--surface-3);
  --card: var(--surface);
  --line: var(--border);
  --line-2: var(--border-subtle);
  --text: var(--ink);
  --text2: var(--ink-2);
  --ok: var(--success);
  --ok-soft: var(--success-soft);
  --fail: var(--danger);
  --fail-soft: var(--danger-soft);
  --black: var(--ink);
  --shadow: var(--sh);
}

/* ────── Dark mode ──────
   Softer "blue ink" — not black. Lifted with gold warmth so the UI
   still feels like Home Therapist at night. Three tonal layers:
   - bg       deep ink           (1)
   - surface  raised card        (2)
   - surface-3 hover / chip bg   (3)
*/
[data-theme="dark"] {
  --bg: #172338;
  --surface: #1E2C48;
  --surface-2: #192641;
  --surface-3: #25345A;
  --surface-overlay: rgba(30, 44, 72, 0.85);
  --border: #33446B;
  --border-subtle: #253455;
  --ink: #EAF0FA;
  --ink-2: #BBC7DB;
  --ink-3: #8695B1;
  --muted: #6B7A97;

  /* Brighten brand in dark so it reads on deep blue */
  --accent: #5A9AE6;
  --accent-ink: #9FC3EF;
  --accent-soft: rgba(90, 154, 230, 0.18);
  --brand-royal-soft: rgba(90, 154, 230, 0.20);
  --brand-sky-soft: rgba(0, 160, 223, 0.20);
  --brand-mint-soft: rgba(46, 217, 195, 0.18);
  --success-soft: rgba(22, 168, 112, 0.20);
  --warn-soft: rgba(244, 217, 123, 0.16);
  --danger-soft: rgba(220, 80, 80, 0.20);
  --info-soft: rgba(0, 160, 223, 0.20);

  --sh-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
  --sh-sm: 0 1px 3px rgba(0, 0, 0, 0.40), 0 1px 2px rgba(0, 0, 0, 0.25);
  --sh:    0 4px 10px rgba(0, 0, 0, 0.30);
  --sh-md: 0 10px 22px rgba(0, 0, 0, 0.38);
  --sh-lg: 0 20px 36px rgba(0, 0, 0, 0.45);
  --sh-xl: 0 30px 48px rgba(0, 0, 0, 0.55);

  --ring: 0 0 0 3px rgba(90, 154, 230, 0.50);
}

/* Auto dark (respects OS setting when data-theme is not set) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #172338;
    --surface: #1E2C48;
    --surface-2: #192641;
    --surface-3: #25345A;
    --surface-overlay: rgba(30, 44, 72, 0.85);
    --border: #33446B;
    --border-subtle: #253455;
    --ink: #EAF0FA;
    --ink-2: #BBC7DB;
    --ink-3: #8695B1;
    --muted: #6B7A97;
    --accent: #5A9AE6;
    --accent-ink: #9FC3EF;
    --accent-soft: rgba(90, 154, 230, 0.18);
    --brand-royal-soft: rgba(90, 154, 230, 0.20);
    --ring: 0 0 0 3px rgba(90, 154, 230, 0.50);
  }
}

/* ────── Base reset + type ────── */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  tab-size: 4;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--lh-normal);
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; letter-spacing: var(--tracking-snug); color: var(--ink); }
h1 { font-size: var(--text-2xl); line-height: var(--lh-tight); letter-spacing: var(--tracking-tight); }
h2 { font-size: var(--text-xl); line-height: var(--lh-tight); }
h3 { font-size: var(--text-lg); line-height: var(--lh-snug); }
h4 { font-size: var(--text-md); line-height: var(--lh-snug); }
p { margin: 0; }
a { color: var(--accent-ink); text-decoration: none; transition: color var(--dur-fast) var(--ease); }
a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
code { font-family: var(--font-mono); font-size: 0.9em; background: var(--surface-2); padding: 1px 6px; border-radius: var(--r-xs); }
hr { border: 0; border-top: 1px solid var(--border-subtle); margin: var(--s-6) 0; }
::selection { background: var(--accent-soft); color: var(--accent-ink); }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ────── Layout primitives ────── */
.ds-container { max-width: var(--container-lg); margin: 0 auto; padding: 0 var(--s-6); }
.ds-container-sm { max-width: var(--container-sm); }
.ds-container-xl { max-width: var(--container-xl); }

.ds-stack { display: flex; flex-direction: column; gap: var(--s-4); }
.ds-stack-sm { gap: var(--s-2); }
.ds-stack-lg { gap: var(--s-6); }

.ds-cluster { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }
.ds-cluster-sm { gap: var(--s-2); }

.ds-row { display: flex; align-items: center; gap: var(--s-3); }
.ds-row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }

.ds-grid { display: grid; gap: var(--s-4); }
.ds-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ds-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ds-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 960px) {
  .ds-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ds-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .ds-grid-4, .ds-grid-3, .ds-grid-2 { grid-template-columns: 1fr; }
}

.ds-divider { border-top: 1px solid var(--border-subtle); }
.ds-mute { color: var(--ink-3); }
.ds-muted { color: var(--muted); }

.ds-section { padding: var(--s-10) 0; border-top: 1px solid var(--border-subtle); }
.ds-section:first-of-type { border-top: 0; padding-top: var(--s-6); }
.ds-eyebrow {
  display: inline-block; padding: 3px 10px; border-radius: var(--r-full);
  background: var(--accent-soft); color: var(--accent-ink);
  font-size: var(--text-xs); font-weight: 700; letter-spacing: var(--tracking-wide);
  text-transform: uppercase; margin-bottom: var(--s-3);
}

/* ────── Buttons ────── */
.ds-btn {
  --btn-bg: var(--accent);
  --btn-ink: #fff;
  --btn-border: transparent;
  --btn-hover: var(--accent-ink);
  --btn-h: 40px;
  --btn-px: 16px;
  --btn-fs: var(--text-base);
  --btn-radius: var(--r);

  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  height: var(--btn-h);
  padding: 0 var(--btn-px);
  background: var(--btn-bg);
  color: var(--btn-ink);
  border: 1px solid var(--btn-border);
  border-radius: var(--btn-radius);
  font-family: inherit;
  font-size: var(--btn-fs);
  font-weight: 600;
  letter-spacing: var(--tracking-snug);
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  box-shadow: var(--sh-xs);
}
.ds-btn:hover { background: var(--btn-hover); box-shadow: var(--sh-sm); text-decoration: none; }
.ds-btn:active { transform: translateY(1px); box-shadow: none; }
.ds-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.ds-btn:disabled, .ds-btn[aria-disabled="true"] {
  opacity: 0.55; cursor: not-allowed; pointer-events: none;
}
.ds-btn .ds-btn-icon { width: 16px; height: 16px; flex-shrink: 0; }

/* Variants */
.ds-btn-secondary {
  --btn-bg: var(--surface);
  --btn-ink: var(--ink);
  --btn-border: var(--border);
  --btn-hover: var(--surface-2);
}
.ds-btn-ghost {
  --btn-bg: transparent;
  --btn-ink: var(--ink-2);
  --btn-border: transparent;
  --btn-hover: var(--surface-2);
  box-shadow: none;
}
.ds-btn-ghost:hover { box-shadow: none; color: var(--ink); }
.ds-btn-subtle {
  --btn-bg: var(--accent-soft);
  --btn-ink: var(--accent-ink);
  --btn-border: transparent;
  --btn-hover: var(--brand-royal-soft);
  box-shadow: none;
}
.ds-btn-danger {
  --btn-bg: var(--danger);
  --btn-ink: #fff;
  --btn-hover: #B41F1F;
}
.ds-btn-dark {
  --btn-bg: var(--ink);
  --btn-ink: #fff;
  --btn-hover: #000;
}
/* In dark mode --ink is near-white, so flip the text to dark for contrast. */
[data-theme="dark"] .ds-btn-dark { --btn-ink: #0E1B33; --btn-hover: #FFFFFF; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ds-btn-dark { --btn-ink: #0E1B33; --btn-hover: #FFFFFF; }
}
/* Gold — for premium moments: Send Invoice, Collect, VIP actions. */
.ds-btn-gold {
  background: var(--brand-gold-grad);
  color: #4A3312;
  border: 0;
  box-shadow: var(--sh-sm), inset 0 1px 0 rgba(255,255,255,0.55), inset 0 -1px 0 rgba(74,51,18,0.12);
  text-shadow: 0 1px 0 rgba(255,255,255,0.35);
}
.ds-btn-gold:hover { background: var(--brand-gold-grad); filter: brightness(1.03) saturate(1.1); box-shadow: var(--sh), inset 0 1px 0 rgba(255,255,255,0.55); }
.ds-btn-gold:active { filter: brightness(0.98); }

/* Royal + gold gradient CTA — signature HT combo for hero moments. */
.ds-btn-duo {
  background: linear-gradient(135deg, var(--brand-royal) 0%, var(--brand-sky) 45%, var(--brand-gold-b) 100%);
  color: #fff;
  border: 0;
  box-shadow: var(--sh-sm), inset 0 -1px 0 rgba(0,0,0,0.14);
}
.ds-btn-duo:hover { filter: brightness(1.06); box-shadow: var(--sh); }

/* Sizes */
.ds-btn-sm { --btn-h: 32px; --btn-px: 12px; --btn-fs: var(--text-sm); --btn-radius: var(--r-sm); }
.ds-btn-lg { --btn-h: 48px; --btn-px: 22px; --btn-fs: var(--text-md); }

.ds-btn-icon-only {
  width: var(--btn-h);
  padding: 0;
  border-radius: var(--r-full);
}
.ds-btn-pill { border-radius: var(--r-full); }

.ds-btn-loading { position: relative; color: transparent !important; pointer-events: none; }
.ds-btn-loading::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: ds-spin 0.7s linear infinite;
  color: #fff; opacity: 1;
}
.ds-btn-secondary.ds-btn-loading::after,
.ds-btn-ghost.ds-btn-loading::after,
.ds-btn-subtle.ds-btn-loading::after { color: var(--accent); }

@keyframes ds-spin { to { transform: rotate(360deg); } }

/* Button group */
.ds-btn-group { display: inline-flex; }
.ds-btn-group .ds-btn { border-radius: 0; margin-left: -1px; }
.ds-btn-group .ds-btn:first-child { border-top-left-radius: var(--r); border-bottom-left-radius: var(--r); margin-left: 0; }
.ds-btn-group .ds-btn:last-child { border-top-right-radius: var(--r); border-bottom-right-radius: var(--r); }

/* ────── Form controls ────── */
.ds-field { display: flex; flex-direction: column; gap: 6px; }
.ds-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: var(--tracking-snug);
}
.ds-label .req { color: var(--danger); margin-left: 2px; }
.ds-help { font-size: var(--text-xs); color: var(--muted); }
.ds-error { font-size: var(--text-xs); color: var(--danger); min-height: 1em; }

.ds-input, .ds-select, .ds-textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-base);
  line-height: 1.4;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  outline: none;
}
.ds-input::placeholder, .ds-textarea::placeholder { color: var(--muted); }
.ds-input:hover, .ds-select:hover, .ds-textarea:hover { border-color: var(--ink-3); }
.ds-input:focus, .ds-select:focus, .ds-textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.ds-input:disabled, .ds-select:disabled, .ds-textarea:disabled {
  background: var(--surface-2); color: var(--ink-3); cursor: not-allowed;
}
.ds-input[aria-invalid="true"], .ds-select[aria-invalid="true"], .ds-textarea[aria-invalid="true"] {
  border-color: var(--danger);
}
.ds-input[aria-invalid="true"]:focus,
.ds-select[aria-invalid="true"]:focus,
.ds-textarea[aria-invalid="true"]:focus {
  box-shadow: var(--ring-danger);
}

.ds-textarea { min-height: 80px; resize: vertical; font-family: inherit; }

.ds-input-wrap { position: relative; display: flex; align-items: center; }
.ds-input-wrap .ds-input { padding-left: 40px; }
.ds-input-icon {
  position: absolute; left: 12px; width: 16px; height: 16px; color: var(--muted);
  pointer-events: none;
}

.ds-select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238A94A7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

/* Checkbox + radio — custom look */
.ds-check, .ds-radio {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: var(--text-base); color: var(--ink); cursor: pointer; user-select: none;
}
.ds-check input, .ds-radio input { position: absolute; opacity: 0; pointer-events: none; }
.ds-check-box, .ds-radio-dot {
  width: 18px; height: 18px; border: 1.5px solid var(--border);
  background: var(--surface); display: inline-grid; place-items: center; flex-shrink: 0;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.ds-check-box { border-radius: 5px; }
.ds-radio-dot { border-radius: 50%; }
.ds-check:hover .ds-check-box, .ds-radio:hover .ds-radio-dot { border-color: var(--accent); }
.ds-check input:checked ~ .ds-check-box, .ds-radio input:checked ~ .ds-radio-dot {
  background: var(--accent); border-color: var(--accent);
}
.ds-check input:checked ~ .ds-check-box::after {
  content: ""; width: 10px; height: 6px;
  border-left: 2px solid #fff; border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px);
}
.ds-radio input:checked ~ .ds-radio-dot::after {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff;
}
.ds-check input:focus-visible ~ .ds-check-box,
.ds-radio input:focus-visible ~ .ds-radio-dot { box-shadow: var(--ring); }

/* Switch */
.ds-switch {
  position: relative;
  display: inline-flex; align-items: center; gap: 10px;
  cursor: pointer; user-select: none; font-size: var(--text-base); color: var(--ink);
}
.ds-switch input { position: absolute; opacity: 0; pointer-events: none; }
.ds-switch-track {
  width: 38px; height: 22px; border-radius: var(--r-full);
  background: var(--surface-3);
  position: relative;
  transition: background var(--dur) var(--ease);
}
.ds-switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: var(--sh-sm);
  transition: transform var(--dur) var(--ease-spring);
}
.ds-switch input:checked ~ .ds-switch-track { background: var(--accent); }
.ds-switch input:checked ~ .ds-switch-track::after { transform: translateX(16px); }
.ds-switch input:focus-visible ~ .ds-switch-track { box-shadow: var(--ring); }

/* ────── Cards ────── */
.ds-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  box-shadow: var(--sh-xs);
  overflow: hidden;
}
.ds-card-hoverable {
  cursor: pointer;
  transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.ds-card-hoverable:hover { transform: translateY(-2px); box-shadow: var(--sh-md); border-color: var(--border); }
.ds-card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.ds-card-head h3 { font-size: var(--text-md); letter-spacing: var(--tracking-snug); }
.ds-card-body { padding: 18px; }
.ds-card-body.ds-tight { padding: 14px 18px; }
.ds-card-foot {
  padding: 12px 18px; border-top: 1px solid var(--border-subtle);
  display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2);
}

/* Hero card — signature blue → gold pour. Reserved, not overused. */
.ds-card-hero {
  background:
    radial-gradient(800px 300px at 120% -20%, rgba(244,217,123,0.55) 0%, transparent 55%),
    linear-gradient(135deg, var(--brand-royal) 0%, var(--brand-royal-ink) 55%, #1B3B6B 100%);
  color: #fff;
  border: 0;
  box-shadow: 0 14px 32px -12px rgba(61,124,201,0.55), 0 4px 10px -4px rgba(212,169,74,0.25);
  position: relative; overflow: hidden;
}
.ds-card-hero::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(400px 180px at 0% 100%, rgba(0,160,223,0.25) 0%, transparent 60%);
  pointer-events: none;
}
.ds-card-hero .ds-card-body { position: relative; z-index: 1; }

/* KPI card — high-density dashboard number */
.ds-kpi {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: 18px 20px;
  transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease);
}
.ds-kpi-hoverable { cursor: pointer; }
.ds-kpi-hoverable:hover { transform: translateY(-2px); box-shadow: var(--sh-md); }
.ds-kpi-label {
  color: var(--ink-3); font-size: var(--text-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: var(--tracking-wide);
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.ds-kpi-value { font-size: var(--text-2xl); font-weight: 700; letter-spacing: var(--tracking-tight); line-height: 1.05; }
.ds-kpi-delta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--text-xs); font-weight: 700;
  padding: 2px 8px; border-radius: var(--r-full); margin-top: 10px;
}
.ds-kpi-delta.up { background: var(--success-soft); color: var(--success); }
.ds-kpi-delta.down { background: var(--danger-soft); color: var(--danger); }
.ds-kpi-delta.flat { background: var(--surface-2); color: var(--ink-3); }

/* Feature KPI — subtle blue→gold wash for the metric that matters most */
.ds-kpi-feature {
  position: relative;
  background:
    linear-gradient(180deg, rgba(61,124,201,0.06) 0%, transparent 80%),
    radial-gradient(120% 80% at 100% 0%, rgba(244,217,123,0.18) 0%, transparent 55%),
    var(--surface);
  border-color: rgba(61,124,201,0.18);
}
.ds-kpi-feature .ds-kpi-value {
  background: linear-gradient(100deg, var(--brand-royal) 0%, var(--brand-royal-ink) 30%, #B48A34 90%);
  background-clip: text; -webkit-background-clip: text; color: transparent;
}
.ds-kpi-sparkle {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--brand-gold-grad);
  box-shadow: 0 0 0 3px rgba(244,217,123,0.25);
  margin-right: 2px;
}

/* ────── Tables ────── */
.ds-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  overflow: hidden;
}
.ds-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.ds-table thead th {
  text-align: left;
  padding: 10px 16px;
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0;
}
.ds-table tbody td {
  padding: 12px 16px; border-bottom: 1px solid var(--border-subtle);
  color: var(--ink); vertical-align: middle;
}
.ds-table tbody tr:last-child td { border-bottom: 0; }
.ds-table tbody tr { transition: background var(--dur-fast) var(--ease); }
.ds-table tbody tr:hover { background: var(--surface-2); }
.ds-table tbody tr.clickable { cursor: pointer; }

/* Responsive: on mobile, list items stack as cards */
@media (max-width: 640px) {
  .ds-table thead { display: none; }
  .ds-table, .ds-table tbody, .ds-table tr, .ds-table td { display: block; width: 100%; }
  .ds-table tr {
    padding: 12px 14px; border-bottom: 1px solid var(--border-subtle);
  }
  .ds-table td {
    padding: 4px 0; border: 0;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
  }
  .ds-table td::before {
    content: attr(data-label);
    font-size: var(--text-xs); color: var(--muted);
    text-transform: uppercase; letter-spacing: var(--tracking-wide); font-weight: 700;
  }
}

/* ────── Chips / tags / badges ────── */
.ds-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--r-full);
  background: var(--surface-2); color: var(--ink-2);
  font-size: var(--text-xs); font-weight: 600;
  border: 1px solid var(--border-subtle);
}
.ds-chip-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.ds-chip-solid { background: var(--accent); color: #fff; border-color: transparent; }
.ds-chip-solid .ds-chip-dot { background: #fff; }
.ds-chip-royal { background: var(--brand-royal-soft); color: var(--brand-royal-ink); border-color: transparent; }
.ds-chip-royal .ds-chip-dot { background: var(--brand-royal); }
.ds-chip-sky   { background: var(--brand-sky-soft); color: var(--brand-sky-ink); border-color: transparent; }
.ds-chip-sky .ds-chip-dot { background: var(--brand-sky); }
.ds-chip-mint  { background: var(--brand-mint-soft); color: var(--brand-mint-ink); border-color: transparent; }
.ds-chip-mint .ds-chip-dot { background: var(--brand-mint); }
.ds-chip-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.ds-chip-success .ds-chip-dot { background: var(--success); }
.ds-chip-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.ds-chip-warn .ds-chip-dot { background: var(--warn); }
.ds-chip-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.ds-chip-danger .ds-chip-dot { background: var(--danger); }
.ds-chip-outline { background: transparent; color: var(--ink-2); border-color: var(--border); }

.ds-chip-x {
  background: transparent; border: 0; color: inherit; opacity: 0.6;
  cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 2px; margin-right: -4px;
}
.ds-chip-x:hover { opacity: 1; }

/* Tag (brand gold treatment for premium service plans) */
.ds-tag-gold {
  background: var(--brand-gold-grad); color: #4A3312;
  padding: 3px 10px; border-radius: var(--r-full);
  font-size: var(--text-xs); font-weight: 700;
  letter-spacing: var(--tracking-snug);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), inset 0 -1px 0 rgba(0,0,0,0.06);
}

/* Gold chip — for rewards, milestones, premium markers */
.ds-chip-gold {
  background: linear-gradient(135deg, rgba(244,217,123,0.35) 0%, rgba(212,169,74,0.30) 100%);
  color: #6B4A12;
  border: 1px solid rgba(180,138,52,0.30);
  font-weight: 700;
}
.ds-chip-gold .ds-chip-dot { background: #B48A34; }

/* Eyebrow gold variant */
.ds-eyebrow-gold {
  display: inline-block; padding: 3px 10px; border-radius: var(--r-full);
  background: linear-gradient(135deg, rgba(244,217,123,0.35) 0%, rgba(212,169,74,0.25) 100%);
  color: #6B4A12;
  font-size: var(--text-xs); font-weight: 700; letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  border: 1px solid rgba(180,138,52,0.30);
}

/* ────── App bar / nav ────── */
.ds-appbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 var(--s-5); min-height: 56px;
  display: grid; grid-template-columns: auto 1fr auto; gap: var(--s-4); align-items: center;
}
.ds-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; letter-spacing: var(--tracking-snug); color: var(--ink);
}
.ds-brand-mark {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--brand-royal) 0%, var(--brand-sky) 100%);
  display: grid; place-items: center; color: #fff; font-weight: 800;
  box-shadow: inset 0 -2px 4px rgba(0,0,0,0.15), 0 2px 8px -2px rgba(61,124,201,0.45);
  overflow: hidden; flex-shrink: 0;
}
.ds-brand-mark img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.ds-nav { display: flex; gap: 2px; align-items: center; }
.ds-nav a {
  padding: 8px 12px; color: var(--ink-2); border-radius: var(--r-sm);
  font-weight: 600; font-size: var(--text-sm);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.ds-nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.ds-nav a.active { color: var(--accent-ink); background: var(--accent-soft); }

/* Theme toggle — icon-only button in the appbar. Cycles light → dark → auto. */
.ds-theme-btn {
  width: 36px; height: 36px; border-radius: var(--r-full);
  background: transparent; border: 1px solid transparent;
  color: var(--ink-3); cursor: pointer;
  display: grid; place-items: center;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
  position: relative;
}
.ds-theme-btn:hover { background: var(--surface-2); color: var(--ink); }
.ds-theme-btn:focus-visible { outline: none; box-shadow: var(--ring); border-color: transparent; }
.ds-theme-btn svg { width: 18px; height: 18px; display: none; }
/* Default (no explicit data-theme) shows the auto icon. */
:root:not([data-theme="light"]):not([data-theme="dark"]) .ds-theme-icon-auto { display: block; }
:root[data-theme="light"] .ds-theme-icon-light { display: block; }
:root[data-theme="dark"] .ds-theme-icon-dark { display: block; }

/* Hamburger button — hidden on desktop, visible below 820px */
.ds-appbar-menu {
  display: none;
}
@media (max-width: 820px) {
  .ds-appbar { grid-template-columns: auto auto 1fr auto; }
  .ds-nav { display: none; }
  .ds-nav.open {
    display: flex; flex-direction: column; align-items: stretch; gap: 2px;
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--surface); border-bottom: 1px solid var(--border-subtle);
    padding: var(--s-2) var(--s-3); box-shadow: var(--sh-md);
  }
  .ds-nav.open a { padding: 12px 14px; border-radius: var(--r-sm); }
  .ds-appbar-menu {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: var(--r-sm);
    background: transparent; border: 0; color: var(--ink-2); cursor: pointer;
    transition: background var(--dur-fast) var(--ease);
  }
  .ds-appbar-menu:hover { background: var(--surface-2); color: var(--ink); }
}

.ds-tabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.ds-tab {
  padding: 12px 16px; background: transparent; border: 0;
  color: var(--ink-3); font-family: inherit; font-size: var(--text-sm); font-weight: 600;
  border-bottom: 2px solid transparent;
  cursor: pointer; white-space: nowrap;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.ds-tab:hover { color: var(--ink); }
.ds-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.ds-breadcrumbs { display: flex; align-items: center; gap: 6px; font-size: var(--text-sm); color: var(--muted); }
.ds-breadcrumbs a { color: var(--muted); }
.ds-breadcrumbs .sep { opacity: 0.5; }
.ds-breadcrumbs .here { color: var(--ink); font-weight: 600; }

/* ────── Empty / loading ────── */
.ds-empty {
  text-align: center; padding: var(--s-12) var(--s-6); color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--r-md); background: var(--surface);
}
.ds-empty-icon { font-size: 2rem; margin-bottom: 8px; opacity: 0.5; }
.ds-empty-title { font-size: var(--text-md); font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.ds-empty-text { font-size: var(--text-sm); color: var(--muted); max-width: 420px; margin: 0 auto var(--s-4); }

.ds-skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: ds-shimmer 1.5s infinite;
  border-radius: var(--r-sm);
  min-height: 12px;
}
@keyframes ds-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ────── Toast ────── */
.ds-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: var(--r);
  font-size: var(--text-sm); font-weight: 600;
  box-shadow: var(--sh-lg); z-index: var(--z-toast);
  animation: ds-toast-in var(--dur) var(--ease-spring);
}
@keyframes ds-toast-in {
  from { transform: translate(-50%, 10px); opacity: 0; }
  to   { transform: translate(-50%, 0);    opacity: 1; }
}

/* ────── Dialog ────── */
.ds-dialog-backdrop {
  position: fixed; inset: 0; background: rgba(14, 27, 51, 0.48);
  backdrop-filter: blur(4px);
  z-index: var(--z-dialog); display: flex; align-items: center; justify-content: center;
  padding: var(--s-5);
  animation: ds-fade-in var(--dur) var(--ease);
}
.ds-dialog {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  width: min(480px, 100%);
  box-shadow: var(--sh-xl);
  overflow: hidden;
  animation: ds-pop-in var(--dur) var(--ease-spring);
}
@keyframes ds-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ds-pop-in {
  from { transform: scale(0.96) translateY(8px); opacity: 0; }
  to   { transform: scale(1) translateY(0);      opacity: 1; }
}
.ds-dialog-head { padding: 18px 20px; border-bottom: 1px solid var(--border-subtle); }
.ds-dialog-body { padding: 18px 20px; color: var(--ink-2); font-size: var(--text-base); }
.ds-dialog-foot { padding: 12px 20px; border-top: 1px solid var(--border-subtle); background: var(--surface-2); display: flex; justify-content: flex-end; gap: 8px; }

/* ────── Utilities ────── */
.ds-hide-sm { }
.ds-show-sm { display: none; }
@media (max-width: 640px) {
  .ds-hide-sm { display: none !important; }
  .ds-show-sm { display: initial; }
}
.ds-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ────── Wizard chrome carve-out (R3, plans/session-rules.md §3) ──────
   HCP-equivalent wizards (estimate-new, job-new, …) opt out of the
   global appbar by setting <body data-htos-chrome="wizard">. The login
   overlay (#htos-login) stays visible so unauth users still see the
   sign-in flow; everything else inside #htos-shell-root collapses.
   The wizard renders its own focused chrome via wizard-shell.js. */
body[data-htos-chrome="wizard"] #htos-shell-root > .htos-appbar,
body[data-htos-chrome="wizard"] #htos-shell-root > .htos-aidrawer,
body[data-htos-chrome="wizard"] #htos-shell-root > .htos-aidrawer-handle {
  display: none !important;
}
body[data-htos-chrome="wizard"] {
  margin: 0;
  padding: 0;
  background: var(--surface);  /* HCP-style white in light mode, dark via tokens */
}
