/* ============================================================
 * Custom Widgets - Universal Design Tokens
 * ============================================================
 * Single source of truth for ALL pages: marketing + SPA + portal.
 * Both the static site (site.css) and the React app (index.css) import this.
 *
 * Loading order (enforced by partials/head.html):
 *   1. theme.js            → sets <html data-theme="light|dark"> before paint
 *   2. design-tokens.css   → defines ALL custom properties for both themes
 *   3. site.css            → marketing components (uses these tokens)
 *   4. (SPA) index.css     → maps shadcn semantic tokens onto these tokens
 *
 * Token naming convention (kebab-case, prefixed):
 *   --cw-color-*           Color values
 *   --cw-radius-*          Border radius
 *   --cw-shadow-*          Shadows
 *   --cw-font-*            Font families
 *   --cw-spacing-*         Spacing scale
 *   --cw-z-*               Z-index layers
 *
 * Do NOT define component styles here - only raw design tokens.
 * Components live in site.css (marketing) and index.css (SPA shadcn mapping).
 * ============================================================ */

/* ---- Color tokens (dark theme is the default) ---- */
:root {
  /* Brand */
  --cw-color-brand: #41CD52;
  --cw-color-brand-light: #70e07f;
  --cw-color-brand-dark: #2fa440;
  --cw-color-brand-ink: #0f2410;          /* text on brand backgrounds */
  --cw-color-brand-text: #41CD52;         /* brand as text on page surfaces */

  /* Backgrounds (dark) */
  --cw-color-bg-body: #131316;
  --cw-color-bg-card: #1b1b1f;
  --cw-color-bg-raised: #232327;
  --cw-color-bg-input: #232327;
  --cw-color-bg-sidebar: #131316;
  --cw-color-bg-footer: #0f0f12;

  /* Text (dark) */
  --cw-color-text-primary: #e9e9ec;
  --cw-color-text-secondary: #a6a6ae;
  --cw-color-text-muted: #a1a1a6;

  /* Borders (dark) */
  --cw-color-line: rgba(255, 255, 255, 0.08);
  --cw-color-line-strong: rgba(255, 255, 255, 0.14);

  /* Semantic */
  --cw-color-success: #10b981;
  --cw-color-error: #ef4444;
  --cw-color-warning: #f59e0b;
  --cw-color-info: #3b82f6;

  /* Reactions (icon tints) */
  --cw-color-reaction-like: #2563eb;
  --cw-color-reaction-love: #e11d48;
  --cw-color-reaction-care: #b45309;
  --cw-color-reaction-haha: #b45309;
  --cw-color-reaction-wow: #7c3aed;
  --cw-color-reaction-sad: #0e7490;
  --cw-color-reaction-angry: #c2410c;
  --cw-color-like: #f17c9d;  /* legacy alias for "liked" state */

  /* Chart palette */
  --cw-color-chart-1: #41CD52;
  --cw-color-chart-2: #70e07f;
  --cw-color-chart-3: #3b82f6;
  --cw-color-chart-4: #f59e0b;
  --cw-color-chart-5: #f17c9d;

  /* Header / footer */
  --cw-color-header-bg: rgba(19, 19, 22, 0.85);
  --cw-color-footer-bg: #0f0f12;

  /* Inverse (for active nav items) */
  --cw-color-inverse-surface: #e9e9ec;
  --cw-color-inverse-on-surface: #131316;

  /* Focus ring */
  --cw-color-focus-ring: #41CD52;

  /* Overlay */
  --cw-color-overlay: rgba(0, 0, 0, 0.45);
}

/* ---- Light theme overrides ---- */
:root[data-theme="light"] {
  --cw-color-brand-text: #15803d;         /* AA contrast on light surfaces */

  /* Backgrounds */

  --cw-color-bg-body: #fafafa;
  --cw-color-bg-card: #ffffff;
  --cw-color-bg-raised: #f4f4f5;
  --cw-color-bg-input: #ffffff;
  --cw-color-bg-sidebar: #fafafa;
  --cw-color-bg-footer: #f4f4f5;

  /* Text */
  --cw-color-text-primary: #171717;
  --cw-color-text-secondary: #525252;
  --cw-color-text-muted: #737373;

  /* Borders */
  --cw-color-line: rgba(8, 8, 8, 0.08);
  --cw-color-line-strong: rgba(8, 8, 8, 0.14);

  /* Header / footer */
  --cw-color-header-bg: rgba(255, 255, 255, 0.82);
  --cw-color-footer-bg: #f1f2f7;

  /* Inverse */
  --cw-color-inverse-surface: #131316;
  --cw-color-inverse-on-surface: #e9e9ec;

  /* Overlay */
  --cw-color-overlay: rgba(0, 0, 0, 0.35);
}

/* ---- System preference fallback (when no explicit choice) ---- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --cw-color-bg-body: #131316;
    --cw-color-bg-card: #1b1b1f;
    --cw-color-bg-raised: #232327;
    --cw-color-bg-input: #232327;
    --cw-color-bg-sidebar: #131316;
    --cw-color-bg-footer: #0f0f12;
    --cw-color-text-primary: #e9e9ec;
    --cw-color-text-secondary: #a6a6ae;
    --cw-color-text-muted: #74747d;
    --cw-color-line: rgba(255, 255, 255, 0.08);
    --cw-color-line-strong: rgba(255, 255, 255, 0.14);
    --cw-color-header-bg: rgba(19, 19, 22, 0.85);
    --cw-color-footer-bg: #0f0f12;
    --cw-color-inverse-surface: #e9e9ec;
    --cw-color-inverse-on-surface: #131316;
    --cw-color-overlay: rgba(0, 0, 0, 0.45);
  }
}

/* ---- Shape tokens ---- */
:root {
  --cw-radius-control: 8px;     /* buttons, inputs, badges */
  --cw-radius-card: 16px;       /* post cards, panels, elevated surfaces */
  --cw-radius-pill: 999px;      /* avatars, follow buttons, search, create */

  /* Radius scale for shadcn (0.6x to 2.6x base) */
  --cw-radius-sm: calc(var(--cw-radius-control) * 0.6);   /* ~5px */
  --cw-radius-md: calc(var(--cw-radius-control) * 0.8);   /* ~6px */
  --cw-radius-lg: var(--cw-radius-control);               /* 8px */
  --cw-radius-xl: calc(var(--cw-radius-control) * 1.4);   /* ~11px */
  --cw-radius-2xl: calc(var(--cw-radius-control) * 1.8);  /* ~14px */
  --cw-radius-3xl: calc(var(--cw-radius-control) * 2.2);  /* ~18px */
  --cw-radius-4xl: calc(var(--cw-radius-control) * 2.6);  /* ~21px */
}

/* ---- Shadow tokens ---- */
:root {
  --cw-shadow-float: 0 16px 40px rgba(0, 0, 0, 0.28);
  --cw-shadow-card: none;  /* cards have no shadow by design */
}

:root[data-theme="light"] {
  --cw-shadow-float: 0 16px 40px rgba(20, 20, 40, 0.1);
}

/* ---- Typography tokens ---- */
:root {
  --cw-font-sans: "Plus Jakarta Sans", system-ui, sans-serif;
  --cw-font-mono: "JetBrains Mono", ui-monospace, monospace;

  /* Font weights */
  --cw-font-weight-regular: 400;
  --cw-font-weight-medium: 500;
  --cw-font-weight-semibold: 600;
  --cw-font-weight-bold: 700;
}

/* ---- Spacing tokens (4px base grid) ---- */
:root {
  --cw-spacing-1: 4px;
  --cw-spacing-2: 8px;
  --cw-spacing-3: 12px;
  --cw-spacing-4: 16px;
  --cw-spacing-5: 20px;
  --cw-spacing-6: 24px;
  --cw-spacing-8: 32px;
  --cw-spacing-10: 40px;
  --cw-spacing-12: 48px;
  --cw-spacing-16: 64px;
}

/* ---- Z-index layers ---- */
:root {
  --cw-z-header: 50;
  --cw-z-drawer: 50;
  --cw-z-modal: 100;
  --cw-z-lightbox: 120;
  --cw-z-toast: 130;
  --cw-z-support-bubble: 99999;
  --cw-z-support-panel: 99999;
}

/* ---- Layout tokens ---- */
:root {
  --cw-max-width: 1280px;
  --cw-header-height: 64px;
  --cw-sidebar-width: 250px;
  --cw-right-sidebar-width: 230px;
}

/* ---- Selection ---- */
::selection {
  background: rgba(65, 205, 82, 0.28);
}

/* ---- Focus visible (accessibility floor) ---- */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--cw-color-focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: var(--cw-color-line-strong);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--cw-color-text-muted);
  background-clip: padding-box;
}

/* ---- Font smoothing ---- */
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---- Helper utilities (used by both marketing and SPA) ---- */
.t-primary { color: var(--cw-color-text-primary); }
.t-secondary { color: var(--cw-color-text-secondary); }
.t-muted { color: var(--cw-color-text-muted); }
.t-accent { color: var(--cw-color-brand-text); }
.t-inverse { color: var(--cw-color-inverse-on-surface); }

.bg-body { background: var(--cw-color-bg-body); }
.bg-card { background: var(--cw-color-bg-card); }
.bg-raised { background: var(--cw-color-bg-raised); }
.bg-input { background: var(--cw-color-bg-input); }

.border-line { border-color: var(--cw-color-line); }
.border-line-strong { border-color: var(--cw-color-line-strong); }

.rounded-control { border-radius: var(--cw-radius-control); }
.rounded-card { border-radius: var(--cw-radius-card); }
.rounded-pill { border-radius: var(--cw-radius-pill); }

.shadow-float { box-shadow: var(--cw-shadow-float); }