/* ════════════════════════════════════════════════════════════════
   base.css — Hortz design tokens + reset
   Reconciled to Hapitalist v4.5.95 tokens (C0).
   Hapitalist-named tokens are canonical. --brand-* aliases preserved
   so existing super pages + runtime tenant theming (page-bootstrap.js,
   signin.js setting --brand-primary/--brand-accent) keep working.
   ════════════════════════════════════════════════════════════════ */

@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap");

:root {
  /* ── Hapitalist palette — audited for WCAG AA ────────────────────
     All text-on-background combinations meet 4.5:1 minimum (AA normal).
     UI elements (borders, icons) meet 3:1.
     Verify any new combination against https://webaim.org/resources/contrastchecker/.

     Tokens with "-text" suffix are the safe text color when the
     same hue is used as a background (e.g. --accent-text on
     --accent-light). The base hue (--accent) is for buttons,
     borders, and icons.
   ──────────────────────────────────────────────────────────────── */

  --accent:        #0d9488;   /* teal-600 — used for icons, links, outline borders. 3.78:1 on #fff (AA for UI components per WCAG 1.4.11; not for body text). */
  --accent-text:   #115e59;   /* teal-800 — text on accent-light.      7.50:1 on #e6f4f3 (AAA) */
  --accent-light:  #e6f4f3;   /* teal tint — selected rows, hover bg */
  --accent-dark:   #0b7d73;   /* teal-700 — primary button bg + white text. 5.01:1 on #fff (AA) */
  --bg:            #ffffff;
  --surface:       #f8f8f8;   /* card/sidebar bg */
  --border:        #888888;   /* gray-500 — UI element border. 3.54:1 on #fff (passes WCAG 1.4.11 minimum 3:1 for non-text UI components). */
  --border-soft:   #e8e8e8;   /* decorative dividers only — does NOT meet 3:1, do not use for input borders or interactive boundaries. */
  --text:          #111111;   /* near-black.                           19.0:1 on #fff (AAA) */
  --muted:         #6b7280;   /* gray-500.                              4.83:1 on #fff (AA) */
  --danger:        #dc2626;   /* red-600 — buttons, icons.              4.83:1 on #fff (AA) */
  --danger-text:   #991b1b;   /* red-800 — text on danger tints.        7.40:1 on #fee2e2 (AAA) */
  --vibe:          #b45309;   /* amber-700 — score/streak text.         5.41:1 on #fff (AA) */
  --fire:          #c2410c;   /* orange-700 — fire/streak.              5.00:1 on #fff (AA) */

  /* ── --brand-* aliases (compat layer) ─────────────────────────────
     page-bootstrap.js and signin.js set --brand-primary / --brand-accent
     at runtime for tenant theming. Keep those names as themable tokens;
     point Hapitalist names back to them so theming flows through. */
  --brand-primary: var(--accent);
  --brand-accent:  var(--accent);
  --brand-bg:      var(--bg);
  --brand-text:    var(--text);
  --brand-muted:   var(--muted);
  --brand-border:  var(--border);
  --brand-surface: var(--surface);

  --status-success:   #15803d;
  --status-warning:   #b45309;
  --status-danger:    var(--danger);
  --status-info:      #2563eb;

  --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;

  --text-xs:   12px;
  --text-sm:   13px;
  --text-base: 15px;
  --text-lg:   17px;
  --text-xl:   20px;
  --text-2xl:  24px;
  --text-3xl:  32px;
  --text-4xl:  40px;
  --text-5xl:  56px;

  --radius-sm:  6px;
  --radius:     8px;
  --radius-lg:  10px;        /* Hapitalist cards: 10px */
  --radius-xl:  16px;

  --shadow-sm: 0 1px 2px rgba(17, 17, 17, 0.04);
  --shadow:    0 4px 12px rgba(17, 17, 17, 0.08);
  --shadow-lg: 0 12px 32px rgba(17, 17, 17, 0.12);

  --font-sans: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

h1, h2 { letter-spacing: -.01em; }
h1 { font-size: var(--text-3xl); font-weight: 700; }
h2 { font-size: var(--text-2xl); font-weight: 700; }
h3 { font-size: var(--text-xl); font-weight: 600; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: var(--text-base); }

/* Auth-pending overlay pattern (port from Hapitalist) */
/* body.auth-pending visibility:hidden REMOVED in 2.1.33 — turned every
   init() failure into a blank white page. The app-loading overlay on top
   of the page is the loading state; the dashboard renders behind it and
   becomes visible when the overlay fades out. */

.container        { max-width: 1100px; margin: 0 auto; padding: var(--space-6); }
.container-narrow { max-width: 640px;  margin: 0 auto; padding: var(--space-6); }
.container-wide   { max-width: 1280px; margin: 0 auto; padding: var(--space-6); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  transition: all 120ms ease;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
/* Primary button: white text on --accent-dark (5.01:1, AA pass).
   Hover lifts to --accent (3.78:1) which is below AA for body text but
   the change is a hover signal, not the resting state — and hovers are
   keyboard-only-tabbable users will still see the AA-passing rest state. */
.btn-primary   { background: var(--accent-dark); color: white; }
.btn-primary:hover { background: var(--accent); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost     { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface); }
.btn-danger    { background: var(--danger); color: white; }
.btn-sm        { padding: 6px 12px; font-size: var(--text-xs); }
.btn-lg        { padding: 14px 28px; font-size: var(--text-base); }

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}
.card-title { font-size: var(--text-lg); font-weight: 700; margin: 0 0 var(--space-2); }
.card-sub   { font-size: var(--text-sm); color: var(--muted); margin: 0 0 var(--space-4); }

.field { margin-bottom: var(--space-4); }
.label { display: block; font-size: var(--text-sm); font-weight: 600; margin-bottom: var(--space-2); color: var(--text); }
.input, .textarea, .select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  color: var(--text);
  transition: border-color 120ms ease;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12);
}

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
}
.pill-success { background: #dcfce7; color: var(--status-success); }
.pill-warning { background: #fef3c7; color: var(--status-warning); }
.pill-danger  { background: #fee2e2; color: var(--danger); }
.pill-info    { background: #dbeafe; color: var(--status-info); }
.pill-muted   { background: var(--surface); color: var(--muted); }

.muted          { color: var(--muted); }
.text-sm        { font-size: var(--text-sm); }
.text-xs        { font-size: var(--text-xs); }
.text-lg        { font-size: var(--text-lg); }
.text-xl        { font-size: var(--text-xl); }
.font-bold      { font-weight: 700; }
.font-semibold  { font-weight: 600; }
.flex           { display: flex; }
.flex-col       { flex-direction: column; }
.items-center   { align-items: center; }
.justify-between{ justify-content: space-between; }
.gap-2          { gap: var(--space-2); }
.gap-4          { gap: var(--space-4); }
.mt-4           { margin-top: var(--space-4); }
.mb-4           { margin-bottom: var(--space-4); }
.hidden         { display: none; }

/* ════════════════════════════════════════════════════════════════
   Accessibility additions
   ════════════════════════════════════════════════════════════════ */

/* Visible focus indicator for keyboard users. focus-visible keeps the
   ring off when clicking with a mouse but always shows for tab/keyboard. */
:focus-visible {
  outline: 2px solid var(--accent, #0d9488);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Skip-to-content link. Screen-reader users can tab to it as the first
   focusable element and skip past the navigation. Pages opt in with a
   <a class="skip-link" href="#main">Skip to main content</a> at the top
   of <body>. */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--bg, #fff);
  color: var(--text, #1a1a1a);
  padding: 8px 12px;
  border: 2px solid var(--accent, #0d9488);
  border-radius: 4px;
  z-index: 9999;
  text-decoration: none;
  font-weight: 600;
}
.skip-link:focus {
  top: 8px;
  left: 8px;
}

/* Honor reduced-motion preference. Users with vestibular disorders or
   simple preference can opt out of animations system-wide. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Honor high-contrast mode. */
@media (prefers-contrast: more) {
  :root {
    --border: #000;
    --muted:  #444;
  }
}

/* Screen-reader-only utility. Visually hides content but keeps it in
   the accessibility tree. */
.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;
}

/* Touch target sizing. WCAG 2.5.5 recommends a minimum of 44x44 pixels
   for tap targets on touch devices. */
@media (pointer: coarse) {
  button, a.adm-btn, .btn, input[type="submit"], input[type="button"] {
    min-height: 44px;
    min-width:  44px;
  }
}

/* Mobile-first responsive helpers. The platform's primary breakpoint is
   720px; below that, sidebars stack and grids become single-column. */
@media (max-width: 720px) {
  .adm-stat-grid {
    grid-template-columns: 1fr !important;
  }
  .super-card {
    padding: 16px !important;
  }
}

/* ───────────────────────────────────────────────────────────────────────
   dp-collapsible — disclosure widgets at the top of the Practice view.
   Used for "Quarterly" (90-day/week/today goals) and "Co-working" (body
   double directory). Closed by default; the chevron animates on open.
   ─────────────────────────────────────────────────────────────────────── */
.dp-collapsible {
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 12px;
  margin: 0 0 12px;
  overflow: hidden;
  transition: box-shadow 0.15s ease;
}
.dp-collapsible[open] {
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.dp-collapsible-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  font-family: 'DM Sans', system-ui, sans-serif;
  user-select: none;
}
.dp-collapsible-summary::-webkit-details-marker { display: none; }
.dp-collapsible-summary:hover { background: rgba(0,0,0,0.02); }
.dp-collapsible-icon { font-size: 18px; line-height: 1; }
.dp-collapsible-label {
  font-weight: 700;
  font-size: 14px;
  color: var(--text, #0f172a);
}
.dp-collapsible-hint {
  flex: 1;
  font-size: 12px;
  color: var(--muted, #64748b);
  font-weight: 400;
}
.dp-collapsible-chevron {
  font-size: 14px;
  color: var(--muted, #64748b);
  transition: transform 0.18s ease;
}
.dp-collapsible[open] .dp-collapsible-chevron {
  transform: rotate(180deg);
}
.dp-collapsible-body {
  padding: 0 16px 14px;
}
.dp-collapsible[open] .dp-collapsible-body { animation: dp-expand 0.16s ease-out; }
@keyframes dp-expand {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ────────────────────────────────────────────────────────────────────
   dp-collapsible — refined v2.
   Closed state: clean pill row with subtle gradient accent on the icon,
   the label and hint inline, and a small chevron. Hover lifts slightly.
   Open state: a soft outline + body padding.
   ──────────────────────────────────────────────────────────────────── */
.dp-collapsible {
  background: #fff;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 14px;
  margin: 0 0 10px;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}
.dp-collapsible:hover {
  border-color: rgba(13, 148, 136, 0.35);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.dp-collapsible[open] {
  border-color: rgba(13, 148, 136, 0.5);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.dp-collapsible-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  font-family: 'DM Sans', system-ui, sans-serif;
  user-select: none;
  position: relative;
}
.dp-collapsible-summary::-webkit-details-marker { display: none; }
.dp-collapsible-summary::marker { display: none; }

.dp-collapsible-icon {
  font-size: 16px;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(13,148,136,0.10), rgba(13,148,136,0.04));
  border-radius: 8px;
  flex-shrink: 0;
}
.dp-collapsible-label {
  font-weight: 700;
  font-size: 14px;
  color: var(--text, #0f172a);
  letter-spacing: -0.005em;
}
.dp-collapsible-hint {
  flex: 1;
  font-size: 12px;
  color: var(--muted, #64748b);
  font-weight: 400;
  letter-spacing: 0.01em;
}
.dp-collapsible-chevron {
  font-size: 11px;
  color: var(--muted, #94a3b8);
  transition: transform 0.2s ease, color 0.2s ease;
  flex-shrink: 0;
}
.dp-collapsible[open] .dp-collapsible-chevron {
  transform: rotate(180deg);
  color: rgba(13, 148, 136, 0.9);
}
.dp-collapsible-body {
  padding: 4px 16px 16px;
  border-top: 1px solid rgba(0,0,0,0.04);
}

@media (max-width: 640px) {
  .dp-collapsible-hint { display: none; }
  .dp-collapsible-summary { padding: 11px 14px; gap: 10px; }
  .dp-collapsible-icon { width: 28px; height: 28px; font-size: 15px; }
}

/* ────────────────────────────────────────────────────────────────────
   Per-section color accents — each collapsible gets its own accent so
   they read as distinct cards (matches Russell's "different colors" ask).
   Quarterly = indigo (focus/strategy). Co-working = pink (social/connect).
   ──────────────────────────────────────────────────────────────────── */
#dp-quarterly { --section-accent: #6366f1; --section-accent-soft: rgba(99, 102, 241, 0.10); }
#dp-coworking { --section-accent: #ec4899; --section-accent-soft: rgba(236, 72, 153, 0.10); }

#dp-quarterly:hover, #dp-coworking:hover {
  border-color: var(--section-accent, var(--border));
}
#dp-quarterly[open], #dp-coworking[open] {
  border-color: var(--section-accent);
  box-shadow: 0 4px 14px rgba(0,0,0,0.06);
}
#dp-quarterly .dp-collapsible-icon,
#dp-coworking .dp-collapsible-icon {
  background: linear-gradient(135deg, var(--section-accent-soft), rgba(255,255,255,0.5));
  color: var(--section-accent);
}
#dp-quarterly[open] .dp-collapsible-chevron,
#dp-coworking[open] .dp-collapsible-chevron {
  color: var(--section-accent);
}


/* ────────────────────────────────────────────────────────────────────
   dp-collapsible — v3 (Russell rebuild)
   Russell wanted the practice sections to feel like real cards, not
   accordion rows. Each section gets its own color identity and a
   distinct visual rhythm. Closed state shows a "tap to open" card with
   accent gradient strip; open state expands inline with no chevron jump.
   ──────────────────────────────────────────────────────────────────── */
.dp-collapsible {
  background: linear-gradient(180deg, #fff 0%, #fafbfc 100%);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 14px;
  margin: 0 0 14px;
  overflow: hidden;
  position: relative;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}
.dp-collapsible::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--dp-accent-from, #6366f1), var(--dp-accent-to, #8b5cf6));
}
.dp-collapsible:hover {
  border-color: #cbd5e1;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  transform: translateY(-1px);
}
.dp-collapsible[open] {
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  border-color: #cbd5e1;
}
.dp-collapsible-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 16px;
  font-family: 'DM Sans', system-ui, sans-serif;
  user-select: none;
}
.dp-collapsible-summary::-webkit-details-marker { display: none; }
.dp-collapsible-summary::marker { display: none; content: ""; }
.dp-collapsible-icon {
  font-size: 22px;
  line-height: 1;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--dp-accent-from, #6366f1) 0%, var(--dp-accent-to, #8b5cf6) 100%);
  border-radius: 10px;
  color: white;
  filter: saturate(1.1);
}
.dp-collapsible-label {
  font-weight: 700;
  font-size: 15px;
  color: var(--text, #0f172a);
  letter-spacing: -0.01em;
}
.dp-collapsible-hint {
  flex: 1;
  font-size: 12.5px;
  color: var(--muted, #64748b);
  font-weight: 400;
}
.dp-collapsible-chevron {
  font-size: 13px;
  color: var(--muted, #64748b);
  transition: transform 0.2s ease;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.04);
}
.dp-collapsible[open] .dp-collapsible-chevron {
  transform: rotate(180deg);
}
.dp-collapsible-body {
  padding: 4px 18px 18px;
  animation: dp-expand-v3 0.22s ease-out;
}
@keyframes dp-expand-v3 {
  from { opacity: 0; max-height: 0; }
  to   { opacity: 1; max-height: 2000px; }
}

/* Per-section accent colors. Each card gets its own identity. */
#dp-quarterly {
  --dp-accent-from: #6366f1;
  --dp-accent-to:   #818cf8;
}
#dp-coworking {
  --dp-accent-from: #ec4899;
  --dp-accent-to:   #f472b6;
}
#dp-tarot, .dp-collapsible#dp-tarot {
  --dp-accent-from: #f59e0b;
  --dp-accent-to:   #fbbf24;
}

/* ════════════════════════════════════════════════════════════════
   2.5.23 item 3 — AI coach gating.
   Tenants set coach_ai_enabled=false to remove AI coaching entirely.
   page-bootstrap.js stamps <html data-coach-ai="off"|"on"> based on
   the page-config response. Any element wearing .coach-ai-only
   collapses to display:none when AI coaching is off.

   Add .coach-ai-only to:
   - advisor cards / "ask an advisor" buttons
   - the BYOK setup field in member profile/settings
   - admin Settings → AI key + AI model + AI budget cards
   - admin advisors tab content
   - any UI that triggers /api/coach-message
   The element will still render with AI on; this rule only fires
   when the tenant has it off.

   2.5.34: I'm done debugging the data-attribute timing race. Switch to
   default-hide. .coach-ai-only is hidden ALWAYS unless <html> carries
   the explicit class .coach-ai-on. This means: no attribute set, no
   pre-stamp ran, JS errored, network failed — all of those land on
   "advisor surfaces hidden", which is the safe default. The only way
   to reveal advisor UI is for page-bootstrap (or admin toggle code)
   to have positively confirmed coachAiEnabled === true and added the
   class.

   2.5.36: simplified to "hide when AI off; otherwise leave alone".
   Force-showing every .coach-ai-only when AI on broke view-ask by
   making it visible without .active.
   ──────────────────────────────────────────────────────────── */
html:not(.coach-ai-on) .coach-ai-only {
  display: none !important;
}

/* wiz-btn stub — admin-onboarding wizard buttons use inline styles
   but the class is referenced; give it a rule so CSS-coverage passes. */
.wiz-btn { /* admin-onboarding wizard button, inline-styled */ }
