:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --good:           #006300;
  --bad:            #d03b3b;

  --series-1: #2a78d6; /* Largecap */
  --series-2: #eb6834; /* Smallcap */
  --series-3: #1baf7a; /* Midcap */
  --series-4: #eda100; /* Flexicap */
  --series-5: #e87ba4; /* Multicap */
  --series-6: #008300; /* Infra */
  --series-7: #4a3aa7; /* PSU */
  --series-8: #e34948; /* Tech */
  --series-9: #6da7ec;  /* Healthcare */
  --series-10:#f0b56b; /* Value */
  --series-11:#67d1ae; /* ELSS */
  --series-12:#f5c869; /* Commodities */
  --series-13:#f0a8c4; /* Arbitrage */
  --series-14:#b4b2a9; /* Other */

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page:           #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);
    --good:           #0ca30c;
    --bad:            #e66767;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --series-4: #c98500; --series-5: #d55181; --series-6: #008300;
    --series-7: #9085e9; --series-8: #e66767; --series-9: #5598e7;
    --series-10:#d9994f; --series-11:#3fae86; --series-12:#d9ab4f;
    --series-13:#d98aab; --series-14:#7a7870;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19; --page: #0d0d0d; --text-primary: #ffffff;
  --text-secondary: #c3c2b7; --text-muted: #898781; --gridline: #2c2c2a;
  --baseline: #383835; --border: rgba(255,255,255,0.10);
  --good: #0ca30c; --bad: #e66767;
}

* { box-sizing: border-box; }
body {
  margin: 0; font-family: var(--font); background: var(--page);
  color: var(--text-primary); -webkit-font-smoothing: antialiased;
}
.app { max-width: 1200px; margin: 0 auto; padding: 20px 16px 64px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 20px;
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

button, .btn {
  font-family: var(--font); font-size: 13px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface-1);
  color: var(--text-primary); border-radius: 8px; padding: 8px 14px;
  cursor: pointer; transition: background .12s;
}
button:hover, .btn:hover { background: var(--gridline); }
button.primary { background: var(--series-1); color: #fff; border-color: transparent; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 22px; }
@media (max-width: 720px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }
.stat-tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat-tile .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-tile .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-tile .sub { font-size: 12px; margin-top: 2px; color: var(--text-secondary); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--gridline); margin-bottom: 18px; }
.tab {
  padding: 9px 16px; font-size: 13px; font-weight: 600; color: var(--text-secondary);
  cursor: pointer; border-bottom: 2px solid transparent; user-select: none;
}
.tab.active { color: var(--text-primary); border-bottom-color: var(--series-1); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.layout { display: grid; grid-template-columns: 1.7fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.card h3 { margin: 0 0 10px; font-size: 14px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

.category-group { margin-bottom: 14px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.category-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--surface-1); cursor: pointer;
  border-bottom: 1px solid var(--gridline);
}
.category-header .swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 8px; }
.category-header .name { font-weight: 700; font-size: 13.5px; }
.category-header .nums { display: flex; gap: 18px; font-size: 12.5px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.category-header .nums b { color: var(--text-primary); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: right; font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em;
     padding: 6px 10px; border-bottom: 1px solid var(--gridline); font-weight: 600; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text-primary); }
th .arrow { font-size: 9px; }
th:first-child, td:first-child { text-align: left; }
td { padding: 8px 10px; border-bottom: 1px solid var(--gridline); font-variant-numeric: tabular-nums; text-align: right; }
tr:last-child td { border-bottom: none; }
.fund-row { cursor: pointer; }
.fund-row:hover { background: var(--gridline); }
.fund-name { display: flex; align-items: center; gap: 8px; text-align: left; }
.expander { width: 16px; height: 16px; display: inline-flex; align-items: center; justify-content: center;
            border: 1px solid var(--border); border-radius: 4px; font-size: 11px; color: var(--text-muted); flex: none; }
.demat-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer; white-space: nowrap;
}
.demat-badge.empty { border-style: dashed; color: var(--text-muted); }
.gain-pos { color: var(--good); }
.gain-neg { color: var(--bad); }
.txn-subrow td { background: var(--page); padding: 0; }
.txn-subtable { padding: 6px 10px 10px 34px; }
.txn-subtable table { font-size: 12px; }
.badge-status { font-size: 10.5px; padding: 1px 7px; border-radius: 999px; font-weight: 700; text-transform: uppercase; }
.badge-status.CONFIRMED { background: rgba(12,163,12,0.12); color: var(--good); }
.badge-status.PENDING { background: rgba(250,178,25,0.18); color: #a86400; }

.chart-wrap { position: relative; height: 260px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 12px; font-size: 12px; }
.legend .item { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.legend .sw { width: 9px; height: 9px; border-radius: 2px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: none;
  align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface-1); border-radius: var(--radius); padding: 20px; width: 380px; max-width: 92vw;
         border: 1px solid var(--border); }
.modal h3 { margin-top: 0; }
.field { margin-bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.field input, .field select {
  font-family: var(--font); font-size: 13px; padding: 7px 9px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--page); color: var(--text-primary);
}
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filters select, .filters input { font-family: var(--font); font-size: 12.5px; padding: 6px 9px;
  border-radius: 7px; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); }

.empty-note { color: var(--text-muted); font-size: 12.5px; padding: 10px 2px; }
.harvest-item { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--gridline); font-size: 13px; }
.harvest-item:last-child { border-bottom: none; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 320px; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; }
.login-card h1 { font-size: 18px; margin: 0 0 18px; }
.login-error { color: var(--bad); font-size: 12.5px; margin-bottom: 10px; }
.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--text-primary); color: var(--surface-1);
  padding: 10px 16px; border-radius: 8px; font-size: 13px; opacity: 0; transform: translateY(8px);
  transition: all .2s; pointer-events: none; z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); }
.fallback-note { font-size: 11px; color: var(--text-muted); font-style: italic; }
