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

:root {
  --bg:        #0d1117;
  --card:      #161b22;
  --card2:     #21262d;
  --border:    #30363d;
  --text:      #e6edf3;
  --muted:     #8b949e;
  --accent:    #58a6ff;
  --green:     #3fb950;
  --red:       #f85149;
  --amber:     #d29922;
  --purple:    #bc8cff;
  --blue:      #58a6ff;
  --radius:    8px;
  --sidebar-w: 220px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Login screen ─────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at 50% 0%, #1a2744 0%, var(--bg) 70%);
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  width: 420px;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.login-logo {
  font-size: 32px;
  margin-bottom: 8px;
}

.login-card h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
}

.login-card .subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 32px;
}

.login-card input[type="password"] {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.15s;
  letter-spacing: 2px;
}

.login-card input[type="password"]:focus { border-color: var(--accent); }

.login-card button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #0d1117;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.login-card button:disabled { opacity: 0.6; cursor: not-allowed; }
.login-card button:not(:disabled):hover { opacity: 0.9; }

#login-error {
  margin-top: 12px;
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
}

/* ── App shell ────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

#app.hidden { display: none; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
}

.sidebar-logo {
  padding: 0 20px 24px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  letter-spacing: 0.3px;
}

.sidebar-logo span { color: var(--accent); }

#sidebar nav { flex: 1; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  border-left: 3px solid transparent;
  transition: all 0.15s;
}

.nav-link:hover { color: var(--text); background: var(--card2); }

.nav-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(88,166,255,0.08);
}

.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

#logout-btn {
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

#logout-btn:hover { border-color: var(--red); color: var(--red); }

/* ── Main content ─────────────────────────────────────────────────────────── */
#main-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
}

.section { display: block; }
.section.hidden { display: none; }

/* ── Section header ───────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.section-header h2 {
  font-size: 20px;
  font-weight: 600;
}

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

.card-header {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}

.card-title {
  font-weight: 600;
  font-size: 15px;
}

.chart-card canvas { max-height: 260px; }

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 14px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 140px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

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

.stat-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.stat-sub { font-size: 11px; margin-top: 4px; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-card { padding: 0; overflow: hidden; }

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

th {
  background: var(--card2);
  color: var(--muted);
  font-weight: 500;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

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

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

.totals-row td { background: var(--card2); }

.num  { text-align: right; font-variant-numeric: tabular-nums; font-family: 'SF Mono', Consolas, monospace; }
.mono { font-family: 'SF Mono', Consolas, monospace; font-size: 12px; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  background: var(--card2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.badge.blue   { background: rgba(88,166,255,0.15);  color: #58a6ff; border-color: rgba(88,166,255,0.3); }
.badge.green  { background: rgba(63,185,80,0.15);   color: #3fb950; border-color: rgba(63,185,80,0.3); }
.badge.red    { background: rgba(248,81,73,0.15);   color: #f85149; border-color: rgba(248,81,73,0.3); }
.badge.amber  { background: rgba(210,153,34,0.15);  color: #d29922; border-color: rgba(210,153,34,0.3); }
.badge.purple { background: rgba(188,140,255,0.15); color: #bc8cff; border-color: rgba(188,140,255,0.3); }
.badge.muted  { background: transparent; color: var(--muted); border-color: var(--border); }

.badge.small { font-size: 10px; padding: 1px 6px; }

/* ── Color utilities ──────────────────────────────────────────────────────── */
.green  { color: var(--green); }
.red    { color: var(--red); }
.amber  { color: var(--amber); }
.blue   { color: var(--blue); }
.purple { color: var(--purple); }
.muted  { color: var(--muted); }
.small  { font-size: 12px; }

/* ── Price input ──────────────────────────────────────────────────────────── */
.price-input {
  width: 110px;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: 'SF Mono', Consolas, monospace;
  text-align: right;
  outline: none;
  transition: border-color 0.15s;
}

.price-input:focus { border-color: var(--accent); }
.price-input::placeholder { color: var(--muted); font-size: 12px; }

/* ── Instrument cards ─────────────────────────────────────────────────────── */
.instrument-card { margin-bottom: 20px; }
.instrument-name { font-weight: 500; }

/* ── STCG / LTCG grid ─────────────────────────────────────────────────────── */
.stcg-ltcg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.sl-total {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--card2);
  border-radius: 6px;
  font-size: 13px;
}

.sl-bucket {
  background: var(--card2);
  border-radius: var(--radius);
  padding: 14px;
}

.sl-bucket h4 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sl-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sl-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sl-stat label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
}

.sl-stat span {
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.sl-stat.highlight { background: rgba(255,255,255,0.04); border-radius: 4px; padding: 4px 6px; }

/* ── Charts row ───────────────────────────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

.chart-wrap h4 {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ── Cards row ────────────────────────────────────────────────────────────── */
.cards-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

/* ── Select input ─────────────────────────────────────────────────────────── */
.select-input {
  padding: 6px 12px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

/* ── % bars ───────────────────────────────────────────────────────────────── */
.pct-bars { display: flex; flex-direction: column; gap: 14px; }

.pct-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pct-label { width: 80px; font-size: 12px; color: var(--muted); }

.pct-track {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.pct-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.pct-num { width: 44px; font-size: 12px; text-align: right; color: var(--text); }

/* ── Timeline ─────────────────────────────────────────────────────────────── */
.timeline { display: flex; flex-direction: column; gap: 0; }

.timeline-item {
  display: flex;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}

.timeline-item:last-child { border-bottom: none; }

.timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 5px;
  flex-shrink: 0;
}

.timeline-dot.green  { background: var(--green); }
.timeline-dot.blue   { background: var(--blue); }
.timeline-dot.muted  { background: var(--muted); }

.timeline-item.matured .timeline-dot { background: var(--muted); }
.timeline-item.urgent  .timeline-dot { background: var(--amber); }

.timeline-body { flex: 1; }

.timeline-date  { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.timeline-title { font-weight: 500; margin-bottom: 4px; }
.timeline-meta  { font-size: 12px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.timeline-meta strong { font-size: 13px; }

/* ── Cashflow timeline ────────────────────────────────────────────────────── */
.cashflow-timeline {
  max-height: 480px;
  overflow-y: auto;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty {
  color: var(--muted);
  padding: 40px;
  text-align: center;
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Utility ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
