:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2230;
  --muted: #6b7385;
  --border: #e3e6ec;
  --accent: #2457c5;
  --accent-soft: #e8eefb;
  --bar: #9db6ea;
  --warn: #b5530c;
  --warn-soft: #fdf1e6;
  --row-hover: #f7f9fd;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1e26;
    --text: #e6e9ef;
    --muted: #98a0b1;
    --border: #2a303b;
    --accent: #7ea2ff;
    --accent-soft: #23304d;
    --bar: #3d5ba8;
    --warn: #f0a160;
    --warn-soft: #3a2a1c;
    --row-hover: #20252f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); margin: 2px 0 0; }
button, input { font: inherit; color: inherit; }
button {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 7px 14px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
input { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 10px; }
input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px;
}
.login-card label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.login-card input { color: var(--text); padding: 10px 12px; }
.error { color: #d23c3c; min-height: 1.2em; margin: 0; font-size: 14px; }

/* каркас */
main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 40px; }
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.date { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
  display: grid; gap: 4px; text-align: left; box-shadow: var(--shadow);
}
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi-warn .kpi-value { color: var(--warn); }
.kpi-warn.active { background: var(--warn-soft); border-color: var(--warn); }

.filters { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border-radius: 999px; padding: 5px 12px; font-size: 14px; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip small { color: var(--muted); margin-left: 4px; }
.filter-right { display: flex; gap: 8px; }
#search { width: 300px; max-width: 60vw; }
.status { color: var(--muted); font-size: 14px; min-height: 1.3em; margin: 4px 0 8px; }
.status.err { color: #d23c3c; }

/* таблица */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  overflow-x: auto; box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; }
thead th {
  position: sticky; top: 0; background: var(--surface); font-size: 13px; color: var(--muted);
  font-weight: 600; cursor: pointer; user-select: none; z-index: 1;
}
thead th.sorted { color: var(--text); }
tbody tr.sup { cursor: pointer; }
tbody tr.sup:hover { background: var(--row-hover); }
tbody tr.sup.open { background: var(--accent-soft); }
td.name { min-width: 200px; }
td.name .caret { display: inline-block; width: 14px; color: var(--muted); transition: transform .15s; }
tr.open td.name .caret { transform: rotate(90deg); }
td.total { font-weight: 650; }
td.share { width: 150px; }
.bar { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.bar span.track { width: 80px; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.bar span.fill { display: block; height: 100%; background: var(--bar); }
.zero { color: var(--muted); }
tfoot td { font-weight: 700; border-bottom: none; }

tr.detail > td { padding: 0 0 0 26px; background: var(--bg); }
table.items { font-size: 14px; }
table.items th { position: static; cursor: default; background: transparent; }
table.items td.item { white-space: normal; min-width: 260px; }
table.items .art { color: var(--muted); font-size: 12px; display: block; }
table.items tr.noprice td { color: var(--warn); }
.more { padding: 8px 12px; color: var(--muted); font-size: 13px; }
.note { font-size: 12px; margin-top: 12px; }

@media (max-width: 760px) {
  h1 { font-size: 19px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 19px; }
  .wh-col, td.share { display: none; }
  #search { width: 100%; max-width: none; }
  .filter-right { width: 100%; }
  th, td { padding: 8px; }
  tr.detail > td { padding-left: 0; }
  table.items .wh-in-item { display: block; color: var(--muted); font-size: 12px; }
}
@media (min-width: 761px) { table.items .wh-in-item { display: none; } }
