:root {
  --bg: #f4f1ec; --panel: #ffffff; --panel2: #f8f5f0; --line: #e3ddd3; --text: #2b241d; --muted: #7a6f63;
  --accent: #b5632a; --accent2: #2f7f86; --good: #2e8b57; --bad: #c0483b; --warn: #c08a1f;
  --c1: #b5632a; --c2: #2f7f86; --c3: #7b5ea7; --c4: #c08a1f; --c5: #4d8f3a; --c6: #c0483b;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08);
  --heat: 181, 99, 42;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17130f; --panel: #211b16; --panel2: #2a231c; --line: #3a3027; --text: #efe7dc; --muted: #a39686;
    --accent: #e0894a; --accent2: #5fb3ba; --good: #5cc08a; --bad: #e0776b; --warn: #e0b04a;
    --c1: #e0894a; --c2: #5fb3ba; --c3: #a78bd6; --c4: #e0b04a; --c5: #7bc067; --c6: #e0776b;
    --shadow: none; --heat: 224, 137, 74;
  }
}
:root[data-theme="dark"] {
  --bg: #17130f; --panel: #211b16; --panel2: #2a231c; --line: #3a3027; --text: #efe7dc; --muted: #a39686;
  --accent: #e0894a; --accent2: #5fb3ba; --good: #5cc08a; --bad: #e0776b; --warn: #e0b04a;
  --c1: #e0894a; --c2: #5fb3ba; --c3: #a78bd6; --c4: #e0b04a; --c5: #7bc067; --c6: #e0776b;
  --shadow: none; --heat: 224, 137, 74;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 1.3em; margin: 0; }
h1, h2, h3 { margin: 0; font-weight: 650; }
h2 { font-size: 17px; margin-bottom: 10px; }
h3 { font-size: 14px; margin-bottom: 8px; }

.top { position: sticky; top: 0; z-index: 10; background: var(--panel); border-bottom: 1px solid var(--line); box-shadow: var(--shadow); }
.top-row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; padding: 10px 16px 6px; }
.brand { font-size: 20px; letter-spacing: .5px; padding-bottom: 4px; }
.brand b { color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; flex: 1; }
.filters label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 2px; }
select, input, button { font: inherit; color: var(--text); }
select, input { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; min-height: 34px; }
.presets { display: flex; gap: 4px; flex-wrap: wrap; }
.presets button, .btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; min-height: 34px; cursor: pointer; }
.presets button.on, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.icon { width: 34px; padding: 0; }
.btn:hover, .presets button:hover { border-color: var(--accent); }
.actions { display: flex; gap: 6px; padding-bottom: 1px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; padding: 0 12px; scrollbar-width: thin; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 9px 12px; cursor: pointer; white-space: nowrap; color: var(--muted); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.status { padding: 6px 16px; font-size: 12px; color: var(--muted); min-height: 26px; }
main { padding: 6px 16px 40px; max-width: 1280px; margin: 0 auto; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 14px; }
.card .note { color: var(--muted); font-size: 12px; margin: -4px 0 10px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.kpi .v { font-size: 26px; font-weight: 700; line-height: 1.15; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi .s { color: var(--muted); font-size: 11px; margin-top: 2px; }
.chart { position: relative; height: 260px; }
.chart.tall { height: 330px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
.scroll { overflow-x: auto; }
.scroll.maxh { max-height: 520px; overflow-y: auto; }
td.wrap { white-space: normal; text-align: left; word-break: break-word; }

.heat td { padding: 4px 6px; font-size: 11.5px; min-width: 42px; text-align: center; border-bottom: 0; border-right: 1px solid var(--panel); }
.heat th { text-align: center; }
.heat td:first-child, .heat th:first-child { text-align: left; position: sticky; left: 0; background: var(--panel); z-index: 1; }
.heat td.na { color: var(--muted); opacity: .4; }

.fun { display: grid; grid-template-columns: minmax(120px, 230px) 1fr minmax(150px, 270px); gap: 3px 12px; align-items: center; }
.fun .lab { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fun .bar { position: relative; height: 24px; background: var(--panel2); border-radius: 6px; overflow: hidden; }
.fun .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent2); border-radius: 6px; min-width: 2px; }
.fun .bar span { position: relative; z-index: 1; padding: 0 8px; font-size: 12px; line-height: 24px; white-space: nowrap; color: #fff; text-shadow: 0 0 3px rgba(0,0,0,.55); font-weight: 600; }
.fun .info { font-size: 12px; color: var(--muted); white-space: nowrap; }
.fun .info b.loss { color: var(--bad); margin-left: 8px; }
.fun .bar em { font-style: normal; color: var(--muted); margin-left: 6px; }
.fun .bar em.loss { color: var(--bad); }
.fun .bar em.ok { color: var(--good); }

.pair { display: grid; grid-template-columns: minmax(110px, 190px) 1fr 70px; gap: 3px 12px; align-items: center; margin-bottom: 8px; }
.pair .bars { display: flex; flex-direction: column; gap: 3px; }
.pair .b { position: relative; height: 14px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.pair .b i { position: absolute; inset: 0 auto 0 0; border-radius: 4px; }
.pair .b span { position: relative; font-size: 10.5px; padding-left: 6px; line-height: 14px; }
.pair .rate { font-weight: 650; text-align: right; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }

.hbars { display: grid; grid-template-columns: minmax(80px, 170px) 1fr 54px; gap: 4px 10px; align-items: center; font-size: 12.5px; }
.hbars .b { height: 14px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.hbars .b i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.hbars .n { text-align: right; color: var(--muted); }
.hbars .l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; align-items: flex-end; }
.row label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 2px; }
.pill { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; background: var(--panel2); border: 1px solid var(--line); }
.pill.bad { color: var(--bad); } .pill.warn { color: var(--warn); }
.empty { color: var(--muted); padding: 24px; text-align: center; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.login-card input { width: 100%; }

@media (max-width: 640px) {
  .top { position: static; }
  .top-row { padding: 8px 12px 4px; gap: 8px; }
  .filters { gap: 6px 8px; }
  .filters { width: 100%; }
  .filters label { flex: 1 1 42%; min-width: 0; }
  .filters select, .filters input { width: 100%; }
  .presets { flex: 1 1 100%; }
  .presets button { flex: 1; }
  .brand { width: 100%; padding-bottom: 0; }
  .actions { width: 100%; }
  main { padding: 4px 12px 40px; }
  .fun { grid-template-columns: 1fr; }
  .fun .info { margin-bottom: 2px; }
  .fun .lab { margin-top: 6px; }
  .pair { grid-template-columns: 1fr 56px; }
  .pair .lab { grid-column: 1 / 3; }
  .kpi .v { font-size: 22px; }
}
.grid > .card { margin-top: 0; }

.scroll.left th, .scroll.left td { text-align: left; }
