/* ============================================================
   EdgeStacker design system — tokens + shared components.
   Dark-first "signal green + carbon". Source of truth:
   docs/design_handoff (redesign bundle) — tokens/*.css.
   ============================================================ */
:root {
  /* --- Signal green (primary brand) --- */
  --green-300: #6df3b8;
  --green-400: #3df0a0;
  --green-500: #2ee08a;
  --green-600: #24d67f;
  --green-700: #12b866;
  --green-800: #0f9354;
  --green-900: #0b8f50;

  /* --- Carbon (dark neutrals) --- */
  --ink-950: #070b0a;
  --ink-900: #080d0b;
  --ink-850: #0a110e;
  --ink-800: #0c1712;
  --ink-700: #0e1512;
  --ink-600: #12201a;
  --ink-500: #1a2a23;

  /* --- Paper (light neutrals / text) --- */
  --paper: #eef3f0;
  --paper-bright: #f4fbf7;
  --slate-400: #8ba398;
  --slate-500: #7f938a;
  --slate-600: #6b7f76;
  --slate-700: #5d7169;

  /* --- Status --- */
  --up: #2ee08a;
  --up-soft: rgba(46, 224, 138, 0.14);
  --down: #ff5f6d;
  --down-soft: rgba(255, 95, 109, 0.14);
  --warn: #ffb454;
  --warn-soft: rgba(255, 180, 84, 0.14);
  --info: #4db8ff;
  --info-soft: rgba(77, 184, 255, 0.14);

  /* --- Borders --- */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.14);
  --border-accent: rgba(46, 224, 138, 0.28);

  /* --- Gradients --- */
  --gradient-brand: linear-gradient(135deg, #3df0a0, #12b866);
  --glow-radial: radial-gradient(1100px 620px at 22% -8%, rgba(35, 210, 130, 0.10), transparent 60%);

  /* --- Semantic aliases --- */
  --bg-app: var(--ink-950);
  --surface-card: var(--ink-700);
  --surface-elevated: var(--ink-800);
  --surface-well: var(--ink-900);
  --surface-hover: var(--ink-600);
  --text-primary: var(--paper);
  --text-secondary: var(--slate-400);
  --text-muted: var(--slate-600);
  --text-on-accent: #052014;
  --accent: var(--green-500);
  --accent-strong: var(--green-700);
  --accent-pressed: var(--green-800);
  --accent-tint: rgba(46, 224, 138, 0.13);
  --focus-ring: rgba(46, 224, 138, 0.45);
  --focus-shadow: 0 0 0 3px var(--focus-ring);

  /* --- Type --- */
  --font-display: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --ls-display: -0.025em;
  --ls-heading: -0.02em;
  --ls-eyebrow: 0.28em;
  --ls-label: 0.16em;

  /* --- Radii --- */
  --radius-xs: 5px;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 18px;
  --radius-2xl: 22px;
  --radius-3xl: 24px;
  --radius-pill: 999px;

  /* --- Shadows & glow --- */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 10px 26px rgba(0, 0, 0, 0.55);
  --shadow-xl: 0 24px 60px rgba(0, 0, 0, 0.6);
  --glow-sm: 0 4px 14px rgba(45, 220, 140, 0.28);
  --glow-md: 0 8px 20px rgba(45, 220, 140, 0.32);
  --glow-lg: 0 12px 34px rgba(18, 180, 102, 0.40);
  --glow-ring: 0 0 0 1px rgba(46, 224, 138, 0.35), 0 8px 24px rgba(45, 220, 140, 0.28);

  /* --- Motion --- */
  --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 120ms;
  --dur-med: 200ms;
  --dur-slow: 320ms;

  /* --- Spacing scale (4px grid) --- */
  --space-0: 0;
  --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: 48px;
  --space-10: 56px;
  --space-12: 80px;

  /* --- Control sizing + layout --- */
  --control-h-sm: 32px;
  --control-h-md: 40px;
  --control-h-lg: 48px;
  --control-pad-x: 16px;
  --container-max: 1400px;
  --sidebar-w: 248px;
  --gutter: 24px;

  --border-w: 1px;
  --shadow-inset-hi: inset 0 1px 0 rgba(255, 255, 255, 0.06);

  /* ----------------------------------------------------------
     Legacy aliases — pre-redesign templates (Improve, Discover,
     jobs/market partials) still reference these names. Values
     point at the new palette so those screens inherit the
     refresh without a rewrite. Remove once all screens are
     ported to the new tokens.
     ---------------------------------------------------------- */
  --canvas-bg: var(--ink-950);
  --app-bg: var(--ink-950);
  --sidebar-bg: var(--ink-900);
  --panel-bg: var(--ink-700);
  --inset-bg: var(--ink-900);
  --hairline-04: rgba(255, 255, 255, 0.04);
  --hairline-05: rgba(255, 255, 255, 0.05);
  --hairline-06: var(--border-subtle);
  --hairline-07: rgba(255, 255, 255, 0.07);
  --hairline-08: rgba(255, 255, 255, 0.08);
  --hairline-10: var(--border);
  --hairline-12: rgba(255, 255, 255, 0.12);
  --text-secondary-2: #cfe0d8;
  --text-mono-muted: var(--slate-600);
  --text-faint: var(--slate-700);
  --text-faint-2: #4d5f57;
  --green-bright: var(--green-400);
  --green-mid: var(--green-600);
  --green-mid-2: var(--green-600);
  --green-deep: var(--green-700);
  --green-deep-2: var(--green-800);
  --green-nav: var(--green-500);
  --green-gradient: var(--gradient-brand);
  --green-selected-bg: var(--accent-tint);
  --green-selected-border: rgba(46, 224, 138, 0.3);
  --green-selected-text: var(--green-400);
  --nav-active-bg: var(--accent-tint);
  --nav-active-border: var(--border-accent);
  --green-tint-bg: rgba(46, 224, 138, 0.09);
  --green-tint-border: var(--border-accent);
  --green-tint-text: #c9f2dd;
  --red-candle: #ef5350;
  --red-text: var(--down);
  --amber: var(--warn);
  --amber-tint-bg: var(--warn-soft);
  --amber-tint-border: rgba(255, 180, 84, 0.3);
  --amber-tint-text: #ffd9a3;
  --candle-up: var(--green-600);
  --candle-down: #ef5350;
  --radius-btn: var(--radius-md);
  --radius-input: var(--radius-md);
  --radius-card: var(--radius-2xl);
  --radius-frame: var(--radius-xl);
  --space-main: 30px 36px;
  --space-card: 20px 22px;
  --space-card-compact: 14px 16px;
  --space-divider: 28px;
  --space-sidebar-gap: 24px;
  --font-ui: var(--font-display);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-body);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: var(--font-body);
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-shadow);
  border-radius: var(--radius-sm);
}

/* ---- motion primitives ---- */
@keyframes es-spin { to { transform: rotate(360deg); } }
@keyframes es-fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes es-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes es-shimmer { 0% { background-position: -300px 0; } 100% { background-position: 300px 0; } }
.es-fade { animation: es-fade var(--dur-slow) var(--ease-out); }
.es-pulse { animation: es-pulse 1.4s ease-in-out infinite; }
.es-skel {
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.03) 25%, rgba(255, 255, 255, 0.07) 50%, rgba(255, 255, 255, 0.03) 75%);
  background-size: 600px 100%;
  animation: es-shimmer 1.3s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .es-fade, .es-pulse, .es-skel { animation: none; }
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ---- text roles ---- */
.mono,
.es-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.es-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
  color: var(--accent);
}
.es-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--text-muted);
}
.eyebrow { /* legacy name */
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--accent);
}
.es-h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 32px;
  letter-spacing: var(--ls-display);
  line-height: 1.05;
  margin: 0;
  color: var(--text-primary);
}

.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-divider) 0;
}

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-md);
  height: 40px;
  padding: 0 16px;
  border: none;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-standard), box-shadow var(--dur-med) var(--ease-standard), background var(--dur-fast);
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn-primary {
  background: var(--gradient-brand);
  color: var(--text-on-accent);
  box-shadow: var(--glow-sm);
}
.btn-primary:hover { box-shadow: var(--glow-md); }
.btn-ghost {
  background: var(--surface-well);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-weight: 500;
}
.btn-ghost:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn-quiet {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 500;
}
.btn-quiet:hover { border-color: var(--border-strong); color: var(--text-primary); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 12.5px; border-radius: var(--radius-sm); }

/* ---- semantic value colors ---- */
.value-positive { color: var(--up); }
.value-negative { color: var(--down); }
.value-neutral { color: var(--text-primary); }
.value-muted { color: var(--text-muted); }

/* ---- app shell ---- */
.es-shell {
  display: flex;
  height: 100vh;
  width: 100%;
  background: var(--bg-app);
  background-image: var(--glow-radial);
}

.es-sidebar {
  width: 240px;
  flex: none;
  background: var(--ink-900);
  border-right: 1px solid var(--border-subtle);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.es-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 22px;
}
.es-wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: var(--ls-heading);
  color: var(--text-primary);
}
.es-wordmark .accent { color: var(--accent); }

.es-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.es-nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.es-nav-item svg { flex: none; }
.es-nav-item:hover { background: var(--surface-hover); color: var(--text-primary); }
.es-nav-item.active {
  background: var(--accent-tint);
  border-color: var(--border-accent);
  color: var(--text-primary);
  font-weight: 600;
}
.es-nav-item.active svg { stroke: var(--accent); }

.es-user-chip {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--border-subtle);
}
.es-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-pill);
  background: var(--gradient-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-on-accent);
  font-weight: 700;
  flex: none;
}
.es-user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.es-user-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Account menu: the user chip is a <details> summary; the panel opens upward
   (the chip sits at the bottom of the sidebar). Shares es-overflow-menu for
   the close-on-outside-click behavior, but overrides the summary sizing that
   rule sets for the Stack's icon-only trigger. */
.es-user-menu {
  position: relative;
  display: block;
  margin-top: auto;
}
.es-user-menu > summary {
  list-style: none;
  cursor: pointer;
  /* Row layout (avatar / name / caret), padding and border-top all come from
     .es-user-chip. Opaque and stacked above the panel so the popover's shadow
     doesn't bleed through behind the username (the panel floats directly
     above). */
  position: relative;
  z-index: 42;
  background: var(--ink-900);
}
.es-user-menu > summary::-webkit-details-marker { display: none; }
.es-user-menu[open] > summary { background: var(--surface-hover); }
.es-user-caret {
  flex: none;
  color: var(--text-secondary);
  transition: transform var(--dur-fast) var(--ease-standard);
}
.es-user-menu[open] .es-user-caret { transform: rotate(180deg); }

.es-user-menu-panel {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 100%;
  margin-bottom: 8px;
  z-index: 41;
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  padding: 6px;
}
.es-user-menu-head { padding: 9px 10px 10px; }
.es-user-menu-email {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.es-user-menu-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 2px;
}
.es-user-menu-sep {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}
.es-user-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  line-height: 1.35;
}
.es-user-menu-item-label {
  display: flex;
  align-items: center;
  gap: 9px;
}
.es-user-menu-item.is-soon { color: var(--text-muted); }
.es-user-menu-soon {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: 2px 6px;
}
.es-user-menu-signout {
  width: 100%;
  cursor: pointer;
  background: transparent;
  border: none;
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--down);
}
.es-user-menu-signout:hover { background: var(--down-soft); }

.es-main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}
.es-page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 36px 32px 96px;
}
.es-page-narrow { max-width: 1000px; }
/* legacy screens (Improve/Discover) render bare into .es-main */
.es-page-legacy { padding: 30px 36px 80px; }

/* ---- page header pattern ---- */
.es-page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

/* ---- market panel (sidebar, legacy screens only) ---- */
.es-market-panel {
  margin-top: 18px;
  background: var(--surface-well);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.es-market-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--text-muted);
}
.es-market-field { display: flex; flex-direction: column; gap: 5px; }
.es-market-field-label { font-size: 11px; color: var(--text-muted); }
.es-symbol-select {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
  width: 100%;
  appearance: none;
}
.es-tf-segmented { display: flex; gap: 5px; }
.es-tf-segment {
  flex: 1;
  text-align: center;
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  padding: 7px 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
}
.es-tf-segment.selected {
  background: var(--accent-tint);
  border-color: var(--border-accent);
  color: var(--green-400);
  font-weight: 600;
}
.es-history-row { display: flex; justify-content: space-between; }
.es-history-track { height: 4px; border-radius: 3px; background: var(--surface-card); position: relative; }
.es-history-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 4px;
  border-radius: 3px;
  background: linear-gradient(90deg, #12b866, #3df0a0);
}
.es-history-thumb {
  position: absolute;
  top: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green-400);
}
.es-market-caption { font-size: 10px; line-height: 1.5; color: var(--slate-700); }
.es-tf-segment.disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.es-market-err { font-size: 11px; color: var(--down, #ff6b6b); margin-top: 2px; }

/* ---- symbol picker (filter-as-you-type) ---- */
.es-symbol-picker { position: relative; width: 100%; }
.es-symbol-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 50;
  max-height: 240px;
  overflow-y: auto;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg, 0 8px 24px rgba(0,0,0,0.35));
}
.es-symbol-option {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 12px;
}
.es-symbol-option.active,
.es-symbol-option:hover { background: var(--accent-tint); }
.es-symbol-opt-sym { font-family: var(--font-mono); color: var(--text-primary); font-weight: 600; }
.es-symbol-opt-name {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- cards ---- */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-2xl);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-compact { padding: 14px 16px; }
.card-well {
  background: var(--surface-well);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 15px;
}

.chip {
  display: inline-block;
  background: var(--surface-well);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.chip:hover { background: var(--surface-hover); color: var(--text-primary); }
.chip.selected { color: var(--text-primary); border-color: var(--border-strong); }

/* mono symbol / origin chips */
.es-sym-chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--radius-xs);
  background: var(--surface-well);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}
.es-origin-chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--radius-xs);
  background: transparent;
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.textarea-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  transition: border-color var(--dur-fast);
}
.textarea-card:focus-within { border-color: var(--border-accent); }
.textarea-card textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: vertical;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.55;
  min-height: 100px;
}
.textarea-card textarea::placeholder { color: var(--text-muted); }

/* ---- banners ---- */
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin: 16px 0;
  font-size: 14px;
  line-height: 1.5;
}
.banner-success {
  background: rgba(46, 224, 138, 0.09);
  border: 1px solid var(--border-accent);
  color: #c9f2dd;
}
.banner-warning {
  background: var(--warn-soft);
  border: 1px solid rgba(255, 180, 84, 0.3);
  color: #ffd9a3;
}
.banner-error {
  background: var(--down-soft);
  border: 1px solid rgba(255, 95, 109, 0.3);
  color: var(--down);
}
.banner-info {
  background: var(--info-soft);
  border: 1px solid rgba(77, 184, 255, 0.3);
  color: #bde2ff;
}

/* ---- metrics ---- */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.metric-cell {
  background: var(--surface-card);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.metric-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.metric-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 23px;
  font-weight: 700;
}
.metric-value.small { font-size: 20px; }

/* ---- tables ---- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.data-table th {
  background: var(--surface-well);
  color: var(--text-muted);
  text-align: left;
  padding: 9px 14px;
  font-weight: 500;
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.data-table td {
  padding: 10px 14px;
  color: var(--text-secondary);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}
.data-table-wrap {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.two-up {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.chart-box {
  width: 100%;
  background: var(--surface-well);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

/* ---- badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  height: 22px;
  padding: 0 9px;
}
.badge-success { background: var(--up-soft); color: var(--up); border: 1px solid var(--border-accent); }
.badge-warning { background: var(--warn-soft); color: var(--warn); border: 1px solid rgba(255, 180, 84, 0.3); }
.badge-error { background: var(--down-soft); color: var(--down); border: 1px solid rgba(255, 95, 109, 0.3); }
.badge-info { background: rgba(77, 184, 255, 0.12); color: var(--info); border: 1px solid rgba(77, 184, 255, 0.3); }
.badge-muted { background: rgba(255, 255, 255, 0.04); color: var(--text-muted); border: 1px solid var(--border); }

/* ---- modal (native <dialog>) ---- */
.es-modal {
  width: 100%;
  max-width: 420px;
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  color: var(--text-primary);
}
.es-modal::backdrop {
  background: rgba(4, 7, 6, 0.68);
  backdrop-filter: blur(8px);
}

/* ---- in-flight feedback (htmx) ---- */
.htmx-request.btn,
.htmx-request .btn {
  opacity: 0.55;
  pointer-events: none;
  position: relative;
}
.htmx-request.btn::after,
.htmx-request .btn::after {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 8px;
  vertical-align: -1px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: es-spin 0.6s linear infinite;
}

.es-global-error {
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: var(--radius-md);
  padding: 13px 16px;
  margin: 0 0 16px;
  font-size: 13.5px;
  background: var(--down-soft);
  border: 1px solid rgba(255, 95, 109, 0.3);
  color: var(--down);
}
.es-global-error button {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

/* ---- details/summary chevron pattern ---- */
details.es-details > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}
details.es-details > summary::-webkit-details-marker { display: none; }
details.es-details > summary::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform var(--dur-fast) var(--ease-standard);
}
details.es-details[open] > summary::after {
  transform: rotate(225deg) translateY(-1px);
}

/* ---- Today: quiet-row summary chevron (own layout, not .es-details) ---- */
.es-quiet-row > summary {
  list-style: none;
}
.es-quiet-row > summary::-webkit-details-marker {
  display: none;
}
.es-quiet-row[open] .es-quiet-chevron {
  transform: rotate(90deg);
}

/* ---- Today: track-record calendar ---- */
.es-cal-cell {
  min-height: 74px;
  padding: 7px;
  border-radius: var(--radius-sm);
  background: var(--surface-well);
  border: 1px solid var(--border-subtle);
}
.es-cal-cell.is-today {
  background: var(--accent-tint);
  border-color: var(--border-accent);
}
.es-cal-cell.out-of-month {
  opacity: 0.35;
  background: transparent;
}
.es-cal-marker {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 16px;
  padding: 0 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.02em;
  cursor: pointer;
}
.es-legend-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 13px;
  border-radius: var(--radius-md);
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  text-align: left;
  cursor: pointer;
}
.es-legend-chip.active {
  background: var(--accent-tint);
  border-color: var(--border-accent);
}
.es-legend-chip.dimmed {
  opacity: 0.45;
}
.es-year-cell {
  height: 30px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 9px;
}

/* ---- The Stack: old playbook dims while a rebuild is in flight ---- */
#playbook-bench-section.htmx-request {
  opacity: 0.4;
  pointer-events: none;
  transition: opacity var(--dur-med) var(--ease-standard);
}

/* ---- The Stack: archive overflow menu ---- */
.es-overflow-menu {
  position: relative;
  display: inline-block;
}
.es-overflow-menu > summary {
  list-style: none;
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.es-overflow-menu > summary::-webkit-details-marker {
  display: none;
}
.es-overflow-menu[open] > summary {
  background: var(--surface-hover);
}
.es-overflow-menu-panel {
  position: absolute;
  top: 32px;
  right: 0;
  z-index: 41;
  width: 230px;
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  padding: 5px;
}
.es-overflow-menu-panel button {
  cursor: pointer;
  width: 100%;
  text-align: left;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 13px;
  line-height: 1.35;
}
.es-overflow-menu-panel button:hover {
  background: var(--surface-hover);
}
.es-overflow-menu-panel button .note {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---- utility: hide while preserving content (Define's describe/report toggle) ---- */
.es-hidden { display: none !important; }

/* ---- Define: placeholder shown where results used to be, right after an
   edit invalidates them (esExpandConfirm) ---- */
.es-cleared-placeholder {
  margin-top: 16px;
  padding: 26px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-2xl);
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ---- borderless text button (DS "ghost": transparent, no border) ---- */
.btn-text {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-weight: 500;
}
.btn-text:hover { background: rgba(255, 255, 255, 0.05); }

/* ---- persistent button loading state: survives past a fast job-dispatch and
   keeps spinning until the polled result lands, so async-job buttons behave
   like synchronous ones (see base.html job-button tracking). ---- */
.btn.es-btn-loading {
  opacity: 0.55;
  pointer-events: none;
  position: relative;
}
.btn.es-btn-loading::after {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 8px;
  vertical-align: -1px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: es-spin 0.6s linear infinite;
}

/* ---- form field label (Space Grotesk, matches the DS Select + date labels) ---- */
.es-field-label {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ---- custom select (DS Select: appearance:none + ▾ chevron, Space Grotesk) ---- */
.es-select-wrap { position: relative; display: inline-block; }
.es-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: var(--control-h-md);
  padding: 0 40px 0 14px;
  background: var(--surface-well);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 14px;
  cursor: pointer;
  outline: none;
  transition: border-color var(--dur-med) var(--ease-standard), box-shadow var(--dur-med) var(--ease-standard);
}
.es-select:focus { border-color: var(--accent); box-shadow: var(--focus-shadow); }
.es-select-chevron {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1;
}

/* ---- date input (DS date field) ---- */
.es-date-input {
  height: var(--control-h-md);
  padding: 0 12px;
  background: var(--surface-well);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 14px;
  color-scheme: dark;
  cursor: pointer;
  outline: none;
}
.es-date-input:focus { border-color: var(--accent); box-shadow: var(--focus-shadow); }
.es-date-input:disabled { opacity: 0.6; cursor: default; }

/* ---- range preset chip ---- */
.es-range-chip {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.es-range-chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.es-range-chip.selected {
  background: var(--accent-tint);
  border-color: var(--border-accent);
  color: var(--accent);
}
