:root {
  --paper: #f7f6f0;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #d1d5db;
  --hairline: rgba(17, 24, 39, 0.08);

  --tab-bg: rgba(17, 24, 39, 0.06);
  --tab-active: #111827;
  --tab-active-text: #ffffff;

  --col-symbol: 80px;
  --col-name: 200px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(rgba(17, 24, 39, 0.045) 1px, transparent 1px) 0 0 / 18px 18px,
    linear-gradient(180deg, #fbfbf8 0%, var(--paper) 100%);
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 14px 22px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 10px;
}

.title .kicker {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 3px 0 2px;
  font-size: 18px;
  font-weight: 850;
  letter-spacing: -0.02em;
}

.meta {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.meta .dot { margin: 0 6px; }

.controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid var(--hairline);
  background: var(--tab-bg);
  color: rgba(17, 24, 39, 0.82);
  border-radius: 7px;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 750;
  font-size: 12px;
  -webkit-tap-highlight-color: transparent;
}

.tab.active {
  background: var(--tab-active);
  border-color: var(--tab-active);
  color: var(--tab-active-text);
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.search input {
  width: 220px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.8);
  outline: none;
  color: var(--text);
  font-size: 16px; /* prevent iOS zoom on focus */
}

.search input:focus {
  border-color: rgba(17, 24, 39, 0.28);
  background: #ffffff;
}

.table-wrap {
  border: 1px solid var(--border);
  background: var(--panel);
  overflow: auto;
  max-height: calc(100vh - 170px);
  -webkit-overflow-scrolling: touch;
}

.report-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 900px;
  font-size: 12px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f3f2ea;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: rgba(17, 24, 39, 0.78);
}

th, td {
  border-bottom: 1px solid rgba(17, 24, 39, 0.08);
  padding: 5px 6px;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

tbody tr:nth-child(2n) td {
  background-image: linear-gradient(rgba(17, 24, 39, 0.018), rgba(17, 24, 39, 0.018));
}

td.left, th.left { text-align: left; }

td.num-empty { color: rgba(107, 114, 128, 0.9); }

td.heat { transition: filter 0.12s ease; }

tbody tr:hover td {
  filter: saturate(1.05);
  background-image: linear-gradient(rgba(17, 24, 39, 0.04), rgba(17, 24, 39, 0.04));
}

/* Sticky columns — need explicit backgrounds so content behind doesn't bleed through */
th.sticky, td.sticky {
  position: sticky;
  z-index: 4;
  background-color: var(--panel);
}

thead th.sticky { background-color: #f3f2ea; }

th.sticky-1, td.sticky-1 {
  left: 0;
  width: var(--col-symbol);
  min-width: var(--col-symbol);
  max-width: var(--col-symbol);
}
th.sticky-2, td.sticky-2 {
  left: var(--col-symbol);
  width: var(--col-name);
  min-width: var(--col-name);
  max-width: var(--col-name);
  overflow: hidden;
  text-overflow: ellipsis;
}

th.sticky-1, td.sticky-1,
th.sticky-2, td.sticky-2 {
  box-shadow: 1px 0 0 rgba(17, 24, 39, 0.10);
}

/* alternating row background for sticky cells */
tbody tr:nth-child(2n) td.sticky {
  background-color: #fcfcfb;
}

thead th.sticky { z-index: 6; }

/* Ticker cell */
.ticker {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.sym {
  font-weight: 900;
  letter-spacing: 0.02em;
  font-size: 11px;
}

/* Name subtitle inside ticker cell — hidden on desktop (Name column visible), shown on mobile */
.sym-name {
  display: none;
  font-size: 9px;
  color: rgba(17, 24, 39, 0.55);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

/* Sorting affordance */
th.sortable {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

th .sort {
  display: inline-block;
  width: 10px;
  margin-left: 4px;
  color: rgba(17, 24, 39, 0.46);
}

th.sorted .sort { color: rgba(17, 24, 39, 0.9); }

/* Group separators */
tr.group-row td {
  background: #efeee6 !important;
  font-weight: 950;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(17, 24, 39, 0.72);
  border-top: 2px solid rgba(17, 24, 39, 0.18);
  font-size: 11px;
}

.footnote {
  margin-top: 8px;
  font-size: 11px;
  color: rgba(107, 114, 128, 0.95);
}

.legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(17, 24, 39, 0.12);
}

.chip-red { background: hsl(0 78% 78%); }
.chip-gray { background: hsl(0 0% 93%); }
.chip-green { background: hsl(135 62% 78%); }

.footnote .dot { margin: 0 4px; color: var(--muted); }

/* ─── Mobile ──────────────────────────────────────────── */

@media (max-width: 760px) {
  .app { padding: 8px 6px 16px; }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
  }

  h1 { font-size: 16px; }

  .controls {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 6px;
  }

  .tabs { gap: 4px; }

  .tab {
    padding: 8px 12px;
    font-size: 13px;
    min-height: 36px;
  }

  .search { flex: 1; }
  .search-label { display: none; }
  .search input {
    width: 100%;
    padding: 8px 10px;
  }

  :root {
    --col-symbol: 100px;
    --col-name: 0px;
  }

  /* Hide name column on mobile — ticker + badge is enough */
  th.sticky-2, td.sticky-2 {
    display: none;
  }

  /* Adjust sticky-1 shadow since sticky-2 is gone */
  th.sticky-1, td.sticky-1 {
    box-shadow: 2px 0 0 rgba(17, 24, 39, 0.12);
  }

  .report-table {
    min-width: 600px;
    font-size: 11px;
  }

  th, td {
    padding: 6px 4px;
  }

  thead th { font-size: 9px; }

  .sym { font-size: 10px; }

  /* Show name subtitle on mobile */
  .sym-name {
    display: block;
    max-width: 100px;
  }

  .table-wrap {
    max-height: calc(100vh - 130px);
    border-radius: 6px;
  }

  .footnote { font-size: 10px; }
  .legend { gap: 4px; }
}

/* Extra small (iPhone SE etc.) */
@media (max-width: 380px) {
  :root { --col-symbol: 88px; }
  .sym-name { max-width: 80px; }
  .report-table { min-width: 520px; font-size: 10px; }
  th, td { padding: 5px 3px; }
  .tab { padding: 6px 8px; font-size: 11px; }
}
