/* BrewLib "Paper & Ink" — theme custom properties (BRE-56 foundation).
   Imported once at the app root (src/main.jsx).

   The `darkMode` boolean sets <html data-theme="paper|ink"> ONLY when the
   BREWLIB_REVAMP build flag is armed (src/lib/revampFlag.js). Every rule below
   is scoped to [data-theme], so with the flag off this stylesheet is inert and
   the legacy visual language is untouched. Token values mirror
   src/components/theme/tokens.js — keep the two in sync (the paper-ink
   foundation smoke asserts parity). */

/* ── Self-hosted fonts (design handoff: Vercel static assets, NOT Supabase) ──
   Variable woff2 from Google Fonts, subset latin + latin-ext, font-display:
   swap. Unreferenced @font-face costs nothing — browsers only fetch a face
   when the revamp styles actually use it. */
@font-face {
  font-family: 'Bricolage Grotesque';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url('/fonts/bricolage-grotesque-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Bricolage Grotesque';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url('/fonts/bricolage-grotesque-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url('/fonts/jetbrains-mono-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url('/fonts/jetbrains-mono-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ── Paper (light, primary) ── */
:root[data-theme='paper'] {
  /* neutrals */
  --canvas: #f4f4f1;
  --surface: #ffffff;
  --sunken: #edede9;
  --engraving: #f2f0e9;
  --input-bg: #ffffff;
  --border: #e7e7e2;
  --border-strong: #949289;
  /* text (type floor: muted >=12px only; nothing under 10px) */
  --text: #18191d;
  --body-text: #3f434a;
  /* Secondary/muted are AA-checked against --sunken AND --engraving, not just
     --surface (BRE-61: #6a6f77/#696e78 measured 4.31–4.49:1 on those layers). */
  --text-secondary: #64696f;
  --muted: #63686f;
  --faint: #d8d8d3;
  /* accent + focus */
  --accent: #f5b33d;
  --accent-deep: #e0a100;
  --accent-text: #8a6410;
  --focus-ring-color: rgba(245, 179, 61, 0.30);
  --focus-ring: 0 0 0 3px rgba(245, 179, 61, 0.30);
  /* semantics */
  /* green is AA-checked as TEXT on its own 9% success tint (BRE-61: #15803d
     measured 4.46:1 there), not only as a fill. */
  --green: #116632;
  --blue: #2f6fe0;
  --red: #dc2626;
  --coral: #f4513a;
  /* buttons */
  --btn-primary-bg: #18191d;
  --btn-primary-text: #ffffff;
  --btn-action-bg: #f5b33d;
  --btn-action-text: #18191d;
  --btn-outline-bg: #ffffff;
  --btn-outline-border: #d8d8d3;
  --btn-outline-text: #18191d;
  --danger: #c0392b;
  /* nav */
  --nav-active-bg: #edede9;
  --nav-active-border: #e0a100;
  --nav-text: #6a6f77;
  --nav-active-text: #18191d;
  /* elevation (three only) + engraving */
  --shadow-rest: 0 1px 2px rgba(20, 20, 25, 0.05);
  --shadow-raise: 0 8px 24px rgba(20, 20, 25, 0.09);
  --shadow-modal: 0 24px 60px rgba(20, 20, 25, 0.14);
  --card-shadow: var(--shadow-rest);
  --engraving-stroke: #6f675b;
  --engraving-opacity: 0.15;
  color-scheme: light;
}

/* ── Ink (dark, hand-designed — NOT an inversion) ── */
:root[data-theme='ink'] {
  --canvas: #15171c;
  --surface: #1c1f27;
  --sunken: #101216;
  --engraving: #20242d;
  --input-bg: #0e1014;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.36);
  --text: #edeff3;
  --body-text: #c3c9d2;
  --text-secondary: #969da9;
  --muted: #828a97;
  --faint: #3a3f46;
  --accent: #f5b33d;
  --accent-deep: #e0a100;
  --accent-text: #dcae54;
  --focus-ring-color: rgba(245, 179, 61, 0.24);
  --focus-ring: 0 0 0 3px rgba(245, 179, 61, 0.24);
  --green: #22c55e;
  --blue: #8fb4ff;
  --red: #fb7185;
  --coral: #fb7185;
  --btn-primary-bg: #f2f4f7;
  --btn-primary-text: #15171c;
  --btn-action-bg: #f5b33d;
  --btn-action-text: #15171c;
  --btn-outline-bg: transparent;
  --btn-outline-border: rgba(255, 255, 255, 0.20);
  --btn-outline-text: #edeff3;
  --danger: #fb7185;
  --nav-active-bg: rgba(245, 179, 61, 0.12);
  --nav-active-border: #f5b33d;
  --nav-text: #969da9;
  --nav-active-text: #edeff3;
  /* on ink, elevation = lighter surface + border; shadows barely read */
  --shadow-rest: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-raise: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-modal: 0 24px 60px rgba(0, 0, 0, 0.55);
  --card-shadow: var(--shadow-rest);
  --engraving-stroke: #ffffff;
  --engraving-opacity: 0.06;
  color-scheme: dark;
}

/* ── Shared, theme-independent tokens (inert unless referenced) ── */
:root[data-theme] {
  /* type */
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* responsive type foundations (ramp: display 50-62 · title 22-26 · body 13-15) */
  --type-display: clamp(50px, 4.2vw + 34px, 62px);
  --type-title: clamp(22px, 1vw + 18px, 26px);
  --type-stat: 22px;
  --type-body: 13px;
  --type-label: 12.5px;
  --type-caps: 10px;
  /* shape — FOUR radii only */
  --radius-inner: 6px;
  --radius-control: 10px;
  --radius-card: 16px;
  --radius-pill: 999px;
  /* density + touch */
  --control-h: 54px;      /* input height */
  --tap-min: 40px;        /* minimum interactive target */
  /* icon sizing */
  --icon-sm: 14px;
  --icon: 18px;
  --icon-lg: 24px;
  /* motion — scoped to "coffee moments", never ambient */
  --press: 120ms;
  --settle: 200ms;
  --ease-brew: cubic-bezier(0.2, 0.7, 0.3, 1);
}

/* ── Base surface + selection (only once a theme is armed) ── */
:root[data-theme],
:root[data-theme] body {
  background-color: var(--canvas);
  color: var(--text);
}
/* scrollbars ride the token layer (BRE-56B app shell); width stays auto */
:root[data-theme] {
  scrollbar-color: var(--border-strong) transparent;
}
:root[data-theme] ::selection {
  background: rgba(245, 179, 61, 0.35);
}
:root[data-theme='ink'] ::selection {
  background: rgba(245, 179, 61, 0.28);
}

/* Focus = amber ring on buttons, chips, links AND inputs — not inputs alone.
   Implemented as outline (follows border-radius, costs no layout) plus a 1px
   ink keyline (box-shadow) so the indicator meets WCAG 1.4.11 non-text
   contrast on both canvases — the translucent amber halo alone cannot reach
   3:1. :focus-visible keeps pointer clicks quiet. */
/* !important so the 1px keyline also wins over INLINE box-shadows (nav
   buttons, toggle, active sidebar item carry elevation inline; inline styles
   otherwise beat any stylesheet rule). The .pi-input focus rule below keeps
   its own !important ring and out-specifies this one. */
:root[data-theme] :is(a, button, input, select, textarea, summary, [role='button'], [role='switch'], [role='checkbox'], [tabindex]):focus-visible {
  outline: 3px solid var(--focus-ring-color);
  outline-offset: 1px;
  box-shadow: 0 0 0 1px var(--text) !important;
}

/* ── Primitive state classes (inline styles can't reach pseudo-states).
      All .pi-* consumers only render when the revamp flag is armed. ── */

/* universal press: 1px compress + border darken, 120ms, --ease-brew */
:root[data-theme] .pi-press {
  transition: transform var(--press) var(--ease-brew), border-color var(--press) var(--ease-brew), background var(--press) var(--ease-brew), box-shadow var(--press) var(--ease-brew), color var(--press) var(--ease-brew), opacity var(--press) var(--ease-brew);
}
:root[data-theme] .pi-press:not(:disabled):active {
  transform: translateY(1px) !important;
  filter: brightness(0.97);
}
:root[data-theme] button.pi-press:not(:disabled):hover {
  transform: none; /* replace the legacy -1px hover lift with border/tone shifts */
}

/* button variants (values via tokens so Ink remaps automatically) */
:root[data-theme] .pi-btn--primary:not(:disabled):hover { filter: brightness(1.12); }
:root[data-theme='ink'] .pi-btn--primary:not(:disabled):hover { filter: brightness(0.94); }
:root[data-theme] .pi-btn--action:not(:disabled):hover { background: var(--accent-deep) !important; }
/* hover border darkens toward --text so it stays >=3:1 against the sunken hover fill */
:root[data-theme] .pi-btn--outline:not(:disabled):hover { border-color: color-mix(in srgb, var(--border-strong) 70%, var(--text)) !important; background: var(--sunken) !important; }
:root[data-theme] .pi-btn--danger:not(:disabled):hover { filter: brightness(1.08); }

/* links — amber/text everywhere, underline on hover */
:root[data-theme] .pi-link {
  color: var(--accent-text);
  text-decoration: none;
  border-radius: var(--radius-inner);
}
:root[data-theme] .pi-link:hover { text-decoration: underline; text-underline-offset: 2px; }

/* chips — selection = ink, never amber */
:root[data-theme] .pi-chip:not(:disabled):hover { border-color: var(--border-strong) !important; }
:root[data-theme] .pi-chip[aria-pressed='true'],
:root[data-theme] .pi-chip[data-selected='true'] {
  background: var(--btn-primary-bg) !important;
  color: var(--btn-primary-text) !important;
  border-color: var(--btn-primary-bg) !important;
}

/* form controls */
:root[data-theme] .pi-input {
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  min-height: var(--control-h);
  padding: 0 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  width: 100%;
  box-sizing: border-box;
  transition: border-color var(--press) var(--ease-brew), box-shadow var(--press) var(--ease-brew);
}
:root[data-theme] textarea.pi-input { padding: 14px; min-height: calc(var(--control-h) * 1.6); resize: vertical; }
:root[data-theme] .pi-input::placeholder { color: var(--muted); }
:root[data-theme] .pi-input:focus,
:root[data-theme] .pi-input:focus-visible {
  outline: none;
  border-color: var(--text);
  /* higher specificity + !important: keeps the amber ring on inputs (the
     --text border already provides the >=3:1 boundary) */
  box-shadow: var(--focus-ring) !important;
}
:root[data-theme] .pi-input[aria-invalid='true'] {
  border-color: var(--red);
  background: #fdf7f5;
}
:root[data-theme='ink'] .pi-input[aria-invalid='true'] { background: rgba(251, 113, 133, 0.08); }

/* table row hover (one table spec) */
:root[data-theme='paper'] .pi-table-row:hover { background: #faf9f6; }
:root[data-theme='ink'] .pi-table-row:hover { background: rgba(255, 255, 255, 0.03); }

/* dialogs */
:root[data-theme] .pi-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(10, 11, 14, 0.45);
}
:root[data-theme='ink'] .pi-dialog-backdrop { background: rgba(0, 0, 0, 0.6); }
:root[data-theme] .pi-dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-modal);
  width: min(440px, 100%);
  max-height: min(80vh, 640px);
  overflow: auto;
  animation: pi-dialog-settle var(--settle) var(--ease-brew);
}
@keyframes pi-dialog-settle {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* skeletons — static --sunken blocks; no shimmer (hard motion limit) */
:root[data-theme] .pi-skeleton {
  background: var(--sunken);
  border-radius: var(--radius-inner);
  min-height: 12px;
}

/* reduced motion — collapse coffee moments to instant state changes.
   (Duplicates the legacy global rule so the revamp honors it standalone.) */
@media (prefers-reduced-motion: reduce) {
  :root[data-theme] *,
  :root[data-theme] *::before,
  :root[data-theme] *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
