:root {
  --bg: #0d1117; --card: #161b22; --line: #262d36; --text: #e6edf3; --muted: #8b949e; --accent: #4e79a7;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 Inter, system-ui, -apple-system, Segoe UI, sans-serif; }
a { color: #8ab4f8; }
code { background: #0b0f14; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 12px; }
.muted { color: var(--muted); }

header { position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center;
  padding: 12px 24px; background: rgba(13,17,23,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 12px; align-items: center; }
.logo { width: 38px; height: 38px; display: block; }
h1 { margin: 0; font-size: 20px; letter-spacing: .3px; }
header p { margin: 0; color: var(--muted); font-size: 12.5px; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input[type=date], input[type=number] { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; color-scheme: dark; }
input[type=number] { width: 80px; }
button { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 12px; cursor: pointer; font: inherit; }
button:hover { border-color: var(--accent); }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button.on { background: var(--accent); border-color: var(--accent); }
.seg.small button { padding: 2px 10px; font-size: 12px; }

main { max-width: 1400px; margin: 0 auto; padding: 16px 24px 40px; }
.range { margin: 4px 0 16px; font-weight: 600; }
.range .muted { font-weight: 400; margin-left: 10px; font-size: 12.5px; }
.loading { text-align: center; padding: 80px 20px; color: var(--muted); }

h2 { font-size: 15px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 32px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
h3 { margin: 0 0 4px; font-size: 14.5px; }
.note { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 700; }
.kpi .s { color: var(--muted); font-size: 12.5px; }
.kpi .d { color: var(--muted); font-size: 11.5px; margin-top: 4px; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; min-width: 0; }
.span2 { grid-column: span 2; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.tools { display: flex; gap: 10px; align-items: center; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.card-h .tools { margin: 0; }
.chart { position: relative; height: 280px; }
.chart.tall { height: 420px; }
.chart.short { height: 180px; }

.table-wrap { overflow: auto; max-height: 560px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
td:first-child { white-space: normal; min-width: 220px; }
th { position: sticky; top: 0; background: var(--card); cursor: pointer; user-select: none; color: var(--muted); font-weight: 600; }
th.asc::after { content: " ▲"; } th.desc::after { content: " ▼"; }
td.num { position: relative; text-align: right; min-width: 90px; }
td.num span { position: relative; }
.cell-bar { position: absolute; left: 4px; top: 25%; bottom: 25%; width: calc((100% - 8px) * var(--w) / 100); background: rgba(78,121,167,.28); border-radius: 2px; }
tbody tr:hover { background: rgba(255,255,255,.03); }

.stat-list, .notes { margin: 0; padding-left: 18px; }
.stat-list li { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; border-bottom: 1px dashed var(--line); list-style: none; margin-left: -18px; }
.stat-list li span { flex: 1; }
.notes li { margin: 4px 0; color: var(--muted); }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; border-top: 1px solid var(--line); }

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; } .span2 { grid-column: auto; }
  header { position: static; }
}

.sync { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; max-width: 1400px; margin: 10px auto 0; padding: 8px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; font-size: 12.5px; color: var(--muted); }
.sync b { color: var(--text); }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.sync.busy .dot { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.sync .track { flex: 1; min-width: 120px; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.sync .bar { height: 100%; width: 0; background: var(--accent); transition: width .6s; }
.sync button { padding: 2px 10px; font-size: 12px; }
@keyframes pulse { 50% { opacity: .3; } }
@media (max-width: 1448px) { .sync { margin-left: 24px; margin-right: 24px; } }
