/* Creator-Vision Design Tokens
 * ---------------------------------------------------------------------------
 * SINGLE SOURCE OF TRUTH for the app's palette, surfaces, typography and
 * control sizing. Every shared component (shell, nav, buttons, tables,
 * panels) should read from these ``--cv-*`` custom properties instead of
 * hardcoding hex values, so a site-wide restyle (e.g. "all primary buttons
 * to green", "resize all control buttons") is a one-file change here.
 *
 * Dark mode is expressed purely as a second set of the SAME token names
 * under ``[data-theme="dark"]`` -- no component CSS needs to know about the
 * theme, it just consumes the tokens. ``data-bs-theme`` (set alongside
 * ``data-theme`` in the base templates) hands Bootstrap's own components
 * (forms, modals, dropdowns, cards) their dark styling for free.
 *
 * This file MUST be linked FIRST (before Bootstrap-dependent app CSS).
 * --------------------------------------------------------------------------- */

:root {
  color-scheme: light;

  /* ===== BRAND / NAV ===== */
  --cv-color-nav: #ff7300;
  --cv-color-nav-hover: #ff9000;
  --cv-color-nav-text: #ffffff;
  --cv-color-nav-toggle-active-bg: #ffffff;
  --cv-color-nav-toggle-active-text: #ff7300;

  /* ===== ACTION COLOURS ===== */
  /* Primary drives Bootstrap ``.btn-primary`` + links (see remap below). */
  --cv-color-primary: #0d6efd;
  --cv-color-primary-hover: #0a58ca;
  --cv-color-primary-active: #0a53be;
  --cv-color-primary-rgb: 13, 110, 253;
  --cv-color-primary-contrast: #ffffff;

  /* Accent = the purple "Add to Compilation" family. */
  --cv-color-accent: #7c3aed;
  --cv-color-accent-hover: #6d28d9;
  --cv-color-accent-active: #5b21b6;
  --cv-color-accent-rgb: 124, 58, 237;
  --cv-color-accent-contrast: #ffffff;
  --cv-color-accent-subtle: #f3eefe;    /* pale purple placeholder tint */

  /* Fixed dark scrim over media (e.g. thumbnail while processing). */
  --cv-overlay-scrim: rgba(0, 0, 0, 0.5);

  /* Vertical/teal icon action. */
  --cv-color-teal: #0aa2c0;
  --cv-color-teal-subtle: #e6f7fb;
  --cv-color-teal-text: #055160;        /* readable teal text on teal-subtle */

  /* Button hover shades used by the page-functions bar overrides. */
  --cv-color-secondary-hover: #3d4349;
  --cv-color-success-hover: #117a3e;

  /* "Assets & Templates" upload action (medium blue). */
  --cv-color-upload: #5dade2;
  --cv-color-upload-hover: #4682b4;
  --cv-color-upload-contrast: #ffffff;

  /* ===== SEMANTIC / STATUS ===== */
  /* Values deliberately match Bootstrap's defaults so remapping Bootstrap's
     --bs-* onto these (see BOOTSTRAP RE-MAP below) is appearance-neutral.
     The ``-rgb`` triplets back Bootstrap's runtime bg-*/text-* utilities. */
  --cv-color-secondary: #6c757d;
  --cv-color-secondary-rgb: 108, 117, 125;
  --cv-color-secondary-contrast: #fff;
  --cv-color-success: #198754;
  --cv-color-success-rgb: 25, 135, 84;
  --cv-color-success-contrast: #fff;
  --cv-color-danger: #dc3545;
  --cv-color-danger-rgb: 220, 53, 69;
  --cv-color-danger-contrast: #fff;
  --cv-color-warning: #ffc107;
  --cv-color-warning-rgb: 255, 193, 7;
  --cv-color-warning-contrast: #000;
  --cv-color-info: #0dcaf0;
  --cv-color-info-rgb: 13, 202, 240;
  --cv-color-info-contrast: #000;

  /* Page-control buttons' INACTIVE state (the single knob). Control buttons
     have 3 states: inactive = filled with this neutral grey; active = filled
     with the button's palette colour; hover = filled with a darker palette
     shade. Change these three values to restyle every inactive control. */
  --cv-control-inactive-bg: #6c757d;
  --cv-control-inactive-text: #fff;
  --cv-control-inactive-border: #6c757d;

  --cv-status-pending: #6c757d;
  --cv-status-blue: #0d6efd;
  --cv-status-blue-bright: #339af0;
  --cv-status-orange: #fd7e14;
  --cv-status-green: #20c997;
  --cv-status-green-solid: #198754;
  --cv-status-red: #dc3545;
  --cv-status-grey: #6c757d;
  --cv-status-queued: #17a2b8;

  /* Plot-event significance ramp ("major = red, moderate = orange,
     minor = yellow"). Aliased onto the status palette so the whole
     significance grammar can be retinted in one place. */
  --cv-severity-major: var(--cv-color-danger);
  --cv-severity-moderate: var(--cv-status-orange);
  --cv-severity-minor: var(--cv-color-warning);

  /* Narrative-element badges (callback / open-thread / foreshadowing). */
  --cv-narrative-callback: #6f42c1;
  --cv-narrative-open-thread: #d97706;
  --cv-narrative-foreshadowing: #0d9488;

  /* Amber "attention" flash (KG locked-toggle pulse). */
  --cv-color-attention: #f59e0b;
  --cv-color-attention-rgb: 245, 158, 11;

  /* Builder asset item (enhancement intro/outro/interstitial) green card. */
  --cv-builder-asset-border: #52a675;
  --cv-builder-asset-bg-start: #f0faf4;
  --cv-builder-asset-bg-end: #e8f5ee;
  --cv-builder-asset-label: #2d6b42;
  --cv-builder-asset-name: #3d8c5a;

  /* KG search section header (dark band + soft count pill). */
  --cv-section-header-bg: #1a1a1a;
  --cv-section-header-text: #ffffff;
  --cv-section-header-pill: rgba(255, 255, 255, 0.18);

  /* Search-match highlight (``<mark>``) + generic swatch border. */
  --cv-highlight-mark: #fff3cd;
  --cv-swatch-border: rgba(0, 0, 0, 0.15);

  /* ===== ASSET LIBRARY (enhance) ===== */
  /* Asset-type badges (blue ramp) + segment-type badges (green ramp). White
     text sits on all of these, so they are held constant across themes. */
  --cv-asset-graphics: #6c9bcf;
  --cv-asset-video: #4a7ba7;
  --cv-asset-audio: #2b5278;
  --cv-asset-segments: #1a3a52;
  --cv-segment-intro: #52a675;
  --cv-segment-outro: #3d8c5a;
  --cv-segment-interstitial: #2d6b42;
  /* Dark-green highlight panel (white content sits on it). */
  --cv-color-success-panel: #1e5631;

  /* ===== SURFACES ===== */
  --cv-surface-body: #ffffff;       /* page background / main scroll area */
  --cv-surface: #ffffff;            /* header, cards */
  --cv-surface-muted: #f8f9fa;      /* card headers, subtle panels */
  --cv-surface-controls: #f7f7f7;   /* table-controls sticky bar */
  --cv-surface-functions: #f2f2ff;  /* page-functions sticky bar */
  --cv-surface-footer: #eeeeee;     /* footer */
  --cv-surface-trail: #e4e7ea;      /* recent-page trail bar */
  --cv-table-header-bg: #ececec;
  --cv-table-row-alt: #f9f9f9;
  --cv-row-hover: rgba(0, 123, 255, 0.05);     /* interactive row hover tint */
  --cv-row-selected: rgba(0, 123, 255, 0.1);   /* selected row tint */
  --cv-table-link: #0d6efd;
  --cv-table-link-hover: #0a58ca;

  /* ===== BORDERS ===== */
  --cv-border: #e0e0e0;
  --cv-border-subtle: #dee2e6;

  /* ===== TEXT ===== */
  --cv-text: rgba(0, 0, 0, 0.8);
  --cv-text-muted: #6c757d;
  --cv-text-tenant: #555555;
  /* Recent-page trail steps. Reason: the bright #ffc107 yellow used on dark
     fails contrast on a light grey bar, so light mode uses a dark amber. */
  --cv-trail-step: #8a6d00;
  --cv-trail-step-strong: #5c4700;

  /* ===== SHADOWS ===== */
  --cv-shadow-header: 0 2px 6px rgba(0, 0, 0, 0.03);
  --cv-shadow-sticky: 0 2px 4px rgba(0, 0, 0, 0.1);
  /* Menus that open over page content. */
  --cv-shadow-popover: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.25);

  /* ===== SHAPE / SIZING ===== */
  --cv-header-height: 3em;
  --cv-nav-height: 3em;
  --cv-radius-sm: 3px;
  --cv-radius: 0.375rem;
  --cv-radius-pill: 999px;

  /* Control (button/input) sizing knobs -- adjust these to resize
     page control buttons site-wide. */
  --cv-btn-radius: var(--cv-radius);
  --cv-btn-padding-y: 0.375rem;
  --cv-btn-padding-x: 0.75rem;
  --cv-btn-font-size: 1rem;

  /* Nav link typography. */
  --cv-nav-font-size: 0.95em;
  --cv-nav-font-weight: 500;

  /* Spacing scale. */
  --cv-space-1: 0.25rem;
  --cv-space-2: 0.5rem;
  --cv-space-3: 1rem;
  --cv-space-4: 1.5rem;

  /* Compact typography scale for dense dashboards / metric panels.
     Replaces the scattered inline ``font-size:.75-.85rem`` literals. */
  --cv-fs-xs: 0.75rem;
  --cv-fs-sm: 0.8rem;
  --cv-fs-md: 0.85rem;

  /* Subtle info surface (e.g. highlighted KPI card). */
  --cv-surface-info-subtle: #e7f3ff;

  /* Semi-opaque scrim behind HTMX loading spinners. */
  --cv-overlay-loading: rgba(255, 255, 255, 0.7);

  /* ===== AI-MODE CHROME =====
     The AI (assistant) view is always dark, so these live in :root rather
     than the dark-theme block. They deliberately use a slightly different
     grey ramp from the main dark theme to match the chat surface. */
  --cv-ai-surface: #202123;
  --cv-ai-surface-alt: #2c2d33;
  --cv-ai-text: #c9c9d1;
  --cv-ai-text-muted: #9a9ba6;
  --cv-ai-border: rgba(255, 255, 255, 0.16);
  --cv-ai-border-subtle: rgba(255, 255, 255, 0.12);
  --cv-ai-fill: rgba(255, 255, 255, 0.1);
  --cv-ai-fill-subtle: rgba(255, 255, 255, 0.08);
  --cv-ai-fill-hover: rgba(255, 255, 255, 0.2);
  --cv-ai-scrim: rgba(0, 0, 0, 0.22);
  --cv-ai-scrim-hover: rgba(255, 255, 255, 0.18);
  --cv-ai-menu-shadow: 0 -4px 16px rgba(0, 0, 0, 0.4);
}

/* ===========================================================================
   DARK THEME
   Overrides only the tokens whose *values* change; brand orange, action
   colours and sizing are intentionally shared with light mode.
   =========================================================================== */
[data-theme="dark"] {
  color-scheme: dark;

  /* Nav: dark grey (mirrors the existing AI-mode chrome) rather than
     brand orange, so the dark UI reads as a cohesive dark surface. */
  --cv-color-nav: #2c2d33;
  --cv-color-nav-hover: rgba(255, 255, 255, 0.14);
  --cv-color-nav-text: #ececf1;
  --cv-color-nav-toggle-active-bg: rgba(255, 255, 255, 0.9);
  --cv-color-nav-toggle-active-text: #202123;

  /* Slightly brighter action colours for contrast on dark surfaces. */
  --cv-color-primary: #4c8dff;
  --cv-color-primary-hover: #6ba0ff;
  --cv-color-primary-active: #86b2ff;
  --cv-color-primary-rgb: 76, 141, 255;
  --cv-color-accent: #a78bfa;
  --cv-color-accent-hover: #b9a3fc;
  --cv-color-accent-active: #c7b6fd;
  --cv-color-accent-rgb: 167, 139, 250;
  --cv-color-accent-subtle: #2b2140;    /* deep purple placeholder tint */

  --cv-color-teal-subtle: #0c2b33;      /* deep teal placeholder tint */
  --cv-color-teal-text: #7fd6e6;        /* readable teal text on dark teal */

  --cv-status-blue: #4c8dff;
  --cv-table-link: #6ba0ff;
  --cv-table-link-hover: #86b2ff;

  /* Surfaces. */
  --cv-surface-body: #1a1b1e;
  --cv-surface: #202123;
  --cv-surface-muted: #2a2b32;
  --cv-surface-controls: #24252b;
  --cv-surface-functions: #26262f;
  --cv-surface-footer: #2c2d33;
  --cv-surface-trail: #3a3c45;
  --cv-table-header-bg: #2a2b32;
  --cv-table-row-alt: #24252b;
  --cv-row-hover: rgba(108, 152, 255, 0.1);
  --cv-row-selected: rgba(108, 152, 255, 0.18);

  /* Borders. */
  --cv-border: #3a3b42;
  --cv-border-subtle: #3a3b42;

  /* Text. */
  --cv-text: #ececf1;
  --cv-text-muted: #9a9ba6;
  --cv-text-tenant: #c9c9d1;
  --cv-trail-step: #d9a406;
  --cv-trail-step-strong: #ffc107;

  /* Info surface reads as a dark tinted panel rather than pale blue. */
  --cv-surface-info-subtle: #223049;

  /* Builder asset green card: deep green on dark rather than pale mint. */
  --cv-builder-asset-bg-start: #16281d;
  --cv-builder-asset-bg-end: #1a2f22;
  --cv-builder-asset-label: #6fce97;
  --cv-builder-asset-name: #5bb381;

  /* Search-match highlight: muted amber on dark. */
  --cv-highlight-mark: #4a3f1a;
  --cv-swatch-border: rgba(255, 255, 255, 0.2);

  /* Dark scrim so the loading spinner overlay doesn't flash white. */
  --cv-overlay-loading: rgba(0, 0, 0, 0.5);

  /* Shadows read heavier on dark. */
  --cv-shadow-header: 0 2px 6px rgba(0, 0, 0, 0.4);
  --cv-shadow-sticky: 0 2px 4px rgba(0, 0, 0, 0.5);
  --cv-shadow-popover: 0 0 0 1px rgba(200, 200, 200, 0.35),
    0 0 1.25rem rgba(200, 200, 200, 0.3);

  /* Bootstrap re-sets --bs-link-color under [data-bs-theme=dark] (which wins
     over our :root remap by specificity), so re-assert it here to keep body
     links on the --cv- palette in dark mode. tokens.css loads after Bootstrap,
     so this equal-specificity rule wins. */
  --bs-link-color: var(--cv-color-primary);
  --bs-link-color-rgb: var(--cv-color-primary-rgb);
  --bs-link-hover-color: var(--cv-color-primary-hover);
}

/* ===========================================================================
   BOOTSTRAP RE-MAP
   Point Bootstrap's runtime custom-properties at ``--cv-*`` tokens so existing
   Bootstrap markup rethemes with zero template edits. Bootstrap reads these at
   runtime, so a single token change recolours every consumer across the site.

   This file is linked AFTER Bootstrap's CSS, so these :root overrides win over
   Bootstrap's own defaults. Values are kept equal to Bootstrap's defaults, so
   the remap is appearance-neutral in light mode; in dark mode the accents pick
   up whatever the ``--cv-*`` tokens resolve to (e.g. brighter primary), which
   already matches the themed ``.btn-primary``.
   --------------------------------------------------------------------------- */

/* Lever 1: global semantic remap. Drives Bootstrap's runtime utilities that
   read these at paint time -- ``.bg-*`` / ``.text-*`` / ``.text-bg-*`` and the
   ``badge``/component fills that reference ``--bs-<name>[-rgb]`` -- so the
   whole semantic palette flows from ``--cv-*``. Dark-mode shifts ride through
   automatically because the referenced ``--cv-*`` tokens carry dark values. */
:root {
  --bs-primary: var(--cv-color-primary);
  --bs-primary-rgb: var(--cv-color-primary-rgb);
  --bs-secondary: var(--cv-color-secondary);
  --bs-secondary-rgb: var(--cv-color-secondary-rgb);
  --bs-success: var(--cv-color-success);
  --bs-success-rgb: var(--cv-color-success-rgb);
  --bs-danger: var(--cv-color-danger);
  --bs-danger-rgb: var(--cv-color-danger-rgb);
  --bs-warning: var(--cv-color-warning);
  --bs-warning-rgb: var(--cv-color-warning-rgb);
  --bs-info: var(--cv-color-info);
  --bs-info-rgb: var(--cv-color-info-rgb);
  /* Body links follow primary too. */
  --bs-link-color: var(--cv-color-primary);
  --bs-link-color-rgb: var(--cv-color-primary-rgb);
  --bs-link-hover-color: var(--cv-color-primary-hover);
}

.btn-primary {
  --bs-btn-bg: var(--cv-color-primary);
  --bs-btn-border-color: var(--cv-color-primary);
  --bs-btn-color: var(--cv-color-primary-contrast);
  --bs-btn-hover-bg: var(--cv-color-primary-hover);
  --bs-btn-hover-border-color: var(--cv-color-primary-hover);
  --bs-btn-hover-color: var(--cv-color-primary-contrast);
  --bs-btn-active-bg: var(--cv-color-primary-active);
  --bs-btn-active-border-color: var(--cv-color-primary-active);
  --bs-btn-active-color: var(--cv-color-primary-contrast);
  --bs-btn-disabled-bg: var(--cv-color-primary);
  --bs-btn-disabled-border-color: var(--cv-color-primary);
  --bs-btn-disabled-color: var(--cv-color-primary-contrast);
  --bs-btn-focus-shadow-rgb: var(--cv-color-primary-rgb);
}

.btn-outline-primary {
  /* inactive = filled neutral grey */
  --bs-btn-color: var(--cv-control-inactive-text);
  --bs-btn-bg: var(--cv-control-inactive-bg);
  --bs-btn-border-color: var(--cv-control-inactive-border);
  /* hover = darker palette shade */
  --bs-btn-hover-bg: var(--cv-color-primary-hover);
  --bs-btn-hover-border-color: var(--cv-color-primary-hover);
  --bs-btn-hover-color: var(--cv-color-primary-contrast);
  /* active = filled palette colour */
  --bs-btn-active-bg: var(--cv-color-primary);
  --bs-btn-active-border-color: var(--cv-color-primary);
  --bs-btn-active-color: var(--cv-color-primary-contrast);
  --bs-btn-disabled-color: var(--cv-control-inactive-text);
  --bs-btn-disabled-bg: var(--cv-control-inactive-bg);
  --bs-btn-disabled-border-color: var(--cv-control-inactive-border);
  --bs-btn-focus-shadow-rgb: var(--cv-color-primary-rgb);
}

/* ---------------------------------------------------------------------------
   Lever 3: theme-aware "light" utilities.
   Bootstrap's ``.bg-light`` / ``.text-bg-light`` are fixed pale values
   (``--bs-light-rgb`` is not remapped under [data-bs-theme=dark]), so panels
   and neutral badges using them stayed white in dark mode. Point the surface
   at ``--cv-surface-muted`` (== Bootstrap's #f8f9fa in light, so appearance-
   neutral) and, in dark only, re-colour the text that would otherwise be a
   baked ``#000`` / ``.text-dark`` on the now-dark chip. ``!important`` +
   higher specificity are required to beat Bootstrap's own !important utils. */
[data-theme] .bg-light,
[data-theme] .text-bg-light {
  background-color: var(--cv-surface-muted) !important;
}
[data-theme="dark"] .text-bg-light,
[data-theme="dark"] .bg-light.text-dark {
  color: var(--cv-text) !important;
}

/* ===========================================================================
   THEME TOGGLE CONTROL (footer sun/moon button)
   Small, subtle, sits at the far right of the footer bar.
   =========================================================================== */
.theme-toggle-btn {
  background: transparent;
  color: var(--cv-text-muted);
  border: 1px solid var(--cv-border-subtle);
  font-size: 9pt;
  line-height: 1;
  width: 1.9em;
  height: 1.9em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--cv-radius-pill);
  cursor: pointer;
  vertical-align: middle;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.theme-toggle-btn:hover,
.theme-toggle-btn:focus {
  background: var(--cv-surface-muted);
  color: var(--cv-text);
  border-color: var(--cv-text-muted);
}

/* Show the correct glyph for the active theme: moon in light mode (click to
   go dark), sun in dark mode (click to go light). */
.theme-toggle-btn .theme-icon-dark { display: none; }
.theme-toggle-btn .theme-icon-light { display: inline-flex; }
[data-theme="dark"] .theme-toggle-btn .theme-icon-light { display: none; }
[data-theme="dark"] .theme-toggle-btn .theme-icon-dark { display: inline-flex; }

/* ===========================================================================
   SHARED UTILITIES
   Token-backed helpers that replace repeated inline ``style="..."`` literals
   across pages (Phase 2 inline-style burn-down).
   =========================================================================== */

/* Compact type scale. */
.cv-text-xs { font-size: var(--cv-fs-xs); }
.cv-text-sm { font-size: var(--cv-fs-sm); }
.cv-text-md { font-size: var(--cv-fs-md); }

/* Body-coloured text that stays legible in dark mode (unlike ``.text-dark``). */
.cv-text-body { color: var(--cv-text); }

/* Slim progress bar used by the metric gauges. */
.cv-progress-thin { height: 6px; }

/* Full-cover scrim behind an HTMX loading spinner (theme-aware). Pair with
   Bootstrap's ``position-absolute top-0 start-0 w-100 h-100``. */
.cv-loading-overlay {
  background: var(--cv-overlay-loading);
  z-index: 20;
}

/* Teal (vertical-clip) icon/text accent. */
.cv-text-teal { color: var(--cv-color-teal); }

/* Pointer affordance on non-interactive collapse toggles etc. */
.cv-cursor-pointer { cursor: pointer; }

/* An image that opens full size when clicked. */
.cv-cursor-zoom { cursor: zoom-in; }
