html { scrollbar-gutter: stable; }

:root {
  --bg: #0f1117;
  --card: #1a1d27;
  --border: #2a2d3a;
  --text: #e2e8f0;
  --muted: #8892a4;
  --pos: #22c55e;
  --neg: #ef4444;
  --accent: #3b82f6;
  --warn: #f59e0b;
  --radius: 8px;
}

.theme-light {
  --bg: #f7f8fa;
  --card: #ffffff;
  --border: #e2e6ed;
  --text: #1a1d27;
  --muted: #5a6378;
  --pos: #16a34a;
  --neg: #dc2626;
  --accent: #2563eb;
  --warn: #d97706;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ── Login ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}

.login-card h1 {
  font-size: 1.2rem;
  margin-bottom: 1.5rem;
  text-align: center;
  color: var(--text);
}

.login-card label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.login-card input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 1rem;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-card button {
  width: 100%;
  padding: 0.65rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
}

.login-card button:hover { filter: brightness(1.1); }

.error {
  color: var(--neg);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: rgba(239,68,68,0.1);
  border-radius: 6px;
}

/* ── Header ── */
header, header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1.25rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.header-left { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.header-right { display: flex; align-items: center; gap: 0.75rem; }

header select, header.app-header select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}

.netliq-block { display: flex; flex-direction: column; gap: 0.1rem; }
.netliq-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.netliq {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.netliq-sub { font-size: 0.95rem; font-weight: 500; font-variant-numeric: tabular-nums; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot.live { background: var(--pos); box-shadow: 0 0 6px var(--pos); }
.dot.reconnecting { background: var(--warn); }

.logout-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.8rem;
}
.logout-link:hover { color: var(--text); }

.data-source-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-live { background: var(--pos); color: #fff; }
.badge-cached { background: var(--warn); color: #fff; }

.btn-ghost {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  color: var(--muted); font-size: 0.8rem; padding: 0.25rem 0.6rem; cursor: pointer;
  font-family: inherit;
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.btn-ghost:disabled { opacity: 0.4; cursor: default; }

.theme-toggle { display: inline-flex; align-items: center; gap: 0.4rem; }
.theme-toggle .theme-icon { font-size: 0.95rem; line-height: 1; }
.theme-toggle .theme-label { font-size: 0.78rem; letter-spacing: 0.02em; }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 4px;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.tab {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-family: inherit;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-count {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.05rem 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--muted);
  background: rgba(148,163,184,0.15);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.tab.active .tab-count { color: var(--accent); background: rgba(96,165,250,0.18); }

/* ── Sizing panel ── */
.sizing-panel {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}
.theme-light .sizing-panel { background: #fafbfc; }

.sizing-panel-intro { flex: 1 1 auto; max-width: 38rem; }
.sizing-panel-title { margin: 0 0 0.25rem; font-size: 0.95rem; font-weight: 600; color: var(--text); }
.sizing-panel-desc { margin: 0; font-size: 0.8rem; line-height: 1.45; color: var(--muted); }
.sizing-panel-fields { display: flex; gap: 1.5rem; flex-shrink: 0; }
.sizing-field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 8rem; }
.sizing-field-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
.sizing-field .factor-input { width: 100%; padding: 0.4rem 0.55rem; font-size: 0.95rem; }
.sizing-field-hint { font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.factor-block { display: flex; flex-direction: column; gap: 0.1rem; }
.factor-input {
  width: 4.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  padding: 0.15rem 0.4rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: inherit;
}
.factor-input:focus { outline: none; border-color: var(--accent); }

/* ── Status Bar ── */
.status-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 26px;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--muted);
  z-index: 100;
  white-space: nowrap;
  overflow: hidden;
}
.status-divider { color: var(--border); }
.status-gateways { display: flex; align-items: center; gap: 10px; }
.status-gw { display: flex; align-items: center; gap: 5px; }
.status-gw-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.status-gw-dot.live { background: var(--pos); box-shadow: 0 0 4px var(--pos); }
.status-gw-dot.offline { background: var(--neg); }

/* ── Main Layout ── */
main {
  padding: 1rem;
  padding-bottom: calc(1rem + 26px);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 100%;
  margin: 0 auto;
}

@media (min-width: 768px) {
  main { padding: 1.25rem; gap: 1.25rem; }
}

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.card h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.75rem;
  font-weight: 500;
}

/* ── Tables ── */
.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 260px);
}

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

table.positions { min-width: 900px; }

thead {
  position: sticky;
  top: 0;
  z-index: 20;
}

thead th {
  background: var(--card);
  text-align: left;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

thead th.col-sticky {
  position: sticky;
  left: 0;
  z-index: 25;
}

td.col-sticky {
  position: sticky;
  left: 0;
  background: var(--card);
  z-index: 5;
}

td {
  padding: 0.5rem 0.5rem;
  border-bottom: 1px solid rgba(42,45,58,0.5);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.theme-light td { border-bottom-color: rgba(226,230,237,0.7); }

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }
.theme-light tr:hover td { background: rgba(0,0,0,0.02); }
tr:hover td.col-sticky { background: color-mix(in srgb, var(--card) 90%, white 10%); }

.num { text-align: right; }
.sym { font-weight: 600; font-family: 'JetBrains Mono', monospace; font-size: 0.9rem; width: 52px; min-width: 52px; max-width: 52px; }
.company { color: var(--muted); font-size: 0.82rem; max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.col-shaded { background: rgba(99,116,150,0.07); }
.theme-light .col-shaded { background: rgba(99,116,150,0.06); }
.col-shaded-ret { background: rgba(20,184,166,0.18); }
.theme-light .col-shaded-ret { background: rgba(20,184,166,0.14); }
.empty { color: var(--muted); text-align: center; padding: 1.5rem; }

tr.group-header { cursor: pointer; user-select: none; }
tr.group-header:hover td { background: rgba(59,130,246,0.14); }
tr.group-header td {
  background: rgba(59,130,246,0.08);
  padding: 0.35rem 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
}
.group-toggle { font-size: 0.7rem; margin-right: 0.4rem; color: var(--accent); }
.group-meta { color: var(--muted); margin-left: 0.4rem; font-weight: normal; }
tr.group-subtotal td {
  background: rgba(255,255,255,0.015);
  font-weight: 600;
  font-size: 0.8rem;
  border-bottom: 2px solid var(--border);
}
tr.group-even td { background: rgba(255,255,255,0.07); }
tr.group-even.group-header td { background: rgba(59,130,246,0.18); }
tr.group-even.group-subtotal td { background: rgba(255,255,255,0.09); }
.theme-light tr.group-even td { background: rgba(0,0,0,0.06); }
.theme-light tr.group-even.group-header td { background: rgba(59,130,246,0.14); }
.theme-light tr.group-even.group-subtotal td { background: rgba(0,0,0,0.08); }
tr.grand-total td {
  border-top: 2px solid var(--border);
  background: var(--card);
  font-weight: 600;
  position: sticky;
  bottom: 0;
  z-index: 1;
}
tr.grand-total-cash td {
  border-top: none;
  color: var(--muted);
  font-weight: 400;
}
tr.grand-total-with-cash td {
  border-top: 1px solid var(--border);
}

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.section-end, td.section-end { border-right: 2px solid var(--border); }
th[title] { cursor: help; }
th[title]:hover { color: var(--accent); }
th.sort-active { color: var(--accent); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: rgba(59,130,246,0.07); }
.edit-btn { background: none; border: 1px solid var(--border); border-radius: 4px; color: var(--muted); font-size: 0.75rem; padding: 0.15rem 0.5rem; cursor: pointer; }
.edit-btn:hover { color: var(--text); border-color: var(--accent); }
.thesis-cell { font-size: 0.85rem; cursor: default; }

/* ── Tier badges ── */
.tier {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  border: 1px solid;
  font-weight: 500;
}
.tier-conviction { color: #a78bfa; background: rgba(167,139,250,0.14); border-color: rgba(167,139,250,0.3); }
.tier-core       { color: #60a5fa; background: rgba(59,130,246,0.14);  border-color: rgba(59,130,246,0.3); }
.tier-spec       { color: #f59e0b; background: rgba(245,158,11,0.14);  border-color: rgba(245,158,11,0.3); }
.tier-toehold    { color: #8892a4; background: rgba(136,146,164,0.14); border-color: rgba(136,146,164,0.3); }

.theme-light .tier-conviction { color: #7c3aed; background: rgba(124,58,237,0.08); border-color: rgba(124,58,237,0.25); }
.theme-light .tier-core       { color: #2563eb; background: rgba(37,99,235,0.08);  border-color: rgba(37,99,235,0.25); }
.theme-light .tier-spec       { color: #d97706; background: rgba(217,119,6,0.08);  border-color: rgba(217,119,6,0.25); }
.theme-light .tier-toehold    { color: #5a6378; background: rgba(90,99,120,0.08);  border-color: rgba(90,99,120,0.25); }

/* ── Edit Panel ── */
.panel-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 40;
}
.theme-light .panel-overlay { background: rgba(15,17,23,0.25); }

.edit-panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 340px;
  background: var(--card);
  border-left: 1px solid var(--border);
  z-index: 50;
  display: flex; flex-direction: column;
  overflow-y: auto;
  transform: translateX(0);
  transition: transform 0.2s cubic-bezier(0.2,0,0,1);
}
.theme-light .edit-panel { box-shadow: -10px 0 30px rgba(15,17,23,0.08); }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.95rem;
}

.panel-close {
  background: none; border: none; color: var(--muted);
  font-size: 1rem; cursor: pointer; padding: 0.25rem;
}
.panel-close:hover { color: var(--text); }

#research-form { padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; flex: 1; }

.field-group { display: flex; flex-direction: column; gap: 0.35rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.field-group label {
  font-size: 0.75rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.hint { font-size: 0.7rem; color: var(--border); text-transform: none; letter-spacing: 0; }

.field-group input,
.field-group select,
.field-group textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.5rem 0.6rem;
  font-size: 0.875rem;
  width: 100%;
  font-family: inherit;
}
.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus {
  outline: none; border-color: var(--accent);
}
.field-group textarea { resize: vertical; }

.panel-actions {
  display: flex; gap: 0.75rem; justify-content: flex-end;
  padding-top: 0.5rem;
  margin-top: auto;
}

.btn-primary {
  background: var(--accent); color: #fff;
  border: none; border-radius: 6px;
  padding: 0.55rem 1.25rem; font-size: 0.9rem; cursor: pointer;
  font-family: inherit;
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 0.55rem 1rem; font-size: 0.9rem; cursor: pointer;
  font-family: inherit;
}
.btn-secondary:hover { color: var(--text); }

/* ── Gateway overlay ── */
.gw-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15, 17, 23, 0.88);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.gw-overlay-box {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 2.5rem 3rem;
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
  max-width: 360px; text-align: center;
}
.gw-overlay-title { font-size: 1.1rem; font-weight: 600; }
.gw-overlay-sub { color: var(--muted); font-size: 0.875rem; line-height: 1.5; }
.gw-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: gw-spin 0.8s linear infinite;
}
@keyframes gw-spin { to { transform: rotate(360deg); } }

/* ── Correlation Tab ── */
.corr-header { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; margin-bottom: 14px; }
.corr-sub { font-size: 0.8rem; color: var(--muted); }

.corr-toggle-bar {
  display: flex; border: 1px solid var(--border); border-radius: 6px;
  overflow: hidden; width: fit-content;
}
.corr-toggle-btn {
  padding: 5px 14px; font-size: 0.78rem; background: none;
  border: none; border-right: 1px solid var(--border);
  color: var(--muted); cursor: pointer; font-family: inherit;
}
.corr-toggle-btn:last-child { border-right: none; }
.corr-toggle-btn.active { background: var(--accent); color: #fff; }
.corr-toggle-btn:not(.active):hover { color: var(--text); }

.corr-k-wrap { display: flex; align-items: center; gap: 6px; }
.corr-k-label { font-size: 0.78rem; color: var(--muted); }
.corr-k-input {
  width: 3.2rem; padding: 4px 6px; font-size: 0.82rem; text-align: center;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-family: inherit;
}
.corr-k-input:focus { outline: none; border-color: var(--accent); }

.corr-cluster-legend {
  display: none; flex-wrap: wrap; gap: 8px; margin-bottom: 14px;
}
.corr-cluster-chip {
  padding: 3px 10px; border-radius: 12px;
  font-size: 0.72rem; font-weight: 600;
}

.corr-layout { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }

/* Heatmap table */
.heatmap-wrap { overflow-x: auto; }
table.heatmap { border-collapse: collapse; width: auto; min-width: unset; }
table.heatmap th, table.heatmap td {
  width: 50px; height: 50px;
  text-align: center; vertical-align: middle;
  font-size: 0.68rem; border: 1px solid var(--border);
  padding: 0;
}
/* Rotated group label on left */
table.heatmap th.group-row-label {
  width: 22px; padding: 0; font-size: 0.63rem; font-weight: 700;
  letter-spacing: 0.07em; text-transform: uppercase; white-space: nowrap;
  border: none; border-right: 2px solid var(--border);
}
table.heatmap th.group-row-label span {
  display: block; writing-mode: vertical-rl; transform: rotate(180deg); padding: 4px 0;
}
/* Ticker row label on left */
table.heatmap th.row-label {
  width: 66px; text-align: right; padding-right: 8px;
  font-weight: 600; font-size: 0.75rem;
  background: var(--card); white-space: nowrap;
  border-right: 1px solid var(--border);
}
table.heatmap th.row-label.benchmark { font-style: italic; color: var(--muted); }
/* Group col-span header row */
table.heatmap th.group-col-label {
  height: 24px; font-size: 0.63rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.07em;
  border-bottom: 2px solid var(--border);
}
table.heatmap th.group-col-label:hover { filter: brightness(1.25); }
table.heatmap th.group-row-label:hover { filter: brightness(1.25); }
table.heatmap th.corner { border: none; background: var(--bg); width: auto; height: auto; }
/* Ticker col headers */
table.heatmap th.col-label {
  font-weight: 600; font-size: 0.72rem;
  background: var(--card); height: 40px;
}
table.heatmap th.col-label.benchmark { font-style: italic; color: var(--muted); background: rgba(136,146,164,0.06); }
/* Group / benchmark borders */
table.heatmap .col-group-start { border-left: 2px solid var(--border) !important; }
table.heatmap tr.row-group-start td,
table.heatmap tr.row-group-start th { border-top: 2px solid var(--border) !important; }
table.heatmap td.diag { background: rgba(59,130,246,0.12); color: var(--accent); font-weight: 700; }
table.heatmap td.benchmark-cell { opacity: 0.8; }

/* Legend */
.corr-legend { margin-top: 12px; }
.corr-legend-bar {
  width: 180px; height: 10px; border-radius: 3px;
  background: linear-gradient(to right, #dc2626, var(--card), #2563eb);
}
.corr-legend-labels {
  display: flex; justify-content: space-between; width: 180px;
  font-size: 0.65rem; color: var(--muted); margin-top: 3px;
}

/* Pairs panel */
.pairs {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px; min-width: 230px;
}
.pairs-title {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; margin-bottom: 8px; padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.pairs-title.pos { color: #60a5fa; }
.pairs-title.div { color: #a3e635; }
.pairs-title.neg { color: #f87171; }
.pairs-spacer { margin-top: 14px; }
.pair-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; border-bottom: 1px solid rgba(42,45,58,0.6);
}
.pair-row:last-child { border-bottom: none; }
.pair-tickers { font-weight: 600; font-size: 0.82rem; }
.pair-corr {
  font-size: 0.8rem; font-weight: 700; padding: 2px 8px;
  border-radius: 4px; min-width: 52px; text-align: center;
}
.c-pos-hi  { background: rgba(37,99,235,0.25);  color: #60a5fa; }
.c-pos-med { background: rgba(99,102,241,0.18); color: #a5b4fc; }
.c-div     { background: rgba(163,230,53,0.12); color: #a3e635; }
.c-neg-med { background: rgba(220,38,38,0.18);  color: #f87171; }
.c-neg-hi  { background: rgba(220,38,38,0.28);  color: #fca5a5; }

/* ── Portfolio History ─────────────────────────────────────────── */
.history-controls {
  display: flex; align-items: center; gap: 16px; margin-bottom: 24px; flex-wrap: wrap;
}.history-period-bar { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.history-period-btn {
  padding: 5px 16px; font-size: 0.78rem; background: none;
  border: none; border-right: 1px solid var(--border);
  color: var(--muted); cursor: pointer; font-family: inherit;
}
.history-period-btn:last-child { border-right: none; }
.history-period-btn.active { background: var(--accent); color: #fff; }
.history-period-btn:not(.active):hover { color: var(--text); }
.history-agg-btn { font: inherit; font-size: 0.75rem; font-weight: 500; color: var(--muted);
  background: none; border: 1px solid var(--border); border-right: none;
  padding: 3px 10px; cursor: pointer; }
.history-agg-btn:last-child { border-right: 1px solid var(--border); border-radius: 0 4px 4px 0; }
.history-agg-btn:first-child { border-radius: 4px 0 0 4px; }
.history-agg-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.history-agg-btn:not(.active):hover { color: var(--text); }
.bench-bar { display: flex; align-items: center; gap: 10px; }
.bench-bar-label { font-size: 0.73rem; color: var(--muted); font-weight: 500; }
.bench-check { display: flex; align-items: center; gap: 4px; font-size: 0.78rem; color: var(--text); cursor: pointer; white-space: nowrap; }
.bench-check input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); }
.bench-ticker-input { width: 64px; font: inherit; font-size: 0.75rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 4px; padding: 2px 6px; color: var(--text);
  text-transform: uppercase; }
.bench-ticker-input:focus { outline: none; border-color: var(--accent); }
.history-flex-btn { margin-left: auto; }
.history-custom-range { display: flex; align-items: center; gap: 6px; }
.history-custom-range input[type="date"] { font: inherit; font-size: 0.78rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 4px; padding: 3px 7px; color: var(--text); cursor: pointer; }
.history-custom-range input[type="date"]:focus { outline: none; border-color: var(--accent); }
.custom-range-sep { color: var(--muted); font-size: 0.78rem; }
.flex-cache-status { font-size: 0.73rem; color: var(--muted); }
.history-main { display: flex; flex-direction: row; gap: 0; align-items: flex-start; }
.history-charts { display: flex; flex-direction: column; gap: 0; flex: 1; min-width: 0; }
.chart-resize-handle { height: 3px; flex-shrink: 0; cursor: row-resize; background: var(--border);
  border-radius: 2px; margin: 5px 0; transition: background 0.15s; }
.chart-resize-handle:hover, .chart-resize-handle.dragging { background: var(--accent); }
.chart-stats-bar { display: flex; align-items: baseline; gap: 14px; min-height: 1.5em;
  padding: 0 2px 4px; flex-wrap: wrap; }
.chart-stats-bar .stat-date { font-size: 0.72rem; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; }
.chart-stats-bar .stat-item { display: flex; align-items: baseline; gap: 4px; font-size: 0.76rem; }
.chart-stats-bar .stat-lbl { color: var(--muted); }
.chart-stats-bar .stat-val { font-family: 'JetBrains Mono', monospace; font-weight: 600; color: var(--text); font-size: 0.74rem; }
.history-chart-wrap { position: relative; height: 300px; }
.history-chart-wrap--tall { height: 340px; }
.history-chart-wrap--short { height: 180px; }
.history-chart-label {
  font-size: 0.72rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 10px;
}
.history-resize-handle { width: 5px; flex-shrink: 0; cursor: col-resize; background: var(--border);
  margin: 0 8px; border-radius: 3px; align-self: stretch; transition: background 0.15s; }
.history-resize-handle:hover, .history-resize-handle.dragging { background: var(--accent); }
.history-tx-panel { width: 360px; flex-shrink: 0; padding-top: 4px; overflow-x: hidden; }
.history-tx-date { font-size: 0.72rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 8px;
  min-height: 1.2em; }
.history-tx-table { width: 100%; border-collapse: collapse; font-size: 0.80rem; table-layout: fixed; }
.history-tx-table th { color: var(--muted); font-weight: 500; text-align: left;
  padding: 4px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.history-tx-table th.num { text-align: right; }
.history-tx-table td { padding: 5px 6px; border-bottom: 1px solid var(--border); color: var(--text); white-space: nowrap; }
.history-tx-table td.num { text-align: right; font-family: 'JetBrains Mono', monospace; font-size: 0.76rem; }
.history-tx-table tr:last-child td { border-bottom: none; }
.history-tx-table .tx-pos { color: var(--pos); }
.history-tx-table .tx-neg { color: var(--neg); }
tr.tx-total-row td { font-weight: 700; border-bottom: 2px solid var(--border); background: rgba(59,130,246,0.10); }
#history-nav-chart, #history-trades-chart { cursor: crosshair; }
