/*
  Mahokshahvata design system.
  Every color is a token; the light theme only swaps tokens. Pages set
  body[data-theme] from localStorage (falling back to the OS preference),
  so :root holds the dark values and body[data-theme="light"] overrides them.

  Motion rules: only transform/opacity animate, never `all`; presses respond
  on :active; hover effects only on devices that really hover; everything
  calms down under prefers-reduced-motion.
*/

:root {
  color-scheme: dark;

  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --surface-3: #3a3a3c;
  --line: rgba(255, 255, 255, 0.10);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #f5f5f7;
  --muted: #98989d;

  --accent: #409cff;            /* accent used as text/lines */
  --accent-fill: #0071e3;       /* accent used behind white text (4.6:1) */
  --accent-fill-hover: #0077ed;
  --accent-soft: rgba(64, 156, 255, 0.14);
  --on-accent: #ffffff;

  --pos: #30d158;
  --pos-soft: rgba(48, 209, 88, 0.14);
  --neg: #ff6961;
  --neg-soft: rgba(255, 105, 97, 0.14);
  --warn: #ffb340;
  --warn-soft: rgba(255, 179, 64, 0.14);
  --neutral: #aeaeb2;
  --neutral-soft: rgba(174, 174, 178, 0.14);

  --nav-bg: rgba(22, 22, 23, 0.72);
  --shadow-card: none;
  --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--line);
  --focus-ring: 0 0 0 3px rgba(64, 156, 255, 0.45);

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

body[data-theme="light"] {
  color-scheme: light;

  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f2f2f7;
  --surface-3: #e5e5ea;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.16);
  --text: #1d1d1f;
  --muted: #6e6e73;

  --accent: #0066cc;
  --accent-fill: #0071e3;
  --accent-fill-hover: #0077ed;
  --accent-soft: rgba(0, 113, 227, 0.10);

  --pos: #1a7f37;
  --pos-soft: rgba(26, 127, 55, 0.10);
  --neg: #c9372c;
  --neg-soft: rgba(201, 55, 44, 0.10);
  --warn: #a15c00;
  --warn-soft: rgba(191, 110, 0, 0.12);
  --neutral: #6e6e73;
  --neutral-soft: rgba(110, 110, 115, 0.12);

  --nav-bg: rgba(245, 245, 247, 0.72);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.14), 0 0 0 1px var(--line);
  --focus-ring: 0 0 0 3px rgba(0, 113, 227, 0.35);
}

/* ------------------------------------------------------------------ base */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font: 400 1rem/1.5 var(--font);
  letter-spacing: -0.011em;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 200ms ease, color 200ms ease;
}

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

button, input, select { font: inherit; color: inherit; letter-spacing: inherit; }

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

h1, h2, h3 { font-family: var(--font-display); color: var(--text); }

/* ------------------------------------------------------------------ navigation */

.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px max(24px, env(safe-area-inset-right)) 10px max(24px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.022em;
  white-space: nowrap;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-size: 0.875rem;
  font-weight: 700;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 2px;
  margin: 0 auto;
}

.nav-links a {
  padding: 6px 12px;
  border-radius: 980px;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  transition: color 150ms ease, background-color 150ms ease;
}
.nav-links a:hover { text-decoration: none; }
.nav-links a.active {
  color: var(--text);
  background: var(--surface-2);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle,
.profile-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 980px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: none;
  transition: transform 160ms var(--ease-out), background-color 150ms ease;
}
.profile-button { padding-left: 4px; }

.profile-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  background: var(--surface-3);
  color: var(--text);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0;
}

.profile-avatar.has-photo { background-size: cover; background-position: center; }

.photo-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.photo-preview {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-3) center / cover no-repeat;
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 600;
}

.profile-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 260px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  display: none;
  z-index: 60;
  transform-origin: top right;
}
.profile-menu.open {
  display: block;
  opacity: 1;
  transform: scale(1);
  transition: opacity 150ms var(--ease-out), transform 150ms var(--ease-out);
}
@starting-style {
  .profile-menu.open { opacity: 0; transform: scale(0.96); }
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.profile-card .profile-avatar { width: 36px; height: 36px; font-size: 0.8125rem; }
.profile-name { margin: 0; font-weight: 600; }
.profile-email { margin: 2px 0 0; color: var(--muted); font-size: 0.8125rem; word-break: break-word; }

.profile-menu-actions { display: grid; gap: 6px; }
.profile-menu-actions button { width: 100%; }
.profile-menu-actions .logout-btn {
  background: var(--neg-soft);
  color: var(--neg);
}

/* ------------------------------------------------------------------ layout */

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px max(24px, env(safe-area-inset-right)) 80px max(24px, env(safe-area-inset-left));
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 20px;
  margin-top: 20px;
}

.performance-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 20px;
  margin: 20px 0;
}

.side-stack { display: grid; gap: 16px; align-content: start; }

.row,
.filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------------ hero */

.hero {
  padding: 8px 0 4px;
}

.hero-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.hero-top-extended { align-items: flex-start; }
.hero-copy { flex: 1 1 420px; min-width: 0; }

.eyebrow {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.25rem, 5vw, 3.5rem);
  line-height: 1.05;
  letter-spacing: -0.028em;
  font-weight: 700;
}

.hero p {
  margin: 12px 0 0;
  max-width: 60ch;
  color: var(--muted);
  font-size: 1.125rem;
  line-height: 1.45;
  letter-spacing: -0.014em;
}

.hero-metric-box {
  display: grid;
  gap: 2px;
  min-width: 200px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}
.hero-metric-box span,
.hero-metric-box small { color: var(--muted); font-size: 0.8125rem; }
.hero-metric-box strong { font-size: 1.1875rem; font-weight: 600; letter-spacing: -0.02em; }

.hero-bottom-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------------ pills, chips, badges */

.hero-pill-row,
.chip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.chip-row { margin-bottom: 14px; }

.sector-pill,
.chip {
  min-height: 32px;
  padding: 5px 14px;
  border: 1px solid var(--line);
  border-radius: 980px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: none;
  transition: transform 160ms var(--ease-out), background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
.sector-pill.active,
.chip.active {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.badge,
.mini-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 980px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.badge.positive, .mini-chip.positive { background: var(--pos-soft); color: var(--pos); }
.badge.negative, .mini-chip.negative { background: var(--neg-soft); color: var(--neg); }

.tag { color: var(--muted); }

/* ------------------------------------------------------------------ stats */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin: 28px 0 8px;
}

.stat {
  position: relative;
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}

/* Colored variants: a small status dot next to the label, not a tinted card. */
.stat-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
}
.accent-card .stat-label::before,
.success-card .stat-label::before,
.warning-card .stat-label::before,
.neutral-card .stat-label::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: none;
}
.accent-card .stat-label::before { background: var(--accent); }
.success-card .stat-label::before { background: var(--pos); }
.warning-card .stat-label::before { background: var(--warn); }
.neutral-card .stat-label::before { background: var(--neutral); }

.stat-value {
  margin-top: 6px;
  font-family: var(--font-display);
  font-size: clamp(1.625rem, 2.4vw, 2rem);
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.8125rem;
}

/* ------------------------------------------------------------------ cards */

.card,
.premium-card,
.premium-visual-card {
  position: relative;
  min-width: 0;
  padding: 24px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}

.card h2 {
  margin: 0 0 16px;
  font-size: 1.25rem;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.card p { color: var(--muted); margin: 0 0 14px; }

.premium-visual-card h2,
.premium-card h2 { margin: 2px 0 0; }
.premium-card h2:only-child,
.premium-card > h2:first-child { margin-bottom: 16px; }

.output-panel h3,
.action-panel h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.012em;
}

.visual-header,
.premium-header,
.output-head,
.compact-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.premium-header { margin-bottom: 18px; }
.compact-header { margin-bottom: 12px; }

.mini-label,
.tile-label {
  display: inline-block;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0;
}

.action-panel,
.output-panel {
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.output-panel { display: grid; gap: 12px; }
.output-panel pre {
  margin: 0;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: 0.75rem/1.5 var(--font-mono);
}

.stacked-actions { display: grid; gap: 10px; margin-top: 12px; }
.stacked-actions button { width: 100%; }

.empty-state {
  display: grid;
  place-items: center;
  min-height: 140px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.9375rem;
  text-align: center;
}

/* ------------------------------------------------------------------ list rows */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.list li:last-child { border-bottom: 0; padding-bottom: 0; }
.list li:first-child { padding-top: 0; }
.list + a { display: inline-block; margin-top: 16px; }  /* "View … →" link under a card's list */
.list .pos, .pos { color: var(--pos); font-weight: 500; }
.list .neg, .neg { color: var(--neg); font-weight: 500; }

.positive { color: var(--pos); }
.negative { color: var(--neg); }

/* ------------------------------------------------------------------ performance + trends */

.sparkline-wrap { position: relative; margin-top: 16px; }
.sparkline-note { margin: 6px 0 0; color: var(--muted); font-size: 0.8125rem; }
.sparkline {
  display: block;
  width: 100%;
  height: 140px;
  overflow: visible;
}
.sparkline-tooltip {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, calc(-100% - 8px));
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}
.sparkline-tooltip span {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 400;
}

.visual-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.visual-footer strong {
  display: block;
  margin-top: 2px;
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.trend-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.trend-tile {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 124px;
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}
.trend-tile strong {
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.trend-tile small { color: var(--muted); font-size: 0.8125rem; }
.trend-tile.positive strong { color: var(--pos); }
.trend-tile.negative strong { color: var(--neg); }
.trend-tile.warning strong { color: var(--warn); }
.trend-tile.accent strong { color: var(--accent); }
.trend-tile.neutral strong { color: var(--text); }

/* ------------------------------------------------------------------ sectors + weights */

.sector-breakdown { display: grid; gap: 14px; margin-bottom: 12px; }
.sector-row { padding: 0; }
.sector-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}
.sector-bar,
.mini-bar {
  height: 6px;
  border-radius: 980px;
  background: var(--surface-2);
  overflow: hidden;
}
.sector-bar span,
.mini-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent-fill);
}
.sector-row small { display: block; margin-top: 6px; color: var(--muted); font-size: 0.8125rem; }

.weight-cell { display: grid; gap: 6px; min-width: 100px; }

.symbol-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ------------------------------------------------------------------ buttons + forms */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 18px;
  border: 0;
  border-radius: 980px;
  background: var(--accent-fill);
  color: var(--on-accent);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 160ms var(--ease-out), background-color 150ms ease, opacity 150ms ease;
}
button.secondary {
  background: var(--surface-2);
  color: var(--text);
}
button:disabled { opacity: 0.45; cursor: default; }
.small-btn { min-height: 32px; padding: 5px 14px; font-size: 0.8125rem; }

/* Instant press feedback, on every pressable thing. */
button:active:not(:disabled),
.sector-pill:active,
.chip:active,
.theme-toggle:active,
.profile-button:active {
  transform: scale(0.97);
}

.button-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 16px; }
.button-row:last-child { margin-bottom: 0; }

/* Controls sitting on a grey panel step up to the card surface so they stay visible. */
.action-panel button.secondary,
.output-panel button.secondary,
.action-panel input,
.action-panel select { background: var(--surface); }

.filter-row { justify-content: flex-start; flex: 1 1 480px; }
.filter-row input,
.filter-row select { flex: 1 1 180px; width: auto; margin-bottom: 0; }
.button-row a { display: inline-block; }
.button-row a:hover { text-decoration: none; }

.label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
}

input,
select {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem; /* 16px: stops iOS zooming the page on focus */
  font-variant-numeric: tabular-nums;
  transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}
input::placeholder { color: var(--muted); opacity: 1; }
input:focus-visible,
select:focus-visible {
  border-color: var(--accent);
  background: var(--surface);
}

.inline-add-cash {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}
.inline-add-cash input { margin-bottom: 0; }

.status {
  margin-bottom: 14px;
  padding: 10px 14px;
  min-height: 20px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.875rem;
}
.status.warning { background: var(--warn-soft); color: var(--warn); }
.status.success { background: var(--pos-soft); color: var(--pos); }
.status.error { background: var(--neg-soft); color: var(--neg); }
.status:empty { display: none; }

/* ------------------------------------------------------------------ tables */

.table-wrap,
.holdings-table-wrap,
.history-table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  color: var(--text);
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}
th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  line-height: 1.35;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: 0; }
thead th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
tbody tr[data-ticker] { cursor: pointer; }

.holdings-table { min-width: 700px; }
.trade-table { min-width: 900px; }

.picks-table { min-width: 860px; }
.picks-table td small { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.history-table { font-size: 0.8125rem; }
.history-table th, .history-table td { padding: 10px 12px; vertical-align: top; }
.history-table td small { color: var(--muted); }

.empty-table-row {
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
}

.trade-output { min-height: 180px; color: var(--text); }
.trade-output .table-wrap { margin-top: 10px; }

/* BUY/SELL badges: token colors, so they stay readable in both themes. */
.trade-pill,
.trade-side {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.trade-buy, .trade-side.buy { background: var(--pos-soft); color: var(--pos); }
.trade-sell, .trade-side.sell { background: var(--neg-soft); color: var(--neg); }

/* ------------------------------------------------------------------ sentiment feed */

.sentiment-shell { display: grid; gap: 12px; margin-top: 18px; }

.sentiment-item {
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}
.sentiment-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 10px;
}
.sentiment-item h3 {
  margin: 0;
  font-size: 1.0625rem;
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: -0.016em;
}
.sentiment-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.8125rem;
}
.sentiment-summary { margin: 0; color: var(--text); line-height: 1.55; }
.sentiment-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.8125rem;
}
.sentiment-footer a { font-weight: 500; }

.sentiment-badge,
.sentiment-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 980px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.sentiment-badge { min-width: 80px; }
.sentiment-pill { margin-top: 10px; background: var(--pos-soft); color: var(--pos); }
.sentiment-badge.positive { background: var(--pos-soft); color: var(--pos); }
.sentiment-badge.negative { background: var(--neg-soft); color: var(--neg); }
.sentiment-badge.neutral,
.sentiment-badge.unknown { background: var(--neutral-soft); color: var(--neutral); }

/* News card: the article on the left, the stocks it affects on the right. */
.news-impact {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.impact-panel { border-left: 1px solid var(--line); padding-left: 20px; }
.impact-panel .mini-label { margin-bottom: 8px; }
.impact-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.impact-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; }
.impact-ticker { font-weight: 600; }
.impact-name { color: var(--muted); font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.impact-meta { grid-column: 1 / -1; color: var(--muted); font-size: 0.75rem; }
.impact-reason { grid-column: 1 / -1; font-size: 0.8125rem; }
.view-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 64px; padding: 3px 10px; border-radius: 980px;
  font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.view-badge.good { background: var(--pos-soft); color: var(--pos); }
.view-badge.bad { background: var(--neg-soft); color: var(--neg); }
.view-badge.wait { background: var(--warn-soft); color: var(--warn); }
.view-badge.none { background: var(--neutral-soft); color: var(--neutral); }
.impact-note { margin: 6px 0 0; color: var(--muted); font-size: 0.8125rem; }
@media (max-width: 760px) {
  .news-impact { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .impact-panel { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 12px; }
}

/* ------------------------------------------------------------------ market detail (market.html) */

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 640px) {
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
}

/* "Explain this stock" panel in the Market page's stock detail */
.explain-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px 20px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.explain-box:has(.explain-result) { display: block; }
.explain-intro { margin: 6px 0 0; color: var(--muted); font-size: 0.9375rem; }
.explain-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px 12px; flex-wrap: wrap; }
.explain-summary { margin: 10px 0 0; font-size: 1.0625rem; line-height: 1.5; }
.explain-sections {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 24px;
  margin-top: 16px;
}
.explain-section ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); line-height: 1.6; }
.explain-bottom { margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--line); line-height: 1.5; }
@media (max-width: 720px) {
  .explain-sections { grid-template-columns: minmax(0, 1fr); }
}

.news-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.news-item:last-child { border-bottom: 0; }
.news-source { margin-bottom: 4px; color: var(--muted); font-size: 0.75rem; font-weight: 600; }
.news-title { margin-bottom: 4px; font-weight: 600; }
.news-summary { color: var(--muted); font-size: 0.9375rem; }

/* ------------------------------------------------------------------ market table */

.market-controls {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  align-items: end;
}
.market-rank { color: var(--muted); }
.market-symbol { font-weight: 600; }
.market-name {
  max-width: 260px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8125rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.market-pagination {
  justify-content: center;
  align-items: center;
  gap: 14px;
}
#marketPageInfo {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ options desk */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 14px;
}
.form-grid .span-2 { grid-column: 1 / -1; }

.underlying-quote {
  color: var(--muted);
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}
.underlying-quote strong { color: var(--text); font-weight: 600; }

.trade-preview {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 16px;
  margin: 4px 0 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}
.trade-preview strong { color: var(--text); font-size: 1rem; font-weight: 600; }
.trade-preview.over-budget { background: var(--neg-soft); color: var(--neg); }
.trade-preview.over-budget strong { color: var(--neg); }

.open-positions { display: grid; }
.position-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.position-row:first-child { padding-top: 0; }
.position-row:last-child { border-bottom: 0; padding-bottom: 0; }
.position-title { font-weight: 600; font-size: 0.9375rem; }
.market-price-line {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
.market-price-line strong { color: var(--text); font-weight: 600; }
.order-rules { margin: 10px 0 0; color: var(--muted); font-size: 0.75rem; }
.trade-preview.over-budget { flex-direction: column; }
.action-panel .trade-preview:not(.over-budget) { background: var(--surface); }
/* One line per trade; the table scrolls sideways on narrow screens instead of wrapping. */
.options-history th,
.options-history td { white-space: nowrap; }
.position-row small { color: var(--muted); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ sentiment suggestions */

.suggestion-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.suggestion-list { display: grid; }
.suggestion-row {
  display: grid;
  gap: 6px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.suggestion-row:first-child { padding-top: 0; }
.suggestion-row:last-child { border-bottom: 0; padding-bottom: 0; }
.suggestion-row[data-ticker] { cursor: pointer; }
.suggestion-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.suggestion-top .symbol-badge { margin-right: 8px; }
.suggestion-name { font-weight: 600; }
.suggestion-condition {
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}
.suggestion-signal { font-size: 0.9375rem; font-weight: 500; }
.suggestion-meta,
.suggestion-headline {
  color: var(--muted);
  font-size: 0.8125rem;
}
.suggestion-headline a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.suggestion-leaders {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8125rem;
}
.leader-chip {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.suggestion-disclaimer {
  margin: 10px 2px 20px;
  color: var(--muted);
  font-size: 0.8125rem;
}

@media (hover: hover) and (pointer: fine) {
  .suggestion-row[data-ticker]:hover .suggestion-name { color: var(--accent); }
}

/* ------------------------------------------------------------------ ticker picker (ticker-picker.js) */

.ticker-picker {
  position: relative;
  margin-bottom: 12px;
}
.ticker-picker > input { margin-bottom: 0; }
.ticker-picker-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 40;
  max-height: 280px;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
}
.ticker-picker.open-up .ticker-picker-list {
  top: auto;
  bottom: calc(100% + 6px);
}
.ticker-picker-list[hidden] { display: none; }
.ticker-picker-option {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 120ms var(--ease-out);
}
.ticker-picker-option[aria-selected="true"] { background: var(--surface-2); }
.ticker-picker-option.current .ticker-picker-symbol { color: var(--accent); }
.ticker-picker-symbol { font-weight: 600; }
.ticker-picker-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.ticker-picker-name,
.ticker-picker-sector {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.ticker-picker-name { font-size: 0.9375rem; }
.ticker-picker-sector { color: var(--muted); font-size: 0.75rem; }
.ticker-picker-quote {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}
.ticker-picker-quote small { font-size: 0.75rem; }
.ticker-picker-empty {
  padding: 10px;
  color: var(--muted);
  font-size: 0.875rem;
}

/* ------------------------------------------------------------------ hover (only where hover is real) */

@media (hover: hover) and (pointer: fine) {
  .nav-links a:hover { color: var(--text); }
  button:hover:not(:disabled) { background: var(--accent-fill-hover); }
  button.secondary:hover:not(:disabled),
  .theme-toggle:hover,
  .profile-button:hover,
  .sector-pill:not(.active):hover,
  .chip:not(.active):hover { background: var(--surface-3); }
  .profile-menu-actions .logout-btn:hover { background: var(--neg-soft); filter: brightness(1.15); }
  tbody tr[data-ticker]:hover td { background: var(--surface-2); }
}

/* ------------------------------------------------------------------ responsive */

@media (max-width: 920px) {
  .grid,
  .performance-shell { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 760px) {
  .nav-inner {
    flex-wrap: wrap;
    row-gap: 8px;
    padding-bottom: 8px;
  }
  .nav-actions { margin-left: auto; }
  /* Links become one horizontally scrolling strip instead of wrapping into rows. */
  .nav-links {
    order: 3;
    flex: 1 0 100%;
    margin: 0 -16px;
    padding: 0 16px 2px;
    overflow-x: auto;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
  }
  .nav-links::-webkit-scrollbar { display: none; }
  #themeToggle { padding: 5px 10px; }
  #profileLabel { display: none; }

  .page { padding: 24px 16px 64px; }
  .hero h1 { font-size: 2.125rem; }
  .hero p { font-size: 1rem; }
  .hero-metric-box { min-width: 0; width: 100%; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }
  .stat { padding: 14px 16px; }
  .stat-value { font-size: 1.375rem; }
  .card, .premium-card, .premium-visual-card { padding: 18px; }
  .sentiment-head { flex-direction: column; gap: 8px; }
  .trend-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .market-controls { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .suggestion-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 380px) {
  .stats, .trend-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ------------------------------------------------------------------ accessibility preferences */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
  }
  button:active:not(:disabled),
  .sector-pill:active,
  .chip:active,
  .theme-toggle:active,
  .profile-button:active { transform: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .navbar {
    background: var(--bg);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  :root, body[data-theme="light"] {
    --line: var(--line-strong);
    --muted: var(--text);
  }
  .navbar { background: var(--bg); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
