/* ============================================================
   COLORS  —  Buddy Design System
   ------------------------------------------------------------
   Three layers:

     1. FOUNDATION — Apple system semantic colors (light + dark).
        The shared native bedrock used by the calmer apps
        (VolBuddy, HABuddy).

     2. INSTRUMENT PALETTE — the studio's SIGNATURE identity:
        a deep-blue surface ramp + a single amber "bearing"
        accent + a green "lock/steady" state + a reserved error
        orange. Born in Pointy (PointyPalette.swift, dark-only)
        and formally extended to a light mode in BusBuddy
        (Theme.swift). Adaptive light/dark below.

     3. APP ACCENTS — each app commits to ONE decisive accent.
        Pointy  → instrument, pinned dark.
        BusBuddy→ instrument, adaptive; bearing = primary CTA,
                  lock = completed/success, error = cancel.
        VolBuddy→ #2F6375 deep teal (its real AccentColor) on
                  native system surfaces. Light + dark.
        HABuddy → systemBlue + warm entity-kind accents (icon).

   Light is the default. Dark applies under prefers-color-scheme
   AND via [data-theme="dark"] / .dark for forced-dark cards/kits
   (Pointy surfaces always force dark).
   ============================================================ */

:root {
  /* ---------- Apple system accent colors (light) ---------- */
  --sys-blue: #007AFF;
  --sys-green: #34C759;
  --sys-indigo: #5856D6;
  --sys-orange: #FF9500;
  --sys-pink: #FF2D55;
  --sys-purple: #AF52DE;
  --sys-red: #FF3B30;
  --sys-teal: #30B0C7;
  --sys-yellow: #FFCC00;
  --sys-mint: #00C7BE;
  --sys-cyan: #32ADE6;
  --sys-brown: #A2845E;

  /* ---------- Gray ramp (systemGray .. systemGray6, light) ---------- */
  --gray-1: #8E8E93;
  --gray-2: #AEAEB2;
  --gray-3: #C7C7CC;
  --gray-4: #D1D1D6;
  --gray-5: #E5E5EA;
  --gray-6: #F2F2F7;

  /* ---------- Backgrounds & surfaces (light) ---------- */
  --bg-base: #FFFFFF;              /* systemBackground */
  --bg-secondary: #F2F2F7;         /* secondarySystemBackground */
  --bg-tertiary: #FFFFFF;          /* tertiarySystemBackground */
  --bg-grouped: #F2F2F7;           /* systemGroupedBackground */
  --bg-grouped-secondary: #FFFFFF; /* secondarySystemGroupedBackground (cards) */

  /* ---------- Labels (light) — alpha over the base ---------- */
  --label-primary: rgba(0, 0, 0, 1);
  --label-secondary: rgba(60, 60, 67, 0.60);
  --label-tertiary: rgba(60, 60, 67, 0.30);
  --label-quaternary: rgba(60, 60, 67, 0.18);

  /* ---------- Fills & separators (light) ---------- */
  --fill-primary: rgba(120, 120, 128, 0.20);
  --fill-secondary: rgba(120, 120, 128, 0.16);
  --fill-tertiary: rgba(118, 118, 128, 0.12);
  --separator: rgba(60, 60, 67, 0.29);
  --separator-opaque: #C6C6C8;

  /* ---------- Semantic status (shared) ---------- */
  --status-success: var(--sys-green);
  --status-warning: var(--sys-orange);
  --status-danger: var(--sys-red);
  --status-info: var(--sys-blue);

  /* ============================================================
     INSTRUMENT PALETTE  (signature identity — adaptive)
     Light values are BusBuddy's; dark values are Pointy's exact
     hexes. Surfaces run deepest → shallowest.
     ============================================================ */
  --inst-bg-void: #F4F7FA;        /* app background (deepest) */
  --inst-bg-base: #FFFFFF;        /* elevated base */
  --inst-bg-panel: #FFFFFF;       /* panel */
  --inst-bg-raised: #E9EFF5;      /* raised panel */
  --inst-bg-control: #D4DEE8;     /* control surface */

  --inst-text: #0D1E2E;           /* ice — primary */
  --inst-text-secondary: #1B3450; /* frost — secondary */
  --inst-text-muted: #4A6B82;     /* muted */
  --inst-text-subtle: #4A7FA0;    /* haze — subtle / metadata */
  --inst-border: #8FA6BC;         /* mist — borders */

  --inst-bearing: #C49000;        /* amber CTA (darkened for light) */
  --inst-bearing-muted: #C49000;
  --inst-steady: #3AB836;         /* green lock / success */
  --inst-steady-muted: #3AB836;
  --inst-error: #FF6B3D;          /* reserved for real errors */

  /* ---- Pointy aliases — PINNED DARK (Pointy is dark-only) ----
     Use these when you want the canonical Pointy instrument look
     regardless of the page theme. */
  --pointy-bg-base: #0D1E2E;
  --pointy-bg-elevated: #102233;
  --pointy-bg-panel: #172D45;
  --pointy-bg-panel-raised: #1B3450;
  --pointy-bg-control: #1E3954;
  --pointy-fg-primary: #E9F8FF;
  --pointy-fg-secondary: #CAE0EE;
  --pointy-fg-muted: #8FAFC3;
  --pointy-fg-subtle: #4A7FA0;
  --pointy-border: #2A5070;
  --pointy-bearing: #FFCD3C;
  --pointy-bearing-muted: #C49000;
  --pointy-steady: #6EF26A;
  --pointy-steady-muted: #3AB836;
  --pointy-error: #FF6B3D;

  /* ---- Canonical Pointy brand-guide names (verbatim) ----
     These are the exact token names from the studio's source-of-truth
     `pointy-brand-guide.html` (ssandke/shared-platform). Aliased here so
     anyone working from that guide finds the names they expect. Reconciled
     June 2026 — every hex matched the reverse-engineered values exactly. */
  --void:    #0D1E2E;   /* page bottom / deepest surface */
  --abyss:   #102233;   /* primary surface */
  --deep:    #172D45;   /* raised cards */
  --slate:   #1B3450;   /* interactive surfaces (buttons, pills) */
  --wave:    #1E3954;   /* borders & dividers */
  --ice:     #E9F8FF;   /* emphasis text */
  --frost:   #CAE0EE;   /* primary body text */
  --haze:    #4A7FA0;   /* secondary text */
  --mist:    #2A5070;   /* tertiary / disabled */
  --bearing: #FFCD3C;   /* direction + primary action (the one warm color) */
  --bearing-dark: #C49000;
  --lock:    #6EF26A;   /* confirmation / locked-on */
  --lock-dk: #3AB836;
  --error:   #FF6B3D;   /* off-bearing warnings, destructive */

  /* ============================================================
     APP ACCENT — VOLBUDDY  (exact, from AccentColor.colorset)
     Deep teal. Sits on native system surfaces; never yellow text.
     ============================================================ */
  --vol-accent: #2F6375;
  --vol-accent-strong: #24505F;
  --vol-growth: #7FC241;          /* green from the "V" icon mark */

  /* ============================================================
     APP ACCENT — HABUDDY  (from app icon: systemBlue + warm)
     Entity-kind accents map to system colors.
     ============================================================ */
  --ha-accent: var(--sys-blue);
  --ha-temp: var(--sys-orange);     /* warm — numeric temperature */
  --ha-light: var(--sys-yellow);    /* lights on */
  --ha-motion: var(--sys-indigo);   /* motion / occupancy active */
  --ha-open: var(--sys-red);        /* door/window open (attention) */
  --ha-closed: var(--gray-1);       /* closed (neutral) */
  --ha-tag-blue: #1F6FEB;           /* icon tag blue */
  --ha-tag-red: #E8472B;            /* icon tag orange-red */

  /* ============================================================
     APP ACCENT — BUSBUDDY  (instrument-derived, from Theme.swift)
     ============================================================ */
  --bus-cta: var(--inst-bearing);   /* Start/Accept/Complete */
  --bus-done: var(--inst-steady);   /* completed stop / success */
  --bus-cancel: var(--inst-error);  /* cancellation / destructive */
}

/* ============================================================
   DARK MODE
   ============================================================ */
@media (prefers-color-scheme: dark) {
  :root {
    --sys-blue: #0A84FF;  --sys-green: #30D158;  --sys-indigo: #5E5CE6;
    --sys-orange: #FF9F0A; --sys-pink: #FF375F;  --sys-purple: #BF5AF2;
    --sys-red: #FF453A;   --sys-teal: #40CBE0;   --sys-yellow: #FFD60A;
    --sys-mint: #66D4CF;  --sys-cyan: #64D2FF;   --sys-brown: #AC8E68;

    --gray-2: #636366;    --gray-3: #48484A;     --gray-4: #3A3A3C;
    --gray-5: #2C2C2E;    --gray-6: #1C1C1E;

    --bg-base: #000000;   --bg-secondary: #1C1C1E; --bg-tertiary: #2C2C2E;
    --bg-grouped: #000000; --bg-grouped-secondary: #1C1C1E;

    --label-primary: rgba(255, 255, 255, 1);
    --label-secondary: rgba(235, 235, 245, 0.60);
    --label-tertiary: rgba(235, 235, 245, 0.30);
    --label-quaternary: rgba(235, 235, 245, 0.16);

    --fill-primary: rgba(120, 120, 128, 0.36);
    --fill-secondary: rgba(120, 120, 128, 0.32);
    --fill-tertiary: rgba(118, 118, 128, 0.24);
    --separator: rgba(84, 84, 88, 0.60);
    --separator-opaque: #38383A;

    /* Instrument palette → Pointy's exact dark hexes */
    --inst-bg-void: #0D1E2E;   --inst-bg-base: #102233;
    --inst-bg-panel: #172D45;  --inst-bg-raised: #1B3450;
    --inst-bg-control: #1E3954;
    --inst-text: #E9F8FF;      --inst-text-secondary: #CAE0EE;
    --inst-text-muted: #8FAFC3; --inst-text-subtle: #4A7FA0;
    --inst-border: #2A5070;
    --inst-bearing: #FFCD3C;   --inst-bearing-muted: #C49000;
    --inst-steady: #6EF26A;    --inst-steady-muted: #3AB836;

    --vol-accent: #5BB3C9;     --vol-accent-strong: #7FCDE0;
  }
}

/* Explicit dark scope (force dark regardless of OS) */
[data-theme="dark"], .dark {
  --sys-blue: #0A84FF;  --sys-green: #30D158;  --sys-indigo: #5E5CE6;
  --sys-orange: #FF9F0A; --sys-pink: #FF375F;  --sys-purple: #BF5AF2;
  --sys-red: #FF453A;   --sys-teal: #40CBE0;   --sys-yellow: #FFD60A;
  --sys-mint: #66D4CF;  --sys-cyan: #64D2FF;   --sys-brown: #AC8E68;
  --gray-2: #636366;    --gray-3: #48484A;     --gray-4: #3A3A3C;
  --gray-5: #2C2C2E;    --gray-6: #1C1C1E;
  --bg-base: #000000;   --bg-secondary: #1C1C1E; --bg-tertiary: #2C2C2E;
  --bg-grouped: #000000; --bg-grouped-secondary: #1C1C1E;
  --label-primary: rgba(255,255,255,1);
  --label-secondary: rgba(235,235,245,0.60);
  --label-tertiary: rgba(235,235,245,0.30);
  --label-quaternary: rgba(235,235,245,0.16);
  --fill-primary: rgba(120,120,128,0.36);
  --fill-secondary: rgba(120,120,128,0.32);
  --fill-tertiary: rgba(118,118,128,0.24);
  --separator: rgba(84,84,88,0.60);
  --separator-opaque: #38383A;
  --inst-bg-void: #0D1E2E;   --inst-bg-base: #102233;
  --inst-bg-panel: #172D45;  --inst-bg-raised: #1B3450;
  --inst-bg-control: #1E3954;
  --inst-text: #E9F8FF;      --inst-text-secondary: #CAE0EE;
  --inst-text-muted: #8FAFC3; --inst-text-subtle: #4A7FA0;
  --inst-border: #2A5070;
  --inst-bearing: #FFCD3C;   --inst-bearing-muted: #C49000;
  --inst-steady: #6EF26A;    --inst-steady-muted: #3AB836;
  --vol-accent: #5BB3C9;     --vol-accent-strong: #7FCDE0;
}
