/* LeapX design tokens */
:root {
  /* Type */
  --font-sans: "Geist", ui-sans-serif, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  /* Neutrals — cool slightly-blue */
  --bg: oklch(0.985 0.003 250);
  --bg-elev: oklch(1 0 0);
  --bg-sunken: oklch(0.965 0.005 250);
  --line: oklch(0.91 0.006 250);
  --line-soft: oklch(0.945 0.005 250);
  --ink: oklch(0.18 0.01 250);
  --ink-2: oklch(0.36 0.012 250);
  --ink-3: oklch(0.54 0.012 250);
  --ink-4: oklch(0.7 0.012 250);

  /* Brand palette — blue (primary interactive), gold (brand highlight),
     green (positive). Set on :root so the whole platform inherits it. */
  --accent: oklch(0.55 0.15 256);        /* blue — primary */
  --accent-ink: oklch(0.34 0.11 256);
  --accent-soft: oklch(0.95 0.035 256);
  --gold: oklch(0.76 0.13 82);           /* gold — brand highlight / value */
  --gold-ink: oklch(0.47 0.10 72);
  --gold-soft: oklch(0.95 0.05 85);

  /* Semantic */
  --success: oklch(0.6 0.14 152);        /* green — positive / realized */
  --success-soft: oklch(0.95 0.045 152);
  --danger: oklch(0.6 0.18 25);
  --danger-soft: oklch(0.96 0.04 25);
  --info: oklch(0.58 0.13 256);          /* info aligns to the brand blue */
  --info-soft: oklch(0.96 0.03 256);
  --warn: oklch(0.72 0.14 80);
  --warn-soft: oklch(0.97 0.04 80);

  /* Radii / shadow */
  --r-sm: 7px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --shadow-sm: 0 1px 2px oklch(0.2 0.01 250 / 0.05);
  --shadow-md: 0 4px 14px oklch(0.2 0.01 250 / 0.06), 0 1px 2px oklch(0.2 0.01 250 / 0.04);

  /* Spacing scale — every UI metric should reference this so a single
     tweak propagates platform-wide. 4-based geometric scale. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 56px;

  /* Density (defaults — comfortable). Overridden by data-density="compact". */
  --row-h: 48px;
  --pad: var(--space-5);     /* 20px — card/page inner padding */
  --pad-sm: var(--space-3);  /* 12px — tight zones */
  --section-gap: var(--space-6);

  --max: 1440px;
}

[data-density="compact"] {
  --row-h: 36px;
  --pad: var(--space-3);
  --pad-sm: var(--space-2);
  --section-gap: var(--space-4);
}

[data-aesthetic="editorial"] {
  --pad: var(--space-7);     /* 32px — generous editorial whitespace */
  --row-h: 56px;
  --section-gap: var(--space-8);
}
[data-aesthetic="dense"] {
  --pad: var(--space-2);
  --row-h: 32px;
  --section-gap: var(--space-3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11";
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }

/* App shell */
.app {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}
@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
.main {
  min-width: 0;
  background: var(--bg);
}

/* Generic */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-7); }
/* Section rhythm — apply to any direct vertical stack to get consistent gaps */
.stack > * + * { margin-top: var(--space-5); }
.stack-lg > * + * { margin-top: var(--space-7); }
.stack-sm > * + * { margin-top: var(--space-3); }
.grow { flex: 1; min-width: 0; }
.mono { font-family: var(--font-mono); font-feature-settings: "zero","ss01"; }
.muted { color: var(--ink-3); }
.dim { color: var(--ink-2); }
.tiny { font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3); font-weight: 500; }
.h-rule { height: 1px; background: var(--line); }
.v-rule { width: 1px; background: var(--line); align-self: stretch; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.card-pad { padding: var(--pad); }
/* Default card padding when the card itself contains content directly */
.card.card-pad { padding: var(--pad); }
/* Card spacing between sibling cards inside a section */
.cards-grid { display: grid; gap: var(--space-4); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  height: 36px; padding: 0 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
  font-weight: 500;
  white-space: nowrap;
  transition: background 120ms, border-color 120ms, box-shadow 120ms;
}
.btn:hover { background: var(--bg-sunken); }
.btn-primary {
  background: var(--ink); color: var(--bg-elev); border-color: var(--ink);
}
.btn-primary:hover { background: oklch(0.28 0.012 250); }
.btn-accent {
  background: var(--accent); color: oklch(0.16 0.05 65); border-color: var(--accent);
}
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg-sunken); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; gap: var(--space-1); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  height: 22px; padding: 0 8px;
  border-radius: 5px;
  font-size: 11px; font-weight: 500;
  background: var(--bg-sunken); color: var(--ink-2);
  border: 1px solid var(--line);
}
.badge.dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; display: inline-block;
}
.badge-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in oklch, var(--success) 22%, transparent); }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in oklch, var(--danger) 22%, transparent); }
.badge-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in oklch, var(--info) 22%, transparent); }
.badge-warn { background: var(--warn-soft); color: oklch(0.45 0.12 80); border-color: color-mix(in oklch, var(--warn) 30%, transparent); }
.badge-accent { background: var(--accent-soft); color: var(--accent-ink); border-color: color-mix(in oklch, var(--accent) 30%, transparent); }
.badge-solid { background: var(--ink); color: var(--bg-elev); border-color: var(--ink); }

/* Inputs */
.input, .select, .textarea {
  height: 38px; padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-elev); color: var(--ink);
  outline: none;
  font-size: 13px;
  transition: border-color 120ms, box-shadow 120ms;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--ink-3);
  box-shadow: 0 0 0 3px oklch(0.85 0.012 250);
}
.textarea { height: auto; padding: var(--space-3); resize: vertical; line-height: 1.55; }
/* Field group — used by inline forms in platform admin */
.field-label { font-size: 11px; color: var(--ink-3); margin-bottom: var(--space-1); display: block; letter-spacing: 0.02em; }
.field { display: flex; flex-direction: column; gap: var(--space-1); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 14px 18px; }
th {
  font-size: 11px; font-weight: 500;
  color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  padding-top: 12px; padding-bottom: 12px;
}
tbody tr { border-bottom: 1px solid var(--line-soft); }
tbody tr:last-child { border-bottom: 0; }
tbody tr:hover { background: var(--bg-sunken); }
tbody td { vertical-align: middle; }

/* Topbar */
.topbar {
  height: 64px; padding: 0 var(--space-7);
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  display: flex; align-items: center; gap: var(--space-4);
  position: sticky; top: 0; z-index: 20;
}
.crumbs { color: var(--ink-3); font-size: 13px; display: flex; align-items: center; gap: var(--space-2); }
.crumbs b { color: var(--ink); font-weight: 500; }

/* Sidebar */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  height: 64px; padding: 0 var(--space-5);
  display: flex; align-items: center; gap: var(--space-3);
  border-bottom: 1px solid var(--line);
}
.brand-name { font-weight: 600; letter-spacing: -0.01em; font-size: 15px; }
.brand-tag { font-size: 10px; color: var(--ink-3); margin-left: auto; font-family: var(--font-mono); }
.nav { flex: 1; padding: var(--space-4) var(--space-3); display: flex; flex-direction: column; gap: var(--space-1); overflow-y: auto; }
.nav-section {
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-4); padding: var(--space-4) var(--space-3) var(--space-2);
  font-weight: 500;
}
.nav-section:first-child { padding-top: var(--space-1); }
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  cursor: pointer;
  font-weight: 450;
  font-size: 13px;
}
.nav-item:hover { background: var(--bg-sunken); color: var(--ink); }
.nav-item.active { background: var(--bg-sunken); color: var(--ink); font-weight: 500; }
.nav-item .count { margin-left: auto; font-size: 11px; color: var(--ink-4); font-family: var(--font-mono); }
.nav-item svg { color: var(--ink-3); flex-shrink: 0; }
.nav-item.active svg { color: var(--accent); }

/* Persona switcher */
.persona-card {
  margin: var(--space-3); padding: var(--space-4);
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--bg-sunken);
  display: flex; flex-direction: column; gap: var(--space-3);
}

/* Page */
.page { padding: var(--space-7) var(--space-8); max-width: var(--max); margin-inline: auto; }
.page-h { display: flex; align-items: end; gap: var(--space-4); margin-bottom: var(--space-2); flex-wrap: wrap; }
.page-h h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin: 0; line-height: 1.25; }
.page-sub { color: var(--ink-3); margin-bottom: var(--space-7); font-size: 13px; line-height: 1.55; }
/* Used by platform admin screens (no .page wrapper) */
.content { padding: var(--space-7) var(--space-8); max-width: var(--max); margin-inline: auto; }

/* Opt-in vertical rhythm — apply .stack on a section to get section-gap
   between its direct children. Default .page / .content don't auto-add
   that gap because individual components already manage their own
   margins inline; doubling them up causes oversized spacing. */

/* KPI tile */
.kpi {
  padding: var(--space-5) var(--space-5);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--bg-elev);
  display: flex; flex-direction: column; gap: var(--space-2);
}
.kpi .lbl { font-size: 11px; color: var(--ink-3); letter-spacing: 0.04em; text-transform: uppercase; font-weight: 500; }
.kpi .val { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; font-family: var(--font-sans); font-feature-settings: "tnum"; line-height: 1.2; }
.kpi .delta { font-size: 12px; color: var(--success); display: flex; align-items: center; gap: var(--space-1); }
.kpi .delta.down { color: var(--danger); }

/* Bars */
.bar {
  height: 6px; background: var(--bg-sunken); border-radius: 999px; overflow: hidden;
}
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* Avatar */
.av {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--bg-sunken); border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; color: var(--ink-2);
  flex-shrink: 0;
}
.av-stack { display: inline-flex; }
.av-stack .av { margin-left: -6px; }
.av-stack .av:first-child { margin-left: 0; }

/* Gate pipeline */
.pipeline { display: flex; align-items: stretch; gap: 0; }
.gate {
  flex: 1; min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  position: relative;
}
.gate:first-child { border-top-left-radius: var(--r-md); border-bottom-left-radius: var(--r-md); }
.gate:last-child { border-top-right-radius: var(--r-md); border-bottom-right-radius: var(--r-md); }
.gate + .gate { border-left: 0; }
.gate.passed { background: oklch(0.96 0.025 150); border-color: color-mix(in oklch, var(--success) 25%, var(--line)); }
.gate.current { background: var(--accent-soft); border-color: color-mix(in oklch, var(--accent) 35%, var(--line)); }
.gate.failed { background: var(--danger-soft); }
.gate .g-name { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-2); }
.gate .g-status { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

/* Misc */
.kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  background: var(--bg-elev);
  color: var(--ink-3);
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Hash chain visual */
.chain-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px;
  border: 1px dashed color-mix(in oklch, var(--success) 35%, var(--line));
  background: color-mix(in oklch, var(--success-soft) 60%, var(--bg-elev));
  color: var(--success);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
}

/* Stripe placeholder */
.stripe {
  background: repeating-linear-gradient(
    -45deg,
    var(--bg-sunken) 0 8px,
    var(--bg-elev) 8px 16px
  );
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 11px;
}

/* Pairwise */
.pw-card {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px;
  background: var(--bg-elev);
  cursor: pointer;
  transition: transform 120ms, border-color 120ms, box-shadow 120ms;
}
.pw-card:hover { border-color: var(--ink-3); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.pw-card.picked { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Score bar */
.score-row { display: grid; grid-template-columns: 1fr 80px 100px; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.score-row:last-child { border-bottom: 0; }

/* Audit */
.audit-row {
  display: grid;
  grid-template-columns: 130px 110px 1fr 200px 28px;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line-soft);
  align-items: center;
  font-size: 13px;
}
.audit-row:hover { background: var(--bg-sunken); }

/* Mobile baseline (kept; the responsive block below tightens further) */
@media (max-width: 880px) {
  .page, .content { padding: var(--space-4); }
  .topbar { padding: 0 var(--space-4); height: 56px; }
  .brand { height: 56px; padding: 0 var(--space-4); }
  .page-h h1 { font-size: 20px; }
  th, td { padding: 10px 12px; }
}

/* ===========================================================================
   RTL support — applied when document.documentElement.dir == "rtl".
   Uses [dir="rtl"] selectors so we can keep all existing LTR rules intact
   and just flip what's strictly directional (sidebar position, paddings,
   text alignment, drawer slide direction).
   =========================================================================== */
[dir="rtl"] body { font-family: "Cairo", "Geist", ui-sans-serif, sans-serif; }
[dir="rtl"] .app { direction: rtl; }
[dir="rtl"] .audit-row { grid-template-columns: 130px 110px 1fr 200px 28px; }
[dir="rtl"] .score-row { grid-template-columns: 1fr 80px 100px; }
[dir="rtl"] .badge.dot { padding-inline-start: 8px; padding-inline-end: 8px; }
[dir="rtl"] .mono { direction: ltr; unicode-bidi: embed; display: inline-block; }
[dir="rtl"] table.table th,
[dir="rtl"] table.table td { text-align: right; }
[dir="rtl"] .crumbs { direction: rtl; }
[dir="rtl"] .nav-item .count { margin-inline-start: auto; }

/* ===========================================================================
   Responsive — drawer sidebar on mobile, fluid tables, modal width.
   Breakpoints: 640px (small phone), 880px (tablet/phone landscape).
   =========================================================================== */

/* Hamburger button — only shown on small screens via .mobile-only */
.hamburger {
  display: none;
  width: 36px; height: 36px;
  align-items: center; justify-content: center;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink-2);
}
.hamburger:active { transform: scale(0.96); }

/* Override the existing 880px rule that just hid the sidebar — replace with
   a slide-over drawer. The sidebar becomes position:fixed off-screen by
   default, and slides in when .sidebar-open is toggled on the .app root. */
@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    display: flex !important;
    position: fixed;
    top: 0; bottom: 0;
    inset-inline-start: 0;
    width: 88vw;
    max-width: 320px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 220ms ease;
    box-shadow: var(--shadow-md);
  }
  [dir="rtl"] .sidebar { transform: translateX(100%); }

  .app.sidebar-open .sidebar { transform: translateX(0); }
  .app.sidebar-open::before {
    content: "";
    position: fixed; inset: 0;
    background: oklch(0.2 0.01 250 / 0.45);
    z-index: 49;
  }

  .hamburger { display: inline-flex; }

  /* Fluid topbar — let crumbs wrap and trim margins */
  .topbar { padding: 0 var(--space-4); gap: var(--space-2); flex-wrap: wrap; }
  .crumbs { font-size: 13px; }

  /* Keep the search + bell on one row, prevent overflow */
  .topbar-actions { flex-wrap: nowrap; min-width: 0; }
  .topbar-search { width: 200px !important; }
  .topbar-search-kbd { display: none; }

  /* Cards/tables breathe a bit less on phone */
  .page, .content { padding: var(--space-4) var(--space-4); }
  .card { border-radius: var(--r-md); }
}

@media (max-width: 640px) {
  /* Collapse the search to an icon-only square so the bell stays visible */
  .topbar-search {
    width: 32px !important;
    padding: 0 !important;
    justify-content: center;
    flex: 0 0 32px;
  }
  .topbar-search-label { display: none; }
}

/* Table horizontal scroll wrapper — every <table class="table"> in a small
   viewport should be horizontally scrollable so columns don't break. */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 880px) {
  table.table { min-width: 560px; }
  table.table th, table.table td { padding: var(--space-3) var(--space-3); font-size: 13px; }

  /* Audit grid → stacked rows on phone-size */
  .audit-row {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
  }

  /* Score rows */
  .score-row { grid-template-columns: 1fr 60px 80px; }

  /* Buttons get bigger touch targets */
  .btn { min-height: 38px; }
  .btn-sm { min-height: 34px; }
}

@media (max-width: 640px) {
  /* Truly phone-sized */
  .page, .content { padding: var(--space-3); }
  .crumbs { font-size: 12px; }
  .crumbs b { font-size: 13px; }

  /* Login card full-width */
  .login-card { width: 100% !important; max-width: 100% !important; padding: 20px !important; }

  /* Quick-pick grid: one column on tiny screens */
  .login-quick-grid { grid-template-columns: 1fr !important; }

  /* Modal: full-width sheet */
  .modal { width: 100% !important; max-width: 100% !important; border-radius: 0 !important; }

  /* Hide tweaks panel — it's a dev affordance */
  .tweaks-panel { display: none !important; }
}

/* Focus rings — accessible without being too loud */
.btn:focus-visible,
.nav-item:focus-visible,
.input:focus-visible,
.select:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Skip-link for keyboard users */
.skip-link {
  position: absolute; left: -9999px; top: 8px;
  background: var(--ink); color: white;
  padding: 8px 14px; border-radius: var(--r-sm);
  z-index: 100;
}
.skip-link:focus { left: 8px; }

/* Locale switcher — compact, fits sidebar persona card */
.locale-switch {
  display: inline-flex;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 2px;
}
.locale-switch button {
  height: 22px; padding: 0 10px;
  font-size: 11px; font-weight: 500;
  color: var(--ink-3);
  border-radius: 4px;
}
.locale-switch button.active {
  background: var(--ink);
  color: var(--bg-elev);
}

/* Impersonation banner on mobile */
@media (max-width: 640px) {
  .imp-banner { flex-direction: column; align-items: flex-start; gap: 6px; padding: 8px 12px; }
}

/* ===========================================================================
   Spacing polish — extra section breathing room inside cards/tables.
   Applied last so it wins over earlier rules.
   =========================================================================== */

/* Page header rhythm — give title block real room above the content */
.page-h + * { margin-top: 0; }
.page-sub + * { margin-top: var(--space-2); }

/* Table-wrap inherits card border-radius so tables-inside-cards look clean */
.card.table-wrap { overflow: hidden; }
.card.table-wrap > table { border-radius: inherit; }

/* Modal */
.modal {
  padding: var(--space-7);
  border-radius: var(--r-lg);
}
.modal-h { margin-bottom: var(--space-5); }
.modal-actions { margin-top: var(--space-6); display: flex; gap: var(--space-2); justify-content: flex-end; }

/* Grid utility for any 2-3 column section */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }
@media (max-width: 880px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; gap: var(--space-3); }
}

/* Sidebar feels more relaxed */
.sidebar { gap: 0; }
.sidebar .brand { letter-spacing: 0.01em; }

/* Page-h on mobile gets less margin so it doesn't dominate the viewport */
@media (max-width: 880px) {
  .page-h { margin-bottom: var(--space-1); }
  .page-sub { margin-bottom: var(--space-4); }
  .modal { padding: var(--space-5); }
}

/* Locale switcher buttons — bump touch target */
.locale-switch button { height: 26px; padding: 0 12px; }

/* When a card holds an inline form with .row gap-2 inside, ensure the
   row visually fits — flex-wrap was already set elsewhere; this keeps
   sub-elements aligned baseline-end. */
.card .row > .field { min-width: 0; }

/* Registration card — keep generous on desktop, tighten on mobile */
@media (max-width: 640px) {
  .register-card { padding: 24px !important; border-radius: 14px !important; }
}

/* Innovation Policy markdown preview — applies inside .md-preview only,
   so it can't leak to other components. */
.md-preview h2 {
  font-size: 18px; font-weight: 600; letter-spacing: -.01em;
  margin: 22px 0 10px; color: var(--ink); padding-bottom: 6px;
  border-bottom: 1px solid var(--line-soft);
}
.md-preview h2:first-child { margin-top: 0; }
.md-preview h3 {
  font-size: 14px; font-weight: 600; margin: 18px 0 8px; color: var(--ink);
}
.md-preview h4 {
  font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .05em;
}
.md-preview p  { margin: 6px 0 10px; color: var(--ink-2); }
.md-preview ul, .md-preview ol { margin: 6px 0 12px; padding-inline-start: 22px; }
.md-preview li { margin: 4px 0; color: var(--ink-2); }
.md-preview code {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 12px; padding: 1px 5px; border-radius: 4px;
  background: var(--bg-sunken); border: 1px solid var(--line-soft); color: var(--ink-2);
}
.md-preview blockquote {
  margin: 10px 0; padding: 6px 14px;
  border-inline-start: 3px solid var(--accent);
  background: color-mix(in oklch, var(--accent) 5%, transparent);
  color: var(--ink-2); border-radius: 0 6px 6px 0;
}
.md-preview blockquote p { margin: 4px 0; }
.md-preview b { color: var(--ink); }

/* ===========================================================================
   UX polish layer — motion, elevation, interaction feedback, and the CSS
   backing the shared feedback primitives (Skeleton / Spinner / Toast /
   Tooltip / EmptyState) added in ui.jsx. Loaded last so it wins. Everything
   here respects prefers-reduced-motion.
   =========================================================================== */

@keyframes lx-fade-up   { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes lx-fade-in   { from { opacity: 0; } to { opacity: 1; } }
@keyframes lx-shimmer   { 0% { background-position: -180% 0; } 100% { background-position: 180% 0; } }
@keyframes lx-spin      { to { transform: rotate(360deg); } }
@keyframes lx-toast-in  { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes lx-pop       { 0% { transform: scale(0.6); opacity: 0; } 60% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }

/* Page content eases in on route change — subtle, never distracting */
.page, .content { animation: lx-fade-up 260ms cubic-bezier(.22,.61,.36,1) both; }

/* --- Buttons: press feedback, hover lift on emphasis, disabled state --- */
.btn { transition: background 130ms, border-color 130ms, box-shadow 130ms, transform 90ms; }
.btn:active { transform: translateY(1px); }
.btn-primary:hover { box-shadow: var(--shadow-md); }
.btn-accent:hover  { box-shadow: var(--shadow-md); filter: brightness(1.02); }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; box-shadow: none; transform: none; }
.btn:disabled:hover { background: var(--bg-elev); }
.btn-primary:disabled:hover { background: var(--ink); }

/* --- Cards: optional hover elevation for clickable cards --- */
.card { transition: border-color 140ms, box-shadow 160ms, transform 160ms; }
.card-hover { cursor: pointer; }
.card-hover:hover { border-color: color-mix(in oklch, var(--accent) 30%, var(--line)); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.kpi { transition: border-color 140ms, box-shadow 160ms; }
.kpi:hover { border-color: color-mix(in oklch, var(--accent) 22%, var(--line)); }

/* --- Clickable list rows (dashboard lists, etc.) --- */
.rowlink { background: transparent; color: inherit; cursor: pointer; transition: background 120ms; }
.rowlink:hover { background: var(--bg-sunken); }

/* --- AI assist bar + buttons (Complete profile, etc.) --- */
.ai-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 22px;
  /* Brand gold — same warm cream as the app header */
  background: linear-gradient(90deg, #f7ebd4 0%, #f1dcb4 100%);
  border-top: 1px solid #e6cfa0;
}
.ai-bar-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; letter-spacing: .02em;
  color: var(--accent-ink);
  padding-inline-end: 4px;
}
.btn-ai {
  background: var(--bg-elev);
  border-color: color-mix(in oklch, var(--accent) 42%, var(--line));
  color: var(--accent-ink);
  font-weight: 600;
  box-shadow: 0 1px 2px color-mix(in oklch, var(--accent) 12%, transparent);
}
.btn-ai:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn-ai svg { color: var(--accent); }
.btn-ai:disabled, .btn-ai[disabled] { color: var(--ink-4); }
.btn-ai:disabled svg, .btn-ai[disabled] svg { color: var(--ink-4); }

/* --- Inputs: focus ring picks up the active accent (cohesive per-theme) --- */
.input:focus, .select:focus, .textarea:focus,
input:focus, select:focus, textarea:focus {
  border-color: color-mix(in oklch, var(--accent) 55%, var(--line));
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input:disabled, .select:disabled, .textarea:disabled { background: var(--bg-sunken); color: var(--ink-3); cursor: not-allowed; }

/* --- Nav: clearer active affordance with an accent indicator bar --- */
.nav-item { position: relative; transition: background 120ms, color 120ms; }
.nav-item.active::before {
  content: ""; position: absolute; inset-inline-start: 0; top: 50%;
  transform: translateY(-50%); height: 60%; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--accent);
}

/* --- Skeleton loaders --- */
.skeleton {
  background: linear-gradient(100deg,
    var(--bg-sunken) 30%,
    color-mix(in oklch, var(--bg-sunken) 50%, var(--bg-elev)) 50%,
    var(--bg-sunken) 70%);
  background-size: 200% 100%;
  animation: lx-shimmer 1.3s ease-in-out infinite;
  border-radius: var(--r-sm);
}
.skeleton.line { height: 12px; }
.skeleton.circle { border-radius: 50%; }

/* --- Spinner --- */
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  animation: lx-spin 700ms linear infinite;
  display: inline-block; flex-shrink: 0;
}

/* --- Toast host + toasts --- */
.toast-host {
  position: fixed; z-index: 200;
  inset-block-end: 20px; inset-inline-end: 20px;
  display: flex; flex-direction: column; gap: 10px;
  max-width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--ink-3);
  border-radius: var(--r-md);
  box-shadow: 0 10px 30px -12px oklch(0.2 0.02 250 / 0.4);
  animation: lx-toast-in 220ms cubic-bezier(.22,.61,.36,1) both;
  font-size: 13px; color: var(--ink);
}
.toast.leaving { animation: lx-fade-in 180ms reverse both; }
.toast .toast-ico { flex-shrink: 0; margin-top: 1px; display: inline-flex; }
.toast .toast-body { flex: 1; min-width: 0; line-height: 1.45; }
.toast .toast-title { font-weight: 600; }
.toast .toast-close { color: var(--ink-4); flex-shrink: 0; padding: 2px; border-radius: 4px; }
.toast .toast-close:hover { color: var(--ink-2); background: var(--bg-sunken); }
.toast-success { border-inline-start-color: var(--success); } .toast-success .toast-ico { color: var(--success); }
.toast-danger  { border-inline-start-color: var(--danger); }  .toast-danger  .toast-ico { color: var(--danger); }
.toast-warn    { border-inline-start-color: var(--warn); }    .toast-warn    .toast-ico { color: oklch(0.55 0.13 80); }
.toast-info    { border-inline-start-color: var(--info); }    .toast-info    .toast-ico { color: var(--info); }
.toast-accent  { border-inline-start-color: var(--accent); }  .toast-accent  .toast-ico { color: var(--accent-ink); }
@media (max-width: 640px) {
  .toast-host { inset-inline: 12px; inset-block-end: 12px; max-width: none; }
}

/* --- Empty states --- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: var(--space-8) var(--space-5);
  gap: var(--space-3);
}
.empty-state .empty-ico {
  width: 52px; height: 52px; border-radius: var(--r-lg);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-sunken); color: var(--ink-3);
  border: 1px solid var(--line);
}
.empty-state .empty-title { font-size: 15px; font-weight: 600; color: var(--ink); letter-spacing: -0.01em; }
.empty-state .empty-sub { font-size: 13px; color: var(--ink-3); max-width: 380px; line-height: 1.55; }

/* --- Lightweight CSS tooltip — add data-tip="text" to any element --- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; inset-block-end: calc(100% + 7px); inset-inline-start: 50%;
  transform: translateX(-50%) translateY(3px);
  background: var(--ink); color: var(--bg-elev);
  padding: 5px 9px; border-radius: 6px;
  font-size: 11px; font-weight: 500; line-height: 1.3; white-space: nowrap;
  letter-spacing: 0; text-transform: none;
  opacity: 0; pointer-events: none; z-index: 120;
  transition: opacity 120ms, transform 120ms;
  box-shadow: var(--shadow-md);
}
[data-tip]::before {
  content: ""; position: absolute; inset-block-end: calc(100% + 2px); inset-inline-start: 50%;
  transform: translateX(-50%) translateY(3px);
  border: 5px solid transparent; border-top-color: var(--ink);
  opacity: 0; pointer-events: none; z-index: 120; transition: opacity 120ms, transform 120ms;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after,
[data-tip]:hover::before, [data-tip]:focus-visible::before {
  opacity: 1; transform: translateX(-50%) translateY(0);
}
[data-tip-pos="bottom"]::after { inset-block: calc(100% + 7px) auto; }

/* Respect users who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .page, .content { animation: none; }
  .skeleton { animation: none; }
  .spinner { animation: lx-spin 700ms linear infinite; } /* keep spinner meaningful */
}
