:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --subtle: #f6f7f9;
  --text: #111418;
  --muted: #6b7280;
  --border: #e8eaee;
  --grid: #eef0f3;
  --accent: #2456d6;
  --accent-wash: rgba(36, 86, 214, 0.08);
  --red: #c62828;
  --red-soft: #fdeceb;
  --on-red: #ffffff;
  --amber: #9a5b00;
  --green: #1b7a3a;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1114;
    --surface: #16191d;
    --subtle: #1b1f24;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #262a31;
    --grid: #22262c;
    --accent: #6b97ff;
    --accent-wash: rgba(107, 151, 255, 0.1);
    --red: #ff6b6b;
    --red-soft: #3a1c1f;
    --on-red: #2a0808;
    --amber: #f0b45a;
    --green: #4cc27a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.loading main, body.loading .top { visibility: hidden; }
h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font: inherit; cursor: pointer; }
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 6px 12px; border-radius: var(--radius); font-weight: 550;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .6; cursor: default; }
.link { border: none; background: none; color: var(--accent); padding: 0; font-weight: 500; }
.link:hover { text-decoration: underline; }
.link:disabled { color: var(--muted); text-decoration: none; cursor: default; }
input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px;
}
input:focus, select:focus { outline: 2px solid var(--accent-wash); border-color: var(--accent); }

/* Header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  max-width: 1200px; margin: 0 auto; padding: 18px 24px 0;
}
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.top-actions { display: flex; align-items: center; gap: 14px; }

main { max-width: 1200px; margin: 0 auto; padding: 8px 24px 48px; }

/* Summary */
.summary { padding: 28px 0 20px; }
.headline { margin: 0; font-size: 28px; font-weight: 650; letter-spacing: -0.02em; }
.headline .count { font-variant-numeric: tabular-nums; }
.headline.has-signals .count { color: var(--red); }
.summary p { margin: 4px 0 0; }
.status-line { font-size: 13px; color: var(--muted); }
.status-line.warn { color: var(--amber); }

/* Tabs */
.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  background: none; border: none; border-bottom: 2px solid transparent; padding: 10px 0;
  color: var(--muted); font-weight: 550; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); }

/* Toolbar */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1 1 240px; min-width: 0; }
.add-form { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.add-form input { width: 240px; }
.msg { font-size: 13px; }
.msg.error { color: var(--red); }
.msg.ok { color: var(--green); }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
th { font-size: 12px; color: var(--muted); font-weight: 550; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sorted { color: var(--text); }
th.sorted::after { content: " ↓"; }
th.sorted.asc::after { content: " ↑"; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--subtle); }
td .sym { font-weight: 650; }
td .name { color: var(--text); margin-left: 6px; }
td .meta { display: block; color: var(--muted); font-size: 12px; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
td small { color: var(--muted); font-size: 12px; }
.drop { font-weight: 600; }
.drop.hit { color: var(--red); }
.up { color: var(--green); }
.down { color: var(--red); }
.empty td { color: var(--muted); padding: 32px 0; text-align: center; cursor: default; }
.empty:hover td { background: none; }

.pill { display: inline-block; font-size: 12px; font-weight: 650; padding: 1px 8px; border-radius: 99px; }
.pill.buy { background: var(--red); color: var(--on-red); }
.pill.near { color: var(--amber); padding-left: 0; padding-right: 0; font-weight: 550; }
.pill.err { color: var(--muted); padding-left: 0; padding-right: 0; font-weight: 500; }

.range { position: relative; width: 80px; height: 14px; display: inline-block; vertical-align: middle; }
.range .track { position: absolute; top: 6px; left: 0; right: 0; height: 2px; border-radius: 1px; background: var(--grid); }
.range .dot { position: absolute; top: 2px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 2px var(--bg); }
.spark { display: block; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark circle { fill: var(--accent); stroke: var(--bg); stroke-width: 2; }

.pager { display: flex; justify-content: space-between; align-items: center; padding: 14px 0; }
.pager span:last-child { display: flex; gap: 18px; }

/* Holdings */
.subhead { font-size: 15px; margin: 32px 0 4px; }
.actions-cell { text-align: right; }
.actions-cell .link { margin-left: 14px; font-size: 13px; }
.pill.held { color: var(--accent); border: 1px solid currentColor; padding: 0 7px; font-weight: 600; margin-left: 4px; }

/* Alerts */
.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.alerts .what span { color: var(--muted); }
.alerts .when { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* Settings */
.settings { max-width: 760px; }
.settings fieldset { border: none; border-bottom: 1px solid var(--border); margin: 0; padding: 4px 0 24px; }
.settings fieldset + fieldset { padding-top: 24px; }
.settings legend { font-size: 15px; font-weight: 650; padding: 0; margin-bottom: 8px; float: left; width: 100%; }
.settings legend + * { clear: both; }
.settings label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; margin: 10px 0; width: fit-content; }
.settings .row { display: flex; gap: 24px; flex-wrap: wrap; clear: both; }
.settings .unit { display: flex; align-items: center; gap: 6px; color: var(--text); }
.settings .unit input { width: 80px; }
.settings label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.help { color: var(--muted); font-size: 13px; margin: 6px 0; clear: both; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 2px 16px; margin: 12px 0; }
.checks label { flex-direction: row; align-items: center; gap: 8px; margin: 3px 0; color: var(--text); font-size: 14px; }
.checks label span { color: var(--muted); font-size: 12px; }
.save-row { display: flex; align-items: center; gap: 12px; padding: 20px 0; position: sticky; bottom: 0; background: var(--bg); }

.footnote { color: var(--muted); font-size: 12px; margin-top: 32px; }

/* Detail drawer */
#drawer-backdrop { position: fixed; inset: 0; background: rgba(15, 17, 20, .3); z-index: 10; }
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(540px, 100%); z-index: 11; overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--border); padding: 24px;
}
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.drawer-head h2 { margin: 0; font-size: 20px; }
.close-btn { background: none; border: none; color: var(--muted); font-size: 20px; padding: 0 4px; line-height: 1; }
.price-line { display: flex; align-items: baseline; gap: 10px; margin: 16px 0 8px; flex-wrap: wrap; }
.price-line .big { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.chart-box { position: relative; margin: 8px 0; }
.chart-box svg { display: block; width: 100%; height: auto; }
.chart-box .axis text { fill: var(--muted); font-size: 11px; }
.chart-box .gridline { stroke: var(--grid); stroke-width: 1; }
.chart-box .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-box .area { fill: var(--accent-wash); }
.chart-box .refline { stroke: var(--muted); stroke-width: 1; }
.chart-box .buyline { stroke: var(--red); stroke-width: 1; }
.chart-box .reflabel { fill: var(--muted); font-size: 11px; }
.chart-box .buylabel { fill: var(--red); font-size: 11px; font-weight: 600; }
.chart-box .crosshair { stroke: var(--muted); stroke-width: 1; }
.chart-box .hover-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 10px; font-size: 12px; box-shadow: 0 4px 12px rgba(0, 0, 0, .08); white-space: nowrap;
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; margin: 16px 0; }
.stats div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-weight: 550; font-variant-numeric: tabular-nums; text-align: right; }
.drawer-foot { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; margin-top: 16px; }

/* Holding box and news in the detail panel */
.holding-box { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 12px; margin: 8px 0 4px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--subtle); }
.holding-box .links { display: flex; gap: 14px; }
.news { list-style: none; margin: 0; padding: 0; }
.news li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.news a { color: var(--text); font-weight: 550; }
.news a:hover { color: var(--accent); text-decoration: none; }
.news .meta { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.news .recent { color: var(--text); }
.drawer-section { margin-top: 24px; }
.drawer-section h3 { font-size: 14px; margin: 0 0 4px; }

/* Dialog */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); width: min(420px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(15, 17, 20, .35); }
.dialog-form { padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.dialog-form h2 { margin: 0; font-size: 18px; }
.dialog-form p { margin: 0; }
.dialog-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); flex: 1; }
.dialog-form .row { display: flex; gap: 12px; }
.dialog-form input { width: 100%; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-page.loading { visibility: visible; }
.login-card { width: min(340px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.login-card .btn { padding: 9px 12px; }

@media (max-width: 720px) {
  .top { padding: 16px 16px 0; }
  main { padding: 4px 16px 40px; }
  .headline { font-size: 24px; }
  .tabs { gap: 18px; }
  th, td { padding: 10px 8px; }
  /* Keep stock, price, drop and status on phones. */
  .col-today, .col-range, .col-trend, .col-value { display: none; }
  td .name { display: none; }
  td .meta { max-width: 120px; }
  th:last-child, td:last-child { padding-left: 4px; }
  th .long { display: none; }
  td small { display: none; }
  .toolbar select { flex: 1 1 40%; }
  .add-form input { flex: 1; width: auto; }
  .stats { grid-template-columns: 1fr; }
  #last-check { display: none; }
}
