/* ── Заявки / статуси ── */
.nav-badge { display: inline-block; min-width: 18px; height: 18px; line-height: 18px; text-align: center;
  background: var(--critical); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 0 5px; margin-left: auto; }
.intake-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.intake-tools .search { min-width: 260px; max-width: 420px; flex: 1; }
.chip-row { display: flex; gap: 6px; flex-wrap: nowrap; align-items: center;
  overflow-x: auto; scrollbar-width: thin; padding-bottom: 2px; }
.chip-row .chip { flex: none; white-space: nowrap; }
.chip-row.chip-sub { padding-top: 8px; border-top: 1px dashed var(--border-2); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-family: inherit; font-size: 12px; font-weight: 600;
  color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 5px 11px; cursor: pointer; }
.chip:hover { color: var(--ink); }
.chip.on { background: color-mix(in srgb, var(--s1) 14%, transparent); color: var(--s1); border-color: color-mix(in srgb, var(--s1) 40%, transparent); }
.chip .pd { width: 7px; height: 7px; border-radius: 50%; }
.chip b { font-variant-numeric: tabular-nums; }
select.status-sel { font-family: inherit; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; max-width: 190px; }
/* Заявки — div-список (тонкі рядки в один рядок, як у LP) */
.ilist { min-width: 860px; user-select: none; font-size: 13px; }
.ilist-head { display: grid; gap: 12px; align-items: center; padding: 8px 14px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); font-weight: 600;
  position: sticky; top: 0; z-index: 5; }
.ilist-row { display: grid; gap: 12px; align-items: center; padding: 4px 14px; min-height: 36px;
  border-bottom: 1px solid var(--border-2); cursor: pointer; transition: background .1s; }
.ilist-row:hover { background: var(--surface-2); }
.ilist-row.selected { background: color-mix(in srgb, var(--s1) 12%, transparent) !important;
  box-shadow: inset 3px 0 0 var(--s1); }
.ilist-day { padding: 9px 14px 5px; font-size: 11px; font-weight: 700; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .05em; background: var(--surface-2);
  border-bottom: 1px solid var(--border-2); }
.ilist-day .muted { font-weight: 600; text-transform: none; letter-spacing: 0; }
.ilist .ic { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ilist .ic.num { text-align: right; font-variant-numeric: tabular-nums; }
.ilist .ellip { overflow: hidden; text-overflow: ellipsis; }
.ilist .st-cell { overflow: visible; }
.ilist .st-cell .status-sel { width: 100%; max-width: 128px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-top: 2px; padding-bottom: 2px; }
.ilist .st-cell .pill { max-width: 128px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* підсвітка збігу пошуку */
mark { background: rgba(255, 210, 0, .42); color: inherit; border-radius: 3px; padding: 0 1px; }
/* панель масових дій — ПЛАВАЮЧА (fixed), щоб не зсувати таблицю при виділенні */
.bulk-bar { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 60; display: flex; align-items: center; gap: 12px; flex-wrap: nowrap;
  padding: 11px 18px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 10px 34px rgba(0,0,0,.22); max-width: calc(100vw - 40px);
  white-space: nowrap; }
.bulk-bar > * { flex: none; }
.bulk-bar b { font-variant-numeric: tabular-nums; }
.status-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.cat-btn { background: none; border: 1px solid var(--border-2); color: var(--muted); cursor: pointer;
  border-radius: 6px; width: 22px; height: 20px; font-size: 11px; line-height: 1; padding: 0; }
.cat-btn:hover { color: var(--ink); background: var(--surface-2); }
/* підпункти Налаштувань у сайдбарі */
.nav-sub { display: flex; flex-direction: column; gap: 1px; margin: 2px 0 4px; }
.nav-subitem { padding: 6px 11px 6px 40px; border-radius: var(--radius-sm); color: var(--ink-2);
  font-size: 13px; cursor: pointer; transition: background .12s, color .12s; }
.nav-subitem:hover { background: var(--surface-2); color: var(--ink); }
.nav-subitem.active { color: var(--s1); font-weight: 600; background: color-mix(in srgb, var(--s1) 10%, transparent); }
.app.rail .nav-sub { display: none; }
.status-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border-2); border-radius: var(--radius-sm); }
.status-row .sw-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.status-row .st-name { font-weight: 600; font-size: 13px; }
.code-ex { background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 9px; padding: 12px 14px;
  font-size: 12px; line-height: 1.5; overflow-x: auto; margin: 8px 0 0; white-space: pre; }
/* модалка порядку колонок */
.col-sort { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.col-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; background: var(--surface);
  border: 1px solid var(--border-2); border-radius: var(--radius-sm); cursor: grab; user-select: none; }
.col-item.dragging { opacity: .55; cursor: grabbing; box-shadow: 0 4px 14px rgba(0,0,0,.14); }
.col-item .col-grip { color: var(--muted); display: flex; align-items: center; cursor: grab; }
.col-item .col-name { font-weight: 600; font-size: 13px; }
.col-move { background: var(--surface-2); border: 1px solid var(--border-2); color: var(--ink-2);
  width: 26px; height: 24px; border-radius: 6px; cursor: pointer; font-size: 10px; line-height: 1; }
.col-move:hover { color: var(--ink); background: var(--surface); }
/* модулі (розширення) */
.mod-nav svg { width: 18px; height: 18px; }
.mod-ic { width: 38px; height: 38px; border-radius: 10px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; color: var(--s1); flex: none; }
.mod-ic svg { width: 20px; height: 20px; }
.mod-card .card-head { gap: 12px; }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .sl { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: background .15s; }
.switch .sl::before { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px;
  background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + .sl { background: var(--s1); }
.switch input:checked + .sl::before { transform: translateX(18px); }
.drawer-mod { margin-top: 4px; }
.np-w { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.np-w-res { font-size: 13px; }
.np-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 12px; text-align: center; }
.np-stats .np-n { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.np-stats .muted { font-size: 12px; }
/* НП: панель автоправил статусів (у модалці налаштувань) */
.np-set-head { display: flex; align-items: center; gap: 12px; padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.np-set-head .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.np-rules { display: flex; flex-direction: column; gap: 8px; }
.np-rules-h, .np-rule { display: grid; grid-template-columns: minmax(150px,1fr) minmax(150px,1fr) minmax(190px,1.6fr) 34px; gap: 10px; align-items: center; }
.np-rules-h { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 0 2px 2px; }
.np-rule { background: var(--surface-2, transparent); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px; }
.np-rule select { width: 100%; font-size: 13px; padding: 6px 8px; }
.np-set-cell { display: flex; align-items: center; gap: 6px; min-width: 0; }
.np-set-cell .pd, .np-chip .pd { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }
.np-exc { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.np-chip { display: inline-flex; align-items: center; gap: 5px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 3px 6px 3px 9px; font-size: 12px; }
.np-chip-x { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 11px; line-height: 1; padding: 0 2px; }
.np-chip-x:hover { color: var(--critical); }
.np-exc-add { max-width: 150px; font-size: 12px; padding: 5px 6px; }
.np-rules-foot { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
@media (max-width: 720px) {
  .np-rules-h { display: none; }
  .np-rule { grid-template-columns: 1fr 1fr; grid-auto-rows: auto; }
  .np-rule .np-exc { grid-column: 1 / -1; }
}
/* НП: секція «Відправлення» (ключі + дефолти) */
.np-sec-div { height: 1px; background: var(--border); margin: 20px 0; }
.np-keys { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.np-key { display: flex; align-items: center; gap: 10px; }
.np-key .np-key-label { flex: 1; max-width: 280px; }
.np-key-mask { font-family: monospace; font-size: 12px; }
.np-key-add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; padding-top: 10px; border-top: 1px dashed var(--border); }
.np-key-newlabel { min-width: 180px; }
.np-key-newval { min-width: 200px; }
.np-sender { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.np-fld { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.np-fld > span { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.np-fld select, .np-fld input { width: 100%; }
.np-sender-hint { padding: 10px 12px; background: var(--bg); border-radius: var(--radius-sm); }
@media (max-width: 720px) { .np-sender { grid-template-columns: 1fr; } }
/* НП: combobox пошуку міста (одне поле + випадаючий список) */
.np-combo { position: relative; }
.np-cres { position: absolute; left: 0; right: 0; top: 100%; z-index: 50; margin-top: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); max-height: 240px; overflow-y: auto; }
.np-cres-item { padding: 7px 10px; cursor: pointer; font-size: 13px; }
.np-cres-item:hover { background: var(--bg); }
.np-cres-empty { padding: 8px 10px; font-size: 13px; }
/* декларативний рендер налаштувань модуля */
.ds-group { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; margin: 18px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.ds-group:first-child { margin-top: 0; }
.ds-field { margin-bottom: 14px; }
.ds-field > label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.ds-field input, .ds-field select, .ds-field textarea { width: 100%; }
.ds-toggle { display: flex; align-items: center; gap: 10px; }
.ds-toggle > span { font-size: 13px; font-weight: 600; }
/* редаговані поля в попапі заявки — компактні рядки «лейбл зліва», як у LP */
.edit-form { display: flex; flex-direction: column; gap: 6px; }
.ef { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: center; }
.ef:has(textarea) { align-items: start; }
.ef:has(textarea) > span { padding-top: 6px; }
.ef > span { font-size: 11px; letter-spacing: .02em; color: var(--muted); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ef input, .ef textarea, .ef select { width: 100%; padding: 5px 9px; font-size: 13px; }
.drawer-save { display: flex; align-items: center; gap: 12px; padding-top: 4px; }
.field-type { font-size: 11px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--border-2); padding: 2px 8px; border-radius: 6px; flex: none; }
/* картка товару: два стовпці, габарити, фото; dblrow = відкриття подвійним кліком */
.dblrow { user-select: none; }
.pr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; }
@media (max-width: 640px) { .pr-grid { grid-template-columns: 1fr; } }
.dims-row { display: flex; gap: 6px; align-items: center; }
.dims-row input { width: 100%; min-width: 0; }
.dims-row span { color: var(--muted); flex: none; }
.photo-row { display: flex; gap: 10px; align-items: center; }
.photo-row img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border-2); flex: none; }
.photo-row input[type="file"] { border: none; padding: 4px 0; font-size: 12px; }
.pcell { display: inline-flex; align-items: center; gap: 8px; }
.pthumb { width: 28px; height: 28px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border-2); flex: none; }
/* попап деталей замовлення/заявки (замість бічного drawer) */
.modal-card.wide { max-width: 860px; }
.detail-head { align-items: flex-start; }
.detail-head .d-oid { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.detail-head h3 { margin: 3px 0 0; font-size: 19px; letter-spacing: -.02em; }
.d-head-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 26px; }
.dcol { display: flex; flex-direction: column; gap: 16px; }
.d-sec .sec-title { margin-bottom: 8px; }
.d-comment { width: 100%; }
.detail-meta { color: var(--muted); font-size: 12px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border-2); }
@media (max-width: 700px) { .detail-grid { grid-template-columns: 1fr; } }
/* LP-стиль: 3 колонки (Контакт | Доставка/Інфо/UTM | Товар) */
.modal-card.lp { max-width: 1320px; }
.modal-card.lp .modal-body { padding: 24px 30px; }
.lp-grid { display: grid; grid-template-columns: 320px 320px 1fr; gap: 20px 36px; align-items: start; }
.lp-grid .d-sec { margin-bottom: 4px; }
.dsec-title { display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
  color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.dsec-title::before, .dsec-title::after { content: ""; height: 1px; background: var(--border-2); flex: 1; }
.ro-val { font-size: 13px; padding: 2px 0; word-break: break-word; color: var(--ink); }
.prod-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.prod-table th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; padding: 4px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.prod-table td { padding: 9px 8px; border-bottom: 1px solid var(--border-2); vertical-align: top; }
.prod-table td small { display: block; color: var(--muted); font-weight: 400; }
.prod-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.prod-total { display: flex; justify-content: space-between; align-items: center; padding: 12px 8px 0; font-size: 15px; font-weight: 700; }
/* редактор позицій заявки */
.prod-edit td { padding: 5px 6px; vertical-align: middle; }
.prod-edit .pe-in { width: 100%; padding: 5px 8px; font-size: 13px; }
.prod-edit .pe-price { max-width: 92px; }
.prod-edit .pe-qty { max-width: 68px; }
.prod-edit .pe-name { min-width: 120px; }
.prod-add { padding: 8px 6px 0; }
.prod-add select { width: 100%; }
/* товар: combobox із пошуком */
.pe-combo { position: relative; }
.pe-results { position: absolute; left: 0; right: 0; top: 100%; z-index: 40; margin-top: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); max-height: 240px; overflow-y: auto; }
.pe-res { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 10px; cursor: pointer; font-size: 13px; }
.pe-res:hover { background: var(--bg); }
.pe-res mark { background: color-mix(in srgb, var(--s1) 22%, transparent); color: inherit; border-radius: 2px; }
.pe-res .muted { white-space: nowrap; font-variant-numeric: tabular-nums; }
/* назва вже доданого товару — не редагується (лише видалити ×) */
.prod-edit .pe-name-ro { padding: 6px 4px; font-size: 13px; font-weight: 500; word-break: break-word; }
/* редактор перекладів */
.tr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; align-items: center; max-height: 460px; overflow-y: auto; }
.tr-grid .tr-src { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tr-grid .tr-in { width: 100%; }
@media (max-width: 640px) { .tr-grid { grid-template-columns: 1fr; gap: 2px 0; } .tr-grid .tr-in { margin-bottom: 8px; } }
@media (max-width: 1040px) { .lp-grid { grid-template-columns: 1fr 1fr; } .lp-grid .dcol-wide { grid-column: 1 / -1; } }
@media (max-width: 680px) { .lp-grid { grid-template-columns: 1fr; } }
code { background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 5px; padding: 1px 5px; font-size: 12px; }

/* ── Автентифікація / доступ ── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--plane); padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 26px; }
.login-card .brand { justify-content: center; padding-bottom: 8px; }
.login-card h2 { margin: 4px 0 2px; font-size: 18px; text-align: center; }
.login-card .lg-sub { color: var(--muted); font-size: 13px; text-align: center; margin-bottom: 20px; }
.login-card label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; margin: 12px 0 5px; }
.login-card input { width: 100%; }
.login-card .lg-btn { width: 100%; margin-top: 20px; padding: 11px; font-size: 14px; font-weight: 600;
  color: #fff; background: var(--s1); border: none; border-radius: var(--radius-sm); cursor: pointer; }
.login-card .lg-btn:hover { filter: brightness(1.05); }
.login-card .lg-err { color: var(--critical); font-size: 13px; margin-top: 12px; text-align: center; min-height: 18px; }

#user-chip { padding: 10px 4px; border-top: 1px solid var(--border-2); display: flex; align-items: center; gap: 8px; }
#user-chip .uc-av { flex: none; }
#user-chip .uc-av { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg,var(--s1),var(--s5));
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
#user-chip .uc-name { font-weight: 600; font-size: 13px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#user-chip .uc-role { color: var(--muted); font-size: 11px; }
#user-chip .uc-actions { margin-left: auto; display: flex; gap: 2px; flex: none; }
#user-chip button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 7px; }
#user-chip button:hover { background: var(--surface-2); color: var(--ink); }
#user-chip button svg { width: 16px; height: 16px; display: block; }

/* Адмін-панель користувачів */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px,1fr)); gap: 6px 18px; }
.perm-group-title { grid-column: 1/-1; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 700; margin: 12px 0 2px; }
.perm-item { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; }
.perm-item input { width: auto; }
.perm-item.inherited { opacity: .65; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); }
.badge.role { background: color-mix(in srgb, var(--s1) 14%, transparent); color: var(--s1); }
.badge.off { background: color-mix(in srgb, var(--critical) 12%, transparent); color: var(--critical); }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 120; display: grid; place-items: center; padding: 20px; }
.modal-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; }
.modal-body { padding: 18px 22px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.btn { font-family: inherit; font-size: 13px; font-weight: 600; border-radius: var(--radius-sm); padding: 9px 16px; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--ink); }
.btn.primary { background: var(--s1); color: #fff; border-color: var(--s1); }
.btn.danger { color: var(--critical); border-color: color-mix(in srgb,var(--critical) 40%, var(--border)); }
.field-row { margin-bottom: 12px; }
.field-row label { display:block; font-size: 11px; text-transform: uppercase; letter-spacing:.05em; color: var(--muted); font-weight:600; margin-bottom: 5px; }
.field-row select, .field-row input { width: 100%; }

/* daily P&L: розділювач місяців + кнопка «завантажити ще» */
tr.dp-month td { background: var(--surface-2); color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em; font-weight: 700; padding: 7px 14px !important; }
.dp-foot { padding: 14px; text-align: center; border-top: 1px solid var(--border-2); }
.dp-more { font-family: inherit; font-size: 13px; font-weight: 600; color: var(--s1);
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 8px 18px; cursor: pointer; }
.dp-more:hover { background: var(--surface-2); }
.dp-more:disabled { opacity: .5; cursor: default; }
.dp-cnt small { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ══════════════════════════════════════════════════════════════════════════
   somio CRM — дизайн-система
   Палітра з валідованої dataviz-системи (CVD-safe, light+dark).
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  color-scheme: light;
  --plane:        #f9f9f7;   /* тло сторінки */
  --surface:      #ffffff;   /* картки */
  --surface-2:    #fbfbfa;   /* субтло (thead, hover) */
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --muted:        #898781;
  --grid:         #e1e0d9;
  --line:         #c3c2b7;
  --border:       rgba(11,11,11,.10);
  --border-2:     rgba(11,11,11,.06);

  /* категоріальні слоти (light) */
  --s1:#2a78d6; --s2:#1baf7a; --s3:#eda100; --s4:#008300;
  --s5:#4a3aa7; --s6:#e34948; --s7:#e87ba4; --s8:#eb6834;

  /* стадії воронки */
  --stage-new:      #2a78d6;   /* синій   — в обробці */
  --stage-shipped:  #eda100;   /* жовтий  — відправлені */
  --stage-won:      #0ca30c;   /* зелений — викуп */
  --stage-lost:     #d03b3b;   /* червоний— втрачені */

  --good:#0ca30c; --warning:#fab219; --serious:#ec835a; --critical:#d03b3b;

  --shadow: 0 1px 2px rgba(11,11,11,.04), 0 4px 16px rgba(11,11,11,.05);
  --radius: 14px;
  --radius-sm: 9px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:        #0d0d0d;
  --surface:      #1a1a19;
  --surface-2:    #232322;
  --ink:          #ffffff;
  --ink-2:        #c3c2b7;
  --muted:        #898781;
  --grid:         #2c2c2a;
  --line:         #383835;
  --border:       rgba(255,255,255,.10);
  --border-2:     rgba(255,255,255,.06);

  --s1:#3987e5; --s2:#199e70; --s3:#c98500; --s4:#008300;
  --s5:#9085e9; --s6:#e66767; --s7:#d55181; --s8:#d95926;

  --stage-new:#3987e5; --stage-shipped:#c98500; --stage-won:#0ca30c; --stage-lost:#e66767;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--plane);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
::selection { background: color-mix(in srgb, var(--s1) 30%, transparent); }

/* ─── Каркас ─────────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 20px;
  font-weight: 700; font-size: 17px; letter-spacing: -.02em;
}
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--s1), var(--s5));
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px;
}
.brand small { color: var(--muted); font-weight: 500; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; display:block; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-weight: 500; cursor: pointer;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: color-mix(in srgb, var(--s1) 12%, transparent); color: var(--s1); font-weight: 600; }
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-spacer { flex: 1; }
/* кнопка згортання меню + режим-рейка (тільки десктоп) */
.rail-toggle { margin-left: auto; background: none; border: none; color: var(--muted); cursor: pointer; padding: 5px; border-radius: 7px; display: grid; place-items: center; flex: none; }
.rail-toggle:hover { background: var(--surface-2); color: var(--ink); }
.rail-toggle svg { width: 18px; height: 18px; }
.app.rail { grid-template-columns: 66px 1fr; }
.app.rail .sidebar { padding: 20px 9px; }
.app.rail .brand { justify-content: center; padding: 4px 0 18px; }
.app.rail .brand-name, .app.rail .rail-toggle { display: none; }
.app.rail .brand .logo { cursor: pointer; }
.app.rail .nav-item { justify-content: center; gap: 0; padding: 10px 0; }
.app.rail .nav-item > span { display: none; }
.app.rail .side-utils { justify-content: center; padding: 2px 0; }
.app.rail #user-chip { justify-content: center; padding: 10px 0; }
.app.rail #user-chip > div:not(.uc-av) { display: none; }
.app.rail .sidebar-foot { display: none; }
.side-utils { display: flex; align-items: center; justify-content: flex-end; gap: 4px; padding: 2px 6px; }
.side-lang { font-size: 12px; font-weight: 600; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2); cursor: pointer; }
.app.rail .side-lang { padding: 4px 3px; }
.side-theme-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; display: grid; place-items: center; }
.side-theme-btn:hover { background: var(--surface-2); color: var(--ink); }
.side-theme-btn svg { width: 18px; height: 18px; display: block; }
.sidebar-foot { color: var(--muted); font-size: 11px; padding: 8px; border-top: 1px solid var(--border-2); }
.sidebar-foot b { color: var(--ink-2); font-weight: 600; }

.main { min-width: 0; display: flex; flex-direction: column; }

/* ─── Топбар / фільтри ───────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--plane) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 9px 26px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
/* тайтл сторінки прибрано на десктопі (щільність як у LP) — показуємо лише на мобілці,
   де сайдбар off-canvas і треба знати, де ти */
.topbar h1 { display: none; font-size: 17px; margin: 0; font-weight: 700; letter-spacing: -.02em; }
.topbar .grow { flex: 1; }
.topbar .menu-toggle { display: none; }   /* гамбургер — лише на мобілці (специфічність > .icon-btn) */
.topbar.empty { display: none; }           /* порожній топбар (без фільтрів) прибираємо на десктопі */
/* збільшений тап-таргет тумблера модуля (візуал не міняється) */
.switch::after { content: ""; position: absolute; inset: -7px -6px; }

.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding-left: 2px; }
select, textarea,
input:not([type="checkbox"]):not([type="radio"]) {
  font-family: inherit; font-size: 13px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 10px; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input[type="color"] { padding: 3px; height: 40px; cursor: pointer; }
select:focus, input:focus, textarea:focus { border-color: var(--s1); box-shadow: 0 0 0 3px color-mix(in srgb, var(--s1) 18%, transparent); }
.search { min-width: 220px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; }
.seg button { border: none; background: none; font-family: inherit; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 5px 11px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.icon-btn { width: 36px; height: 36px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.icon-danger { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, var(--border)); }
table.data .icon-btn { width: 32px; height: 32px; display: inline-grid; vertical-align: middle; }

.content { padding: 14px 26px 60px; }

/* ─── Картки / сітка ─────────────────────────────────────────────────────── */
.grid { display: grid; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 18px; }
.card h3 { margin: 0 0 2px; font-size: 14px; font-weight: 650; }
.card .sub { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h3 { margin: 0; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(184px, 1fr)); gap: 16px; }
.kpi { padding: 16px 18px; }
.kpi .k-label { color: var(--muted); font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.kpi .k-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.kpi .k-val { font-size: 27px; font-weight: 700; letter-spacing: -.02em; margin-top: 8px; line-height: 1; }
.kpi .k-sub { color: var(--ink-2); font-size: 12px; margin-top: 7px; }
.kpi .k-sub b { color: var(--ink); }

/* ─── Таблиця ────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data thead th {
  position: sticky; top: 0; background: var(--surface-2);
  text-align: left; font-weight: 600; color: var(--ink-2); font-size: 11px;
  text-transform: uppercase; letter-spacing: .04em;
  padding: 8px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
  cursor: pointer; user-select: none;
}
table.data thead th.no-sort { cursor: default; }
table.data thead th .arr { color: var(--s1); font-size: 10px; }
table.data tbody td { padding: 7px 14px; border-bottom: 1px solid var(--border-2); vertical-align: middle; line-height: 1.3; }
table.data tbody td small { line-height: 1.2; }
table.data tr.cat-group td { background: var(--surface-2, rgba(120,130,150,.06)); font-weight: 700;
  font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-2); padding: 8px 14px; }
table.data tr.cat-group:hover td { background: var(--surface-2, rgba(120,130,150,.06)); }
table.data tbody tr { cursor: pointer; transition: background .1s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .muted { color: var(--muted); }
.cust { font-weight: 600; }
.cust small { display: block; color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }

/* Статус-піл */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill .pd { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.pill.new     { background: color-mix(in srgb, var(--stage-new) 12%, transparent);     color: color-mix(in srgb, var(--stage-new) 72%, var(--ink)); }
.pill.shipped { background: color-mix(in srgb, var(--stage-shipped) 15%, transparent); color: color-mix(in srgb, var(--stage-shipped) 60%, var(--ink)); }
.pill.won     { background: color-mix(in srgb, var(--stage-won) 13%, transparent);     color: color-mix(in srgb, var(--stage-won) 65%, var(--ink)); }
.pill.lost    { background: color-mix(in srgb, var(--stage-lost) 13%, transparent);    color: color-mix(in srgb, var(--stage-lost) 70%, var(--ink)); }
.pill.new .pd{background:var(--stage-new)} .pill.shipped .pd{background:var(--stage-shipped)}
.pill.won .pd{background:var(--stage-won)} .pill.lost .pd{background:var(--stage-lost)}

/* Пагінація */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 4px 2px; color: var(--ink-2); font-size: 13px; }
.pager .pg-btns { display: flex; gap: 6px; }
.pager button { font-family: inherit; font-size: 13px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.pager button:hover:not(:disabled) { background: var(--surface-2); }
.pager button:disabled { opacity: .4; cursor: default; }

/* ─── Drawer (деталі замовлення) ─────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.34); z-index: 90; opacity: 0; pointer-events: none; transition: opacity .18s; }
.overlay.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 460px; max-width: 94vw;
  background: var(--surface); border-left: 1px solid var(--border); z-index: 100;
  transform: translateX(100%); transition: transform .22s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,.14);
}
.drawer.open { transform: translateX(0); }
.drawer-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.drawer-head .oid { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.drawer-head h2 { margin: 3px 0 0; font-size: 20px; letter-spacing: -.02em; }
.drawer-body { padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; }
.dl { display: grid; grid-template-columns: 116px 1fr; gap: 9px 14px; font-size: 13px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; color: var(--ink); word-break: break-word; }
.sec-title { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.prod-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border-2); }
.prod-row:last-child { border: none; }
.prod-row .pn { font-weight: 600; }
.prod-row .pn small { display: block; color: var(--muted); font-weight: 400; }
.prod-row .pp { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.total-row { display: flex; justify-content: space-between; font-size: 16px; font-weight: 700; padding-top: 12px; }

/* ─── Чарти / загальне ───────────────────────────────────────────────────── */
.chart-svg { width: 100%; display: block; overflow: visible; }
.chart-svg text { font-family: var(--sans); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; font-size: 12px; color: var(--ink-2); }
.legend .li { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.chart-tip {
  position: fixed; z-index: 200; pointer-events: none; opacity: 0;
  background: var(--ink); color: var(--plane);
  padding: 8px 11px; border-radius: 9px; font-size: 12px; line-height: 1.5;
  box-shadow: 0 6px 22px rgba(0,0,0,.28); transition: opacity .1s; white-space: nowrap;
}
.chart-tip b { color: #fff; }
:root[data-theme="dark"] .chart-tip { background: #f4f4f2; color: #111; box-shadow: 0 6px 22px rgba(0,0,0,.5); }
:root[data-theme="dark"] .chart-tip b { color: #000; }
.chart-empty { color: var(--muted); font-size: 13px; padding: 40px; text-align: center; }

/* barlist (топ-товари/менеджери/міста) */
.barlist { display: flex; flex-direction: column; gap: 11px; }
.barlist .row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.barlist .nm { font-weight: 550; font-size: 13px; }
.barlist .nm small { color: var(--muted); font-weight: 400; }
.barlist .vv { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.barlist .track { grid-column: 1 / -1; height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.barlist .fill { height: 100%; border-radius: 999px; }

/* skeleton / loader */
.sk { background: linear-gradient(90deg, var(--surface-2) 25%, color-mix(in srgb, var(--surface-2) 55%, var(--muted) 12%) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sh 1.3s infinite; border-radius: 8px; }
@keyframes sh { 0%{background-position:100% 0} 100%{background-position:-100% 0} }

/* стадія-легенда для донат-центру */
.donut-center { text-align: center; }
.donut-center .dc-v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.donut-center .dc-l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.updated { color: var(--muted); font-size: 12px; }
.tag-src { font-size: 11px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border-2); padding: 2px 7px; border-radius: 6px; white-space: nowrap; }

/* затемнення під висувним сайдбаром (лише мобілка) */
.nav-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.34); z-index: 70;
  opacity: 0; pointer-events: none; transition: opacity .18s; }
.nav-scrim.show { opacity: 1; pointer-events: auto; }

@media (max-width: 900px) {
  .app, .app.rail { grid-template-columns: 1fr; }   /* rail не діє на мобілці */
  .rail-toggle { display: none; }                    /* на мобілці — гамбургер, не рейка */
  .app.rail .sidebar { padding: 20px 14px; }
  .app.rail .brand-name, .app.rail .nav-item > span, .app.rail #user-chip > div:not(.uc-av) { display: revert; }
  .app.rail .nav-item { justify-content: flex-start; gap: 11px; padding: 9px 11px; }
  .app.rail #user-chip { justify-content: flex-start; }
  .sidebar { position: fixed; z-index: 80; transform: translateX(-100%); transition: transform .2s; width: 240px; box-shadow: 4px 0 24px rgba(0,0,0,.18); }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 12px 14px 60px; }
  .topbar { padding: 8px 14px; }
  .topbar .menu-toggle { display: grid; }  /* гамбургер видно */
  .topbar h1 { display: block; }           /* тайтл повертаємо (сайдбар схований) */
  .topbar.empty { display: flex; }         /* на мобілці топбар потрібен (☰ + тайтл) */
  .np-stats { grid-template-columns: repeat(2, 1fr); }  /* 4→2 колонки */
  .bulk-bar { left: 12px; right: 12px; transform: none; white-space: normal; flex-wrap: wrap; justify-content: center; }
  .kpis { grid-template-columns: 1fr 1fr; }
  /* багатоколонкові ряди чартів (inline grid-template-columns) → 2 колонки на планшеті */
  .content .grid { grid-template-columns: 1fr 1fr !important; }
  table.data { font-size: 12.5px; }
  table.data tbody td, table.data thead th { padding-left: 10px; padding-right: 10px; }
  /* тап-таргети ≥36px на мобілці (десктопну щільність не чіпаємо) */
  .col-move { width: 36px; height: 36px; font-size: 13px; }
  .seg button { padding-top: 9px; padding-bottom: 9px; }
  .chip { padding: 8px 12px; }
  #drawer-status.status-sel { min-height: 36px; padding-top: 7px; padding-bottom: 7px; }
  #ch-funnel .barlist .row { padding-block: 6px; }
}
@media (max-width: 460px) {
  .kpis { grid-template-columns: 1fr; }
  .np-stats { grid-template-columns: repeat(2, 1fr); }
  .seg { flex-wrap: wrap; }
  /* багатоколонкові ряди чартів (inline grid-template-columns) → 1 колонка на телефоні */
  .content .grid { grid-template-columns: 1fr !important; }
}
