:root {
  --bg: #0f1419;
  --panel: #1a2129;
  --panel-2: #222b35;
  --text: #e6edf3;
  --muted: #8b98a5;
  --border: #2d3742;
  --green: #2ec27e;
  --red: #f0556d;
  --amber: #e0a52b;
  --blue: #4a9eff;
  --grey: #8b98a5;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.muted { color: var(--muted); font-weight: 400; font-size: 0.85em; }
.error { background: rgba(240,85,109,0.15); color: var(--red); padding: 0.6rem 0.8rem;
  border-radius: 8px; margin-bottom: 0.8rem; font-size: 0.9em; }

/* ---- login ---- */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--panel); padding: 2rem; border-radius: 14px; width: min(360px, 90vw);
  border: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.4rem; }
.login-card h1 { margin: 0; font-size: 1.4rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.25rem; margin-top: 0.6rem;
  font-size: 0.8rem; color: var(--muted); }
.login-card input { background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 0.6rem; border-radius: 8px; font-size: 1rem; }
.login-card button, .panel button { margin-top: 1rem; background: var(--blue); color: #04121f;
  border: 0; padding: 0.7rem; border-radius: 8px; font-weight: 600; font-size: 1rem; cursor: pointer; }

/* ---- topbar ---- */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 1rem;
  flex-wrap: wrap; background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 0.7rem 1rem; }
.brand { font-weight: 700; }
.header-stats { display: flex; gap: 1rem; flex: 1; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.header-stats .stat b { font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 0.8rem; }
.logout { color: var(--muted); text-decoration: none; font-size: 0.85em; }
.logout:hover { color: var(--text); }

.state-chip { position: relative; display: inline-flex; align-items: center; gap: 0.45rem;
  background: var(--panel-2); padding: 0.35rem 0.7rem; border-radius: 999px; cursor: default;
  border: 1px solid var(--border); font-size: 0.85rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--grey); }
.dot.green { background: var(--green); } .dot.red { background: var(--red); }
.dot.amber { background: var(--amber); } .dot.blue { background: var(--blue); } .dot.grey { background: var(--grey); }
.tooltip { display: none; position: absolute; top: 130%; right: 0; width: 240px; background: #0b0f14;
  border: 1px solid var(--border); padding: 0.6rem 0.7rem; border-radius: 8px; font-size: 0.8rem;
  color: var(--text); box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.state-chip:hover .tooltip, .state-chip:focus .tooltip, .state-chip.open .tooltip { display: block; }

/* ---- panels ---- */
main { max-width: 960px; margin: 0 auto; padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 1rem 1.2rem; }
.panel h2 { margin: 0 0 0.8rem; font-size: 1.05rem; }
.banner { background: rgba(224,165,43,0.15); color: var(--amber); border-radius: 10px;
  padding: 0.7rem 1rem; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 0.8rem; }
.metric { background: var(--panel-2); border-radius: 10px; padding: 0.7rem; }
.metric .v { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric .k { color: var(--muted); font-size: 0.75rem; }

.equity { width: 100%; height: 160px; margin-top: 1rem; }
.equity path.line { fill: none; stroke: var(--blue); stroke-width: 2; }
.equity path.area { fill: rgba(74,158,255,0.12); stroke: none; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.pos { color: var(--green); } .neg { color: var(--red); }
.tag { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.72rem; font-weight: 600; }
.tag.uptrend { background: rgba(46,194,126,0.18); color: var(--green); }
.tag.held { background: rgba(46,194,126,0.28); color: var(--green); }
.tag.flat { background: rgba(139,152,165,0.18); color: var(--muted); }
.tag.unknown { background: rgba(139,152,165,0.12); color: var(--muted); }
.empty { color: var(--muted); padding: 0.6rem 0; }
.updated { text-align: center; }

/* ---- mobile: tables become cards ---- */
@media (max-width: 680px) {
  table thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { background: var(--panel-2); border-radius: 10px; margin-bottom: 0.6rem; padding: 0.3rem 0.6rem; }
  td { display: flex; justify-content: space-between; border-bottom: 1px solid var(--border); text-align: right; }
  td:last-child { border-bottom: 0; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 0.75rem; text-align: left; }
}
