:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #e2e6ea;
  --text: #1f2933;
  --muted: #6b7785;
  --accent: #2f6fed;
  --accent-dark: #1f56c4;
  --ok: #1f9d55;
  --warn: #d97706;
  --bad: #d64545;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 50, .08), 0 6px 20px rgba(20, 30, 50, .06);
  /* ── тема и цвета: всё, что можно перенастроить ── */
  --soft: #eef2f7;            /* мягкие плашки, наведение */
  --soft-2: #f7f9fc;          /* очень светлые полосы таблиц */
  --on-accent: #ffffff;       /* текст на акценте */
  --st-new-bg: #fdecec;       /* статусы: фон / текст */
  --st-new-fg: #d64545;
  --st-await-bg: #fff4e5;
  --st-await-fg: #d97706;
  --st-paid-bg: #e8f6ee;
  --st-paid-fg: #1f9d55;
  --st-storage-bg: #fff4e5;
  --st-storage-fg: #d97706;
  --st-issued-bg: #e8f6ee;
  --st-issued-fg: #1f9d55;
  --st-failed-bg: #fdecec;
  --st-failed-fg: #d64545;
  --st-scrap-bg: #eef2f7;
  --st-scrap-fg: #6b7785;
  --st-blacklist-bg: #2b2f3a;
  --st-blacklist-fg: #ffffff;
  --row-cut: #f3e9ff;         /* строки в списке заказов */
  --row-cdek: #e3f6dc;
  /* метки клиентов */
  --cl-phone-bg: #fff4e5;
  --cl-phone-fg: #d97706;
  --cl-note-bg: #eef2f7;
  --cl-note-fg: #6b7785;
  --cl-bronze-bg: #f6e3d0;
  --cl-bronze-fg: #96581d;
  --cl-gold-bg: #fbeec2;
  --cl-gold-fg: #8a6d1a;
  --cl-platinum-bg: #e4e8ef;
  --cl-platinum-fg: #38506f;
  --cl-rhythm-ok-bg: #e8f6ee;
  --cl-rhythm-ok-fg: #1f9d55;
  --cl-rhythm-pause-bg: #fff4e5;
  --cl-rhythm-pause-fg: #d97706;
  --cl-rhythm-late-bg: #fff4e5;
  --cl-rhythm-late-fg: #b45309;
  --cl-rhythm-long-bg: #fdecec;
  --cl-rhythm-long-fg: #d64545;
  --wait-file-bg: #fff4e5;
  --wait-file-fg: #d97706;

}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text); background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- каркас ---------- */
header {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
header h1 { font-size: 16px; margin: 0; font-weight: 650; white-space: nowrap; }
header h1 span { color: var(--muted); font-weight: 400; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 8px;
  cursor: pointer; color: var(--muted); font-weight: 500;
}
nav button:hover { background: var(--soft); color: var(--text); }
nav button.active { background: var(--accent); color: var(--on-accent); }
.spacer { flex: 1; }
main { padding: 18px 20px 60px; max-width: 1500px; margin: 0 auto; }
.hidden { display: none !important; }

/* ---------- сайдбар ---------- */
.app { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { font-size: 17px; font-weight: 700; padding: 16px 18px 4px; }
.sidebar .brand span { color: var(--muted); font-weight: 400; font-size: 11.5px; display: block; margin-top: 2px; }
.sidebar nav { flex-direction: column; gap: 2px; padding: 10px; flex-wrap: nowrap; }
.sidebar nav button { text-align: left; padding: 9px 12px; border-radius: 8px; width: 100%; }
.sidebar nav button.active { background: var(--accent); color: var(--on-accent); }
.sidebar nav .sep { height: 1px; background: var(--line); margin: 8px 4px; }
.sidebar .side-foot {
  margin-top: auto; padding: 12px 18px; font-size: 11.5px; color: var(--muted);
  border-top: 1px solid var(--line); line-height: 1.5;
}
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 15px; margin: 0; font-weight: 650; }
.topbar h1 span { color: var(--muted); font-weight: 400; font-size: 13px; }
.main-col { min-width: 0; }
.main-col main { max-width: none; }

/* ---------- карточки и панели ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 15px; font-weight: 650; }
.panel h2 .sub { color: var(--muted); font-weight: 400; font-size: 13px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.card .value { font-size: 21px; font-weight: 650; margin-top: 4px; }
.card .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.card.accent .value { color: var(--accent); }
.card.bad .value { color: var(--bad); }
.card.ok .value { color: var(--ok); }
.card.warn .value { color: var(--warn); }

/* ---------- формы ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: var(--panel);
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #cfe0ff; border-color: var(--accent); }

/* выпадающий список подсказок (выбор клиента) */
.ac-list {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 60; margin-top: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(20, 30, 50, .14); max-height: 260px; overflow: auto;
}
.ac-row { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid #f1f4f7; line-height: 1.35; }
.ac-row:last-child { border-bottom: 0; }
.ac-row:hover { background: var(--soft); }
.ac-row b { font-weight: 600; }
.ac-mail { color: var(--muted); font-size: 12px; margin-left: 6px; }
.ac-meta { color: var(--muted); font-size: 11.5px; margin-left: 6px; }
.ac-empty { padding: 8px 10px; color: var(--muted); font-size: 12.5px; }

/* дни рождения на сводке */
.bd-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 7px 10px; border-radius: 8px; cursor: pointer;
}
.bd-row:hover { background: var(--soft); }
.bd-row.soon { opacity: .85; }
.bd-meta { color: var(--muted); font-size: 12px; }
.bd-when { color: var(--muted); font-size: 12px; min-width: 42px; }

/* бонусы и уровни */
.pill.lvl-bronze { background: #f6e3d0; color: #96581d; }
.pill.lvl-gold { background: #fbeec2; color: #8a6d1a; }
.pill.lvl-platinum { background: #e4e8ef; color: #38506f; }
.pill.bonus { background: #e6f4ea; color: #1f7a45; }
.bonus-line { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.progress { height: 6px; background: #eef2f7; border-radius: 4px; overflow: hidden; }
.progress > div { height: 6px; background: var(--accent); border-radius: 4px; }

/* дни рождения: плитки со счётчиками */
.bd-stat { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.bd-stat > span {
  background: var(--soft-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; font-size: 12.5px; color: var(--muted);
}
.bd-stat b { color: var(--text); font-size: 14px; margin-left: 4px; }
.bd-cap { font-size: 12px; color: var(--muted); margin: 10px 0 4px; text-transform: uppercase;
  letter-spacing: .04em; }
textarea { resize: vertical; min-height: 60px; }
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 14px;
  cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 13px; }

/* ---------- таблицы ---------- */
.table-wrap { overflow: auto; max-height: 68vh; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; background: var(--panel); }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th {
  position: sticky; top: 0; background: var(--soft-2); z-index: 1; cursor: pointer;
  font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
}
th:hover { color: var(--text); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--soft-2); }
tbody tr.blank { color: var(--muted); font-style: italic; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; max-width: 320px; }
tfoot td { background: var(--soft-2); font-weight: 600; position: sticky; bottom: 0; }
.money-bad { color: var(--bad); font-weight: 600; }
.money-ok { color: var(--ok); }
.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px;
  background: #eef2f7; color: var(--muted);
}
.pill.status { background: var(--st-await-bg); color: var(--st-await-fg); }
.pill.debt { background: var(--st-failed-bg); color: var(--st-failed-fg); }
.pill.paid { background: var(--st-paid-bg); color: var(--st-paid-fg); }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 10px; color: var(--muted); }
.pager .btn { padding: 4px 10px; }

/* ---------- модальные окна ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(20, 28, 44, .45); z-index: 50;
  display: flex; justify-content: center; align-items: flex-start; padding: 40px 16px; overflow: auto;
}
.modal {
  background: var(--panel); border-radius: 12px; box-shadow: 0 20px 60px rgba(10, 20, 40, .3);
  width: min(980px, 100%); padding: 18px 20px;
}
.modal.wide { width: min(1180px, 100%); }
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal .head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.modal .head .close { margin-left: auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 14px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 14px; }
.section { margin-top: 16px; }
.section > h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- диаграммы ---------- */
.chart { width: 100%; height: 220px; }
.chart text { font-size: 10px; fill: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 22px; }
.bars .bar .fill { width: 100%; background: linear-gradient(180deg, #6f9dff, #2f6fed); border-radius: 4px 4px 0 0; }
.bars .bar .cap { font-size: 11px; color: var(--muted); white-space: nowrap; }
.bars .bar:hover .fill { background: var(--accent-dark); }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1f2933; color: var(--on-accent); padding: 10px 18px; border-radius: 8px; z-index: 90;
  box-shadow: var(--shadow);
}
.toast.err { background: var(--bad); }
.empty { color: var(--muted); padding: 20px; text-align: center; }

/* Группы меню: разделы как в 1С */
.nav-group { margin-bottom: 2px; }
.nav-head {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 9px 12px; border: 0; background: transparent;
  font: inherit; font-size: 11.5px; font-weight: 700; letter-spacing: .4px;
  text-transform: uppercase; color: var(--muted); cursor: pointer;
  border-radius: 8px;
}
.nav-head:hover { background: rgba(47, 111, 237, .07); color: #2f6fed; }
.nav-head .caret { font-size: 10px; opacity: .7; }
.nav-items { display: flex; flex-direction: column; gap: 1px; margin: 2px 0 6px; }
.nav-items button { margin-left: 6px; }

/* ── тёмная тема ─────────────────────────────────────────────── */
body[data-theme="dark"] {
  --bg: #161a22;
  --panel: #1e2430;
  --line: #2c3444;
  --text: #e8ecf4;
  --muted: #8d97a8;
  --soft: #262d3b;
  --soft-2: #202634;
  --on-accent: #ffffff;
  --st-new-bg: #3a2326;
  --st-new-fg: #ff9a9a;
  --st-await-bg: #3a2f1c;
  --st-await-fg: #ffc166;
  --st-paid-bg: #1c3327;
  --st-paid-fg: #6fd39a;
  --st-storage-bg: #3a2f1c;
  --st-storage-fg: #ffc166;
  --st-issued-bg: #1c3327;
  --st-issued-fg: #6fd39a;
  --st-failed-bg: #3a2326;
  --st-failed-fg: #ff9a9a;
  --st-scrap-bg: #2c3444;
  --st-scrap-fg: #b6c0d0;
  --st-blacklist-bg: #e8ecf4;
  --st-blacklist-fg: #161a22;
  --row-cut: #2b2340;
  --row-cdek: #1d3a26;
  --wait-file-bg: #3a2f1c;
  --wait-file-fg: #ffc166;
  --cl-phone-bg: #3a2f1c;
  --cl-phone-fg: #ffc166;
  --cl-note-bg: #2c3444;
  --cl-note-fg: #b6c0d0;
  --cl-bronze-bg: #3d2c1c;
  --cl-bronze-fg: #e2b183;
  --cl-gold-bg: #3a3418;
  --cl-gold-fg: #e8d27a;
  --cl-platinum-bg: #2a3444;
  --cl-platinum-fg: #a9c2e0;
  --cl-rhythm-ok-bg: #1c3327;
  --cl-rhythm-ok-fg: #6fd39a;
  --cl-rhythm-pause-bg: #3a2f1c;
  --cl-rhythm-pause-fg: #ffc166;
  --cl-rhythm-late-bg: #3d2c1c;
  --cl-rhythm-late-fg: #ffab5e;
  --cl-rhythm-long-bg: #3a2326;
  --cl-rhythm-long-fg: #ff9a9a;
}
