:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface-1: #ffffff;
  --text-primary: #191919;
  --text-secondary: #666666;
  --border: #e3e3e0;
  --grid: #ececec;
  --axis: #b5b5b5;
  --series-1: #257de0;   /* events / buys */
  --series-2: #f47230;   /* sells */
  --series-0: #9a9a9a;   /* placebo (neutral reference) */
  --neg: #ec4647;        /* diverging negative pole */
  --pos: #257de0;        /* diverging positive pole */
  --ok: #0a7d24;
  --bad: #c62828;
  --warn-bg: #fff6e0;
  --link: #1b64be;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111111;
    --surface-1: #191919;
    --text-primary: #efefef;
    --text-secondary: #9c9c9c;
    --border: #2c2c2c;
    --grid: #262626;
    --axis: #4a4a4a;
    --series-1: #338ced;
    --series-2: #e76624;
    --series-0: #7a7a7a;
    --neg: #eb6263;
    --pos: #338ced;
    --ok: #3fbf5f;
    --bad: #ef6b6b;
    --warn-bg: #2b2414;
    --link: #6aabf1;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
       background: var(--bg); color: var(--text-primary); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.8rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1.2rem 0 .4rem; }
code { font-size: .9em; }
.top { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: .6rem 1rem;
       background: var(--surface-1); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; color: var(--text-primary); }
.top nav { display: flex; gap: .2rem; flex-wrap: wrap; flex: 1; }
.top nav a { padding: .3rem .6rem; border-radius: 6px; color: var(--text-secondary); }
.top nav a.on { background: var(--bg); color: var(--text-primary); font-weight: 600; }
.logout button { background: none; border: 1px solid var(--border); color: var(--text-secondary); border-radius: 6px;
                 padding: .25rem .6rem; cursor: pointer; }
main { max-width: 1200px; margin: 0 auto; padding: 1rem; }
footer { text-align: center; color: var(--text-secondary); font-size: .8rem; padding: 2rem 1rem; }
.muted { color: var(--text-secondary); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.2rem; margin: 1rem 0; }
.card.warn { background: var(--warn-bg); }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; border: 1px solid var(--border); font-size: .8rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.filters select, .filters input, .filters button, .loginbox input, .loginbox button {
  font: inherit; padding: .4rem .6rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary); }
.filters button, .loginbox button { background: var(--series-1); color: #fff; border: 0; cursor: pointer; }
.tablewrap { overflow-x: auto; background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; }
table.data { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.data th, table.data td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { font-weight: 600; color: var(--text-secondary); font-size: .8rem; white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.placebo td:first-child { padding-left: 1.4rem; }
.seg { color: var(--text-secondary); font-size: .75rem; white-space: nowrap; }
.tag { display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 99px; border: 1px solid var(--border); white-space: nowrap; }
.tag.insider_buy::before { content: "●"; color: var(--series-1); margin-right: .25rem; }
.tag.insider_sell::before { content: "●"; color: var(--series-2); margin-right: .25rem; }
.tag.ok { color: var(--ok); } .tag.bad { color: var(--bad); } .tag.run { color: var(--text-secondary); }
.err { color: var(--bad); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .6rem; margin: 1rem 0; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .8rem; }
.kpi span { display: block; color: var(--text-secondary); font-size: .8rem; }
.kpi b { font-size: 1.15rem; }
.kpi small { display: block; color: var(--text-secondary); font-size: .75rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }
.chartbox { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: .5rem; }
svg.chart { width: 100%; height: auto; display: block; }
svg .grid { stroke: var(--grid); stroke-width: 1; }
svg .axis { stroke: var(--axis); stroke-width: 1; }
svg .zero { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }
svg .event-line { stroke: var(--text-secondary); stroke-width: 1; }
svg .tick { fill: var(--text-secondary); font-size: 11px; }
svg .dlabel { fill: var(--text-primary); font-size: 11px; }
svg .bar.pos { fill: var(--pos); }
svg .bar.neg { fill: var(--neg); }
svg .hit { fill: transparent; }
svg .hit:hover { fill: var(--text-primary); fill-opacity: .06; }
svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; }
svg .line.s1 { stroke: var(--series-1); }
svg .line.s0 { stroke: var(--series-0); stroke-dasharray: 5 3; }
svg .mark { stroke: var(--surface-1); stroke-width: 2; }
svg .mark.buy { fill: var(--series-1); }
svg .mark.sell { fill: var(--series-2); }
.legend { font-size: .85rem; color: var(--text-secondary); display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.sw { display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-left: .6rem; }
.sw:first-child { margin-left: 0; }
.sw.s1, .sw.buy { background: var(--series-1); }
.sw.s0 { background: var(--series-0); }
.sw.sell { background: var(--series-2); }
.pager { display: flex; gap: 1rem; }
body.login { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.loginbox { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: .8rem; }
.loginbox label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--text-secondary); }
.loginbox h1 { margin: 0; }
@media (max-width: 600px) {
  main { padding: .6rem; }
  table.data th, table.data td { padding: .4rem .45rem; }
  .top { gap: .4rem; }
}
