/*
 * Kapable Platform — Shared Theme Tokens
 *
 * Include this file in every platform app for consistent dark/light theming.
 * Pair with kapable-theme.js (IIFE in <head>) for cookie-based theme sync.
 *
 * v0.8.0 · GARNET (oklch hue 4) — operator-ratified in Specimen 2026-07-11.
 * Petrol (v0.7.x) retired. New tokens: --kp-on-accent, --kp-rule,
 * --kp-icon-olive/--kp-icon-rose (teal/coral aliased for compat).
 *
 * Token contract: all apps MUST use these variable names for core surfaces,
 * text, borders, and accent colors. App-specific tokens (e.g. status dots,
 * sidebar widths) live in the app's own CSS.
 */

/* Display face — the brand's human register (BRAND.md). Vendored beside this
   file; a missing font file degrades silently to the serif system stack. */
@font-face {
  font-family: "Kapable Display";
  src: url("kapable-display.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

/* Machine register — the platform's own voice (BRAND.md): labels, statuses,
   counts, code, and the wordmark. JetBrains Mono, vendored so the mono voice
   renders identically off-Mac; latin-subset variable woff2 (wght 100–800),
   SIL OFL 1.1 (assets/OFL-JetBrainsMono.txt). A missing font file degrades
   silently to the ui-monospace system stack. */
@font-face {
  font-family: "JetBrains Mono";
  src: url("kapable-mono.woff2") format("woff2");
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --kp-radius: 3px;
  --kp-radius-sm: 3px;
  --kp-radius-lg: 6px;
  --kp-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --kp-font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --kp-font-display: "Kapable Display", "New York", Georgia, serif;
  font-family: var(--kp-font);
}

/* Wordmark — always lowercase text "kapable", machine register (BRAND.md) */
.kp-wordmark {
  font-family: var(--kp-font-mono);
  font-weight: 600;
  letter-spacing: -0.01em;
  text-transform: lowercase;
}

/* ── Dark ── */
[data-theme="dark"] {
  --kp-bg:          oklch(0.165 0.0028 4);
  --kp-surface:     oklch(0.205 0.0028 4);
  --kp-surface-hi:  oklch(0.25 0.003 4);
  --kp-border:      oklch(0.31 0.0036 4);
  --kp-border-strong: oklch(0.42 0.004 4);
  --kp-border-subtle: oklch(0.31 0.0036 4 / 0.5);
  --kp-rule:        oklch(0.93 0.0012 4 / 0.14);
  --kp-text:        oklch(0.93 0.0012 4);
  --kp-text-dim:    oklch(0.72 0.0028 4);
  --kp-text-muted:  oklch(0.68 0.0028 4);
  --kp-text-disabled: oklch(0.46 0.0024 4);
  --kp-accent:      oklch(0.74 0.11 4);
  --kp-accent-hi:   oklch(0.79 0.11 4);
  --kp-accent-bg:   oklch(0.74 0.11 4 / 0.12);
  --kp-on-accent:   oklch(0.17 0.03 4);
  --kp-danger:      oklch(0.71 0.16 30);
  --kp-danger-bg:   oklch(0.71 0.16 30 / 0.13);
  --kp-success:     oklch(0.76 0.11 152);
  --kp-success-bg:  oklch(0.76 0.11 152 / 0.13);
  --kp-warn:        oklch(0.8 0.12 88);
  --kp-warn-bg:     oklch(0.8 0.12 88 / 0.13);
  --kp-info:        oklch(0.74 0.1 240);
  --kp-info-bg:     oklch(0.74 0.1 240 / 0.13);
  /* Elevation — garnet-black tints, never pure #000 */
  --kp-shadow:      0 3px 12px oklch(0.08 0.004 4 / 0.45);
  --kp-shadow-lg:   0 8px 28px oklch(0.08 0.004 4 / 0.55);
  /* Icon accent family — six hues at matched OKLCH lightness/chroma */
  --kp-icon-indigo: oklch(0.76 0.11 265);
  --kp-icon-sky:    oklch(0.78 0.1 225);
  --kp-icon-olive:  oklch(0.78 0.09 135);
  --kp-icon-amber:  oklch(0.8 0.1 90);
  --kp-icon-violet: oklch(0.76 0.11 305);
  --kp-icon-rose:   oklch(0.77 0.11 350);
  color-scheme: dark;
}

/* ── Light ── */
[data-theme="light"] {
  --kp-bg:          oklch(0.972 0.001 4);
  --kp-surface:     oklch(0.99 0.0006 4);
  --kp-surface-hi:  oklch(0.935 0.0016 4);
  --kp-border:      oklch(0.865 0.0024 4);
  --kp-border-strong: oklch(0.72 0.0032 4);
  --kp-border-subtle: oklch(0.865 0.0024 4 / 0.5);
  --kp-rule:        oklch(0.24 0.004 4 / 0.13);
  --kp-text:        oklch(0.24 0.004 4);
  --kp-text-dim:    oklch(0.46 0.0056 4);
  --kp-text-muted:  oklch(0.5 0.005 4);
  --kp-text-disabled: oklch(0.68 0.003 4);
  --kp-accent:      oklch(0.435 0.125 4);
  --kp-accent-hi:   oklch(0.385 0.125 4);
  --kp-accent-bg:   oklch(0.435 0.125 4 / 0.08);
  --kp-on-accent:   #fff;
  --kp-danger:      oklch(0.53 0.19 33);
  --kp-danger-bg:   oklch(0.53 0.19 33 / 0.08);
  --kp-success:     oklch(0.5 0.1 152);
  --kp-success-bg:  oklch(0.5 0.1 152 / 0.1);
  --kp-warn:        oklch(0.55 0.12 85);
  --kp-warn-bg:     oklch(0.55 0.12 85 / 0.11);
  --kp-info:        oklch(0.5 0.1 240);
  --kp-info-bg:     oklch(0.5 0.1 240 / 0.09);
  /* Elevation — garnet-black tints, never pure #000 */
  --kp-shadow:      0 2px 8px oklch(0.2 0.006 4 / 0.1);
  --kp-shadow-lg:   0 8px 24px oklch(0.2 0.006 4 / 0.14);
  /* Icon accent family — six hues at matched OKLCH lightness/chroma */
  --kp-icon-indigo: oklch(0.5 0.13 265);
  --kp-icon-sky:    oklch(0.52 0.11 225);
  --kp-icon-olive:  oklch(0.52 0.1 135);
  --kp-icon-amber:  oklch(0.55 0.11 90);
  --kp-icon-violet: oklch(0.5 0.12 305);
  --kp-icon-rose:   oklch(0.52 0.13 350);
  color-scheme: light;
}

/* ── Backward-compatible aliases ──
   Apps that already use --bg, --fg, etc. can opt into these
   aliases instead of a full rename. New apps should use --kp-* directly. */
[data-theme="dark"], [data-theme="light"] {
  --bg:       var(--kp-bg);
  --bg-2:     var(--kp-surface);
  --bg-3:     var(--kp-surface-hi);
  --border:   var(--kp-border);
  --fg:       var(--kp-text);
  --fg-dim:   var(--kp-text-dim);
  --accent:   var(--kp-accent);
  --accent-2: var(--kp-accent-hi);
  --accent-bg:var(--kp-accent-bg);
  --danger:   var(--kp-danger);
  --radius:   var(--kp-radius);
  /* v0.8.0: teal/coral slots retired; alias to the garnet-era olive/rose */
  --kp-icon-teal:  var(--kp-icon-olive);
  --kp-icon-coral: var(--kp-icon-rose);
}

/* ── Base resets ── */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--kp-bg); color: var(--kp-text); }
a { color: var(--kp-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Text selection — brand-tinted (upstreamed from kv2-launchpad 6903d25) ── */
::selection { background: var(--kp-accent-bg); color: var(--kp-accent); }

/* ── Focus — global visible indicator for keyboard users ── */
:focus-visible {
  outline: 2px solid var(--kp-accent);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

/* ── Skip link ── */
.kp-skip-link {
  position: absolute; left: -9999px; top: auto;
  width: 1px; height: 1px; overflow: hidden;
  z-index: 9999;
  padding: 12px 24px; border-radius: var(--kp-radius);
  /* Text mirrors .kp-btn: --kp-bg flips per theme so contrast holds on the
     light dark-mode accent (hardcoded #fff was 2.5:1 there). */
  background: var(--kp-accent); color: var(--kp-on-accent);
  font-size: 14px; font-weight: 600; font-family: var(--kp-font);
  text-decoration: none; white-space: nowrap;
}
.kp-skip-link:focus {
  position: fixed; left: 16px; top: 16px;
  width: auto; height: auto; overflow: visible;
}

/* ── Touch target minimum ── */
.kp-touch-target {
  min-height: 44px; min-width: 44px;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ── Screen-reader only ── */
.kp-sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ── Footer ── */
.kp-footer {
  padding: 24px 18px;
  text-align: center;
  color: var(--kp-text-muted);
  font-size: 12px;
  letter-spacing: 0.02em;
  border-top: 1px solid var(--kp-border-subtle);
  margin-top: auto;
}
.kp-footer a { color: var(--kp-text-dim); }
.kp-footer a:hover { color: var(--kp-accent); text-decoration: none; }

/* ── Shared topbar ── */
.kp-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; height: 48px;
  background: var(--kp-surface); border-bottom: 1px solid var(--kp-border);
}
.kp-topbar-left  { display: flex; align-items: center; gap: 8px; }
.kp-topbar-right { display: flex; align-items: center; gap: 8px; }

.kp-brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 16px;
  color: var(--kp-text); text-decoration: none;
}
.kp-brand:hover { text-decoration: none; color: var(--kp-accent); }
.kp-brand-logo { width: 24px; height: 24px; border-radius: 4px; }
.kp-brand-sep {
  color: var(--kp-text-muted); font-weight: 400; font-size: 14px;
  margin: 0 2px;
}
.kp-app-name {
  color: var(--kp-text-dim); font-weight: 500; font-size: 14px;
}

/* ── Theme toggle button ── */
/* NOTE: .kp-theme-btn (32px) and .kp-btn (~29px computed) are below the 44px
   touch-target floor. Deliberately NOT resized in this pass — the rendered
   header uses .kp-header-icon-btn (defined in kapable-header.css), so changing
   these here risks breaking live header layout without fixing the real chrome.
   The 44px-vs-WCAG-2.5.8-24px floor decision is deferred to the
   DESIGN-SYSTEM.md reconciliation. */
.kp-theme-btn {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 6px;
  background: none; border: 1px solid transparent;
  color: var(--kp-text-dim); cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.kp-theme-btn:hover { background: var(--kp-surface-hi); border-color: var(--kp-border); color: var(--kp-text); }
.kp-theme-btn svg { width: 16px; height: 16px; }

/* ── Common button ── */
.kp-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--kp-radius);
  background: var(--kp-accent); border: 0;
  font-size: 13px; font-weight: 500; cursor: pointer; font-family: var(--kp-font);
  transition: background 0.15s;
}
.kp-btn { color: var(--kp-on-accent); }
.kp-btn:hover { background: var(--kp-accent-hi); }
.kp-btn.secondary { background: var(--kp-surface-hi); color: var(--kp-text); border: 1px solid var(--kp-border); }
.kp-btn.secondary:hover { border-color: var(--kp-border-strong); }
.kp-btn.danger { background: var(--kp-danger); }

/* ── Common form inputs ── */
.kp-input, .kp-textarea, .kp-select {
  background: var(--kp-surface-hi); color: var(--kp-text); border: 1px solid var(--kp-border);
  padding: 7px 10px; border-radius: var(--kp-radius); font-size: 13px; width: 100%;
  font-family: var(--kp-font);
  transition: border-color 0.15s;
}
.kp-input:focus, .kp-textarea:focus, .kp-select:focus {
  border-color: var(--kp-accent);
  outline: 2px solid var(--kp-accent); outline-offset: -1px;
}
.kp-input::placeholder, .kp-textarea::placeholder { color: var(--kp-text-disabled); }

/* ── User avatar ── */
.kp-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--kp-accent-bg); color: var(--kp-accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px; flex-shrink: 0;
}

/* ── Muted text ── */
.kp-muted { color: var(--kp-text-dim); font-size: 13px; }

/* ── Keyboard-key chip ──
   Machine register (mono) for shortcut hints: cmd+K palettes, footer hints,
   help overlays. Promoted from kv2-launchpad (IMP-2025) so every consumer
   renders shortcut keys identically. */
.kp-kbd {
  display: inline-block;
  font-family: var(--kp-font-mono); font-size: 10px; line-height: 1;
  padding: 3px 5px 2px;
  border: 1px solid var(--kp-border); border-bottom-width: 2px;
  border-radius: var(--kp-radius-sm);
  background: var(--kp-surface-hi); color: var(--kp-text-dim);
}

/* ── Loading ── */
.kp-loading { color: var(--kp-text-dim); text-align: center; padding: 60px 0; }

/* ── Scrollbars — machine-quiet, no track background (operator law 2026-07-11) ──
   Thin thumb in the border tone, fully transparent track, both engines.
   Never paint a scrollbar background on any Kapable surface. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--kp-border-strong) transparent;
}
::-webkit-scrollbar { width: 10px; height: 10px; background: transparent; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--kp-border-strong);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--kp-text-muted); background-clip: padding-box; }

/* ── Reduced motion (vestibular a11y) ──
   Honour the OS "reduce motion" preference fleet-wide: neutralize transitions,
   animations, and smooth scrolling for users who opt out. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
