/* ============================================================
   STICKY BOOKS — DESIGN TOKENS
   Raw brand values live here, and only here. Components read the
   semantic names below, never a hex code or a magic number — retune
   the brand by editing this file and every component follows.

   Concept: honeycomb ledger. Cream paper, honey highlights, a grape
   accent, thick "ink" outlines and hard offset shadows — a sticker
   pressed onto a page, not a soft SaaS gradient.
   ============================================================ */

:root {
  /* ---------- Palette (raw) ----------
     Brand kit: only these four colors are approved, in the pairings
     documented below (see each semantic text-on-* token). */
  --ink:        #1A1410; /* dark bistre — borders, body text, shadows */
  --cream:      #FFF8ED; /* page background */
  --cream-2:    #F0E4D0; /* hairline dividers on cream */
  --honey:      #F1B727; /* amber gold — primary action color */
  --honey-soft: #F9E2A9; /* tinted highlight surface */
  --grape:      #6B3FA0; /* royal violet — accent color */
  --grape-soft: #EAE0F5; /* tinted accent surface */
  --white:      #FFFFFF;

  /* ---------- Semantic surfaces ---------- */
  --bg-page:      var(--cream);
  --bg-surface:   var(--white);
  --bg-highlight: var(--honey-soft);
  --bg-accent:    var(--grape);

  /* ---------- Semantic text ----------
     Each text-on-* follows the brand kit's approved pairings:
       dark bistre bg  -> amber gold or cream
       amber gold bg   -> dark bistre or royal violet
       royal violet bg -> cream or amber gold
       cream/white bg  -> royal violet or dark bistre
     Muted text isn't a separate brand color — it's dark bistre at
     reduced strength, so it stays "on brand" at any weight. */
  --text-body:      var(--ink);
  --text-muted:     color-mix(in srgb, var(--ink) 62%, transparent);
  --text-on-honey:  var(--ink);
  --text-on-accent: var(--cream);

  /* ---------- Border ink ----------
     Semantic indirection for the thick ink outline/shadow used throughout
     the sticker look (.card, .status-pill, .btn, .data-table, etc.) --
     components reference THIS, never raw --ink directly, so dark mode can
     flip every sticker border/shadow at once without also flipping --ink
     itself (which --text-on-honey depends on staying dark). */
  --border-ink: var(--ink);

  /* ---------- Hairline ----------
     Same indirection as --border-ink, one step down in weight: the subtle
     cream-2 dividers/fills (data-table hairlines, spreadsheet chrome,
     select/dropdown borders) -- never raw --cream-2 directly, so dark mode
     can swap it for something that still reads as "a bit lighter than the
     surrounding surface" instead of staying a pale tan that goes invisible
     (or worse, glaring) against a dark page. */
  --hairline: var(--cream-2);

  /* ---------- Action (buttons) ---------- */
  --action-bg:     var(--honey);
  --action-border: var(--border-ink);
  --action-shadow: 3px 3px 0 var(--border-ink);

  /* ---------- Status pills ---------- */
  --status-open:        #FFD54A;
  --status-open-text:   var(--ink);
  --status-cured:       #7CC576;
  --status-cured-text:  #123A0E;
  --status-empty:       var(--cream-2);
  --status-empty-text:  #5A5044; /* darker than --text-muted — needed since --text-muted (translucent) fails contrast on --cream-2, this clears 6.2:1 */

  /* ---------- Flags (row/cell-level warnings — distinct from PO status
     pills above, which are about order lifecycle, not inventory urgency) --- */
  --flag-critical:      #F7D5C7;
  --flag-critical-text: #7A2E12; /* 6.1:1 on --flag-critical */
  --flag-warning:       var(--honey-soft);
  --flag-warning-text:  var(--ink);

  /* ---------- Focus ---------- */
  --focus-ring: var(--grape);

  /* ---------- Type ---------- */
  --font-display: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --font-body:    "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-mono:    "Space Mono", ui-monospace, SFMono-Regular, monospace;

  --weight-regular: 400;
  --weight-bold:    700;
  --weight-heavy:   800;

  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.25rem;
  --text-xl:   1.5rem;
  --text-2xl:  2rem;
  --text-3xl:  2.75rem;

  /* ---------- Space ---------- */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.5rem;
  --space-6:  2rem;
  --space-8:  3rem;
  --space-10: 4rem;

  /* ---------- Shape ---------- */
  --border-width: 2px;
  --radius-md:   0.75rem;
  --radius-lg:   1.25rem;
  --radius-pill: 999px;

  /* ---------- Shadow ---------- */
  --shadow-sticker: 4px 4px 0 var(--border-ink);

  /* ---------- Motion ---------- */
  --dur-fast: 150ms;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   DARK MODE — honeycomb palette
   Explicit user toggle (html[data-theme="dark"], not
   prefers-color-scheme — see ThemesController/theme_controller.js).
   Marketing/auth pages always render data-theme="light" (see
   application.html.erb), so this block is inert there regardless of
   any stored preference.
   ============================================================ */
html[data-theme="dark"] {
  /* One new dark-only primitive -- same relationship cream-2 has to
     cream, just on the dark side: a card surface needs to read as
     slightly LIGHTER than the page behind it to still look "lifted". */
  --ink-soft: #241C16;

  /* Flips every sticker border/shadow (.card, .btn, .status-pill,
     .data-table, etc.) at once -- see --border-ink above. */
  --border-ink: var(--cream);
  --hairline: color-mix(in srgb, var(--cream) 15%, var(--ink-soft));

  --bg-page:    var(--ink);
  --bg-surface: var(--ink-soft);
  --bg-highlight: color-mix(in srgb, var(--honey) 20%, var(--ink-soft));
  /* --bg-accent (grape), --text-on-honey, --text-on-accent, and
     --focus-ring are intentionally left unset here: grape/honey are
     vivid enough to read against either page color, and the
     text-on-honey/text-on-accent pairings don't depend on the page
     background at all (the chip they sit on doesn't change color). */

  --text-body:  var(--cream);
  --text-muted: color-mix(in srgb, var(--cream) 62%, transparent);

  /* status-open/status-cured stay untouched -- bright accent chips,
     already high-contrast against either page color. status-empty and
     the two flag colors (which wash a whole row, not a small badge) do
     need adjustment: left alone, a "quiet/empty" chip would become the
     brightest thing on the page, and a pale row-tint reads as visibly
     broken against a dark page instead of as a quiet highlight. */
  --status-empty: var(--ink-soft);
  --status-empty-text: var(--text-muted);

  --flag-critical: color-mix(in srgb, #F7D5C7 30%, var(--ink-soft));
  --flag-critical-text: #F7D5C7;
  --flag-warning: color-mix(in srgb, var(--honey) 25%, var(--ink-soft));
  --flag-warning-text: var(--honey-soft);
}

/* ============================================================
   AUTHENTICATED APP — dark mode tokens
   Separate, --app-prefixed semantic layer for the raw-Tailwind
   authenticated-app views (purchase orders, products, vendors,
   settings, etc.) -- NOT used by marketing/auth pages, which stay on
   the honeycomb layer above. Light values reproduce today's exact
   Tailwind gray/red/amber/green/indigo/blue/purple/emerald colors
   already in use, so adding this changes nothing visible until
   html[data-theme="dark"] is set by the user toggle.
   ============================================================ */
:root {
  --app-bg: #F9FAFB; --app-surface: #FFFFFF;
  --app-surface-hover: #F9FAFB; --app-surface-active: #F3F4F6;

  --app-border: #E5E7EB; --app-border-strong: #D1D5DB; --app-border-subtle: #F3F4F6;

  --app-text: #111827; --app-text-secondary: #374151; --app-text-muted: #6B7280;
  --app-text-faint: #9CA3AF; --app-text-faintest: #D1D5DB; --app-text-close: #4B5563;

  /* Primary button (bg-gray-900 text-white hover:bg-gray-700) -- a
     button-chrome role, independent of --app-text even though it's the
     same raw "gray-900" in light mode. See components.css .btn-primary. */
  --app-btn-primary-bg: #111827; --app-btn-primary-bg-hover: #374151; --app-btn-primary-text: #FFFFFF;

  --app-success-bg: #F0FDF4; --app-success-border: #BBF7D0;
  --app-success-text: #166534; --app-success-text-subtle: #15803D;

  --app-warning-bg: #FFFBEB; --app-warning-border: #FDE68A;
  --app-warning-text: #92400E; --app-warning-text-accent: #D97706;

  --app-error-bg: #FEF2F2; --app-error-border: #FECACA;
  --app-error-text: #991B1B; --app-error-accent: #DC2626;

  /* Avatar chip colors (PurchaseOrdersHelper#activity_avatar_classes) */
  --app-avatar-vendor-bg: #FDE68A; --app-avatar-vendor-text: #92400E;

  /* Notification unread highlight (notifications/index.html.erb) */
  --app-unread-bg: #EEF2FF; --app-unread-dot: #6366F1;

  /* Status/response/payment/match badge tones -- PurchaseOrdersHelper.
     Each is the existing "{hue}-50 bg / {hue}-700ish text" soft-pill pair. */
  --app-tone-gray-bg: #F3F4F6;   --app-tone-gray-text: #6B7280;
  --app-tone-red-bg: #FEF2F2;    --app-tone-red-text: #B91C1C;
  --app-tone-amber-bg: #FFFBEB;  --app-tone-amber-text: #B45309;
  --app-tone-green-bg: #F0FDF4;  --app-tone-green-text: #15803D;
  --app-tone-blue-bg: #EFF6FF;   --app-tone-blue-text: #1D4ED8;
  --app-tone-purple-bg: #FAF5FF; --app-tone-purple-text: #7E22CE; --app-tone-purple-border: #E9D5FF;
  --app-tone-indigo-bg: #EEF2FF; --app-tone-indigo-text: #4338CA;

  /* Inline indigo links (_product_form.html.erb, show.html.erb) -- a
     different role than the badge/chip above: plain text on --app-surface. */
  --app-link-indigo: #6366F1; --app-link-indigo-hover: #3730A3;

  /* Emerald inline text (purchase_orders/show.html.erb) */
  --app-text-emerald: #059669;
}

html[data-theme="dark"] {
  --app-bg: #0B0F17; --app-surface: #111827;
  --app-surface-hover: #1F2937; --app-surface-active: #374151;

  --app-border: #374151; --app-border-strong: #4B5563; --app-border-subtle: #1F2937;

  --app-text: #F3F4F6; --app-text-secondary: #D1D5DB; --app-text-muted: #9CA3AF;
  --app-text-faint: #6B7280; --app-text-faintest: #4B5563; --app-text-close: #9CA3AF;

  /* Primary button inverts -- stays the single highest-contrast chrome
     element either way, instead of a near-black button on an
     already near-black surface. */
  --app-btn-primary-bg: #F3F4F6; --app-btn-primary-bg-hover: #D1D5DB; --app-btn-primary-text: #111827;

  --app-success-bg: #052E16; --app-success-border: #166534;
  --app-success-text: #BBF7D0; --app-success-text-subtle: #86EFAC;

  --app-warning-bg: #451A03; --app-warning-border: #92400E;
  --app-warning-text: #FDE68A; --app-warning-text-accent: #FBBF24;

  --app-error-bg: #450A0A; --app-error-border: #991B1B;
  --app-error-text: #FECACA; --app-error-accent: #F87171;

  --app-avatar-vendor-bg: #92400E; --app-avatar-vendor-text: #FDE68A;

  --app-unread-bg: #1E1B4B; --app-unread-dot: #818CF8;

  --app-tone-gray-bg: #374151;   --app-tone-gray-text: #D1D5DB;
  --app-tone-red-bg: #450A0A;    --app-tone-red-text: #FCA5A5;
  --app-tone-amber-bg: #451A03;  --app-tone-amber-text: #FBBF24;
  --app-tone-green-bg: #052E16;  --app-tone-green-text: #86EFAC;
  --app-tone-blue-bg: #172554;   --app-tone-blue-text: #93C5FD;
  --app-tone-purple-bg: #3B0764; --app-tone-purple-text: #D8B4FE; --app-tone-purple-border: #6B21A8;
  --app-tone-indigo-bg: #1E1B4B; --app-tone-indigo-text: #A5B4FC;

  --app-link-indigo: #818CF8; --app-link-indigo-hover: #A5B4FC;

  --app-text-emerald: #34D399;
}
