:root {
  color-scheme: light;
  --page: #fbf6f8;
  --surface: #ffffff;
  --surface-2: #f8ecf1;
  --text: #1d1519;
  --text-2: #5c5057;
  --muted: #968a90;
  --grid: #f0e4e9;
  --axis: #dccbd2;
  --border: rgba(120, 40, 80, 0.12);
  --accent: #c23668;
  --accent-soft: #fbe3ec;
  --up: #1f7a3a;
  --down: #c62f4a;
  --danger: #c62f4a;
  --series-1: #d6457f; /* ETFs & stocks */
  --series-2: #e59a3a; /* crypto */
  --series-3: #7c5cc4; /* cash */
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #120e10;
    --surface: #1c1719;
    --surface-2: #282023;
    --text: #fbf4f7;
    --text-2: #cdbfc5;
    --muted: #8f8388;
    --grid: #2e2529;
    --axis: #3d3237;
    --border: rgba(255, 200, 225, 0.1);
    --accent: #c23668;
    --accent-soft: #3a1f2a;
    --up: #3cbf63;
    --down: #ef6b84;
    --danger: #ef6b84;
    --series-1: #e0558f;
    --series-2: #c27a1f;
    --series-3: #8a73de;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #120e10;
  --surface: #1c1719;
  --surface-2: #282023;
  --text: #fbf4f7;
  --text-2: #cdbfc5;
  --muted: #8f8388;
  --grid: #2e2529;
  --axis: #3d3237;
  --border: rgba(255, 200, 225, 0.1);
  --accent: #c23668;
  --accent-soft: #3a1f2a;
  --up: #3cbf63;
  --down: #ef6b84;
  --danger: #ef6b84;
  --series-1: #e0558f;
  --series-2: #c27a1f;
  --series-3: #8a73de;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 var(--font);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 16px; }

button, input { font: inherit; color: inherit; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn {
  border: 0;
  background: none;
  padding: 4px 6px;
  border-radius: 6px;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.card {
  box-shadow: 0 1px 3px rgba(120, 40, 80, 0.05);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* --- Header --- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.topbar h1 {
  font-size: 20px;
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.01em;
}
.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f29bbd, var(--accent));
}
.updated { color: var(--muted); font-size: 13px; }

/* --- Hero --- */

.hero {
  background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.hero-label { color: var(--text-2); font-size: 14px; }
.hero-value { font-size: 48px; font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; }
.hero-change { font-size: 15px; margin-top: 4px; }

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
}
.segmented button {
  border: 0;
  background: none;
  padding: 5px 12px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text-2);
}
.segmented button[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .segmented button[aria-pressed="true"] { color: #f7a8c6; }
}
:root[data-theme="dark"] .segmented button[aria-pressed="true"] { color: #f7a8c6; }

.up { color: var(--up); }
.down { color: var(--down); }
.flat, .na { color: var(--muted); }
.note { color: var(--muted); font-size: 13px; }

/* --- Stat tiles --- */

.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.tile-head { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 14px; }
.tile-head .btn { margin-left: auto; padding: 2px 10px; font-size: 13px; }
.tile-value { font-size: 26px; font-weight: 600; margin-top: 6px; }
.tile-sub { font-size: 13px; margin-top: 2px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* --- Allocation --- */

.alloc-bar {
  display: flex;
  gap: 2px;
  height: 14px;
  margin: 12px 0 10px;
}
.alloc-bar > div { border-radius: 4px; min-width: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend b { color: var(--text); font-weight: 600; }

/* --- Chart --- */

.chart-card { margin-top: 12px; }
.chart-wrap { position: relative; margin-top: 10px; }
.chart-wrap svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart-empty {
  height: 120px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}
.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 12px));
}
.tooltip b { display: block; font-size: 14px; }

/* --- Positions --- */

.section { margin-top: 24px; }
.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.section-head h2 { margin-right: auto; }
.section-head .sum { color: var(--text-2); }

.table-card { padding: 0; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: right; }
th:first-child, td:first-child { text-align: left; }
th {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 1px solid var(--grid);
}
td { border-top: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
tr:first-child td { border-top: 0; }
.pos-name { font-weight: 500; }
.pos-id { font-size: 12px; color: var(--muted); }
.stale { color: var(--muted); font-size: 12px; margin-left: 4px; cursor: help; }
td.actions { width: 1%; white-space: nowrap; }
.empty-row td { text-align: center; color: var(--muted); padding: 24px; }

/* --- Dialog --- */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 20px;
  width: min(400px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h3 { margin-bottom: 14px; font-size: 17px; }
label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 12px; }
label input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page);
  font-size: 15px;
}
label input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.lookup { min-height: 20px; font-size: 13px; margin: -6px 0 12px; }
.lookup.ok { color: var(--text); }
.lookup.err { color: var(--danger); }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--danger);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

/* --- Login --- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background:
    radial-gradient(circle at 15% 10%, var(--accent-soft), transparent 45%),
    radial-gradient(circle at 85% 90%, var(--accent-soft), transparent 40%);
}
.login .card {
  width: min(360px, 100%);
  padding: 28px 24px 24px;
  background: linear-gradient(160deg, var(--accent-soft), var(--surface) 55%);
  box-shadow: 0 10px 30px rgba(120, 40, 80, 0.1);
}
.login h1 { font-size: 22px; display: flex; align-items: center; gap: 8px; letter-spacing: -0.01em; }
.login .brand-dot { width: 16px; height: 16px; }
.login .tagline { color: var(--text-2); font-size: 14px; margin: 4px 0 20px; }
.login .btn { width: 100%; padding: 10px; margin-top: 4px; }
.login-link { text-align: center; font-size: 13px; margin: 14px 0 0; }
.login-link a { color: var(--accent); text-decoration: none; }
.login-link a:hover { text-decoration: underline; }

/* --- Mobile --- */

@media (max-width: 760px) {
  .tiles { grid-template-columns: 1fr; }
  .hero-value { font-size: 40px; }
  .hide-sm { display: none; }
  th, td { padding: 10px 8px; }
  .updated { display: none; }
}
