/* Rebel Grantfinder — application design system.
 *
 * Loaded after Pico. Two jobs:
 *   1. Retune Pico's tokens for a dense operations console. Pico scales its
 *      root font size up to 125% on wide screens, which is what made every
 *      page feel oversized; everything downstream is rem-based, so pinning
 *      that one value does most of the compaction.
 *   2. Layer on the app's own components (shell, tiles, pills, boards).
 *
 * Themes: tokens are declared three times — light, OS-dark, and forced-dark
 * via [data-theme]. Pico keys off the same [data-theme] attribute, so the
 * toggle in the sidebar moves both layers together.
 */

/* ══ Tokens ═══════════════════════════════════════════════════════════════ */

:root {
  color-scheme: light;

  /* Surfaces & ink */
  --app-bg: #f5f6f9;
  --app-surface: #ffffff;
  --app-surface-2: #fafbfc;
  --app-surface-3: #f1f3f7;
  --app-border: #e3e6ec;
  --app-border-strong: #cfd4de;
  --app-ink: #10141d;
  --app-ink-2: #39415a;
  --app-muted: #6a7387;

  /* Brand */
  --app-brand: #4f46e5;
  --app-brand-hover: #4338ca;
  --app-brand-ink: #ffffff;
  --app-brand-soft: rgba(79, 70, 229, 0.09);
  --app-brand-soft-2: rgba(79, 70, 229, 0.16);
  --app-brand-ring: rgba(79, 70, 229, 0.35);

  /* Semantics */
  --app-ok: #047857;
  --app-ok-soft: #d9f2e6;
  --app-warn: #a35a07;
  --app-warn-soft: #fbeed2;
  --app-bad: #c62828;
  --app-bad-soft: #fbe0e0;
  --app-info: #1d4ed8;
  --app-info-soft: #dfe8fe;
  --app-accent: #4338ca;
  --app-accent-soft: #e5e3fd;
  --app-neutral-soft: #eceef2;
  --app-neutral-ink: #545c6e;

  /* Radii */
  --r-sm: 0.375rem;
  --r-md: 0.5rem;
  --r-lg: 0.75rem;
  --r-xl: 1rem;

  /* Elevation */
  --shadow-xs: 0 1px 2px rgba(16, 22, 35, 0.05);
  --shadow-sm: 0 1px 3px rgba(16, 22, 35, 0.07), 0 1px 2px rgba(16, 22, 35, 0.04);
  --shadow-md: 0 6px 16px -4px rgba(16, 22, 35, 0.11), 0 2px 6px -2px rgba(16, 22, 35, 0.06);
  --shadow-lg: 0 18px 40px -12px rgba(16, 22, 35, 0.22), 0 4px 10px -4px rgba(16, 22, 35, 0.1);

  /* ── Pico retune ────────────────────────────────────────────────────── */
  --pico-font-size: 87.5%; /* 14px — overrides Pico's 100→125% ramp */
  --pico-line-height: 1.5;
  --pico-font-family-sans-serif: -apple-system, BlinkMacSystemFont, "Inter",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --pico-font-family-monospace: ui-monospace, SFMono-Regular, "SF Mono", Menlo,
    "Cascadia Mono", Consolas, monospace;
  --pico-font-family: var(--pico-font-family-sans-serif);

  --pico-spacing: 1rem;
  --pico-typography-spacing-vertical: 0.75rem;
  --pico-block-spacing-vertical: 0.85rem;
  --pico-block-spacing-horizontal: 1rem;
  --pico-form-element-spacing-vertical: 0.4rem;
  --pico-form-element-spacing-horizontal: 0.6rem;
  --pico-nav-element-spacing-vertical: 0.4rem;
  --pico-nav-element-spacing-horizontal: 0.4rem;
  --pico-border-radius: var(--r-md);
  --pico-outline-width: 2px;
}

/* Pico declares its palettes at `:root:not([data-theme=dark])` and friends,
 * which outrank a plain `:root`. `:root:root` matches in every theme at that
 * same specificity, so one mapping serves light and dark: each --pico-* points
 * at an --app-* token, and only those get re-declared per theme below. */
:root:root {
  --pico-background-color: var(--app-bg);
  --pico-color: var(--app-ink);
  --pico-muted-color: var(--app-muted);
  --pico-muted-border-color: var(--app-border);
  --pico-h1-color: var(--app-ink);
  --pico-h2-color: var(--app-ink);
  --pico-h3-color: var(--app-ink);
  --pico-h4-color: var(--app-ink);
  --pico-h5-color: var(--app-ink);
  --pico-h6-color: var(--app-ink);

  --pico-card-background-color: var(--app-surface);
  --pico-card-border-color: var(--app-border);
  --pico-card-sectioning-background-color: var(--app-surface-2);
  --pico-card-box-shadow: var(--shadow-xs);

  --pico-primary: var(--app-brand);
  --pico-primary-background: var(--app-brand);
  --pico-primary-hover-background: var(--app-brand-hover);
  --pico-primary-border: var(--app-brand);
  --pico-primary-hover-border: var(--app-brand-hover);
  --pico-primary-inverse: var(--app-brand-ink);
  --pico-primary-focus: var(--app-brand-soft);
  --pico-primary-hover: var(--app-brand-hover);
  --pico-primary-underline: rgba(79, 70, 229, 0.4);

  --pico-secondary: var(--app-ink-2);
  --pico-secondary-hover: var(--app-ink);
  --pico-secondary-background: var(--app-surface);
  --pico-secondary-hover-background: var(--app-surface-3);
  --pico-secondary-border: var(--app-border-strong);
  --pico-secondary-hover-border: var(--app-border-strong);
  --pico-secondary-inverse: var(--app-ink-2);
  --pico-secondary-focus: var(--app-brand-soft);

  --pico-contrast: var(--app-ink);
  --pico-contrast-background: var(--app-ink);
  --pico-contrast-hover-background: #000000;
  --pico-contrast-border: var(--app-ink);
  --pico-contrast-inverse: #ffffff;

  --pico-form-element-background-color: var(--app-surface);
  --pico-form-element-selected-background-color: var(--app-surface-3);
  --pico-form-element-border-color: var(--app-border-strong);
  --pico-form-element-color: var(--app-ink);
  --pico-form-element-placeholder-color: #9aa1b1;
  --pico-form-element-active-background-color: var(--app-surface);
  --pico-form-element-active-border-color: var(--app-brand);
  --pico-form-element-focus-color: var(--app-brand);

  --pico-table-border-color: var(--app-border);
  --pico-table-row-stripped-background-color: var(--app-surface-2);
  --pico-code-background-color: var(--app-surface-3);
  --pico-code-color: var(--app-ink-2);
  --pico-ins-color: var(--app-ok);
  --pico-del-color: var(--app-bad);
  --pico-mark-background-color: #fdf0c4;
  --pico-mark-color: var(--app-ink);
  --pico-text-selection-color: var(--app-brand-soft-2);
  --pico-blockquote-border-color: var(--app-border);
  --pico-accordion-border-color: var(--app-border);
  --pico-progress-background-color: var(--app-surface-3);
  --pico-progress-color: var(--app-brand);
}

@media (min-width: 1900px) {
  :root { --pico-font-size: 93.75%; }
}

/* Dark — follows the OS unless the user forced light. */
@media (prefers-color-scheme: dark) {
  :root:root:not([data-theme="light"]) {
    color-scheme: dark;

    --app-bg: #0a0c11;
    --app-surface: #14171e;
    --app-surface-2: #191d26;
    --app-surface-3: #212632;
    --app-border: #262b36;
    --app-border-strong: #363d4b;
    --app-ink: #eef1f7;
    --app-ink-2: #b3bccd;
    --app-muted: #8d97a9;

    --app-brand: #7c7bf5;
    --app-brand-hover: #918ff8;
    --app-brand-ink: #0b0d14;
    --app-brand-soft: rgba(124, 123, 245, 0.14);
    --app-brand-soft-2: rgba(124, 123, 245, 0.26);
    --app-brand-ring: rgba(124, 123, 245, 0.45);

    --app-ok: #34d399;
    --app-ok-soft: rgba(52, 211, 153, 0.15);
    --app-warn: #fbbf24;
    --app-warn-soft: rgba(251, 191, 36, 0.15);
    --app-bad: #f87171;
    --app-bad-soft: rgba(248, 113, 113, 0.15);
    --app-info: #7dabfb;
    --app-info-soft: rgba(125, 171, 251, 0.15);
    --app-accent: #a5a2fb;
    --app-accent-soft: rgba(165, 162, 251, 0.16);
    --app-neutral-soft: rgba(255, 255, 255, 0.07);
    --app-neutral-ink: #a7b0c0;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 6px 16px -4px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 18px 40px -12px rgba(0, 0, 0, 0.7);

    --pico-contrast-background: #eef1f7;
    --pico-contrast-hover-background: #ffffff;
    --pico-contrast-border: #eef1f7;
    --pico-contrast-inverse: #0a0c11;
    --pico-primary-underline: rgba(124, 123, 245, 0.4);
    --pico-mark-background-color: #6b5a1a;
    --pico-form-element-placeholder-color: #737d90;
  }
}

/* Dark — forced by the theme toggle. */
:root:root[data-theme="dark"] {
  color-scheme: dark;

  --app-bg: #0a0c11;
  --app-surface: #14171e;
  --app-surface-2: #191d26;
  --app-surface-3: #212632;
  --app-border: #262b36;
  --app-border-strong: #363d4b;
  --app-ink: #eef1f7;
  --app-ink-2: #b3bccd;
  --app-muted: #8d97a9;

  --app-brand: #7c7bf5;
  --app-brand-hover: #918ff8;
  --app-brand-ink: #0b0d14;
  --app-brand-soft: rgba(124, 123, 245, 0.14);
  --app-brand-soft-2: rgba(124, 123, 245, 0.26);
  --app-brand-ring: rgba(124, 123, 245, 0.45);

  --app-ok: #34d399;
  --app-ok-soft: rgba(52, 211, 153, 0.15);
  --app-warn: #fbbf24;
  --app-warn-soft: rgba(251, 191, 36, 0.15);
  --app-bad: #f87171;
  --app-bad-soft: rgba(248, 113, 113, 0.15);
  --app-info: #7dabfb;
  --app-info-soft: rgba(125, 171, 251, 0.15);
  --app-accent: #a5a2fb;
  --app-accent-soft: rgba(165, 162, 251, 0.16);
  --app-neutral-soft: rgba(255, 255, 255, 0.07);
  --app-neutral-ink: #a7b0c0;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 6px 16px -4px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 18px 40px -12px rgba(0, 0, 0, 0.7);

  --pico-contrast-background: #eef1f7;
  --pico-contrast-hover-background: #ffffff;
  --pico-contrast-border: #eef1f7;
  --pico-contrast-inverse: #0a0c11;
  --pico-primary-underline: rgba(124, 123, 245, 0.4);
  --pico-mark-background-color: #6b5a1a;
  --pico-form-element-placeholder-color: #737d90;
}

/* ══ Base ═════════════════════════════════════════════════════════════════ */

body {
  background: var(--app-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  --pico-typography-spacing-top: 0;
  margin-top: 0;
  font-weight: 650;
  letter-spacing: -0.014em;
  line-height: 1.25;
}

h1 { font-size: 1.375rem; margin-bottom: 0.3rem; }
h2 { font-size: 1.0625rem; margin-bottom: 0.5rem; }
h3 { font-size: 0.9375rem; margin-bottom: 0.4rem; }
h4 { font-size: 0.875rem; margin-bottom: 0.35rem; }
h5, h6 { font-size: 0.8125rem; margin-bottom: 0.35rem; }

p { margin-bottom: 0.7rem; }
small { font-size: 0.78rem; }

a { text-underline-offset: 0.16em; text-decoration-thickness: from-font; }

code, kbd, samp {
  font-size: 0.82em;
  padding: 0.1rem 0.3rem;
  border-radius: var(--r-sm);
}

hr { border-color: var(--app-border); margin: 1rem 0; }

::selection { background: var(--app-brand-soft-2); }

:focus-visible {
  outline: 2px solid var(--app-brand);
  outline-offset: 2px;
}

/* Thin, unobtrusive scrollbars for the dense panes. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--app-border-strong) transparent;
}
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--app-border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

/* ══ App shell ════════════════════════════════════════════════════════════ */

.app-shell {
  display: grid;
  grid-template-columns: 13.75rem minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 160ms ease;
}
html[data-sidebar="collapsed"] .app-shell {
  grid-template-columns: minmax(0, 1fr);
}

.app-sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.75rem 0.6rem 0.75rem;
  border-right: 1px solid var(--app-border);
  background: linear-gradient(180deg, var(--app-surface) 0%, var(--app-surface-2) 100%);
}
html[data-sidebar="collapsed"] .app-sidebar { display: none; }

.app-sidebar-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.3rem 0.7rem;
  border-bottom: 1px solid var(--app-border);
}

.app-brand,
.app-brand:link,
.app-brand:visited,
.app-brand:hover,
.app-brand:focus {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 auto;
  min-width: 0;
  padding: 0;
  border: none;
  text-decoration: none;
  color: var(--app-ink);
}

.app-brand-mark {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: var(--r-md);
  background: linear-gradient(140deg, var(--app-brand) 0%, #8b5cf6 55%, #06b6d4 130%);
  color: #fff;
  box-shadow: 0 2px 6px -1px var(--app-brand-ring);
}
.app-brand-mark svg { width: 0.95rem; height: 0.95rem; }

.app-brand-text { min-width: 0; line-height: 1.15; }
.app-brand-name {
  display: block;
  font-size: 0.8125rem;
  font-weight: 650;
  letter-spacing: -0.012em;
  white-space: nowrap;
}
.app-brand-sub {
  display: block;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--app-muted);
}

/* Nav */
.app-sidebar nav {
  display: block;
  margin: 0;
  padding: 0;
  justify-content: unset;
}
.app-sidebar nav ul {
  display: flex;
  flex-direction: column;
  gap: 0.0625rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.app-sidebar nav li { display: block; margin: 0; padding: 0; width: 100%; }
.app-sidebar nav li::before { display: none; content: none; }

.nav-group {
  margin: 0.55rem 0 0.2rem;
  padding: 0 0.55rem;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--app-muted);
  opacity: 0.75;
}
.nav-group:first-child { margin-top: 0; }

.app-sidebar nav a,
.app-sidebar nav a:link,
.app-sidebar nav a:visited {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.55rem;
  border-radius: var(--r-md);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.3;
  text-decoration: none;
  color: var(--app-ink-2);
  background: transparent;
  transition: background 120ms ease, color 120ms ease;
}
.app-sidebar nav a svg {
  flex: 0 0 auto;
  width: 0.9375rem;
  height: 0.9375rem;
  opacity: 0.7;
  transition: opacity 120ms ease;
}
.app-sidebar nav a:hover,
.app-sidebar nav a:focus {
  color: var(--app-ink);
  background: var(--app-surface-3);
  text-decoration: none;
}
.app-sidebar nav a:hover svg { opacity: 1; }

.app-sidebar nav a[aria-current="page"],
.app-sidebar nav a[aria-current="page"]:link,
.app-sidebar nav a[aria-current="page"]:visited,
.app-sidebar nav a[aria-current="page"]:hover,
.app-sidebar nav a[aria-current="page"]:focus {
  font-weight: 600;
  color: var(--app-brand);
  background: var(--app-brand-soft);
}
.app-sidebar nav a[aria-current="page"] svg { opacity: 1; }
.app-sidebar nav a[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -0.6rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 1.15rem;
  border-radius: 0 3px 3px 0;
  background: var(--app-brand);
}

.app-sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 0.3rem 0;
  border-top: 1px solid var(--app-border);
}
.app-sidebar-footer form { margin: 0; flex: 1 1 auto; }
.app-sidebar-footer form button { width: 100%; }
.signout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}
.signout-btn svg { flex: 0 0 auto; width: 0.875rem; height: 0.875rem; }

/* Icon buttons (sidebar collapse, theme toggle) */
button.icon-btn,
button.sidebar-toggle,
button.sidebar-reopen {
  --pico-color: var(--app-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
  width: 1.75rem;
  height: 1.75rem;
  min-width: 0;
  border: 1px solid var(--app-border);
  border-radius: var(--r-md);
  background: var(--app-surface);
  color: var(--app-muted);
  box-shadow: none;
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease, border-color 120ms ease;
}
button.icon-btn svg,
button.sidebar-toggle svg,
button.sidebar-reopen svg { width: 0.875rem; height: 0.875rem; }

button.icon-btn:hover,
button.icon-btn:focus,
button.sidebar-toggle:hover,
button.sidebar-toggle:focus,
button.sidebar-reopen:hover,
button.sidebar-reopen:focus {
  color: var(--app-ink);
  background: var(--app-surface-3);
  border-color: var(--app-border-strong);
}

button.sidebar-reopen {
  display: none;
  position: sticky;
  top: 0.5rem;
  z-index: 20;
  width: auto;
  padding: 0 0.6rem;
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
}
html[data-sidebar="collapsed"] button.sidebar-reopen { display: inline-flex; }

/* Theme toggle swaps its glyph with the active scheme. */
.theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
}
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }

.app-main {
  width: 100%;
  max-width: 96rem;
  margin-inline: auto;
  padding: 1.1rem 1.5rem 3rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Flash message from ?message= */
.app-flash {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 1rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--app-border);
  border-left: 3px solid var(--app-brand);
  border-radius: var(--r-md);
  background: var(--app-surface);
  box-shadow: var(--shadow-xs);
  font-size: 0.8125rem;
  color: var(--app-ink-2);
}

/* ══ Page furniture ═══════════════════════════════════════════════════════ */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--app-border);
}
.page-header > div > p,
.page-header > div > .muted { margin-bottom: 0; font-size: 0.8125rem; }
.page-header h1 { margin-bottom: 0.15rem; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0.6rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--app-muted);
  text-decoration: none;
}
.back-link:hover { color: var(--app-brand); }
.back-link::before { content: "←"; }

.muted { color: var(--app-muted); }
.actions { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.field-error { color: var(--app-bad); }

.section-label {
  display: block;
  margin: 0 0 0.5rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--app-muted);
}

section { margin-bottom: 1.25rem; }
section:last-child { margin-bottom: 0; }

/* ══ Buttons ══════════════════════════════════════════════════════════════ */

button,
button[type="submit"], /* Pico stretches this one specifically */
[type="submit"],
[type="button"],
[type="reset"],
[role="button"] {
  width: auto;
  padding: 0.4rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 550;
  line-height: 1.35;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
  transition: background 120ms ease, border-color 120ms ease,
    color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}
button:not(.icon-btn):not(.sidebar-toggle):not(.sidebar-reopen):active,
[role="button"]:active { transform: translateY(0.5px); }

a[role="button"] { text-decoration: none; display: inline-flex; align-items: center; gap: 0.35rem; }

button.secondary,
[role="button"].secondary {
  color: var(--app-ink-2);
  background: var(--app-surface);
  border-color: var(--app-border-strong);
}
button.secondary:hover,
[role="button"].secondary:hover {
  color: var(--app-ink);
  background: var(--app-surface-3);
  border-color: var(--app-border-strong);
}

button.outline,
[role="button"].outline { box-shadow: none; }

button.tiny,
[role="button"].tiny {
  padding: 0.2rem 0.5rem;
  font-size: 0.72rem;
  border-radius: var(--r-sm);
}

button:disabled,
[type="submit"]:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

/* ══ Forms ════════════════════════════════════════════════════════════════ */

label { font-size: 0.8125rem; font-weight: 500; }

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
select,
textarea {
  font-size: 0.8125rem;
  border-radius: var(--r-md);
  box-shadow: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus,
select:focus,
textarea:focus {
  box-shadow: 0 0 0 3px var(--app-brand-soft);
}
textarea { min-height: 6rem; line-height: 1.55; }
[type="search"] { border-radius: var(--r-md); }
[type="checkbox"], [type="radio"] { --pico-border-radius: 0.25rem; }

fieldset { margin-bottom: 0.75rem; }

/* Page-level edit forms: a measured card rather than inputs stretched across
 * the full viewport. Opt-in via a class — a descendant selector rooted at
 * `.app-main > form` would outrank the filter-bar component rules below. */
.form-card {
  max-width: 46rem;
  margin-bottom: 1rem;
  padding: 1rem 1.1rem 1.1rem;
  border: 1px solid var(--app-border);
  border-radius: var(--r-lg);
  background: var(--app-surface);
  box-shadow: var(--shadow-xs);
}
.form-card > label {
  display: block;
  margin-bottom: 0.85rem;
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--app-muted);
}
.form-card > label > input,
.form-card > label > select,
.form-card > label > textarea { margin-top: 0.2rem; margin-bottom: 0; }
.form-card > label small {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.72rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}
.form-card > label.reindex {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--app-ink-2);
}
.form-card > .grid { margin-bottom: 0.85rem; }
.form-card > .actions {
  padding-top: 0.75rem;
  margin-top: 0.25rem;
  border-top: 1px solid var(--app-border);
}

/* Toolbar — the compact filter row that replaces stacked full-width fields. */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--app-border);
  border-radius: var(--r-lg);
  background: var(--app-surface);
  box-shadow: var(--shadow-xs);
}
.toolbar > label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1 1 9rem;
  min-width: 7rem;
  max-width: 20rem;
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--app-muted);
}
.toolbar > label input,
.toolbar > label select,
.toolbar > label textarea { margin: 0; height: auto; }
.toolbar > label.reindex,
.toolbar label.reindex {
  flex: 0 0 auto;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  max-width: none;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--app-ink-2);
  align-self: center;
  white-space: nowrap;
}
.toolbar label.reindex input { margin: 0; }
.toolbar .actions { flex: 0 0 auto; align-self: flex-end; }
.toolbar button, .toolbar [role="button"] { margin: 0; }

/* Run launcher — same shape, brand-tinted so it reads as an action bar. */
.run-launcher {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--app-border);
  border-left: 3px solid var(--app-brand);
  border-radius: var(--r-lg);
  background: var(--app-surface);
  box-shadow: var(--shadow-xs);
}
.run-launcher select,
.run-launcher input,
.run-launcher button { margin: 0; }
.run-launcher > select { min-width: 13rem; max-width: 18rem; align-self: center; }
.run-launcher > label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin: 0;
  flex: 0 1 9rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--app-muted);
}
.run-launcher label.reindex {
  flex-direction: row;
  align-items: center;
  align-self: center;
  gap: 0.35rem;
  flex: 0 0 auto;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--app-ink-2);
  white-space: nowrap;
}
.run-launcher > button { align-self: center; margin-left: auto; }

.run-banner {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  margin: 0 0 1rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--app-border);
  border-left: 3px solid var(--app-warn);
  border-radius: var(--r-md);
  background: var(--app-surface);
  box-shadow: var(--shadow-xs);
  font-size: 0.8125rem;
}
.run-banner strong { font-weight: 600; }
.run-banner::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--app-warn);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}
@media (prefers-reduced-motion: reduce) {
  .run-banner::before { animation: none; }
}

/* Run modal — the interstitial held up while a synchronous pipeline POST
   is in flight. No dismiss control: closing it would not call off the work. */
.run-modal > article {
  max-width: 32rem;
  padding: 1.25rem 1.4rem 1rem;
  border-left: 3px solid var(--app-brand);
}
.run-modal header {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0 0 0.85rem;
  padding: 0;
  border: 0;
  background: none;
}
.run-modal header h2 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
}
.run-modal-spinner {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--app-brand-soft-2);
  border-top-color: var(--app-brand);
  border-radius: 999px;
  animation: run-modal-spin 0.8s linear infinite;
}
@keyframes run-modal-spin { to { transform: rotate(360deg); } }
.run-modal p { margin-bottom: 0.6rem; font-size: 0.875rem; }
.run-modal progress { margin: 0.2rem 0 0.85rem; }
.run-modal-estimate { color: var(--app-ink-2); }
.run-modal-slow {
  padding: 0.5rem 0.65rem;
  border-radius: var(--r-md);
  background: var(--app-warn-soft);
  color: var(--app-warn);
}
.run-modal footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 1rem -1.4rem -1rem;
  padding: 0.7rem 1.4rem;
  background: var(--app-surface-2);
}
.run-modal-elapsed {
  font-size: 0.8125rem;
  color: var(--app-muted);
}
.run-modal-elapsed strong {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--app-ink-2);
}
.run-modal footer [role="button"] { margin: 0; font-size: 0.8125rem; }
@media (prefers-reduced-motion: reduce) {
  .run-modal-spinner { animation-duration: 3s; }
}

/* ══ Cards, panels, tiles ═════════════════════════════════════════════════ */

article {
  border: 1px solid var(--app-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}
article > h2:first-child,
article > h3:first-child { margin-top: 0; }

.panel {
  margin-bottom: 1rem;
  border: 1px solid var(--app-border);
  border-radius: var(--r-lg);
  background: var(--app-surface);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.panel > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--app-border);
  background: var(--app-surface-2);
}
.panel > header h2,
.panel > header h3 {
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--app-muted);
}
.panel > header .actions a { font-size: 0.78rem; }
.panel-body { padding: 0.75rem 0.85rem; }
.panel-body > :last-child { margin-bottom: 0; }
.panel > .table-card {
  margin-bottom: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
}
.panel > .table-card table { border-bottom: none; }
.panel-body > .table-card:last-child { margin-bottom: 0; }

/* KPI tiles */
.kpi-row {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  margin-bottom: 1.25rem;
}
.kpi {
  position: relative;
  display: block;
  padding: 0.7rem 0.85rem 0.75rem;
  border: 1px solid var(--app-border);
  border-radius: var(--r-lg);
  background: var(--app-surface);
  box-shadow: var(--shadow-xs);
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}
.kpi::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, var(--app-brand), transparent 70%);
  opacity: 0;
  transition: opacity 140ms ease;
}
a.kpi:hover {
  border-color: var(--app-border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  text-decoration: none;
}
a.kpi:hover::after { opacity: 1; }
.kpi-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--app-muted);
}
.kpi-label svg { width: 0.8125rem; height: 0.8125rem; opacity: 0.8; }
.kpi-value {
  display: block;
  margin-top: 0.3rem;
  font-size: 1.65rem;
  font-weight: 650;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--app-ink);
}
.kpi-sub {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.72rem;
  color: var(--app-muted);
}

/* Legacy stat cards (`.grid-cards article` with h3 + p) get the same look. */
.grid-cards {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  margin-bottom: 1.25rem;
}
.grid-cards article {
  margin: 0;
  padding: 0.7rem 0.85rem 0.75rem;
  background: var(--app-surface);
}
.grid-cards article h3 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.grid-cards article p {
  margin: 0.15rem 0 0;
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--app-muted);
}

/* Fact tiles: `.grid > article` whose first child is a <strong> label. */
.grid { --pico-grid-column-gap: 0.6rem; --pico-grid-row-gap: 0.6rem; margin-bottom: 1rem; }
.grid > article {
  margin: 0;
  padding: 0.6rem 0.8rem;
  background: var(--app-surface);
  font-size: 0.875rem;
}
.grid > article > strong:first-child {
  display: block;
  margin-bottom: 0.1rem;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--app-muted);
}
.grid > article > strong:first-child + br { display: none; }

/* Empty state */
.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  border: 1px dashed var(--app-border-strong);
  border-radius: var(--r-lg);
  background: var(--app-surface);
  box-shadow: none;
}
.empty-state h2 { font-size: 0.9375rem; }
.empty-state p { font-size: 0.8125rem; margin-bottom: 0.75rem; }
.empty-state > :last-child { margin-bottom: 0; }

/* ══ Tables ═══════════════════════════════════════════════════════════════ */

table {
  margin-bottom: 0.85rem;
  font-size: 0.8125rem;
  border-collapse: collapse;
}
thead th {
  padding: 0.45rem 0.7rem;
  font-size: 0.6563rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--app-muted);
  background: var(--app-surface-2);
  border-bottom: 1px solid var(--app-border);
  white-space: nowrap;
}
tbody td {
  padding: 0.5rem 0.7rem;
  vertical-align: top;
  border-bottom: 1px solid var(--app-border);
  line-height: 1.45;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 100ms ease; }
tbody tr:hover { background: var(--app-surface-2); }
td small, td .muted small { font-size: 0.72rem; }

/* Row links read as content, not as chrome: ink-coloured until hovered. */
td a:not([role="button"]) {
  font-weight: 550;
  color: var(--app-ink);
  text-decoration: none;
}
td a:not([role="button"]):hover {
  color: var(--app-brand);
  text-decoration: underline;
}
td.actions a:not([role="button"]) {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--app-muted);
  text-decoration: none;
}
td.actions a:not([role="button"]):hover { color: var(--app-brand); text-decoration: underline; }
.key-list a { color: var(--app-ink); text-decoration: none; }
.key-list a:hover { color: var(--app-brand); text-decoration: underline; }

/* Framed, horizontally scrollable table container. */
.table-card {
  margin-bottom: 0.85rem;
  border: 1px solid var(--app-border);
  border-radius: var(--r-lg);
  background: var(--app-surface);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  overflow-x: auto;
}
.table-card table { margin: 0; width: 100%; }
.table-card thead th:first-child,
.table-card tbody td:first-child { padding-left: 0.85rem; }
.table-card thead th:last-child,
.table-card tbody td:last-child { padding-right: 0.85rem; }

/* Cell helpers */
.cell-title { font-weight: 550; color: var(--app-ink); }
.cell-sub {
  display: block;
  margin-top: 0.1rem;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--app-muted);
}
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.result-count {
  margin: 0 0 0.6rem;
  font-size: 0.78rem;
  color: var(--app-muted);
}

/* Pagination */
nav[aria-label="Pagination"] {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0;
  margin-top: 0.75rem;
  font-size: 0.78rem;
}
nav[aria-label="Pagination"] ul { margin: 0; padding: 0; list-style: none; display: flex; gap: 0.4rem; }
nav[aria-label="Pagination"] li { padding: 0; margin: 0; }
nav[aria-label="Pagination"] a,
nav[aria-label="Pagination"] span {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: var(--r-md);
  text-decoration: none;
}
nav[aria-label="Pagination"] a {
  border: 1px solid var(--app-border-strong);
  color: var(--app-ink-2);
  background: var(--app-surface);
}
nav[aria-label="Pagination"] a:hover { background: var(--app-surface-3); color: var(--app-ink); }
nav[aria-label="Pagination"] span.muted { border: 1px solid transparent; }

/* ══ Pills & scores ═══════════════════════════════════════════════════════ */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.005em;
  line-height: 1.55;
  white-space: nowrap;
  background: var(--app-neutral-soft);
  color: var(--app-neutral-ink);
}

.pill-suggested,
.pill-draft { background: var(--app-accent-soft); color: var(--app-accent); }

.pill-shortlisted,
.pill-probed { background: var(--app-info-soft); color: var(--app-info); }

.pill-declared,
.pill-completed,
.pill-interested,
.pill-ready { background: var(--app-ok-soft); color: var(--app-ok); }

.pill-applied,
.pill-queued,
.pill-running,
.pill-in_review { background: var(--app-warn-soft); color: var(--app-warn); }

.pill-failed { background: var(--app-bad-soft); color: var(--app-bad); }

.pill-lost,
.pill-passed,
.pill-archived { background: var(--app-neutral-soft); color: var(--app-neutral-ink); }

.pill-won,
.pill-pursuing_as_sub {
  background: var(--app-ok);
  color: #ffffff;
}
[data-theme="dark"] .pill-won,
[data-theme="dark"] .pill-pursuing_as_sub { color: #06231a; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pill-won,
  :root:not([data-theme="light"]) .pill-pursuing_as_sub { color: #06231a; }
}

.score {
  display: inline-block;
  min-width: 2.15rem;
  padding: 0.1rem 0.4rem;
  text-align: center;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.6875rem;
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
}
.score-high { background: #059669; }
.score-mid { background: #d97706; }
.score-low { background: #dc2626; }
.score-none { background: #94a3b8; }

/* Filter chip strip */
.stat-strip {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.stat-strip a,
.stat-strip span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.65rem;
  border: 1px solid var(--app-border);
  border-radius: 999px;
  background: var(--app-surface);
  text-decoration: none;
  font-size: 0.7813rem;
  font-weight: 500;
  color: var(--app-ink-2);
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}
.stat-strip a strong,
.stat-strip span strong {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--app-ink);
}
.stat-strip a:hover {
  border-color: var(--app-border-strong);
  background: var(--app-surface-3);
  color: var(--app-ink);
}
.stat-strip a[aria-current="page"] {
  border-color: transparent;
  background: var(--app-brand);
  color: var(--app-brand-ink);
  font-weight: 600;
}
.stat-strip a[aria-current="page"] strong { color: var(--app-brand-ink); }

/* ══ Boards ═══════════════════════════════════════════════════════════════ */

.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(12.5rem, 1fr);
  gap: 0.6rem;
  overflow-x: auto;
  padding-bottom: 0.75rem;
  align-items: start;
}
.board--wrap {
  grid-auto-flow: row;
  grid-auto-columns: auto;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  overflow-x: visible;
}
.board-column {
  border: 1px solid var(--app-border);
  border-radius: var(--r-lg);
  background: var(--app-surface-2);
  padding: 0.55rem;
  box-shadow: var(--shadow-xs);
}
.board-column > header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.55rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--app-border);
}
.board-column > header strong {
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  color: var(--app-ink);
}
.board-column > header p {
  flex-basis: 100%;
  margin: 0.15rem 0 0;
  font-size: 0.7rem;
  line-height: 1.4;
}
.board-card {
  margin: 0 0 0.45rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--app-border);
  border-radius: var(--r-md);
  background: var(--app-surface);
  box-shadow: var(--shadow-xs);
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}
.board-card:hover {
  border-color: var(--app-border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.board-card-head { display: flex; gap: 0.4rem; align-items: flex-start; }
.board-card-head a {
  font-size: 0.8125rem;
  font-weight: 550;
  line-height: 1.35;
  color: var(--app-ink);
  text-decoration: none;
}
.board-card-head a:hover { color: var(--app-brand); text-decoration: underline; }
.board-card-meta {
  margin: 0.4rem 0 0;
  font-size: 0.7rem;
  line-height: 1.45;
}
.board-card-actions { display: flex; gap: 0.3rem; margin-top: 0.5rem; flex-wrap: wrap; }
.board-card-actions form { margin: 0; }
.board-empty { margin: 0; font-size: 0.75rem; padding: 0.25rem 0.1rem; }

/* Board filter row */
.board-filter {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.board-filter select { margin: 0; width: auto; min-width: 12rem; }
.board-filter button,
.board-filter a[role="button"] { margin: 0; }

/* ══ Pipeline track & timeline ════════════════════════════════════════════ */

.pipeline-track {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  margin: 0 0 1rem;
  padding: 0.3rem;
  border: 1px solid var(--app-border);
  border-radius: var(--r-lg);
  background: var(--app-surface);
  box-shadow: var(--shadow-xs);
}
.pipeline-step {
  flex: 1 1 6rem;
  text-align: center;
  padding: 0.35rem 0.4rem;
  border-radius: var(--r-md);
  font-size: 0.75rem;
  font-weight: 550;
  color: var(--app-muted);
  white-space: nowrap;
}
.pipeline-step.is-current {
  background: var(--app-brand);
  color: var(--app-brand-ink);
  font-weight: 650;
}

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--app-border);
}
.timeline li:last-child { border-bottom: none; padding-bottom: 0; }
.timeline li::before { display: none; content: none; }
.timeline-head { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.timeline p { margin: 0.35rem 0 0; font-size: 0.8125rem; }

/* ══ Misc component styles used by individual pages ═══════════════════════ */

.reindex {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  margin: 0;
  font-size: 0.78rem;
  font-weight: 500;
}
.reindex input { margin: 0; }

.declare-form {
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) minmax(10rem, 2fr) auto;
  gap: 0.5rem;
  align-items: end;
  margin-top: 0.75rem;
}
.declare-form label,
.declare-form select,
.declare-form input,
.declare-form button { margin: 0; }
.declare-form label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--app-muted);
}
@media (max-width: 48rem) {
  .declare-form { grid-template-columns: 1fr; }
}

.proposal-section {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--app-border);
}
.proposal-section:last-of-type { border-bottom: none; }
.proposal-section textarea[name="notes"] { min-height: 4rem; }

/* `ul li { list-style: square }` in Pico targets the item, so resetting the
 * list alone does nothing — these have to say it on the li. */
.key-list { padding: 0; margin: 0; }
.key-list li {
  list-style: none;
  padding: 0.4rem 0;
  margin: 0;
  border-bottom: 1px solid var(--app-border);
  font-size: 0.8125rem;
}
.key-list li:last-child { border-bottom: none; }
.key-list li::before { display: none; content: none; }

.tag-row { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0; padding: 0; }
.tag-row li { list-style: none; margin: 0; padding: 0; }
.tag-row li::before { display: none; content: none; }
.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--app-border);
  border-radius: 999px;
  background: var(--app-surface-2);
  font-size: 0.72rem;
  color: var(--app-ink-2);
}

dl { margin: 0; font-size: 0.8125rem; }
dt { font-weight: 600; color: var(--app-muted); }
dd { margin: 0 0 0.5rem; }

.dl-inline {
  display: grid;
  grid-template-columns: minmax(6rem, auto) 1fr;
  gap: 0.3rem 1rem;
  align-items: baseline;
}
.dl-inline dt {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.dl-inline dd { margin: 0; overflow-wrap: anywhere; }

/* Proportion bar, e.g. grants-by-source. */
.meter {
  display: block;
  height: 0.35rem;
  min-width: 3rem;
  border-radius: 999px;
  background: var(--app-surface-3);
  overflow: hidden;
}
.meter > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--app-brand), #8b5cf6);
}

/* Panels sitting inside a Pico .grid own their own spacing, and size to their
 * content rather than stretching to the tallest sibling. */
.grid:has(> .panel) { align-items: start; }
.grid > .panel { margin-bottom: 0; }

/* Secondary line inside a data cell: `<a>…</a><br><small class="muted">…` is
 * the established markup, so promote it rather than rewrite every table. */
td > br { display: none; }
td > small { display: block; margin-top: 0.1rem; line-height: 1.4; }
td > small + small { margin-top: 0; }

/* Board column accents, keyed to the same hues as the status pills. */
.board-column { position: relative; }
.board-column::before {
  content: "";
  position: absolute;
  inset: -1px -1px auto -1px;
  height: 2px;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--app-border-strong);
}
.board-column--suggested::before { background: var(--app-accent); }
.board-column--shortlisted::before,
.board-column--probed::before { background: var(--app-info); }
.board-column--declared::before,
.board-column--interested::before { background: var(--app-ok); }
.board-column--applied::before { background: var(--app-warn); }
.board-column--won::before,
.board-column--pursuing_as_sub::before { background: var(--app-ok); }
.board-column--lost::before,
.board-column--passed::before { background: var(--app-border-strong); }

progress { height: 0.4rem; border-radius: 999px; }

details summary { font-size: 0.8125rem; }

/* ══ Login ════════════════════════════════════════════════════════════════ */

.login-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1.5rem;
  background:
    radial-gradient(60rem 40rem at 15% -10%, var(--app-brand-soft), transparent 60%),
    radial-gradient(50rem 35rem at 110% 110%, rgba(6, 182, 212, 0.1), transparent 60%),
    var(--app-bg);
}
.login-card {
  width: min(21rem, 100%);
  margin: 0;
  padding: 1.5rem 1.4rem 1.4rem;
  border: 1px solid var(--app-border);
  border-radius: var(--r-xl);
  background: var(--app-surface);
  box-shadow: var(--shadow-lg);
}
.login-card header {
  margin-bottom: 1.1rem;
  padding: 0;
  border: none;
  background: none;
  text-align: center;
}
.login-card .app-brand-mark {
  width: 2.35rem;
  height: 2.35rem;
  margin: 0 auto 0.7rem;
  border-radius: var(--r-lg);
}
.login-card .app-brand-mark svg { width: 1.3rem; height: 1.3rem; }
.login-card h1 { font-size: 1.125rem; margin-bottom: 0.2rem; }
.login-card header p { margin: 0; font-size: 0.8125rem; color: var(--app-muted); }
.login-card label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--app-muted);
}
.login-card button { width: 100%; margin-top: 0.25rem; }
.login-error {
  margin-bottom: 0.75rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--app-bad);
  border-radius: var(--r-md);
  background: var(--app-bad-soft);
  color: var(--app-bad);
  font-size: 0.78rem;
}

/* ══ Responsive ═══════════════════════════════════════════════════════════ */

/* Narrow viewports keep the sidebar on the left — it narrows to an icon rail
 * rather than becoming top navigation. Labels are hidden, so every control
 * carries a title attribute for its tooltip. */
@media (max-width: 46rem) {
  .app-shell { grid-template-columns: 3.25rem minmax(0, 1fr); }
  html[data-sidebar="collapsed"] .app-shell { grid-template-columns: minmax(0, 1fr); }

  .app-sidebar {
    align-items: stretch;
    gap: 0.45rem;
    padding: 0.6rem 0.35rem 0.6rem;
    overflow-x: hidden;
  }
  .app-sidebar-head {
    justify-content: center;
    margin: 0;
    padding: 0.1rem 0 0.55rem;
  }
  .app-brand,
  .app-brand:link,
  .app-brand:visited { justify-content: center; flex: 0 0 auto; }
  .app-brand-text { display: none; }
  .app-sidebar-head .sidebar-toggle { display: none; }

  /* Group headings collapse to a hairline so the sections stay legible. */
  .nav-group {
    height: 1px;
    margin: 0.4rem 0.3rem;
    padding: 0;
    overflow: hidden;
    text-indent: -999em;
    background: var(--app-border);
  }
  .nav-group:first-child { display: none; }

  .app-sidebar nav a,
  .app-sidebar nav a:link,
  .app-sidebar nav a:visited {
    justify-content: center;
    gap: 0;
    padding: 0.45rem 0;
  }
  .app-sidebar nav a svg { width: 1.0625rem; height: 1.0625rem; }
  .app-sidebar nav a[aria-current="page"]::before { left: -0.35rem; }
  .nav-label { display: none; }

  .app-sidebar-footer {
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.55rem 0 0;
  }
  .app-sidebar-footer form button { padding: 0.35rem 0; }

  .app-main { padding: 1rem 0.9rem 2.5rem; }
}

@media (max-width: 40rem) {
  .page-header { gap: 0.5rem; }
  .kpi-row, .grid-cards { grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); }
  .kpi-value { font-size: 1.4rem; }
}
