:root {
  /* «Наша» тема (за замовчуванням): темне меню, світла робоча частина */
  --side-bg: #2b2f36;
  --side-hover: #353a42;
  --side-active: #3d434c;
  --side-text: #e6e8eb;
  --side-muted: #8b929c;
  --side-sep: #444a53;
  --brand-name: #d9b968;
  --accent: #2f7fe0;
  --dot: #33b5ff;
  --bg: #ffffff;
  --surface: #ffffff;
  --panel: #f5f6f8;
  --panel2: #fbfbfc;
  --soft-panel: #eef3fb;
  --hover: #f4f6f8;
  --accent-soft: #e3edfb;
  --chip: #eef0f3;
  --line: #e3e6ea;
  --border: #cfd4da;
  --head: #eef0f3;
  --text: #1f2328;
  --muted: #6b7280;
  --faint: #b4b9c0;
  --link: #2f7fe0;
  --green: #3bb54a;
  --danger: #d93a3a;
  --danger-soft: #fdeaea;
  --danger-line: #f3c2c2;
  --warn: #f0952b;
  --warn-soft: #fff4e0;
  --warn-text: #9a5b00;
  --dark: #3a3f47;
  --focus: #bcd6f7;
  --bubble-in: #f1f3f6;
  --bubble-out: #e7f0fd;
  --grp: #e6f6ea;
  --grp-hover: #d9f0df;
  --grp-sel: #d4ecdc;
  --shadow: rgba(0,0,0,.12);
  color-scheme: light;
}

/* Світла тема: світле і бічне меню */
:root[data-theme="light"] {
  --side-bg: #f5f6f8;
  --side-hover: #eaedf1;
  --side-active: #e3edfb;
  --side-text: #1f2328;
  --side-muted: #8b929c;
  --side-sep: #dfe3e8;
  --brand-name: #a8812c;
}

/* Темна тема */
:root[data-theme="dark"] {
  --side-bg: #121418;
  --side-hover: #1d2026;
  --side-active: #262a32;
  --side-text: #e6e8eb;
  --side-muted: #7d848e;
  --side-sep: #2a2e35;
  --accent: #4a90ea;
  --link: #6aa6f0;
  --bg: #171a1f;
  --surface: #1f2329;
  --panel: #262a31;
  --panel2: #1b1e23;
  --soft-panel: #1b1f26;
  --hover: #262b33;
  --accent-soft: #23324a;
  --chip: #2b3038;
  --line: #2e333b;
  --border: #3b414b;
  --head: #242830;
  --text: #e4e6ea;
  --muted: #9aa1ab;
  --faint: #5d646e;
  --danger-soft: #3a2224;
  --danger-line: #6b3236;
  --warn-soft: #3a2f1c;
  --warn-text: #f0b45a;
  --dark: #0f1114;
  --focus: #2c4a73;
  --bubble-in: #2a2e36;
  --bubble-out: #23324a;
  --grp: #1f3326;
  --grp-hover: #25402e;
  --grp-sel: #2a4733;
  --shadow: rgba(0,0,0,.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

.app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 220px; flex: none; background: var(--side-bg); color: var(--side-text);
  display: flex; flex-direction: column; transition: width .15s ease;
}
.brand { display: flex; flex-direction: column; align-items: center; padding: 18px 0 14px; gap: 6px; }
.brand-mark {
  width: 64px; height: 64px; border-radius: 50%; background: #fff; color: #222;
  border: 3px solid #c9a24b; display: grid; place-items: center;
  font: 700 34px/1 Georgia, "Times New Roman", serif;
}
.brand-name { font: 600 13px/1 Georgia, serif; letter-spacing: 3px; color: var(--brand-name); }
.menu { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 6px 0; scrollbar-width: none; } /* прокрутка колесом або пальцем, без смуги */
.menu::-webkit-scrollbar { display: none; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 22px;
  background: none; border: 0; color: var(--side-text); text-align: left; font-size: 15px;
  border-left: 4px solid transparent; position: relative;
}
.menu-item svg { width: 20px; height: 20px; flex: none; }
.menu-item:hover:not(:disabled) { background: var(--side-hover); }
.menu-item.active { background: var(--side-active); border-left-color: var(--accent); }
.menu-item:disabled { color: var(--side-muted); cursor: default; }
.menu-sep { height: 1px; background: var(--side-sep); margin: 6px 22px; }
.last-letter { position: relative; }
.has-new .last-letter::after {
  content: ""; position: absolute; left: calc(100% + 6px); top: 50%; transform: translateY(-50%);
  width: 7px; height: 7px; border-radius: 50%; background: var(--dot);
}
.icon-dot { display: none; }
.collapse-btn {
  border: 0; background: none; color: var(--side-muted); padding: 14px 22px; text-align: left;
  border-top: 1px solid var(--side-sep);
}
.collapse-btn svg { width: 20px; height: 20px; transition: transform .15s; }
.collapse-btn:hover { color: var(--side-text); }

.app.collapsed .sidebar { width: 64px; }
.app.collapsed .brand-mark { width: 40px; height: 40px; font-size: 22px; border-width: 2px; }
.app.collapsed .brand-name, .app.collapsed .menu-label { display: none; }
.app.collapsed .menu-item { padding: 13px 0; justify-content: center; }
.app.collapsed .menu-sep { margin: 6px 12px; }
.app.collapsed .collapse-btn { text-align: center; padding: 14px 0; }
.app.collapsed .collapse-btn svg { transform: rotate(180deg); }
.app.collapsed .has-new .icon-dot {
  display: block; position: absolute; top: 9px; left: 38px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--dot);
}

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 14px 24px;
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 28px; font-weight: 400; margin: 0; flex: 1; }
.search {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 3px;
  padding: 0 10px; height: 38px; width: 280px; color: var(--muted);
}
.search svg { width: 18px; height: 18px; }
.search input { border: 0; outline: 0; flex: 1; min-width: 0; height: 100%; background: transparent; }
.home-empty { padding: 40px 24px; color: var(--muted); }

.content { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 18px 24px 12px; gap: 14px; }

.tiles { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; }
.tile {
  min-width: 190px; padding: 10px 16px; border-radius: 3px; color: #fff;
  display: flex; flex-direction: column; justify-content: center;
}
.tile b { font-size: 20px; font-weight: 600; }
.tile span { font-size: 14px; opacity: .95; }
.tile.blue { background: var(--accent); }
.tile.orange { background: var(--warn); }
.tile.green { background: var(--green); }
.tile.dark { background: var(--dark); }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; position: relative; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 3px; color: var(--text); white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: #33a342; }
.btn.blue { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.blue:hover { background: #2470cc; }
.btn.danger { color: var(--danger); border-color: var(--danger-line); }
.btn.danger:hover { background: var(--danger-soft); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.link { border: 0; background: none; color: var(--link); padding: 0 4px; height: auto; }
.toolbar .sep { width: 1px; height: 30px; background: var(--line); }
.toolbar .spacer { flex: 1; }
.muted { color: var(--muted); }

.popover {
  position: absolute; top: 44px; z-index: 30; background: var(--surface); border: 1px solid var(--border);
  border-radius: 3px; box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 12px;
}
.cal { width: 300px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head b { text-transform: capitalize; font-weight: 600; }
.cal-nav { border: 0; background: none; width: 30px; height: 30px; border-radius: 3px; }
.cal-nav:hover { background: var(--panel); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-wd { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-day {
  height: 34px; border: 0; background: none; border-radius: 3px; position: relative;
  font-variant-numeric: tabular-nums;
}
.cal-day:hover { background: var(--panel); }
.cal-day.other { color: var(--faint); }
.cal-day.today { font-weight: 700; color: var(--accent); }
.cal-day.in-range { background: var(--accent-soft); }
.cal-day.edge { background: var(--accent); color: #fff; }
.cal-day.has::after {
  content: ""; position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: .5;
}
.cal-hint { font-size: 12px; color: var(--muted); margin: 8px 0; }
.cal-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 14px; padding: 3px 10px; font-size: 13px; }
.chip:hover { background: var(--panel); }
.src-list { display: flex; flex-direction: column; gap: 8px; min-width: 200px; }
.src-list label { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* ---------- Table ---------- */
.table-scroll { flex: 1; min-height: 0; overflow: auto; border: 1px solid var(--line); }
table.orders { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 1080px; }
.orders th {
  position: sticky; top: 0; z-index: 2; background: var(--head); text-align: left; font-weight: 500;
  padding: 12px 10px; white-space: nowrap; border-bottom: 1px solid var(--line);
}
.orders td { padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.orders tbody tr { cursor: pointer; }
.orders tbody tr:hover { background: var(--hover); }
.orders tbody tr.selected { background: var(--accent-soft); }
.orders .col-check { width: 40px; text-align: center; cursor: default; }
.orders .col-check input { width: 18px; height: 18px; cursor: pointer; margin: 0; }
.orders .col-num { width: 96px; white-space: nowrap; }
/* Ширина колонки = найдовший базовий статус («Скасовано»); довші власні статуси обрізаються. */
.orders .col-status { width: 118px; }
.orders .col-company { width: 130px; }
.orders td .pill { white-space: normal; max-width: 100%; line-height: 1.25; vertical-align: top; padding: 4px 7px; overflow-wrap: break-word; }
.th-filter {
  display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 0;
  font-weight: 500; color: inherit;
}
.th-filter svg { width: 15px; height: 15px; color: var(--muted); }
.th-filter.on { color: var(--accent); }
.th-filter.on svg { color: var(--accent); }
.st-list { display: flex; flex-direction: column; gap: 8px; min-width: 230px; }
.st-list label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.st-list .cnt { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.st-note { font-size: 12px; color: var(--muted); }
.orders .col-sum { width: 110px; text-align: right; }
.num { color: var(--link); }
.date-main { font-variant-numeric: tabular-nums; }
.date-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sum { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 500; }
.sub { font-size: 13px; color: var(--muted); }
.empty-row td { text-align: center; color: var(--muted); padding: 40px; cursor: default; }
.table-foot { display: flex; align-items: center; gap: 16px; font-size: 13px; color: var(--muted); }
.table-foot .spacer { flex: 1; }

.pill {
  display: inline-block; color: #fff; border-radius: 3px; padding: 4px 10px; font-size: 13px;
  line-height: 1.25; max-width: 180px;
}
.src { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; white-space: nowrap; }
.src i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; flex: none; }
.oos {
  display: inline-block; background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger-line);
  font-size: 12px; padding: 1px 6px; border-radius: 3px; white-space: nowrap;
}

/* ---------- Modal ---------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(20,24,30,.45); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 2px; width: min(960px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25);
  display: flex; flex-direction: column;
}
.modal.small { width: min(460px, 100%); }
.modal-head {
  display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.modal-head h2 { margin: 0; font-size: 20px; font-weight: 500; }
.modal-head .spacer { flex: 1; }
.icon-btn { border: 0; background: none; width: 34px; height: 34px; border-radius: 3px; color: var(--muted); display: grid; place-items: center; }
.icon-btn:hover { background: var(--panel); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.modal-body { display: grid; grid-template-columns: 1fr 300px; gap: 0; }
.modal-body.single { display: block; padding: 18px 20px; }
.items { padding: 16px 20px; border-right: 1px solid var(--line); }
.items h3, .side h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.item { display: flex; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item img { width: 72px; height: 72px; border-radius: 2px; flex: none; object-fit: cover; background: var(--panel); }
.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.item-meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.item-qty { font-size: 13px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.item-sum { text-align: right; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.item-toggle { font-size: 12px; margin-top: 6px; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; min-width: 120px; }
.qty-step { display: inline-flex; border: 1px solid var(--border); border-radius: 3px; overflow: hidden; }
.qty-step button { width: 30px; height: 30px; border: 0; background: var(--surface); font-size: 17px; line-height: 1; color: var(--text); }
.qty-step button:hover:not(:disabled) { background: var(--panel); }
.qty-step button:disabled { color: var(--faint); cursor: default; }
.qty-step input {
  width: 46px; height: 30px; border: 0; border-left: 1px solid var(--border); border-right: 1px solid var(--border);
  text-align: center; font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield;
}
.qty-step input::-webkit-outer-spin-button, .qty-step input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty-step input:focus { outline: 2px solid var(--focus); }
.qty-was { font-size: 12px; color: var(--muted); font-weight: 400; }
.item-del {
  display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 2px 0;
  color: var(--danger); font-size: 12px;
}
.item-del svg { width: 14px; height: 14px; }
.item-del:hover { text-decoration: underline; }
.item.removed img, .item.removed .item-main { opacity: .45; }
.tag-removed {
  display: inline-block; background: var(--chip); color: var(--muted); border: 1px solid var(--border);
  font-size: 12px; padding: 1px 6px; border-radius: 3px; white-space: nowrap;
}
.side { padding: 16px 20px; display: flex; flex-direction: column; gap: 18px; background: var(--panel2); }
.field-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.check input { width: 17px; height: 17px; margin: 1px 0 0; }
.history { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.reason { background: var(--panel); padding: 8px 10px; border-radius: 3px; font-size: 13px; }
.modal-foot {
  display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.modal-foot .total { font-size: 18px; flex: 1; }
.modal-foot .total b { font-variant-numeric: tabular-nums; }

.status-picker { position: relative; }
.status-btn {
  display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 3px; padding: 5px 8px;
}
.status-btn svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.status-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5; background: var(--surface);
  border: 1px solid var(--border); border-radius: 3px; box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px;
}
.status-opt {
  display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; text-align: left;
  padding: 6px 8px; border-radius: 3px;
}
.status-opt:hover { background: var(--panel); }
.status-opt i { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.status-opt.current { font-weight: 600; }
.status-add { color: var(--link); border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; }
.add-form { border-top: 1px solid var(--line); margin-top: 4px; padding: 8px 2px 2px; display: flex; flex-direction: column; gap: 6px; }
.add-form .row { display: flex; gap: 6px; }
.err { color: var(--danger); font-size: 12px; }
.inp {
  border: 1px solid var(--border); border-radius: 3px; padding: 7px 9px; width: 100%; background: var(--surface);
}
.inp:focus { outline: 2px solid var(--focus); border-color: var(--accent); }
textarea.inp { resize: vertical; min-height: 70px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.items-edit { display: flex; flex-direction: column; gap: 8px; }
.item-edit { display: grid; grid-template-columns: 2fr 1fr 1fr 70px 100px auto auto; gap: 6px; align-items: center; }
.item-edit-head { font-size: 12px; color: var(--muted); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #2b2f36; color: #fff; padding: 10px 18px; border-radius: 3px; opacity: 0;
  pointer-events: none; transition: all .2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .topbar h1 { font-size: 22px; }
  .search { width: 100%; order: 3; }
  .content { padding: 12px 16px; }
  .tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .tile { min-width: 0; padding: 8px 10px; }
  .tile b { font-size: 17px; }
  .tile span { font-size: 12px; }
  .modal-body { grid-template-columns: minmax(0, 1fr); }
  .item { flex-wrap: wrap; }
  .item-main { flex: 1 1 160px; }
  .item-side {
    width: 100%; min-width: 0; flex-direction: row; flex-wrap: wrap; align-items: center;
    justify-content: flex-end; gap: 6px 12px;
  }
  .items { border-right: 0; border-bottom: 1px solid var(--line); }
  .form-grid { grid-template-columns: 1fr; }
  .item-edit { grid-template-columns: 1fr 1fr; }
  .backdrop { padding: 0; }
}

/* Серія правок 2 */
.orders td.col-num .date-sub { margin-top: 2px; }
.orders .sub.ext { font-variant-numeric: tabular-nums; }
/* Замовлення з одним номером площадки від різних компаній — разом світло-зеленим. */
.orders tbody tr.grp td { background: var(--grp); }
.orders tbody tr.grp:hover td { background: var(--grp-hover); }
.orders tbody tr.grp td.col-check { box-shadow: inset 4px 0 0 #3bb54a; }
.orders tbody tr.grp.selected td { background: var(--grp-sel); }
.btn.on { border-color: var(--accent); color: var(--accent); }
.co-tag { background: var(--chip); border-radius: 3px; padding: 2px 8px; font-size: 13px; }
.arch-tag { background: var(--warn-soft); color: var(--warn-text); border-radius: 3px; padding: 2px 8px; font-size: 13px; }

/* ---------- Перемикач теми ---------- */
.theme-sw { display: inline-flex; border: 1px solid var(--border); border-radius: 18px; padding: 2px; gap: 2px; background: var(--surface); flex: none; }
.theme-sw button {
  width: 32px; height: 30px; border: 0; border-radius: 15px; background: none; color: var(--muted);
  display: grid; place-items: center; padding: 0;
}
.theme-sw button svg { width: 17px; height: 17px; }
.theme-sw button:hover { color: var(--text); }
.theme-sw button.on { background: var(--accent); color: #fff; }
.topbar .theme-sw { margin-left: 4px; }
:root[data-theme="dark"] .brand-mark { box-shadow: 0 0 0 2px #000; }
:root[data-theme="dark"] img { filter: brightness(.92); }
:root[data-theme="dark"] .oos { color: #ff8a8a; }
