/* ============================================================
   tokens.css — Agent HQ design tokens (LOCKED)
   Source of truth: projects/agent-hq/DESIGN_SYSTEM.md
   Authority:       D-2026-05-03-70 (JF directive #3)
   Scope:           Every dashboard surface and the marketing
                    website EXCEPT the chat tab.
   Load order:      FIRST stylesheet on every page, BEFORE any
                    component or page-specific CSS.
   Edit policy:     Do NOT edit values here without updating
                    DESIGN_SYSTEM.md and bumping the design
                    schema in DECISIONS.md.
   ============================================================ */

/* ---- 0. Font import --------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

/* ---- 1a. Light theme (DEFAULT) ---------------------------- */
:root {
  /* Surfaces */
  --color-bg:               #FAF9F7;
  --color-bg-subtle:        #F5F2EE;
  --color-card:             #FFFFFF;
  --color-card-hover:       #FDFCFA;
  --color-border:           #ECE9E4;
  --color-border-strong:    #D6D1C9;

  /* Text */
  --color-text:             #1F2937;
  --color-text-strong:      #0F172A;
  --color-text-muted:       #6B7280;
  --color-text-faint:       #9CA3AF;
  --color-text-on-accent:   #FFFFFF;

  /* Accent — used sparingly */
  --color-accent:           #0D9488;
  --color-accent-hover:     #0F766E;
  --color-accent-soft:      #CCFBF1;
  --color-accent-faint:     #F0FDFA;

  /* Semantic */
  --color-success:          #15803D;
  --color-success-soft:     #D1FAE5;
  --color-warning:          #B45309;
  --color-warning-soft:     #FEF3C7;
  --color-danger:           #B91C1C;
  --color-danger-soft:      #FEE2E2;
  --color-info:             #1D4ED8;
  --color-info-soft:        #DBEAFE;

  /* Shadows — subtle, warm */
  --shadow-card:            0 1px 2px rgba(20, 14, 8, 0.04), 0 1px 6px rgba(20, 14, 8, 0.05);
  --shadow-card-hover:      0 1px 2px rgba(20, 14, 8, 0.05), 0 4px 12px rgba(20, 14, 8, 0.08);
  --shadow-overlay:         0 8px 32px rgba(20, 14, 8, 0.16);
  --shadow-pill:            0 1px 3px rgba(13, 148, 136, 0.18);

  /* ---- 2a. Typography ------------------------------------- */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Menlo, Consolas, monospace;

  /* Sizes */
  --font-size-xs:           12px;
  --font-size-sm:           13px;
  --font-size-body:         14px;
  --font-size-body-lg:      16px;
  --font-size-h6:           14px;
  --font-size-h5:           16px;
  --font-size-h4:           18px;
  --font-size-h3:           22px;
  --font-size-h2:           28px;
  --font-size-h1:           36px;
  --font-size-display:      48px;

  /* Weights */
  --font-weight-light:      300;
  --font-weight-regular:    400;
  --font-weight-medium:     500;
  --font-weight-semibold:   600;
  --font-weight-bold:       700;

  /* Line heights */
  --line-height-tight:      1.2;
  --line-height-snug:       1.35;
  --line-height-normal:     1.5;
  --line-height-relaxed:    1.65;

  /* Letter spacing */
  --letter-spacing-tight:   -0.02em;
  --letter-spacing-normal:  0;
  --letter-spacing-wide:    0.04em;

  /* ---- 3. Spacing scale ----------------------------------- */
  --space-0:                0;
  --space-1:                4px;
  --space-2:                8px;
  --space-3:                12px;
  --space-4:                16px;
  --space-5:                20px;
  --space-6:                24px;
  --space-8:                32px;
  --space-10:               40px;
  --space-12:               48px;
  --space-16:               64px;
  --space-20:               80px;
  --space-24:               96px;

  /* ---- 4. Border radii ------------------------------------ */
  --radius-sm:              6px;
  --radius-md:              10px;
  --radius-lg:              14px;
  --radius-xl:              20px;
  --radius-full:            9999px;

  /* ---- 7. Motion ------------------------------------------ */
  --motion-fast:            140ms;
  --motion-default:         200ms;
  --motion-slow:            320ms;
  --motion-easing:          cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- 1b. Dark theme (option in Settings) ------------------ */
[data-theme="dark"] {
  /* Surfaces — deep navy with VISIBLE elevation between layers */
  --color-bg:               #0B1424;
  --color-bg-subtle:        #0F1A2E;
  --color-card:             #142037;
  --color-card-hover:       #182842;
  --color-border:           #1F2D44;
  --color-border-strong:    #2A3A55;

  /* Text */
  --color-text:             #E2E8F0;
  --color-text-strong:      #F5F7FA;
  --color-text-muted:       #9CA8BB;
  --color-text-faint:       #6B7790;
  --color-text-on-accent:   #FFFFFF;

  /* Accent — same teal but brightened for dark contrast */
  --color-accent:           #14B8A6;
  --color-accent-hover:     #2DD4BF;
  --color-accent-soft:      #134E4A;
  --color-accent-faint:     #0F2E2C;

  /* Semantic — brightened for dark mode contrast */
  --color-success:          #4ADE80;
  --color-success-soft:     #14532D;
  --color-warning:          #FBBF24;
  --color-warning-soft:     #78350F;
  --color-danger:           #F87171;
  --color-danger-soft:      #7F1D1D;
  --color-info:             #60A5FA;
  --color-info-soft:        #1E3A8A;

  /* Shadows — slight glow + depth (NOT flat) */
  --shadow-card:            0 1px 2px rgba(0, 0, 0, 0.36), 0 1px 6px rgba(0, 0, 0, 0.42);
  --shadow-card-hover:      0 1px 2px rgba(0, 0, 0, 0.36), 0 6px 20px rgba(20, 184, 166, 0.08);
  --shadow-overlay:         0 12px 48px rgba(0, 0, 0, 0.55);
  --shadow-pill:            0 1px 3px rgba(20, 184, 166, 0.32);
}

/* ============================================================
   Base reset + body defaults
   ============================================================ */

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-regular);
  line-height: var(--line-height-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ---- 2c. Heading defaults --------------------------------- */
h1 { font-size: var(--font-size-h1); font-weight: var(--font-weight-bold);     line-height: var(--line-height-tight);  letter-spacing: var(--letter-spacing-tight); color: var(--color-text-strong); margin: 0 0 var(--space-4); }
h2 { font-size: var(--font-size-h2); font-weight: var(--font-weight-bold);     line-height: var(--line-height-snug);   letter-spacing: var(--letter-spacing-tight); color: var(--color-text-strong); margin: 0 0 var(--space-4); }
h3 { font-size: var(--font-size-h3); font-weight: var(--font-weight-bold);     line-height: var(--line-height-snug);   color: var(--color-text-strong); margin: 0 0 var(--space-3); }
h4 { font-size: var(--font-size-h4); font-weight: var(--font-weight-semibold); line-height: var(--line-height-snug);   color: var(--color-text); margin: 0 0 var(--space-2); }
h5 { font-size: var(--font-size-h5); font-weight: var(--font-weight-semibold); line-height: var(--line-height-snug);   color: var(--color-text); margin: 0 0 var(--space-2); }
h6 { font-size: var(--font-size-h6); font-weight: var(--font-weight-semibold); line-height: var(--line-height-snug);   color: var(--color-text); text-transform: uppercase; letter-spacing: var(--letter-spacing-wide); margin: 0 0 var(--space-2); }
p  { font-size: var(--font-size-body); font-weight: var(--font-weight-regular); line-height: var(--line-height-normal); color: var(--color-text); margin: 0 0 var(--space-4); }
small, .muted { font-size: var(--font-size-sm); color: var(--color-text-muted); }
.faint { font-size: var(--font-size-xs); color: var(--color-text-faint); font-weight: var(--font-weight-light); }
code, pre { font-family: var(--font-mono); font-size: 0.94em; }
a { color: var(--color-accent); text-decoration: none; }
a:hover { color: var(--color-accent-hover); text-decoration: underline; }

/* ============================================================
   5. Component defaults
   ============================================================ */

/* ---- 5a. Cards ------------------------------------------- */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-card);
  transition: box-shadow var(--motion-fast) ease, transform var(--motion-fast) ease;
}

.card:hover {
  box-shadow: var(--shadow-card-hover);
}

.card-hero {
  border-radius: var(--radius-xl);
  padding: var(--space-8);
}

/* ---- 5b. Buttons ----------------------------------------- */
.btn {
  font-family: var(--font-sans);
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-medium);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: background var(--motion-fast) ease, border-color var(--motion-fast) ease, transform 80ms ease;
  min-height: 44px; /* mobile tap target */
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  text-decoration: none;
}

.btn:active { transform: scale(0.98); }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--color-accent-faint), 0 0 0 4px var(--color-accent);
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  padding: var(--space-4) var(--space-6);
  font-weight: var(--font-weight-bold);
}
.btn-primary:hover { background: var(--color-accent-hover); }

.btn-secondary {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border-strong);
}
.btn-secondary:hover { background: var(--color-bg-subtle); }

.btn-ghost {
  background: transparent;
  color: var(--color-accent);
}
.btn-ghost:hover { background: var(--color-accent-faint); }

.btn-danger {
  background: var(--color-danger);
  color: var(--color-text-on-accent);
}
.btn-danger:hover { filter: brightness(0.92); }

/* ---- 5c. Inputs ------------------------------------------ */
.input,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="number"],
input[type="tel"],
input[type="url"],
textarea,
select {
  font-family: var(--font-sans);
  font-size: var(--font-size-body);
  background: var(--color-card);
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  min-height: 44px;
  transition: border-color var(--motion-fast) ease, box-shadow var(--motion-fast) ease;
  width: 100%;
}

.input:focus,
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-faint);
}

textarea { min-height: 96px; resize: vertical; line-height: var(--line-height-normal); }

label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  margin-bottom: var(--space-1);
}

/* ---- 5d. Pills + badges ---------------------------------- */
.pill {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  padding: 2px 10px;
  border-radius: var(--radius-full);
  background: var(--color-bg-subtle);
  color: var(--color-text-muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.pill-success { background: var(--color-success-soft); color: var(--color-success); }
.pill-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.pill-danger  { background: var(--color-danger-soft);  color: var(--color-danger); }
.pill-accent  { background: var(--color-accent-soft);  color: var(--color-accent); }
.pill-info    { background: var(--color-info-soft);    color: var(--color-info); }

/* Status dot — used in Home health indicator (D-68) */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-success);
  box-shadow: var(--shadow-pill);
}
.status-dot.warning { background: var(--color-warning); }
.status-dot.danger  { background: var(--color-danger); }
.status-dot.muted   { background: var(--color-text-faint); box-shadow: none; }

/* ---- Dividers -------------------------------------------- */
hr,
.divider {
  border: 0;
  height: 1px;
  background: var(--color-border);
  margin: var(--space-6) 0;
}

/* ============================================================
   6. Mobile rules
   ============================================================ */

@media (max-width: 1024px) {
  /* Sidebar collapses to hamburger drawer below this width.
     Layout-specific rules live in dashboard CSS; tokens.css
     only enforces tap-target + spacing minimums. */
}

@media (max-width: 768px) {
  /* Pricing cards stack vertically — handled in page CSS */
  h1 { font-size: 30px; }
  h2 { font-size: 24px; }
  .card-hero { padding: var(--space-6); }
}

@media (max-width: 600px) {
  .card { padding: var(--space-4); }
  .btn  { padding: var(--space-3) var(--space-4); }
  .btn-primary { padding: var(--space-3) var(--space-5); }
}

/* ============================================================
   8. Legacy token compatibility shim
   D-2026-05-03-77 — D-70 §9 steps 5-7 module migration.
   The dashboard shell's inline :root defines the original
   dark-glass tokens (--bg, --text, --purple, --surface…).
   Existing modules consume those names extensively. Rather
   than rewrite every module's <style> block, we redefine the
   legacy names as ALIASES of the new --color-* tokens —
   scoped to #hq-content so the chat shell (which lives
   OUTSIDE #hq-content) keeps its dark-glass look. JF rule:
   "do NOT touch the chat tab."
   ============================================================ */

#hq-content,
#hq-content .module-slot {
  /* Surfaces */
  --bg:           var(--color-bg);
  --surface:      var(--color-card);
  --surface-2:    var(--color-card-hover);
  --glass-border: var(--color-border);

  /* Text */
  --text:        var(--color-text);
  --text-muted:  var(--color-text-muted);
  --text-dim:    var(--color-text-faint);

  /* Accent + brand colors */
  --purple:      var(--color-accent);
  --green:       var(--color-success);
  --accent:      var(--color-accent);

  /* Radii + typography */
  --radius:      var(--radius-lg);
  --radius-sm:   var(--radius-md);
  --font:        var(--font-sans);
}

/* The onboarding overlay also self-mounts to <body> outside #hq-content
   and styles itself directly with --color-* tokens. Nothing extra needed. */

/* Force Plus Jakarta Sans on every non-chat module. Modules historically
   hardcode `font-family: 'Inter', system-ui, sans-serif` in their style
   blocks, which bypasses the --font alias above. Use a higher-specificity
   selector here to override module-level rules without `!important`. */
#hq-content .module-slot,
#hq-content .module-slot * {
  font-family: var(--font-sans);
}
/* Code/mono elements opt back out (preserve mono per design tokens). */
#hq-content .module-slot code,
#hq-content .module-slot pre,
#hq-content .module-slot kbd,
#hq-content .module-slot samp {
  font-family: var(--font-mono);
}

/* ============================================================
   9. Motion — reduced-motion preference
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 60ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 60ms !important;
    scroll-behavior: auto !important;
  }
  /* Disable transforms entirely (per DESIGN_SYSTEM.md §7) */
  .card:hover,
  .btn:active,
  *[class*="hover-translate"] { transform: none !important; }
}
