:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1d2330; --muted: #667085; --line: #e4e7ec;
  --accent: #2856d9; --accent-weak: #e8eefc;
  --pos: #137a3a; --pos-bg: #e6f4ea; --neg: #b42318; --neg-bg: #fdecea; --amber: #8a5a00; --amber-bg: #fff4d6;
  --off-bg: #eef0f3; --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.45rem; margin: 0 0 .6rem; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h2 small, dt small { font-weight: 400; color: var(--muted); font-size: .8em; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; background: #fff; padding: 6px 10px; z-index: 10; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.topbar { display: flex; flex-wrap: wrap; gap: .5rem 1.2rem; align-items: center; padding: .7rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; gap: .2rem; flex-wrap: wrap; }
.topbar nav a { padding: .35rem .7rem; border-radius: 8px; text-decoration: none; color: var(--text); }
.topbar nav a[aria-current="page"] { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.logout { margin-left: auto; }
main { max-width: 1280px; margin: 0 auto; padding: 1rem; }
main:focus { outline: none; }
.foot { max-width: 1280px; margin: 0 auto; padding: 1rem; color: var(--muted); font-size: .8rem; }

.pagehead { margin-bottom: 1rem; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center; margin: .3rem 0; }
.filters label { display: flex; gap: .4rem; align-items: center; }
select, input, button { font: inherit; }
select, input[type=text], input:not([type]), input[type=password], input[type=date], input[type=file] {
  padding: .4rem .55rem; border: 1px solid #c9ced8; border-radius: 8px; background: #fff; max-width: 100%; }
.seg { display: inline-flex; border: 1px solid #c9ced8; border-radius: 8px; overflow: hidden; padding: 0; margin: 0; }
.seg-item input { position: absolute; opacity: 0; }
.seg-item span, .seg-link { display: inline-block; padding: .35rem .8rem; cursor: pointer; text-decoration: none; color: var(--text); }
.seg-item input:checked + span, .seg-link[aria-current="page"] { background: var(--accent); color: #fff; }
.seg-item input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: -3px; }
button.primary, button.secondary { padding: .45rem .9rem; border-radius: 8px; border: 1px solid var(--accent); cursor: pointer; }
button.primary { background: var(--accent); color: #fff; }
button.secondary { background: #fff; color: var(--accent); }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }
button.link.danger { color: var(--neg); }
.sync { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; margin: .4rem 0; }
.hint { color: var(--muted); font-size: .86rem; margin: .4rem 0; }
.muted { color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 560px), 1fr)); gap: 1rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; min-width: 0; }
.panel.narrow { max-width: 560px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; margin: 0 0 .8rem; }
.kpis > div { background: var(--bg); border-radius: 8px; padding: .55rem .7rem; }
.kpis dt { font-size: .82rem; color: var(--muted); }
.kpis dd { margin: .15rem 0 0; font-size: 1.15rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpis dd.sub { font-size: .8rem; font-weight: 400; color: var(--muted); }
.kpi-line { margin: .3rem 0; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .zero { color: var(--text); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: .42rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pname { display: block; font-weight: 550; }
td .pname { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; min-width: 160px; }
.meta { display: block; color: var(--muted); font-size: .8rem; }
tr.risk-out td:first-child, tr.risk-red td:first-child { box-shadow: inset 4px 0 0 var(--neg); }
tr.risk-amber td:first-child { box-shadow: inset 4px 0 0 #e0a100; }

.badge { display: inline-block; padding: .05rem .45rem; border-radius: 999px; font-size: .76rem; background: var(--off-bg); color: var(--text); margin: .1rem 0; }
.badge.red { background: var(--neg-bg); color: var(--neg); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.green { background: var(--pos-bg); color: var(--pos); }
.state { padding: .55rem .75rem; border-radius: 8px; margin: .4rem 0 .7rem; }
.state-loading { background: var(--off-bg); color: var(--muted); }
.state-empty { background: var(--off-bg); }
.state-off { background: var(--off-bg); border-left: 4px solid #98a2b3; }
.state-stale { background: var(--amber-bg); color: var(--amber); border-left: 4px solid #e0a100; }
.state-error { background: var(--neg-bg); color: var(--neg); border-left: 4px solid var(--neg); }
.state-ok { background: var(--pos-bg); color: var(--pos); }
details summary { cursor: pointer; color: var(--accent); margin: .4rem 0; }

.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin-bottom: .6rem; }
.tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--text); border-bottom: 3px solid transparent; }
.tabs a[aria-current="page"] { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
.metric-switch { display: flex; flex-wrap: wrap; gap: .35rem; border: 0; padding: 0; margin: 0 0 .4rem; }
.chip input { position: absolute; opacity: 0; }
.chip span { display: inline-block; padding: .3rem .7rem; border: 1px solid #c9ced8; border-radius: 999px; cursor: pointer; font-size: .86rem; background: #fff; }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.chip-off span { color: var(--muted); border-style: dashed; }

.ps-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem; }
.ps { background: var(--bg); border-radius: 8px; padding: .6rem .8rem; }
.ps h3 { margin: 0 0 .3rem; font-size: .9rem; }
.ps dl { margin: 0; } .ps dl > div { display: flex; justify-content: space-between; gap: .5rem; font-size: .88rem; }
.ps dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

.cards { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: .8rem; }
.card-btn { width: 100%; height: 100%; display: flex; gap: .7rem; text-align: left; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .7rem; cursor: pointer; box-shadow: var(--shadow); color: inherit; }
.card-btn:hover { border-color: #b5c3ef; }
.thumb { flex: 0 0 72px; height: 92px; border-radius: 8px; overflow: hidden; background: var(--off-bg); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.card .pname { font-size: .9rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.mval { font-size: 1.3rem; font-weight: 700; margin-top: .3rem; font-variant-numeric: tabular-nums; }
.mval.muted { font-size: 1rem; font-weight: 500; }
.munit { font-size: .78rem; color: var(--muted); }
.capline { font-size: .82rem; margin-top: .2rem; } .capline small { display: block; color: var(--muted); }
.spark { width: 100%; height: 28px; margin-top: .3rem; }
.spark .ln { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.spark .zero { stroke: #c9ced8; stroke-width: 1; vector-effect: non-scaling-stroke; }
.flags { margin-top: .25rem; display: flex; flex-wrap: wrap; gap: .25rem; }
.cap-positive .card-btn { border-left: 4px solid var(--pos); }
.cap-loss .card-btn { border-left: 4px solid var(--neg); }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(900px, calc(100vw - 16px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(16, 24, 40, .45); }
.dialog-head { position: sticky; top: 0; background: #fff; display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--line); z-index: 1; }
.dialog-head h2 { margin: 0; font-size: 1.05rem; }
#detail-body { padding: 1rem; }
button.icon { font-size: 1.5rem; line-height: 1; background: none; border: 0; cursor: pointer; padding: .1rem .5rem; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: .8rem; }
figure { margin: 0; } figcaption { font-size: .8rem; color: var(--muted); }
.chart { width: 100%; height: 150px; }
.chart .axis { stroke: #98a2b3; stroke-width: 1; }
.chart .tick { font-size: 10px; fill: var(--muted); }
.chart .bar-pos { fill: #5b84e8; } .chart .bar-neg { fill: #e06b5f; } .chart .gap { fill: #eef0f3; }
.formulas { font-size: .86rem; padding-left: 1.1rem; }

.login-box { max-width: 380px; margin: 10vh auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; }
.form { display: flex; flex-direction: column; gap: .7rem; align-items: flex-start; }
.form label, .login-box label { display: flex; flex-direction: column; gap: .2rem; width: 100%; }
.login-box form { display: flex; flex-direction: column; gap: .8rem; }
form.inline { display: inline; }
.hist { display: inline-block; margin-right: .8rem; font-size: .86rem; }
code { background: var(--off-bg); padding: 0 .3rem; border-radius: 4px; }

@media (max-width: 640px) {
  body { font-size: 14px; }
  main { padding: .6rem; }
  .logout { margin-left: 0; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .thumb { flex-basis: 56px; height: 72px; }
  th, td { padding: .35rem .3rem; }
}
