:root {
  --bg: #f3f5fb; --card: #ffffff; --border: #e2e6f0; --ink: #0f172a; --ink-soft: #5b6475;
  --primary: #4f46e5; --primary-soft: #eef2ff; --heading: #1e1b4b; --row-alt: #f8f9fd;
  --row-buy: #dcfce7; --row-loss: #fee2e2; --good: #047857; --bad: #be123c;
  --series-1: #2a78d6; --series-2: #eb6834; --grid: #e6e8ef; --radius: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom); }
button, input { font: inherit; }

.hero { display: flex; align-items: center; gap: 14px; color: #fff;
  padding: calc(14px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 14px max(18px, env(safe-area-inset-left));
  background: linear-gradient(90deg, #7c3aed, #2563eb 50%, #06b6d4); }
.hero-icon { width: 46px; height: 46px; border-radius: 11px; box-shadow: 0 2px 8px rgb(0 0 0 / .18); }
.hero-text { flex: 1; min-width: 0; }
.hero h1 { margin: 0; font-size: 22px; font-weight: 650; }
.hero p { margin: 2px 0 0; color: #e0e7ff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.pill::before { content: "● "; }
.pill.on { background: #15803d; } .pill.off { background: #475569; } .pill.warn { background: #b45309; }

.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: 12px max(16px, env(safe-area-inset-left)) 0; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { border: 0; border-radius: 10px 10px 0 0; padding: 10px 18px; background: #e4e8f4; color: var(--ink-soft);
  font-weight: 600; cursor: pointer; white-space: nowrap; min-height: 44px; }
.tabs button.active { background: var(--card); color: var(--primary); }
main { padding: 0 max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); }
.panel { display: none; background: var(--card); border-radius: 0 var(--radius) var(--radius) var(--radius); padding: 16px; }
.panel.active { display: block; }
h2 { font-size: 16px; margin: 20px 0 8px; }
h2 .hint { font-size: 13px; font-weight: 400; color: var(--ink-soft); margin-left: 8px; }
h3 { margin: 0 0 8px; font-size: 16px; }
.note { color: var(--ink-soft); font-size: 13px; }

.tiles { display: grid; gap: 10px; }
.tiles.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.tiles.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tile { border-radius: var(--radius); padding: 10px 14px; color: #fff; min-width: 0; }
.tile .label { font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; opacity: .82; }
.tile .value { font-size: 21px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; opacity: .9; }
.stats { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
.stat { background: var(--row-alt); border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; min-width: 0; }
.stat .label { font-size: 12px; color: var(--ink-soft); } .stat .value { font-weight: 650; font-variant-numeric: tabular-nums; }
@media (max-width: 1100px) { .tiles.six { grid-template-columns: repeat(3, minmax(0, 1fr)); } .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 640px) { .tiles.six, .tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); } .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .hero p { white-space: normal; } }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 14px 0 4px; }
.actions label { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); font-size: 14px; }
.switch { color: var(--ink) !important; font-size: 15px !important; }
.switch input { width: 22px; height: 22px; min-height: 0; accent-color: var(--primary); }
button { border: 0; border-radius: 10px; padding: 10px 16px; min-height: 44px; cursor: pointer; font-weight: 600; background: var(--primary-soft); color: var(--primary); }
button.accent { background: var(--primary); color: #fff; }
button.danger { background: #fff1f2; color: var(--bad); }
button:disabled { opacity: .55; cursor: default; }
button.small { min-height: 32px; padding: 5px 12px; font-size: 13px; }
input { border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; min-height: 44px; background: #fff; color: var(--ink); width: 100%; }
.actions input { width: auto; }
input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.chip { background: #16a34a; color: #fff; border-radius: 8px; padding: 6px 12px; font-weight: 650; }
.chip.none { background: #64748b; }

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); max-height: 520px; -webkit-overflow-scrolling: touch; }
.table-wrap.five { max-height: 238px; }  /* header plus five rows */
.table-wrap.tall { max-height: calc(100vh - 230px); }
table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
th { position: sticky; top: 0; background: var(--heading); color: #fff; font-weight: 600; text-align: center; padding: 9px 10px; white-space: nowrap; z-index: 1; }
td { padding: 9px 10px; text-align: center; white-space: nowrap; border-top: 1px solid var(--border); }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; }
th:first-child { z-index: 2; }
td:first-child { background: inherit; font-weight: 600; }
td.text { text-align: left; }
tbody tr { background: var(--card); } tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr.win { background: var(--row-buy); } tbody tr.loss { background: var(--row-loss); }
tbody tr.clickable { cursor: pointer; }
.empty { padding: 22px; text-align: center !important; color: var(--ink-soft); }
.yes { color: var(--good); font-weight: 700; } .no { color: var(--bad); }
.tag { border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600; background: var(--primary-soft); color: var(--primary); }
.tag.sell { background: var(--bad); color: #fff; }

.card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); padding: 14px; }
.chart-card { margin-top: 10px; }
.chart-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: baseline; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--ink-soft); }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.chart { position: relative; height: 300px; touch-action: pan-y; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .tip { position: absolute; top: 4px; right: 4px; background: rgb(255 255 255 / .95); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 13px; pointer-events: none; display: none; }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.form label { display: block; margin: 10px 0 0; font-size: 14px; color: var(--ink-soft); }
.form label input { margin-top: 4px; }
.row { display: flex; gap: 8px; margin-top: 14px; } .row.wrap { flex-wrap: wrap; }
.error { color: var(--bad); font-size: 14px; min-height: 1em; margin: 8px 0 0; }
details.log { margin-top: 14px; }
details.log pre { background: var(--row-alt); border-radius: 10px; padding: 10px; font-size: 12px; overflow: auto; max-height: 300px; }

dialog.sheet { border: 0; border-radius: 16px; padding: 22px; width: min(440px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgb(15 23 42 / .3); }
dialog::backdrop { background: rgb(15 23 42 / .45); }
.login-icon { width: 64px; height: 64px; border-radius: 15px; display: block; margin-bottom: 10px; }
.signout { background: rgb(255 255 255 / .18); color: #fff; padding: 6px 14px; min-height: 36px; border-radius: 999px; font-size: 13px; white-space: nowrap; }
.signout:hover { background: rgb(255 255 255 / .3); }
.login-page { min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, #7c3aed, #2563eb 55%, #06b6d4); padding: 16px; }
.login-wrap { width: 100%; display: flex; justify-content: center; padding: 0; }
.login-card { width: min(400px, 100%); padding: 26px; box-shadow: 0 20px 60px rgb(15 23 42 / .3); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card button { width: 100%; margin-top: 4px; }
@media (max-width: 640px) { .hero .pill { display: none; } }
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(140%);
  background: var(--heading); color: #fff; padding: 12px 18px; border-radius: 12px; max-width: min(560px, calc(100vw - 24px));
  transition: transform .25s ease, opacity .25s ease; z-index: 50; font-size: 14px; opacity: 0; visibility: hidden; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }
.toast.error { background: var(--bad); }
