/* fugazi — terminal/Bloomberg theme.
 * Dense, data-forward, monospace-first. Sharp corners, hairline rules,
 * amber + cyan accents on a near-black ground. Light mode is a dim "paper
 * terminal" — same density, inverted.
 *
 * Theme is chosen by [data-theme] on <html>; see the no-FOUC inline script
 * in views.templ. Tokens use RGB channels (e.g. --fg-rgb) so alpha-tinted
 * rules adapt without per-theme overrides.
 */
/* Self-hosted IBM Plex Mono — latin + latin-ext per weight. */
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/IBMPlexMono-Regular.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/IBMPlexMono-Regular-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/IBMPlexMono-Medium.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/IBMPlexMono-Medium-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/IBMPlexMono-Bold.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/IBMPlexMono-Bold-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg: #13171e;
  --bg-elev: #0b0e13;
  --bg-elev-2: #11151c;
  --fg: #d6dde8;
  --fg-dim: #8a93a3;
  --fg-faint: #7b8496;
  --card: #0b0e13;
  --primary: #f5a623;          /* amber — primary accent / CTA */
  --primary-fg: #07090c;
  --accent: #4ad8e6;           /* cyan — secondary accent */
  --secondary: #11151c;
  --muted-fg: #7b8496;
  --border: rgba(214, 221, 232, 0.10);
  --border-strong: rgba(214, 221, 232, 0.20);
  --input: rgba(214, 221, 232, 0.06);
  --ring: #f5a623;
  --good: #4ad8a0;             /* mint green — up / good */
  --warn: #f5a623;             /* amber — caution */
  --bad: #ff5c57;              /* red — down / bad */
  --neutral: #8a93a3;
  --radius: 0;
  --radius-sm: 0;
  --radius-xs: 0;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font-sans: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-display: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --bg-rgb: 19, 23, 30;
  --fg-rgb: 214, 221, 232;
  --primary-rgb: 245, 166, 35;
  --accent-rgb: 74, 216, 230;
  --good-rgb: 74, 216, 160;
  --warn-rgb: 245, 166, 35;
  --bad-rgb: 255, 92, 87;

  --header-bg: rgba(7, 9, 12, 0.92);
  --btn-hover-bg: #161b24;
  --btn-primary-hover-bg: #ffba3a;
  --focus-ring: rgba(245, 166, 35, 0.25);
  --row-hover: rgba(245, 166, 35, 0.04);
  --row-stripe: rgba(214, 221, 232, 0.015);
  --warning-bg: rgba(245, 166, 35, 0.05);
  --toast-shadow: rgba(0, 0, 0, 0.55);
  --dialog-backdrop: rgba(0, 0, 0, 0.7);

  --rev-bar-bg: rgba(74, 216, 230, 0.35);
}

[data-theme="light"] {
  --bg: #f4f1ea;
  --bg-elev: #efebdf;
  --bg-elev-2: #e6e1d2;
  --fg: #1a1d24;
  --fg-dim: #52565f;
  --fg-faint: #6e6a5e;
  --card: #efebdf;
  --primary: #96500b;          /* darker amber for paper contrast */
  --primary-fg: #f4f1ea;
  --accent: #15707c;
  --secondary: #e6e1d2;
  --muted-fg: #6e6a5e;
  --border: rgba(26, 29, 36, 0.16);
  --border-strong: rgba(26, 29, 36, 0.30);
  --input: rgba(26, 29, 36, 0.08);
  --ring: #96500b;
  --good: #1f6440;
  --warn: #96500b;
  --bad: #b8362c;
  --neutral: #52565f;

  --bg-rgb: 244, 241, 234;
  --fg-rgb: 26, 29, 36;
  --primary-rgb: 150, 80, 11;
  --accent-rgb: 21, 112, 124;
  --good-rgb: 31, 100, 64;
  --warn-rgb: 150, 80, 11;
  --bad-rgb: 184, 54, 44;

  --header-bg: rgba(244, 241, 234, 0.92);
  --btn-hover-bg: #dcd6c4;
  --btn-primary-hover-bg: #7f4509;
  --focus-ring: rgba(150, 80, 11, 0.25);
  --row-hover: rgba(150, 80, 11, 0.06);
  --row-stripe: rgba(26, 29, 36, 0.02);
  --warning-bg: rgba(150, 80, 11, 0.08);
  --toast-shadow: rgba(0, 0, 0, 0.18);
  --dialog-backdrop: rgba(0, 0, 0, 0.32);

  --rev-bar-bg: rgba(21, 112, 124, 0.30);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

/* The hidden attribute must win even over class display rules (e.g. the
   engine-weight sliders' .assumptions grid), or toggling .hidden has no
   visible effect. */
[hidden] {
  display: none !important;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 2px;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  letter-spacing: 0;
  margin: 0 0 0.5rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

h1 {
  font-size: 1.05rem;
}

h2 {
  font-size: 0.85rem;
  color: var(--fg-dim);
}

h3 {
  font-size: 0.78rem;
  color: var(--fg-dim);
}

p {
  margin: 0 0 0.6rem;
}

code,
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

::selection {
  background: rgba(var(--primary-rgb), 0.3);
  color: var(--fg);
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.3rem 0.5rem;
  line-height: 1;
  border: 1px solid var(--border);
}
.theme-toggle .theme-icon-dark,
.theme-toggle .theme-icon-light {
  display: none;
  font-size: 0.85rem;
}
[data-theme="dark"] .theme-toggle .theme-icon-light {
  display: inline;
}
[data-theme="light"] .theme-toggle .theme-icon-dark {
  display: inline;
}

/* ---------- Layout ---------- */
.container {
  max-width: 80rem;
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}

.container.narrow {
  max-width: 48rem;
}

@media (max-width: 40rem) {
  .container {
    padding: 0.75rem 0.75rem 4rem;
  }
}

/* ---------- Header ---------- */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 2.5rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border-strong);
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  font-size: 0.78rem;
}

.header .logo {
  width: 22px;
  height: 22px;
  border-radius: 0;
  background: var(--primary);
  color: var(--primary-fg);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  flex: none;
  text-transform: uppercase;
}

.header .brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--fg);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.header .spacer {
  flex: 1;
}

.header a,
.header button {
  font-size: 0.78rem;
  color: var(--fg-dim);
}

.header a.btn-ghost {
  color: var(--fg-dim);
}

/* ---------- Buttons / inputs ---------- */
button,
.btn,
a.btn-ghost {
  font: inherit;
  color: var(--fg);
  background: var(--secondary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.72rem;
  transition: border-color 0.12s var(--ease), background 0.12s var(--ease), color 0.12s var(--ease);
}
button:hover,
.btn:hover,
a.btn-ghost:hover {
  border-color: var(--ring);
  background: var(--btn-hover-bg);
  color: var(--fg);
}
.header a.btn-ghost:hover {
  color: var(--fg);
}

/* Mobile header: two rows — brand + links wrap below the logo. */
@media (max-width: 40rem) {
  .header {
    height: auto;
    min-height: 2.5rem;
    flex-wrap: wrap;
    row-gap: 0;
    padding: 0.35rem 0.75rem;
    font-size: 0.72rem;
  }
  .header .spacer {
    display: none;
  }
  .header .brand {
    flex: 1;
  }
  .header a.btn-ghost,
  .header button.btn-ghost {
    padding: 0.35rem 0.4rem;
  }
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: var(--primary);
  font-weight: 700;
}
.btn-primary:hover {
  background: var(--btn-primary-hover-bg);
  border-color: var(--btn-primary-hover-bg);
  color: var(--primary-fg);
}

.btn-ghost,
a.btn-ghost {
  background: transparent;
  border-color: transparent;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.btn-ghost:hover,
a.btn-ghost:hover {
  background: var(--secondary);
  border-color: var(--border);
  text-decoration: none;
}

input[type="text"],
input[type="search"],
input[type="number"],
select {
  font: inherit;
  font-size: 0.8rem;
  color: var(--fg);
  background: var(--input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.55rem;
  width: 100%;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
input::placeholder {
  color: var(--fg-faint);
  text-transform: none;
  letter-spacing: 0;
}
input[type="text"]:focus,
input[type="search"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 1px var(--focus-ring);
}

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 1px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  height: 4px;
}
/* Touch: the slider track is thin, so pad the touch target around it. */
@media (pointer: coarse) {
  input[type="range"] {
    height: auto;
    padding: 0.9rem 0;
    background: linear-gradient(var(--fg-faint), var(--fg-faint)) center/100% 4px no-repeat;
  }
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
}
.card h2 {
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.card h2::before {
  content: "▸";
  color: var(--primary);
  font-size: 0.7rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
}
.stat {
  background: var(--card);
  border: none;
  border-radius: 0;
  padding: 0.7rem 0.85rem;
  position: relative;
}
.stat::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  opacity: 0.6;
}

.stat .label {
  font-size: 0.65rem;
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.stat .value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.45rem;
  font-weight: 500;
  color: var(--fg);
  letter-spacing: -0.01em;
}
.stat .sub {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--fg-faint);
  margin-top: 0.2rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- Letter badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  border-radius: 0;
  border: 1px solid var(--border-strong);
  line-height: 1;
  text-transform: uppercase;
}
.badge.sm {
  height: 1.5rem;
  min-width: 1.5rem;
  padding: 0 0.35rem;
  font-size: 0.75rem;
}
.badge.md {
  height: 1.75rem;
  min-width: 1.75rem;
  padding: 0 0.45rem;
  font-size: 0.85rem;
}
.badge.lg {
  height: 2.5rem;
  min-width: 2.5rem;
  padding: 0 0.65rem;
  font-size: 1.3rem;
}

.grade-good {
  color: var(--good);
  border-color: rgba(var(--good-rgb), 0.5);
  background: rgba(var(--good-rgb), 0.08);
}
.grade-ok {
  color: var(--accent);
  border-color: rgba(var(--accent-rgb), 0.4);
  background: rgba(var(--accent-rgb), 0.06);
}
.grade-warn {
  color: var(--warn);
  border-color: rgba(var(--warn-rgb), 0.5);
  background: rgba(var(--warn-rgb), 0.08);
}
.grade-bad {
  color: var(--bad);
  border-color: rgba(var(--bad-rgb), 0.5);
  background: rgba(var(--bad-rgb), 0.08);
}
.grade-none {
  color: var(--fg-faint);
  border-color: var(--border);
}

.fund-badge {
  color: var(--accent);
  border-color: rgba(var(--accent-rgb), 0.5);
  background: rgba(var(--accent-rgb), 0.08);
}
.fund-note {
  color: var(--fg-dim);
  font-style: italic;
  font-size: 0.85rem;
}

/* ---------- Watchlist ---------- */
.watchlist-summary {
  font-size: 0.75rem;
  color: var(--fg-dim);
  margin-bottom: 0.5rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.4rem 0.6rem;
  border-left: 2px solid var(--primary);
  background: var(--bg-elev);
}

/* ---------- Watchlist picker ---------- */
.wl-picker {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.wl-picker-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-faint);
}
.wl-select {
  width: auto;
  min-width: 14rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238a93a3' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 2rem;
  cursor: pointer;
}
.wl-select:hover {
  border-color: var(--ring);
}
.wl-new {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--fg-dim);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: border-color 0.12s var(--ease), color 0.12s var(--ease), background 0.12s var(--ease);
}
.wl-new:hover {
  border-color: var(--ring);
  color: var(--primary);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin: 0.75rem 0;
}
.filters > * {
  flex: 0 0 auto;
}
.filters .pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  flex: 1 1 100%;
}
.filters input[type="search"] {
  flex: 1 1 18rem;
  min-width: 12rem;
}
.filter-search {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1 1 100%;
}
.filter-search-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex: none;
}
.pill-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.pill {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.25rem 0.6rem;
  border-radius: 0;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--fg-dim);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: border-color 0.12s var(--ease), color 0.12s var(--ease), background 0.12s var(--ease);
}
.pill:hover {
  border-color: var(--ring);
  color: var(--primary);
}
.pill.active {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--bg);
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 0;
  overflow-x: auto;
  background: var(--card);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

th,
td {
  padding: 0.45rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  font-weight: 500;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border-strong);
}
/* Sticky watchlist header only where .table-wrap is not a horizontal
   scroll container (a sticky th inside one offsets against the wrapper
   and is painted over the first row). */
@media (min-width: 640px) {
  #watchlist .table-wrap {
    overflow-x: visible;
  }
  #watchlist th {
    position: sticky;
    top: 2.5rem;
    z-index: 1;
  }
}
/* On phones the main table scrolls horizontally inside .table-wrap; pad
   rows so the tap target stays reasonable and keep number columns narrow. */
@media (max-width: 40rem) {
  #watchlist table {
    font-size: 0.72rem;
  }
  #watchlist th,
  #watchlist td {
    padding: 0.55rem 0.45rem;
  }
  #watchlist .td-name {
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
tbody tr:nth-child(even) {
  background: var(--row-stripe);
}
tbody tr {
  border-left: 2px solid transparent;
  transition: border-color 0.08s var(--ease);
}
tbody tr:last-child td {
  border-bottom: none;
}
tbody tr:hover {
  background: var(--row-hover);
  border-left-color: var(--primary);
}

.td-num,
.th-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.td-ticker {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.02em;
}
.td-name {
  color: var(--fg-faint);
  font-size: 0.72rem;
}

tr.row-clickable {
  cursor: pointer;
}

/* Touch: keep interactive controls at the 44px minimum hit area. */
@media (pointer: coarse) {
  button,
  .btn,
  .pill,
  .chip,
  .sort-link,
  .header a,
  .header button {
    min-height: 44px;
  }
  .pill,
  .chip {
    padding: 0.45rem 0.8rem;
  }
  /* Header buttons at full 44px would blow the bar height on phones;
     2.25rem is still comfortably tappable in the wrap layout. */
  .header a.btn-ghost,
  .header button.btn-ghost {
    min-height: 2.25rem;
  }
}

/* ---------- Small screens ---------- */
@media (max-width: 40rem) {
  /* Watchlist picker: full-width select so long list names don't overflow. */
  .wl-picker {
    flex-wrap: wrap;
  }
  .wl-select {
    flex: 1 1 auto;
    min-width: 0;
  }

  /* Filters stack; pill groups get horizontal scroll instead of wrapping
     into a tall block. */
  .filters {
    flex-direction: column;
    align-items: stretch;
  }
  .filters .pill-row {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 0.25rem;
    -webkit-overflow-scrolling: touch;
  }
  .filters .pill-group {
    flex: none;
  }

  /* Summary line can be long; let it wrap. */
  .watchlist-summary {
    overflow-wrap: anywhere;
  }

  /* Detail header: actions drop below the title. */
  .detail-actions {
    margin-left: 0;
    width: 100%;
  }

  /* Stat tiles: two per row on phones. */
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .stat .value {
    font-size: 1.15rem;
  }

  /* Charts: the 10-year bar grid needs more room than a phone gutter;
     scroll it instead of crushing the columns. */
  .chart-panel {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Cards that hold wide tables scroll inside their own box. */
  .card > table,
  .models-card {
    min-width: 0;
  }
  .models-card,
  .card:has(> .models-table),
  .card:has(> .annual-table) {
    overflow-x: auto;
  }
  .models-table,
  .annual-table {
    min-width: 34rem;
  }

  /* Dialogs: use the full viewport width on phones. */
  dialog {
    max-width: 94vw;
    padding: 1rem;
  }

  /* Toasts span the width so long error text stays readable. */
  .toasts {
    left: 0.75rem;
    right: 0.75rem;
    width: auto;
  }

  /* Hero copy breathes a little less. */
  .hero {
    padding: 2rem 0 1.5rem;
    padding-left: 0.9rem;
    margin: 1rem 0;
  }
  .hero h1 {
    font-size: 1.3rem;
  }
}

.sort-link {
  color: var(--fg-faint);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
th > .sort-link {
  display: flex;
  height: 100%;
  width: 100%;
  padding: 0.3rem 0;
}
.sort-link:hover,
.sort-link:focus-visible {
  color: var(--fg);
  text-decoration: none;
}
.sort-link.active {
  color: var(--primary);
}
.sort-link .sort-dir {
  font-size: 0.6rem;
  margin-left: 0.15rem;
}

td.empty-cell {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--fg-faint);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .spinner,
  .add-indicator,
  .btn-indicator,
  .add-pending::before {
    animation-duration: 0s;
  }
  .hero .cursor,
  .toast.fade {
    animation: none;
  }
  .toast.fade {
    opacity: 1;
  }
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Add / search ---------- */
.add-form {
  display: flex;
  gap: 0.4rem;
  align-items: flex-start;
}
.add-form input {
  flex: 1;
}
.add-results {
  position: relative;
  margin-top: 0.25rem;
}
.dropdown {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 0;
  z-index: 10;
  max-height: 18rem;
  overflow-y: auto;
  box-shadow: 0 8px 24px var(--toast-shadow);
}
.dropdown-item {
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.dropdown-item:last-child {
  border-bottom: none;
}
.dropdown-item:hover,
.dropdown-item.active {
  background: var(--row-hover);
  box-shadow: inset 2px 0 0 0 var(--primary);
}
.dropdown-item .tick {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--accent);
  text-transform: uppercase;
}
.dropdown-item .nm {
  color: var(--fg-faint);
  font-size: 0.75rem;
}
.dropdown-item.adding {
  pointer-events: none;
  opacity: 0.6;
}
.add-pending {
  margin-top: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--fg-dim);
}
.add-pending::before {
  content: "";
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border: 1px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 0.4rem;
  vertical-align: -2px;
}

/* ---------- Detail page ---------- */
.back-link {
  display: inline-block;
  font-size: 0.78rem;
  margin-bottom: 0.5rem;
  color: var(--fg-dim);
}
.back-link:hover {
  color: var(--fg);
}
.detail-header {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.detail-header h1 {
  margin: 0;
  font-size: 1.1rem;
  text-transform: none;
  letter-spacing: 0;
}
.detail-header .subtitle {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.2rem;
}
.detail-actions {
  display: flex;
  gap: 0.35rem;
  margin-left: auto;
}

/* Vertical rhythm between stacked cards inside a detail column. */
.stack-above {
  margin-top: 1rem;
}

/* Grade card header row: badge + investment score. */
.grade-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

/* Generic muted helper text (used inside cards). */
.hint {
  font-size: 0.7rem;
  color: var(--fg-dim);
  margin-bottom: 0.5rem;
}

.shares-line {
  font-size: 0.75rem;
  color: var(--fg-dim);
  margin: 0 0 0.75rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.shares-line .num {
  font-family: var(--font-mono);
  color: var(--primary);
}

.warnings {
  margin: 0.75rem 0;
  display: grid;
  gap: 0.3rem;
}
.warning {
  font-size: 0.75rem;
  padding: 0.4rem 0.6rem;
  border-left: 2px solid var(--warn);
  background: var(--warning-bg);
  border-radius: 0;
  font-family: var(--font-mono);
}
.warning .code {
  font-family: var(--font-mono);
  color: var(--warn);
  font-size: 0.68rem;
  text-transform: uppercase;
  margin-right: 0.5rem;
  letter-spacing: 0.06em;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin-top: 1px;
  background: var(--border);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.detail-grid > div {
  background: var(--bg);
  padding: 1px 0;
  display: grid;
  gap: 1px;
  /* Keep cards at natural height when the other column is taller. */
  align-content: start;
}
.detail-grid > div > .card {
  margin: 0;
}
.detail-grid .card {
  border: none;
  border-radius: 0;
}
@media (max-width: 60rem) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Chart ---------- */
.chart {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.chart-head h2 {
  margin: 0;
}
.chart-toggle {
  display: flex;
  gap: 0.3rem;
}
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.6rem 0;
}
.pager-btn {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
}
.pager-btn:hover:not(.disabled) {
  border-color: var(--accent);
}
.pager-btn.disabled {
  color: var(--fg-faint);
  pointer-events: none;
  border-color: var(--border);
}
.pager-info {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.chart-panel {
  position: relative;
  display: flex;
  gap: 0.4rem;
}
.chart-main {
  display: flex;
  flex: 1;
  min-width: 0;
  gap: 0.4rem;
}
.chart-hover {
  cursor: crosshair;
}
.chart-crosshair {
  position: absolute;
  /* Span only the plot area: chartPadY insets of the 160-unit viewBox. */
  top: 3.75%;
  height: 92.5%;
  width: 1px;
  background: var(--border-strong);
  pointer-events: none;
  z-index: 2;
}
.chart-tip {
  position: absolute;
  z-index: 3;
  min-width: 8rem;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  padding: 0.4rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  pointer-events: none;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.4);
}
.tip-year {
  color: var(--fg);
  font-weight: 700;
  margin-bottom: 0.25rem;
}
.tip-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--fg-dim);
}
.tip-row b {
  color: var(--fg);
  font-weight: 500;
}
.tip-row.rev b { color: var(--accent); }
.tip-row.ni b { color: var(--good); }
.tip-row.oe b { color: var(--warn); }
.chart-y-axis {
  position: relative;
  width: 3.2rem;
  flex: none;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--fg-faint);
}
.chart-y-axis-bars {
  height: 11rem;
}
.chart-y-tick {
  position: absolute;
  right: 0.25rem;
  transform: translateY(50%);
  white-space: nowrap;
}
.chart-svg {
  width: 100%;
  height: 11rem;
  display: block;
  flex: 1;
  min-width: 0;
}
.chart-gridline {
  stroke: var(--border);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.chart-zero {
  stroke: var(--border-strong);
  stroke-width: 1;
  stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke;
}
.chart-line {
  fill: none;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}
.chart-line.rev { stroke: var(--accent); }
.chart-line.ni { stroke: var(--good); }
.chart-line.oe { stroke: var(--warn); }
.chart-dot.rev { fill: var(--accent); }
.chart-dot.ni { fill: var(--good); }
.chart-dot.oe { fill: var(--warn); }
.chart-x-row {
  border-bottom: none;
  /* Skip the y-axis gutter (3.2rem) + gap so year labels align with dots. */
  padding-left: 3.6rem;
}
.chart-x-row .chart-cell {
  border-left: none;
}
.chart-legend {
  display: flex;
  gap: 0.75rem;
  font-size: 0.7rem;
  color: var(--fg-dim);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.chart-legend .swatch {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 0;
  margin-right: 0.3rem;
  vertical-align: -1px;
}
.rev-swatch {
  background: var(--rev-bar-bg);
  border: 1px solid var(--accent);
}
.ni-swatch {
  background: var(--good);
}
.oe-swatch {
  background: var(--warn);
}
.chart-bars {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols, 10), 1fr);
}
.chart-cell {
  display: flex;
  flex-direction: column;
}
.chart-cell:first-child {
  border-left: 1px solid var(--border);
}
.chart-cell:hover {
  background: var(--row-hover);
}
.chart-cell:hover .chart-x {
  color: var(--fg);
}
.chart-col {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 11rem;
  gap: 2px;
}
/* Positive region: bars grow up from the zero line. */
.chart-pos {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  padding: 0.25rem 0.1rem 0;
  border-bottom: 1px solid var(--border-strong);
}
/* Negative region: bars hang down from the zero line. */
.chart-neg {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  padding: 0 0.1rem;
  border-top: 1px solid var(--border-strong);
}
.chart-bar {
  width: 30%;
  min-height: 0;
  border-radius: 0;
}
.chart-bar.rev {
  background: var(--rev-bar-bg);
  border-top: 1px solid var(--accent);
}
.chart-bar.ni {
  background: var(--good);
}
.chart-bar.oe {
  background: var(--warn);
}
/* Negative bars hang below the zero line: flip the accent edge downward. */
.chart-neg .chart-bar {
  border-top: none;
}
.chart-neg .chart-bar.rev {
  background: var(--rev-bar-bg);
  border-bottom: 1px solid var(--accent);
}
.chart-neg .chart-bar.ni {
  background: var(--good);
}
.chart-neg .chart-bar.oe {
  background: var(--warn);
}
.chart-x {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--fg-faint);
  text-align: center;
  padding: 0.2rem 0 0;
}

/* ---------- Annual table ---------- */
.annual-table {
  font-size: 0.72rem;
}
.annual-table th,
.annual-table td {
  padding: 0.3rem 0.45rem;
}

/* ---------- Assumptions ---------- */
.assumptions {
  display: grid;
  gap: 0.75rem;
}
.assumption {
  display: grid;
  gap: 0.2rem;
}
.assumption .row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.assumption .row .v {
  font-family: var(--font-mono);
  color: var(--primary);
  font-weight: 500;
}
.assumption .hint {
  margin-bottom: 0;
}

/* ---------- Engine mode + weight sliders ---------- */
.engine-section {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.engine-mode {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
}
.engine-mode .row-inline {
  font-size: 0.8rem;
}

/* Dialog forms: label above field, fields full width. */
dialog form label {
  display: grid;
  gap: 0.25rem;
  margin-bottom: 0.6rem;
}
dialog form label > span {
  font-size: 0.7rem;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
dialog form .btn-ghost[type="button"] {
  align-self: start;
  margin-bottom: 0.6rem;
}
dialog form div[style*="display:flex"] {
  flex-wrap: wrap;
}

/* ---------- Valuation models breakdown table ---------- */
.models-card {
  margin-bottom: 1rem;
}
.models-table {
  width: 100%;
  font-size: 0.78rem;
  border-collapse: collapse;
}
.models-table th,
.models-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.models-table th {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-faint);
}
.models-table .td-num {
  font-family: var(--font-mono);
  text-align: right;
}
.models-note {
  color: var(--fg-faint);
  font-size: 0.7rem;
}

/* ---------- IV breakdown ---------- */
.iv-dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.3rem 1rem;
  font-size: 0.78rem;
  margin: 0;
}
.iv-dl dt {
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.72rem;
}
.iv-dl dd {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  margin: 0;
  color: var(--fg);
}
.iv-dl dt {
  cursor: help;
}

/* Silent extension flags shown under the IV breakdown. These are modeling
 * choices (net-debt bridge, fade terminal, implied growth) that don't
 * warrant a full warning block but should be visible to the user. */
.iv-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.iv-flag {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--accent);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.1rem 0.35rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---------- Grade card / slices ---------- */
.slices {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.6rem;
}
.slice {
  display: grid;
  gap: 0.15rem;
}
.slice .row {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.slice .row .v {
  font-family: var(--font-mono);
  color: var(--fg);
}
.slice .row .slice-weight {
  color: var(--fg-dim);
}
.slice .note {
  font-size: 0.68rem;
  color: var(--fg-faint);
  font-family: var(--font-mono);
}
.slice .bar {
  height: 2px;
  background: var(--bg-elev-2);
  border-radius: 0;
  overflow: hidden;
}
.slice .bar > span {
  display: block;
  height: 100%;
  background: var(--primary);
  transition: width 0.2s var(--ease);
}
.slice .bar.good > span {
  background: var(--good);
}
.slice .bar.warn > span {
  background: var(--warn);
}
.slice .bar.bad > span {
  background: var(--bad);
}

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  z-index: 50;
  width: min(90vw, 26rem);
  font-family: var(--font-mono);
}
.toast {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--neutral);
  border-radius: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  box-shadow: 0 8px 24px var(--toast-shadow);
  animation: toast-in 0.15s var(--ease);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.toast.success {
  border-left-color: var(--good);
  color: var(--good);
}
.toast.error {
  border-left-color: var(--bad);
  color: var(--bad);
}
.toast.message {
  border-left-color: var(--accent);
}
.toast.fade {
  opacity: 0;
  transition: opacity 0.3s var(--ease);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
}

/* ---------- Hero ---------- */
.hero {
  padding: 3.5rem 0 2rem;
  text-align: left;
  border-left: 3px solid var(--primary);
  padding-left: 1.25rem;
  margin: 2rem 0;
}
.hero h1 {
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
  text-transform: none;
  letter-spacing: -0.01em;
  font-family: var(--font-display);
  color: var(--fg);
  font-weight: 600;
}
.hero h1::before {
  content: "> ";
  color: var(--primary);
  font-weight: 700;
}
.hero .cursor {
  display: inline-block;
  width: 0.55rem;
  height: 1.05rem;
  background: var(--primary);
  margin-left: 0.15rem;
  vertical-align: -2px;
  animation: blink 1.1s steps(2) infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}
.hero p {
  color: var(--fg-dim);
  max-width: 34rem;
  margin: 0 0 1.25rem;
  font-size: 0.82rem;
  line-height: 1.6;
}
.hero .add-form {
  max-width: 28rem;
  margin: 0;
}

/* ---------- Method page ---------- */
.method {
  font-size: 0.82rem;
  max-width: 48rem;
  line-height: 1.65;
}
.method h2 {
  margin-top: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}
.method h3 {
  margin-top: 1.25rem;
  font-size: 0.78rem;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.method p,
.method li {
  color: var(--fg);
  line-height: 1.65;
}
.method code {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 0.05rem 0.3rem;
  border-radius: 0;
  font-size: 0.85em;
  color: var(--accent);
}

/* ---------- Empty / spinner ---------- */
.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--fg-faint);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.empty::before {
  content: "// ";
  color: var(--fg-faint);
}
.spinner {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border: 1px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
  margin-right: 0.4rem;
}
.add-indicator {
  display: none;
  width: 0.75rem;
  height: 0.75rem;
  border-width: 1px;
  border-top-color: var(--primary-fg);
  margin-right: 0;
  margin-left: 0.3rem;
  vertical-align: -1px;
}
.htmx-request .add-indicator,
.add-indicator.htmx-request {
  display: inline-block;
}
.btn-indicator {
  display: none;
  width: 0.75rem;
  height: 0.75rem;
  border-width: 1px;
  border-top-color: var(--primary-fg);
  margin-right: 0;
  margin-left: 0.3rem;
  vertical-align: -1px;
}
.htmx-request .btn-indicator,
.btn-indicator.htmx-request {
  display: inline-block;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Dialog ---------- */
dialog {
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: 0;
  padding: 1.25rem;
  max-width: min(92vw, 32rem);
  box-shadow: 0 16px 48px var(--toast-shadow);
}
dialog::backdrop {
  background: var(--dialog-backdrop);
  backdrop-filter: blur(2px);
}
dialog h2 {
  margin-top: 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
  margin-bottom: 0.75rem;
}

/* ---------- Scrollbar (terminal feel) ---------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 0;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--fg-faint);
}