:root {
  color-scheme: light;
  --surface-0: #f4f3ef;
  --surface-1: #fcfcfb;
  --border: #e2e0da;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77756f;
  --accent: #2a78d6;
  --profit: #2a78d6;
  --loss: #e34948;
  --good: #0ca30c;
  --critical: #d03b3b;
  --grid: #e2e0da;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --border: #2f2f2c;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #9a998f;
    --accent: #3987e5;
    --profit: #3987e5;
    --loss: #e66767;
    --grid: #383835;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --border: #2f2f2c;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #9a998f;
  --accent: #3987e5;
  --profit: #3987e5;
  --loss: #e66767;
  --grid: #383835;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--surface-0); color: var(--text-primary); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--text-muted); font-size: 0.85rem; }

.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface-1); border-right: 1px solid var(--border); padding: 20px 14px; display: flex; flex-direction: column; gap: 16px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text-primary); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a { color: var(--text-secondary); padding: 7px 10px; border-radius: 8px; }
.sidebar nav a.active, .sidebar nav a:hover { background: var(--surface-0); color: var(--text-primary); text-decoration: none; }
.nav-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 14px 10px 4px; }
.user { border-top: 1px solid var(--border); padding-top: 12px; font-size: 0.9rem; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
.content { padding: 24px 28px 48px; min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 18px; }
.flash { background: var(--surface-1); border: 1px solid var(--border); border-left: 4px solid var(--good); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }

.period { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 0.9rem; }
.period-label { font-weight: 600; margin-right: 6px; }
.period input, .period button, .auth input, .auth button { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-1); color: var(--text-primary); }
.period button, .auth button { background: var(--accent); border-color: var(--accent); color: #fff; cursor: pointer; }
.presets { display: flex; flex-wrap: wrap; gap: 10px; width: 100%; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--text-secondary); font-size: 0.85rem; }
.tile .value { font-size: 1.45rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 4px; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; overflow-x: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.grid-2 > .card { margin-bottom: 0; }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--text-secondary); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { font-weight: 650; border-bottom: 0; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-secondary); white-space: nowrap; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; }
.badge.profit::before { background: var(--profit); }
.badge.loss::before { background: var(--loss); }
.share { height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; min-width: 60px; }
.share > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--text-muted); stroke-width: 1; }
.chart .bar.pos rect.mark { fill: var(--profit); }
.chart .bar.neg rect.mark { fill: var(--loss); }
.chart .bar rect.hit { fill: transparent; }
.chart .bar:hover rect.hit { fill: var(--grid); opacity: .5; }
.chart text { fill: var(--text-secondary); font-size: 11px; }
.legend { display: flex; gap: 14px; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 8px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend .pos::before { background: var(--profit); }
.legend .neg::before { background: var(--loss); }
details summary { cursor: pointer; color: var(--accent); margin-top: 8px; }

.alerts { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.alerts li { border-left: 3px solid var(--critical); padding-left: 10px; }
.alerts li.info { border-left-color: var(--accent); }

.auth { max-width: 380px; margin: 10vh auto; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; }
.auth form { display: flex; flex-direction: column; gap: 12px; }
.auth label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--text-secondary); }
.auth .errorlist { color: var(--critical); margin: 0; padding-left: 18px; font-size: 0.9rem; }
.qr { background: #fff; padding: 12px; border-radius: 8px; width: 220px; }
.qr svg { width: 100%; height: auto; }
code.secret { word-break: break-all; font-size: 0.85rem; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 10px; }
  .sidebar nav { flex-direction: row; overflow-x: auto; flex-wrap: nowrap; width: 100%; order: 3; }
  .sidebar nav a { white-space: nowrap; }
  .nav-label { display: none; }
  .user { border: 0; padding: 0; margin-left: auto; display: flex; gap: 10px; align-items: center; }
  .content { padding: 16px; }
}
.card.sync { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; }
button.secondary { font: inherit; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-0); color: var(--text-primary); cursor: pointer; }
.flash.error { border-left-color: var(--critical); }
