/* ─── Reset & Base ─── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #fafafa;
  --bg-card: #ffffff;
  --bg-hover: #f5f5f5;
  --border: #e5e5e5;
  --text: #171717;
  --text-secondary: #737373;
  --text-muted: #a3a3a3;
  --accent: #2563eb;
  --accent-light: #eff6ff;
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --yellow: #ca8a04;
  --yellow-bg: #fefce8;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.04);
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Header ─── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 100;
}

h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

h1 .accent {
  color: var(--accent);
}

nav {
  display: flex;
  gap: 8px;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: var(--sans);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-ghost.loading {
  opacity: 0.5;
  pointer-events: none;
}

/* ─── Main ─── */
main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 32px;
}

/* ─── Fund Selector ─── */
.fund-selector {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.fund-card {
  flex: 1;
  min-width: 280px;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow);
}

.fund-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.fund-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.fund-card .fund-meta {
  font-size: 13px;
  color: var(--text-secondary);
}

.fund-card .fund-aum {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  margin-top: 12px;
  color: var(--accent);
}

.fund-card .fund-aum-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ─── Fund Detail ─── */
.fund-detail.hidden { display: none; }

.fund-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  gap: 24px;
  flex-wrap: wrap;
}

.fund-header h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.fund-desc {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 600px;
  margin-top: 4px;
}

.quarter-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.quarter-selector select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 13px;
  background: var(--bg-card);
  cursor: pointer;
}

.vs {
  color: var(--text-muted);
  font-size: 12px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  margin-bottom: 16px;
  cursor: pointer;
}

.back-link:hover { color: var(--accent); }

/* ─── Stats ─── */
.fund-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
}

.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }

/* ─── Table ─── */
.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable:hover { color: var(--text); }
th.active { color: var(--accent); }
th.asc::after { content: ' ↑'; }
th.desc::after { content: ' ↓'; }

td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tr:hover td {
  background: var(--bg-hover);
}

/* Name column */
.col-name { min-width: 200px; }

.position-name {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.position-name .ticker-link {
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  font-size: 14px;
}

.position-name .ticker-link:hover {
  text-decoration: underline;
}

.position-name .issuer {
  font-size: 12px;
  color: var(--text-secondary);
}

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-left: 6px;
}

.badge-call { background: #dbeafe; color: #1d4ed8; }
.badge-put { background: #fce7f3; color: #be185d; }
.badge-new { background: var(--green-bg); color: var(--green); }
.badge-exited { background: var(--red-bg); color: var(--red); }

/* Value cells */
.cell-value {
  font-family: var(--mono);
  font-size: 13px;
}

.cell-shares {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--mono);
}

/* Change column */
.change-positive { color: var(--green); }
.change-negative { color: var(--red); }
.change-neutral { color: var(--text-muted); }

.change-bar {
  display: inline-block;
  height: 4px;
  border-radius: 2px;
  margin-left: 8px;
  vertical-align: middle;
}

.change-bar.positive { background: var(--green); }
.change-bar.negative { background: var(--red); }

/* ─── Side Panel ─── */
.side-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s;
}

.side-panel-overlay.visible { opacity: 1; }
.side-panel-overlay.hidden { display: none; }

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 460px;
  max-width: 90vw;
  height: 100vh;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  box-shadow: -10px 0 30px rgba(0,0,0,0.08);
  z-index: 300;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.side-panel.visible {
  transform: translateX(0);
}

.side-panel.hidden {
  transform: translateX(100%);
}

.side-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 24px;
  border-bottom: 1px solid var(--border);
}

.side-panel-header h3 {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}

.panel-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.btn-close {
  background: none;
  border: none;
  font-size: 28px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.btn-close:hover { color: var(--text); }

.side-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.panel-section {
  margin-bottom: 24px;
}

.panel-section h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.panel-section p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.panel-section ul {
  list-style: none;
  padding: 0;
}

.panel-section ul li {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 0 6px 16px;
  position: relative;
  line-height: 1.5;
}

.panel-section ul li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 12px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.panel-position-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.panel-position-item {
  padding: 10px;
  background: var(--bg);
  border-radius: 6px;
}

.panel-position-item .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
}

.panel-position-item .value {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  margin-top: 2px;
}

/* ─── Loading / Empty ─── */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}

.loading::before {
  content: '';
  display: block;
  width: 24px;
  height: 24px;
  margin: 0 auto 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.research-pending {
  font-style: italic;
  color: var(--text-muted);
  font-size: 13px;
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 1000;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ─── Footer ─── */
footer {
  text-align: center;
  padding: 20px 32px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  header { padding: 12px 16px; }
  main { padding: 16px; }
  .fund-header { flex-direction: column; }
  .fund-stats { grid-template-columns: 1fr 1fr; }

  th, td { padding: 8px 10px; }
  .col-prev, .col-curr { min-width: 120px; }

  .side-panel { width: 100vw; max-width: 100vw; }
}
