:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e3e6ea;
  --text: #171a1f;
  --muted: #6b7280;
  --accent: #2f6df6;
  --accent-soft: #e8efff;
  --bar: #2f6df6;
  --bar-soft: #dbe6ff;
  --danger: #c02b3a;
  --danger-soft: #fdecee;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1c2128;
    --border: #2a313a;
    --text: #e6e9ee;
    --muted: #9aa4b2;
    --accent: #6f9bff;
    --accent-soft: #1d2a45;
    --bar: #6f9bff;
    --bar-soft: #26324b;
    --danger: #ff8b95;
    --danger-soft: #3a1f24;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 13px; }
.muted { color: var(--muted); }

/* --- вход ---------------------------------------------------------------- */

body.auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}

.auth-mark {
  width: 44px; height: 44px;
  margin: 0 auto 14px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 22px; font-weight: 600;
}

.auth-card h1 { font-size: 20px; }
.auth-sub { margin: 6px 0 22px; color: var(--muted); font-size: 14px; }
.auth-card form { text-align: left; }
.auth-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.auth-card input {
  width: 100%; padding: 10px 12px; margin-bottom: 16px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font-size: 15px;
}
.auth-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.auth-card button {
  width: 100%; padding: 11px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 500; cursor: pointer;
}
.auth-card button:hover { filter: brightness(1.06); }

.alert {
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid currentColor; border-radius: 8px;
  padding: 9px 12px; margin-bottom: 18px; font-size: 14px; text-align: left;
}

/* --- шапка --------------------------------------------------------------- */

.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.brand .mark {
  width: 26px; height: 26px; display: grid; place-items: center;
  border-radius: 7px; background: var(--accent-soft); color: var(--accent); font-size: 15px;
}
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 6px 12px; border-radius: 7px; color: var(--muted); font-size: 14px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.user { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user .who { font-weight: 500; }
.user .role {
  padding: 2px 8px; border-radius: 20px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.logout { color: var(--muted); }
.logout:hover { color: var(--danger); }

/* --- каркас -------------------------------------------------------------- */

.wrap { max-width: 1240px; margin: 0 auto; padding: 20px 24px 60px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.card-head h2 { font-size: 15px; }
.card-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.hint { margin-left: auto; font-size: 12px; color: var(--muted); }
.counter { color: var(--muted); font-weight: 400; font-size: 13px; }

.cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 1100px) { .cols { grid-template-columns: 1fr 1fr; } }
@media (max-width: 720px) { .cols { grid-template-columns: 1fr; } }

/* --- фильтры ------------------------------------------------------------- */

.filters { padding: 14px 18px; }
.filters-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters-row + .filters-row { margin-top: 10px; }
.spacer { flex: 1; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 500; }

.field { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.field.grow { flex: 1; min-width: 150px; }
.field.small { font-size: 12px; }
.field input, .field select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font-size: 14px; width: 100%;
}
.field input[type=date] { width: auto; }
.field select:focus, .field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.ghost {
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font-size: 13px; cursor: pointer;
  display: inline-block;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }

.active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 10px; border-radius: 20px; font-size: 12px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid transparent;
}
.tag button {
  border: 0; background: transparent; color: inherit; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 0 2px;
}

/* --- KPI ----------------------------------------------------------------- */

.kpis {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px;
}
@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, 1fr); } }

.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px;
}
.kpi .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi .value { font-size: 22px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* --- график -------------------------------------------------------------- */

.chart { display: flex; align-items: flex-end; gap: 10px; height: 190px; padding-top: 20px; }
.bar-wrap { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; cursor: pointer; }
.bar-val { font-size: 11px; color: var(--muted); text-align: center; margin-bottom: 5px; font-variant-numeric: tabular-nums; }
.bar { background: var(--bar-soft); border-radius: 6px 6px 0 0; min-height: 3px; transition: background .12s; }
.bar-wrap:hover .bar, .bar-wrap.on .bar { background: var(--bar); }
.bar-lbl { font-size: 11px; color: var(--muted); text-align: center; margin-top: 6px; }

/* --- разрезы ------------------------------------------------------------- */

.breakdown { display: flex; flex-direction: column; gap: 2px; }
.breakdown.scrollable { max-height: 340px; overflow-y: auto; }

.row {
  display: grid; grid-template-columns: 1fr auto auto;
  gap: 12px; align-items: center;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; position: relative;
}
.row:hover { background: var(--surface-2); }
.row.on { background: var(--accent-soft); }
.row .name { font-size: 14px; z-index: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .name small { color: var(--muted); font-size: 12px; margin-left: 6px; }
.row .sum { font-size: 14px; font-variant-numeric: tabular-nums; font-weight: 500; z-index: 1; }
.row .pct { font-size: 12px; color: var(--muted); width: 46px; text-align: right; z-index: 1; }
.row .fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--bar-soft); border-radius: 8px; opacity: .55;
}

/* --- операции ------------------------------------------------------------ */

.table-scroll { overflow-x: auto; }
table.ops { width: 100%; border-collapse: collapse; font-size: 14px; }
table.ops th {
  text-align: left; font-size: 12px; font-weight: 500; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.ops th.sortable { cursor: pointer; user-select: none; }
table.ops th.sortable:hover { color: var(--text); }
table.ops th.num, table.ops td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.ops td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.ops tr:last-child td { border-bottom: 0; }
table.ops tbody tr:hover { background: var(--surface-2); }
td.desc { max-width: 380px; }
td.desc .msg { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
td.date { white-space: nowrap; color: var(--muted); }
td.date b { color: var(--text); font-weight: 400; display: block; }
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px;
  background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap;
}

.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; font-size: 13px; color: var(--muted); }
.pager button[disabled] { opacity: .4; cursor: default; }

.empty { padding: 26px; text-align: center; color: var(--muted); font-size: 14px; }
.foot { margin-top: 22px; font-size: 12px; color: var(--muted); line-height: 1.6; max-width: 760px; }

.placeholder h2 { font-size: 17px; margin-bottom: 10px; }
.placeholder p { margin: 8px 0; }
.placeholder .ghost { margin-top: 12px; }

.loading { opacity: .5; transition: opacity .1s; }
