:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --text: #172033;
  --muted: #5d6b85;
  --border: #e1e6f0;
  --primary: #0f9d74;
  --primary-hover: #0b8562;
  --primary-soft: rgba(15, 157, 116, 0.12);
  --danger: #d64545;
  --warn-bg: #fff6e0;
  --warn-border: #f2d38a;
  --warn-text: #6b4e00;
  --bar: #14b386;
  --bar-2: #0f9d74;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);
  --tip: #ffdd00;
  --tip-hover: #ffe633;
  --tip-text: #1d1a05;
  --tip-soft: rgba(255, 221, 0, 0.16);
  --tip-border: rgba(214, 178, 0, 0.45);
  --tip-shadow: rgba(214, 178, 0, 0.35);
  --radius: 14px;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0d1220;
  --surface: #151c2e;
  --surface-2: #1c2539;
  --text: #e7ecf5;
  --muted: #94a1ba;
  --border: #263049;
  --primary: #2fd09f;
  --primary-hover: #4fe0b3;
  --primary-soft: rgba(47, 208, 159, 0.14);
  --danger: #ff6b6b;
  --warn-bg: #2b2414;
  --warn-border: #5c4a1c;
  --warn-text: #f3d48a;
  --bar: #2fd09f;
  --bar-2: #1fae84;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
  --tip-soft: rgba(255, 221, 0, 0.08);
  --tip-border: rgba(255, 221, 0, 0.28);
  --tip-shadow: rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; padding-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 30px; width: 46px; height: 46px; display: grid; place-items: center; background: var(--primary-soft); border-radius: 12px; }
.brand h1 { font-size: 1.25rem; margin: 0; letter-spacing: -0.01em; }
.tagline { margin: 0; color: var(--muted); font-size: .88rem; }
.icon-btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); width: 42px; height: 42px; border-radius: 12px; cursor: pointer; font-size: 18px; display: grid; place-items: center; }
.icon-btn:hover { border-color: var(--primary); }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: inline; }

main.wrap { padding-top: 22px; padding-bottom: 30px; display: flex; flex-direction: column; gap: 20px; }

/* Banner */
.banner { display: flex; gap: 16px; align-items: center; justify-content: space-between; background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text); padding: 14px 16px; border-radius: var(--radius); font-size: .92rem; }
.banner[hidden] { display: none; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.card h2 { font-size: 1.05rem; margin: 0 0 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2 { margin: 0; }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat { padding: 18px 20px; }
.stat-label { color: var(--muted); font-size: .85rem; font-weight: 500; }
.stat-value { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: .8rem; }
.stat.accent { background: linear-gradient(135deg, var(--primary), var(--bar-2)); border-color: transparent; color: #fff; }
.stat.accent .stat-label, .stat.accent .stat-sub { color: rgba(255, 255, 255, .85); }
[data-theme="dark"] .stat.accent { color: #06281d; }
[data-theme="dark"] .stat.accent .stat-label, [data-theme="dark"] .stat.accent .stat-sub { color: rgba(6, 40, 29, .8); }

.grid { display: grid; grid-template-columns: 1fr 1.25fr; gap: 20px; }

/* Form */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: .85rem; font-weight: 500; }
.field small { color: var(--muted); font-weight: 400; }
.req { color: var(--danger); font-weight: 600; }
input, select {
  font: inherit; font-size: .95rem; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input.invalid { border-color: var(--danger); }
.hint { color: var(--muted); font-size: .8rem; margin: 10px 0 0; }
.form-error { color: var(--danger); font-size: .85rem; margin: 10px 0 0; }
.form-actions { display: flex; gap: 10px; margin-top: 14px; }

/* Buttons */
.btn {
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; text-decoration: none;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 10px 16px; border-radius: 10px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
[data-theme="dark"] .btn-primary { color: #06281d; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-small { padding: 7px 12px; font-size: .82rem; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.banner .btn { flex-shrink: 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn { position: relative; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); text-decoration: underline; cursor: pointer; }

/* Chart */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .bar { fill: var(--bar); transition: opacity .15s; }
.chart .bar:hover { opacity: .8; }
.chart .bar.zero { fill: var(--border); }
.chart .axis-label { fill: var(--muted); font-size: 12px; }
.chart .val-label { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }

/* Table */
.table-wrap { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 10px; }
table.holdings { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.holdings th, .holdings td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.holdings thead th { background: var(--surface-2); color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.holdings .num { text-align: right; }
.holdings tbody tr:hover td { background: var(--surface-2); }
.holdings tfoot td { font-weight: 700; border-bottom: 0; background: var(--surface-2); }
.holdings th:first-child, .holdings td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.holdings thead th:first-child, .holdings tfoot td:first-child { background: var(--surface-2); }
.holdings tbody tr:hover td:first-child { background: var(--surface-2); }
.ticker { font-weight: 700; }
.tag { display: inline-block; font-size: .65rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 2px 6px; border-radius: 6px; margin-left: 6px; background: var(--warn-bg); color: var(--warn-text); border: 1px solid var(--warn-border); vertical-align: middle; }
.muted { color: var(--muted); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions button { border: 1px solid var(--border); background: transparent; color: var(--muted); border-radius: 8px; padding: 5px 9px; cursor: pointer; font: inherit; font-size: .8rem; }
.row-actions button:hover { color: var(--text); border-color: var(--primary); }
.row-actions button.del:hover { color: var(--danger); border-color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 28px 10px 10px; }
.empty[hidden] { display: none; }

/* Footer */
.footer { border-top: 1px solid var(--border); background: var(--surface); padding: 24px 0 30px; margin-top: 10px; }
.tip-card {
  display: flex; align-items: center; gap: 18px; margin: 0 auto 18px; max-width: 820px;
  padding: 20px 22px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--tip-soft), var(--primary-soft));
  border: 1px solid var(--tip-border);
}
.tip-card-emoji { font-size: 34px; width: 58px; height: 58px; flex-shrink: 0; display: grid; place-items: center; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); }
.tip-card-body { flex: 1; min-width: 0; }
.tip-card-title { font-size: 1.02rem; margin: 0 0 2px; }
.tip-card-text { margin: 0; color: var(--muted); font-size: .88rem; }

.tip-btn {
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; cursor: pointer;
  font: inherit; font-weight: 700; text-decoration: none; border-radius: 999px;
  background: var(--tip); color: var(--tip-text); border: 1px solid transparent;
  box-shadow: 0 2px 8px var(--tip-shadow); transition: transform .15s, box-shadow .15s, background .15s;
}
.tip-btn:hover { background: var(--tip-hover); transform: translateY(-1px); box-shadow: 0 4px 14px var(--tip-shadow); }
.tip-btn:focus-visible { outline: 3px solid var(--tip-border); outline-offset: 2px; }
.tip-btn-header { padding: 8px 14px; font-size: .85rem; }
.tip-btn-large { padding: 12px 22px; font-size: .98rem; flex-shrink: 0; }
.tip-btn.is-disabled {
  cursor: not-allowed; background: var(--surface-2); color: var(--muted);
  border-color: var(--border); box-shadow: none; transform: none; pointer-events: none;
}
.tip-btn.is-disabled .tip-icon { filter: grayscale(1); opacity: .7; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.disclaimer, .privacy, .copyright { color: var(--muted); font-size: .8rem; margin: 6px 0; text-align: center; max-width: 820px; margin-left: auto; margin-right: auto; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: .9rem; opacity: 0; transition: all .25s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Responsive */
@media (max-width: 960px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .wrap { padding: 0 14px; }
  .tagline { display: none; }
  .brand h1 { font-size: 1.08rem; }
  .cards { gap: 10px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 1.3rem; }
  .card { padding: 16px; }
  .banner { flex-direction: column; align-items: flex-start; }
  .field-row { grid-template-columns: 1fr; gap: 10px; }
  .tip-btn-header { padding: 0; width: 42px; height: 42px; justify-content: center; }
  .tip-btn-header .tip-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .tip-card { flex-direction: column; text-align: center; gap: 12px; padding: 18px 16px; }
  .tip-btn-large { width: 100%; justify-content: center; }
  .holdings th, .holdings td { padding: 9px 10px; }
  .table-hint { display: block; }
}
.table-hint { display: none; color: var(--muted); font-size: .78rem; margin: 0 0 8px; }
