:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e5e7eb;
  --brand: #2f5bea; --brand-d: #2347c2; --red: #d33b3b; --red-bg: #fdeeee; --orange: #c46a0a; --orange-bg: #fff4e5;
  --green: #18864b; --green-bg: #e8f6ee; --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }

.layout { display: flex; min-height: 100vh; }
.side { width: 220px; background: #1d2330; color: #cfd5e2; padding: 18px 12px; flex-shrink: 0; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.side .logo { font-weight: 700; color: #fff; font-size: 18px; padding: 0 10px 18px; }
.side nav a { display: block; color: #cfd5e2; padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
.side nav a.active, .side nav a:hover { background: #2c3446; color: #fff; }
.side .me { margin-top: auto; padding: 10px; font-size: 13px; border-top: 1px solid #2c3446; }
.side .me b { color: #fff; display: block; }
.side .me a { color: #9fb3ff; margin-right: 10px; }
.main { flex: 1; padding: 22px 26px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.mobile-bar { display: none; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; white-space: nowrap; }
.stat .sub { color: var(--muted); font-size: 12px; }
.stat.red .value { color: var(--red); }
.stat.orange .value { color: var(--orange); }
.stat.green .value { color: var(--green); }
.two { grid-template-columns: 1fr 1fr; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #fafbfc; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7f9ff; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.table-wrap table tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; background: #fafbfc; }
.empty { padding: 26px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.gray { background: #eef0f3; color: var(--muted); }
.badge.blue { background: #e9efff; color: var(--brand); }
.muted { color: var(--muted); }
.red-t { color: var(--red); font-weight: 600; }

button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button:hover { border-color: #c9ced6; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: var(--brand-d); }
button.danger { color: var(--red); border-color: #f2c4c4; }
button.small { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }

input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #d3d7de; border-radius: 8px; background: #fff; width: 100%; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d4ff; border-color: var(--brand); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters input, .filters select { width: auto; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border-radius: 99px; }
.tabs button.on { background: var(--text); color: #fff; border-color: var(--text); }

.modal-bg { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 14px; overflow-y: auto; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 860px; }
.modal h2 { display: flex; justify-content: space-between; align-items: center; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.error { background: var(--red-bg); color: var(--red); padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; }
.x { border: 0; background: none; font-size: 22px; padding: 0 4px; color: var(--muted); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2330; color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; }
#toast.show { opacity: 1; }

.login { max-width: 360px; margin: 12vh auto; }
.login h1 { margin-bottom: 18px; text-align: center; }
.items-table td { padding: 6px; }
.items-table input, .items-table select { padding: 6px 8px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; }
.kv div:nth-child(odd) { color: var(--muted); }
.bar { height: 8px; background: #eef0f3; border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--red); }

@media (max-width: 820px) {
  .layout { display: block; }
  .side { position: fixed; left: -240px; z-index: 40; transition: left .2s; width: 230px; }
  .side.open { left: 0; }
  .mobile-bar { display: flex; align-items: center; gap: 10px; background: #1d2330; color: #fff; padding: 10px 14px; position: sticky; top: 0; z-index: 30; }
  .mobile-bar button { background: none; border: 0; color: #fff; font-size: 22px; padding: 0 6px; }
  .main { padding: 14px; }
  .two { grid-template-columns: 1fr; }
  .row { flex-direction: column; gap: 0; }
  .kv { grid-template-columns: 1fr; }
  .kv div:nth-child(odd) { margin-top: 6px; }
}

/* Конструктор отчётов */
.rb-row { display: flex; gap: 12px; flex-wrap: wrap; }
.rb-row .field { flex: 1; min-width: 150px; }
.checks { display: flex; gap: 16px; flex-wrap: wrap; }
.checks label { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 14px; margin: 0; cursor: pointer; }
.checks input { width: auto; }
.rep-title { color: #1f3864; font-size: 19px; margin: 4px 0 10px; }
table.rep { min-width: 420px; }
table.rep th { background: #1f3864; color: #fff; font-size: 14px; text-transform: none; letter-spacing: 0; }
table.rep td { border-bottom: 1px solid #d9dee8; }
table.rep td.it { font-style: italic; padding-left: 18px; }
table.rep tr.blk td { font-weight: 700; }
table.rep tr.blk.opening td, table.rep tr.blk.closing td { background: #1f3864; color: #fff; }
table.rep tr.blk.shipped td, table.rep tr.blk.paid td { background: #d9e1f2; color: #1f3864; }
table.rep tr.opening:not(.blk) td, table.rep tr.closing:not(.blk) td { background: #eef2fb; }
table.rep tr.paid:not(.blk) td.num { color: #1a3fd6; }
@media print { .side, .mobile-bar, .rb, .topbar { display: none !important; } .main { padding: 0; } }
