/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --bg:           #0a0a0a;
  --bg-2:         #111;
  --bg-3:         #1a1a1a;
  --border:       #2a2a2a;
  --text:         #ddd;
  --text-dim:     #888;
  --text-muted:   #555;
  --positive:     #4ade80;
  --negative:     #f87171;
  --accent:       #1a7f37;
  --accent-hover: #166d2f;
  --danger:       #b91c1c;
  --input-bg:     #0f0f0f;
  --radius:       4px;
  --font:         system-ui, -apple-system, sans-serif;

  /* Asset type colors (shared by CSS and JS via getComputedStyle) */
  --color-crypto: #144d14;
  --color-stock:  #14314d;
  --color-etf:    #143838;
  --color-mf:     #452f06;
  --color-metal:  #3c3c3c;
  --color-cash:   #4d4d14;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { background: var(--bg); color: var(--text); font-family: var(--font); min-height: 100vh; }

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

/* ── Visibility toggle ──────────────────────────────────────────────────────── */
html.totals-hidden [data-total-value]         { visibility: hidden; }
html.totals-hidden [data-total-placeholder]   { display: inline !important; }
html:not(.totals-hidden) [data-total-placeholder] { display: none; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.page-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.main-content {
  padding: 1rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* ── Top bar ─────────────────────────────────────────────────────────────────── */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  gap: 12px;
}

.top-bar-left { display: flex; align-items: center; gap: 8px; }
.top-bar-right { display: flex; align-items: center; gap: 8px; position: relative; }

.brand { font-weight: 700; font-size: 16px; color: var(--text); }

.top-total { font-size: 13px; font-weight: 600; }
.top-total-placeholder { font-size: 13px; font-weight: 600; letter-spacing: 0.1em; display: none; }

.settings-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 180px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.settings-panel.hidden { display: none; }

.settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.settings-row input[type=checkbox] { cursor: pointer; }

.qr-wrap { margin-top: 4px; text-align: center; }
.qr-img  { max-width: 100px; border: 1px solid var(--border); border-radius: var(--radius); }

/* ── Auth ────────────────────────────────────────────────────────────────────── */
.auth-box {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-brand { display: flex; align-items: center; gap: 8px; justify-content: center; }
.brand-logo  { font-size: 24px; }
.brand-name  { font-size: 20px; font-weight: 700; }
.auth-tagline { text-align: center; color: var(--text-dim); font-size: 13px; }
.auth-form   { display: flex; flex-direction: column; gap: 10px; }
.auth-footer { text-align: center; color: var(--text-dim); font-size: 12px; }

/* ── Summary strip ──────────────────────────────────────────────────────────── */
#summary-strip { padding: 12px 0; overflow-x: auto; }
.summary-inner {
  display: flex;
  gap: 32px;
  justify-content: center;
  align-items: flex-start;
  white-space: nowrap;
  padding: 0 16px;
}
.summary-item  { text-align: center; }
.summary-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.summary-value { font-size: 15px; font-weight: 600; }
.summary-pct   { font-size: 12px; opacity: 0.8; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }

/* ── Charts ──────────────────────────────────────────────────────────────────── */
.charts-section {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin: 16px 0;
}
.charts-stack { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.chart-box { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.chart-pie  { flex: 0 0 204px; }
.growth-chart-wrap { position: relative; height: 200px; }
.pl-chart-wrap     { position: relative; height: 180px; }
.realized-chart-wrap { position: relative; height: 180px; }
.chart-range-buttons { display: flex; gap: 6px; margin-bottom: 8px; }
.chart-range-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 2px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
}
.chart-range-btn.active, .chart-range-btn:hover {
  border-color: var(--positive);
  color: var(--positive);
}
.chart-label { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }
.pl-total { margin-top: 10px; font-size: 15px; font-weight: 600; }

/* ── Add trade form ──────────────────────────────────────────────────────────── */
.add-trade-wrap { margin: 12px 0; }
.add-trade-form { margin-top: 10px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.form-group { display: flex; flex-direction: column; gap: 4px; min-width: 80px; }
.form-group label { font-size: 11px; color: var(--text-dim); }
.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.form-import-link { font-size: 12px; color: var(--text-dim); }
.form-error { color: var(--negative); font-size: 12px; margin-top: 6px; padding: 6px; background: rgba(248,113,113,0.1); border-radius: var(--radius); }

/* ── Holdings table ──────────────────────────────────────────────────────────── */
.holdings-table-wrap { overflow-x: auto; margin-top: 8px; }
.holdings-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.holdings-table th {
  text-align: right;
  padding: 6px 10px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.holdings-table th:first-child,
.holdings-table td:first-child { text-align: left; }
.holdings-table td {
  text-align: right;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.holdings-table tbody tr:hover { background: var(--bg-3); }

/* Asset type row accents */
.holding-row.crypto   { border-left: 2px solid var(--color-crypto); }
.holding-row.stock,
.holding-row.etf      { border-left: 2px solid var(--color-stock); }
.holding-row.mf       { border-left: 2px solid var(--color-mf); }
.holding-row.metal    { border-left: 2px solid var(--color-metal); }
.holding-row.cash     { border-left: 2px solid var(--color-cash); }

.delta { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.3; }
.delta small { font-size: 11px; opacity: 0.7; }
.delta.stale { opacity: 0.5; }
.na { color: var(--text-muted); }

.ticker-text { font-weight: 600; }
.btn-icon {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 14px;
}
.btn-icon:hover { color: var(--text); }

/* ── Table totals ────────────────────────────────────────────────────────────── */
.totals-row {
  display: flex;
  gap: 24px;
  justify-content: center;
  padding: 8px 0;
  margin-top: 4px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.totals-item { text-align: center; }
.totals-label { font-size: 11px; color: var(--text-dim); }
.totals-value { font-weight: 600; }
.totals-pct   { font-size: 11px; opacity: 0.8; }

/* ── Trades panel ────────────────────────────────────────────────────────────── */
.trades-panel { margin-top: 20px; }
.trades-list  { margin-top: 10px; }
.trades-toolbar { display: flex; gap: 8px; margin-bottom: 8px; }

.trades-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.trades-table th, .trades-table td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
}
.trades-table th { color: var(--text-dim); font-size: 11px; text-transform: uppercase; }

/* ── Modals ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal h3 { font-size: 15px; font-weight: 600; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

.categories-header {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.categories-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  cursor: pointer;
}
.categories-row .flex-1 { flex: 1; }

/* ── Password prompt ─────────────────────────────────────────────────────────── */
.password-prompt {
  max-width: 340px;
  margin: 40px auto;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.password-form { display: flex; flex-direction: column; gap: 10px; }

/* ── Buttons ──────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-sm { padding: 3px 10px; font-size: 12px; }
.btn-full { width: 100%; }
.btn-primary   { background: var(--accent);  color: #fff; }
.btn-secondary { background: var(--bg-3); color: var(--text); border-color: var(--border); }
.btn-danger    { background: var(--danger); color: #fff; }

/* ── Inputs ──────────────────────────────────────────────────────────────────── */
input, select, textarea {
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  padding: 5px 8px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #555; }
.input-sm   { padding: 3px 7px; font-size: 12px; }
.input-full { width: 100%; padding: 8px 10px; }
.hidden { display: none !important; }

/* ── Alerts ──────────────────────────────────────────────────────────────────── */
.alert {
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 13px;
}
.alert-error { background: rgba(185,28,28,0.15); border: 1px solid rgba(185,28,28,0.4); color: #fca5a5; }
.alert-info  { background: rgba(59,130,246,0.15); border: 1px solid rgba(59,130,246,0.4); color: #93c5fd; }
.alert-list  { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.link-style { cursor: pointer; color: var(--positive); text-decoration: underline; }
.empty-message { color: var(--text-muted); font-size: 13px; margin: 16px 0; }
.flex-1 { flex: 1; }
.overflow-auto { overflow: auto; }
