:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --pos: #15803d; --neg: #b91c1c; --warnbg: #fff7e6; --warnline: #f0c36d;
  --chip: #eef2ff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --card: #1b1f27; --text: #e5e7eb; --muted: #9aa3b2; --line: #2b313c;
    --accent: #60a5fa; --pos: #4ade80; --neg: #f87171; --warnbg: #2a2416; --warnline: #7a5f22; --chip: #232a3a;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
.hidden { display: none !important; }
header { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
nav a { padding: 6px 12px; border-radius: 6px; color: var(--text); text-decoration: none; }
nav a.active { background: var(--chip); color: var(--accent); font-weight: 600; }
main { padding: 16px 20px 40px; max-width: 1500px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; }
h3 { margin: 0 0 10px; font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }
code { background: var(--chip); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
button, .btn { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 7px 14px; font: inherit; cursor: pointer; text-decoration: none; display: inline-block; }
button.ghost, .btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--neg); border: 1px solid var(--line); padding: 4px 8px; }
button:disabled { opacity: .5; cursor: default; }
input, select { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--text); }
label { display: inline-flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label input, .stack label select { color: var(--text); }
fieldset { border: 1px solid var(--line); border-radius: 6px; }
legend { color: var(--muted); font-size: 13px; }
.inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin: 10px 0; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.mkts { display: flex; gap: 10px; flex-wrap: wrap; }
.mkts label { flex-direction: row; align-items: center; gap: 4px; color: var(--text); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi .v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .s { color: var(--muted); font-size: 12px; }
.kpi.main { border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } header { gap: 10px; flex-wrap: wrap; } }
.chartbox { position: relative; height: 300px; }
table { border-collapse: collapse; width: 100%; }
.pl td { padding: 5px 4px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.pl td:last-child { text-align: right; }
.pl td.pct { color: var(--muted); text-align: right; width: 60px; font-size: 12px; }
.pl tr.sub td:first-child { padding-left: 18px; color: var(--muted); }
.pl tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
.tablewrap { overflow-x: auto; }
.data th, .data td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.data th { font-size: 12px; color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--card); }
.data th:first-child, .data td:first-child { text-align: left; }
.data td.prod { white-space: normal; min-width: 260px; max-width: 420px; }
.data td.prod .t { display: flex; gap: 8px; align-items: center; }
.data td.prod img { width: 32px; height: 32px; object-fit: contain; border-radius: 4px; background: #fff; }
.data td.prod .sku { color: var(--muted); font-size: 12px; }
.data tr.acct td { background: var(--chip); }
.data.small td, .data.small th { font-size: 12px; padding: 4px 6px; }
.data.small td.msg { text-align: left; white-space: normal; max-width: 700px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.warn { background: var(--warnbg); border: 1px solid var(--warnline); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; font-size: 13px; }
.warn a { color: var(--accent); }
.counts { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; }
.periods { background: var(--bg); }
.periods td { text-align: left !important; }
.periods table td, .periods table th { padding: 4px; border: 0; text-align: left; }
.periods input { width: 90px; }
.periods input[name=note] { width: 200px; }
.periods input[type=date] { width: 140px; }
.badge { display: inline-block; padding: 1px 6px; border-radius: 10px; font-size: 11px; background: var(--chip); color: var(--muted); }
.badge.err { background: #fde2e2; color: #991b1b; }
.badge.ok { background: #dcfce7; color: #166534; }
.login { min-height: 100vh; display: grid; place-items: center; }
.login form { width: 320px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0 0 6px; font-size: 20px; }
.err { color: var(--neg); min-height: 1em; margin: 0; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; max-width: 420px; z-index: 50; }
