/* ---------- Base ---------- */
:root {
  --bg: #0E0E10;
  --panel: #17171A;
  --panel-2: #1F1F23;
  --border: #2A2A30;
  --border-strong: #3A3A42;
  --text: #F0F0F2;
  --text-dim: #A0A0A8;
  --text-faint: #6A6A72;
  --green: #2ECC71;
  --red: #FF4D4D;
  --yellow: #F2C94C;
  --accent: #6FA8FF;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.25);
  --maxw: 1200px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter",
               Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1; /* tabular numbers */
}

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

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: max(32px, env(safe-area-inset-top, 0px))
           max(24px, env(safe-area-inset-right, 0px))
           max(64px, env(safe-area-inset-bottom, 0px))
           max(24px, env(safe-area-inset-left, 0px));
}

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 28px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.site-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}
.site-sub {
  color: var(--text-dim);
  font-size: 12px;
}
.back-link {
  display: inline-block;
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 14px;
}
.back-link:hover { color: var(--text); }

/* ---------- Loading & empty ---------- */
.loading, .empty {
  color: var(--text-dim);
  text-align: center;
  padding: 60px 0;
  font-size: 14px;
}

/* ---------- Portfolio grid (home) ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
@media (max-width: 980px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
  text-decoration: none;
  color: inherit;
  display: block;
}
.card:hover {
  border-color: var(--border-strong);
  background: var(--panel-2);
  transform: translateY(-1px);
  text-decoration: none;
}
.card-name {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.card-display-name {
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
  margin-top: 2px;
}
.card-ytd {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 6px 0 12px;
}
.card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.card-stat-label {
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.card-stat-value {
  font-size: 14px;
  font-weight: 600;
  margin-top: 2px;
}

/* ---------- Detail page ---------- */
.detail-header {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 6px;
}
.detail-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}
.detail-subtitle {
  font-size: 16px;
  color: var(--text-dim);
  font-weight: 500;
}
.detail-desc {
  color: var(--text-dim);
  margin: 0 0 22px 0;
}

/* Summary strip */
.summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 22px;
}
@media (max-width: 720px) { .summary { grid-template-columns: repeat(2, 1fr); } }
.metric-label {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.metric-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-top: 4px;
}

/* Monthly returns */
.section-title {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin: 24px 0 10px;
}
.months {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
@media (max-width: 720px) { .months { grid-template-columns: repeat(6, 1fr); } }
.month-cell {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 4px;
  text-align: center;
}
.month-name {
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
}
.month-gain {
  font-size: 13px;
  font-weight: 700;
  margin-top: 2px;
}

/* Prior years chips */
.years {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.year-chip {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
}
.year-chip .y { color: var(--text-faint); }
.year-chip .g { font-weight: 700; }

/* Tables */
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 22px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 12px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }

/* Color helpers */
.up { color: var(--green); }
.down { color: var(--red); }
.flat { color: var(--text-dim); }
.rsi-hot { color: var(--red); }
.rsi-cold { color: var(--green); }

/* Empty table state */
.empty-row td {
  text-align: center;
  color: var(--text-faint);
  padding: 28px 0;
  font-style: italic;
}

/* ---------- Sparkline ---------- */
.spark {
  display: block;
  width: 100%;
  height: 100%;
}
.spark-wrap {
  margin: 8px 0 12px;
  width: 100%;
  height: 44px;
}
.spark-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 6px;
  height: 140px;
}
.spark-card .spark { height: 110px; }

/* ---------- Last updated ---------- */
.card-updated {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-faint);
}
.detail-updated {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-faint);
}

/* ---------- Sortable headers ---------- */
th.sortable {
  cursor: pointer;
  user-select: none;
}
th.sortable:hover { color: var(--text); }
th.sorted { color: var(--text); }
.sort-ind {
  font-size: 10px;
  margin-left: 4px;
  color: var(--accent);
}

/* ---------- Mobile tap-to-expand ---------- */
/* Mobile-only cells are hidden on desktop */
.mobile-cell { display: none; }

@media (max-width: 720px) {
  /* Hide secondary columns on mobile */
  th.secondary, td.secondary { display: none; }

  /* Hide ALL desktop tds on mobile and show mobile-cell instead.
     Each row collapses to a single tappable summary line. */
  tr.data-row td:not(.mobile-cell) { display: none; }
  tr.data-row .mobile-cell {
    display: block;
    padding: 0;
    border-bottom: 1px solid var(--border);
  }

  thead {
    /* On mobile we hide the sortable header completely — taps are the
       interaction model, not column sorting. */
    display: none;
  }

  table { display: block; }
  tbody { display: block; }
  tr.data-row { display: block; cursor: pointer; }

  .mobile-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    font-size: 14px;
  }
  .mobile-summary .m-prim {
    font-variant-numeric: tabular-nums;
  }
  .mobile-summary .m-sep {
    color: var(--text-faint);
    font-size: 12px;
  }
  .mobile-caret {
    margin-left: auto;
    color: var(--text-faint);
    font-size: 18px;
    line-height: 1;
    transform: rotate(0deg);
    transition: transform 0.15s ease;
  }
  tr.data-row.expanded .mobile-caret { transform: rotate(90deg); }

  .mobile-expand {
    display: none;
    padding: 4px 14px 14px;
    background: var(--panel-2);
    border-top: 1px solid var(--border);
  }
  tr.data-row.expanded .mobile-expand { display: block; }

  .kv {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
    border-bottom: 1px dashed var(--border);
  }
  .kv:last-child { border-bottom: none; }
  .kv .k { color: var(--text-dim); }
  .kv .v { font-variant-numeric: tabular-nums; font-weight: 600; }
}
