/**
 * SwiftGigs design tokens — single source of truth for color.
 * Light/dark: hooks existing body.light / html.light / html[data-qg-theme].
 * Tasker/Poster: hooks html[data-qg-mode="worker"|"poster"] (worker = tasker)
 *                and html[data-mode="tasker"|"poster"] / body.qg-mode-*.
 *
 * The 11 core tokens are authoritative. Everything below them is an alias kept
 * so existing page CSS keeps resolving — do not delete aliases without grepping.
 * Component primitives live in qg-swift.css, not here.
 */
:root {
  /* ── Core palette (dark is the default theme) ── */
  --bg: #0B0A14;
  --surface: #16131F;
  --surface-alt: #201C2C;
  --border: #2C2740;
  --text: #F4F0FA;
  --text-muted: #9C93AC;
  --primary: #8B5CF6;
  --primary-text: #FFFFFF;
  --teal: #2DD4BF;
  --teal-tint: #123832;
  --green: #4ADE80;

  /* Label colour for text sitting ON a --teal fill. White fails badly there:
     1.9:1 against the dark-mode teal and 3.7:1 against the light-mode teal,
     where AA wants 4.5:1. One value serves both themes — 9.2:1 on #2DD4BF and
     4.6:1 on #0D9488 — so there is deliberately no light-mode override. */
  --teal-text: #05201C;

  /* ── Semantic accents (not part of the redesign spec, values unchanged) ── */
  --attention: #fbbf24;
  --danger: #f87171;

  /* Label colour for text sitting ON a --danger fill. White gave 2.8:1 here,
     well under AA. Unlike --teal-text this DOES need a light-mode override:
     the two danger fills sit on opposite sides of the lightness midpoint, so
     no single label can serve both. Dark theme's #f87171 is a light red and
     takes dark text (6.6:1); light theme's #b91c1c is a dark red and keeps
     white (6.5:1). */
  --danger-text: #2A0A0A;

  /* Label colour for text on an --accent-soft fill — the badge/pill idiom used
     ~34 times across the app. Flat var(--accent) fails AA on its own tint in
     two of the four theme/mode combinations: 4.1:1 for poster purple in dark
     mode and 3.17:1 for tasker teal in light mode, against a 4.5:1 bar. Mixing
     30% of --text in lifts the worst case to 5.11:1 while keeping the hue
     recognisable. Pair this with --accent-soft; use plain --accent on --surface. */
  --accent-on-soft: color-mix(in srgb, var(--accent) 70%, var(--text));

  /* Modal backdrop. Deliberately has no light-mode override: a scrim's job is
     to dim whatever sits behind it, so it stays dark in both themes. Deriving
     it from --bg would invert it to a white wash on light mode and brighten
     the page instead of dimming it. */
  --scrim: rgba(11, 10, 20, 0.78);

  /* ── Flow accents ──
   * Posting flow = purple, earning flow = teal.
   * NOTE: this inverts the previous mapping, where tasker was purple and
   * poster was teal. Flip these two lines to revert. */
  --accent-poster: var(--primary);
  --accent-tasker: var(--teal);
  --accent: var(--accent-tasker);

  /* Label colour for text on an --accent fill. Tracks whichever flow is active,
     so a CTA can say `background: var(--accent); color: var(--accent-text)` and
     stay legible in both modes. Defaults to the tasker value, matching --accent. */
  --accent-text: var(--teal-text);

  /* ── Derived structure ── */
  --line-strong: color-mix(in srgb, var(--border) 60%, var(--text-muted));
  --text-secondary: color-mix(in srgb, var(--text) 72%, var(--text-muted));

  /* ── Fills ──
   * CTAs are flat in this design. The gradient vars are kept as single-stop
   * gradients so existing `background: var(--grad-accent)` rules render flat
   * instead of needing 37 stylesheets edited. */
  --grad-tasker: linear-gradient(var(--accent-tasker), var(--accent-tasker));
  --grad-poster: linear-gradient(var(--accent-poster), var(--accent-poster));
  --grad-accent: linear-gradient(var(--accent), var(--accent));

  /* Wordmark only — never use for surfaces or buttons. */
  --grad-wordmark: linear-gradient(100deg, var(--primary) 0%, var(--teal) 100%);

  /* Soft fills (derive automatically from the core tokens) */
  --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --money-soft: color-mix(in srgb, var(--green) 14%, transparent);
  --attention-soft: color-mix(in srgb, var(--attention) 14%, transparent);
  --danger-soft: color-mix(in srgb, var(--danger) 14%, transparent);

  /* ── Aliases for existing page CSS ── */
  --brand: var(--primary);
  --money: var(--green);
  --on-accent: var(--primary-text);
  --surface-1: var(--surface);
  --surface-2: var(--surface-alt);
  --card-bg: var(--surface);
  --line: var(--border);
  --text-primary: var(--text);
  --text-faint: var(--text-muted);
  --purple: var(--primary);
  --purple-light: var(--primary);
  --lavender: var(--primary);
  --nav-bg: var(--surface);
  --tab-bg: var(--surface);

  /* Moved here from qg-role-theme.css, which defined them only inside its
     worker/poster token blocks. Those blocks shadowed the core palette and had
     to go, but dashboard.html, messages.html and qg-features.css consume these
     13 times, so they live here now and derive like everything else. */
  --surface-hover: var(--surface-alt);
  --input-bg: var(--surface-alt);
  --border-hover: var(--accent);
}

/* ── Light theme (same mechanism as qg-theme.js paint) ── */
html.light,
html[data-qg-theme="light"],
body.light {
  --bg: #F7F2FC;
  --surface: #FFFFFF;
  --surface-alt: #F1E9FA;
  --border: #E8DFF2;
  --text: #1A1523;
  --text-muted: #6B6478;
  --primary: #6B21A8;
  --primary-text: #FFFFFF;
  --teal: #0D9488;
  --teal-tint: #E3F5F1;
  --green: #15803D;

  /* Darker for AA on white */
  --attention: #92400e;
  --danger: #b91c1c;
  --danger-text: #ffffff;

  /* Soft fills tint toward white so chips read on light surfaces */
  --accent-soft: color-mix(in srgb, var(--accent) 14%, #ffffff);
  --money-soft: color-mix(in srgb, var(--green) 12%, #ffffff);
  --attention-soft: color-mix(in srgb, var(--attention) 12%, #ffffff);
  --danger-soft: color-mix(in srgb, var(--danger) 12%, #ffffff);
}

/* ── Mode-aware accent (posting purple vs earning teal) ── */
html[data-qg-mode="worker"],
html[data-mode="tasker"],
body.qg-mode-worker {
  --accent: var(--accent-tasker);
  --grad-accent: var(--grad-tasker);
  --accent-text: var(--teal-text);
}

html[data-qg-mode="poster"],
html[data-mode="poster"],
body.qg-mode-poster {
  --accent: var(--accent-poster);
  --grad-accent: var(--grad-poster);
  --accent-text: var(--primary-text);
}

/* Legacy poster aliases — previously forced teal, now follow the flow accent. */
html[data-qg-mode="poster"],
html[data-mode="poster"],
body.qg-mode-poster,
html.light[data-qg-mode="poster"],
html[data-qg-theme="light"][data-qg-mode="poster"],
html.light[data-mode="poster"],
body.light.qg-mode-poster {
  --purple: var(--accent-poster);
  --purple-light: var(--accent-poster);
  --lavender: var(--accent-poster);
}

/*
 * Bridge to existing role-theme variable names so shared chrome can
 * gradually adopt tokens without a full restyle pass.
 */
html {
  --qg-mode-accent: var(--accent);
  --qg-mode-gradient: var(--grad-accent);
  --role-accent: var(--accent);
  --role-accent-soft: var(--accent-soft);
}
