:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --accent: #2f6fde;
  --accent-hover: #2560c6;
  --accent-weak: #eaf1fd;
  --ok: #1f7a45;
  --ok-bg: #e7f6ed;
  --warn: #8a5300;
  --warn-bg: #fff3e0;
  --error: #b42318;
  --error-bg: #fdecea;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
}
* { box-sizing: border-box; }
html { scroll-padding-top: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* --- Шапка --- */
header.top {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 0 24px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}
header.top .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 12px 0; color: var(--text); white-space: nowrap; }
header.top .brand:hover { text-decoration: none; }
header.top .brand img { width: 24px; height: 24px; }
header.top nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
header.top nav a { padding: 15px 10px 13px; color: var(--muted); border-bottom: 2px solid transparent; }
header.top nav a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
header.top nav a:hover { text-decoration: none; color: var(--text); }
header.top .header-right { display: flex; align-items: center; gap: 12px; }
.mode-pill { background: var(--warn-bg); color: var(--warn); border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.mode-pill:hover { text-decoration: none; }
.mode-pill.live { background: var(--ok-bg); color: var(--ok); }
.mode-pill .short { display: none; }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }

/* --- Заголовки сторінок --- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px 24px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.page-head .subtitle { color: var(--muted); margin: 4px 0 0; max-width: 760px; }
.back { display: inline-block; margin-bottom: 8px; color: var(--muted); }
h1 { font-size: 22px; line-height: 1.3; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 28px 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }

/* --- Картки, сітки --- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.cols-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.cols-side { display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 16px; align-items: start; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); color: var(--text); display: block; }
a.stat:hover { text-decoration: none; border-color: var(--border-strong); }
.stat .value { font-size: 24px; font-weight: 700; line-height: 1.3; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* --- Таблиці --- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.table-wrap table { border: 0; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .02em; background: var(--surface-2); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr[data-href] { cursor: pointer; }
tr[data-href]:hover td { background: var(--surface-2); }
tr.chosen td { background: var(--ok-bg); }
tr.inactive td { color: var(--muted); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }

/* --- Дрібниці --- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--bg); border: 1px solid var(--border); white-space: nowrap; color: var(--text); }
.badge.paid, .badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.awaiting_payment, .badge.pending, .badge.info { background: var(--accent-weak); color: var(--accent); border-color: transparent; }
.badge.manager, .badge.warn, .badge.skipped { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.failed, .badge.expired, .badge.reversed, .badge.error { background: var(--error-bg); color: var(--error); border-color: transparent; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; vertical-align: -1px; }
.with-swatch { display: inline-flex; align-items: center; gap: 6px; }

/* --- Повідомлення --- */
.flash { display: flex; align-items: flex-start; gap: 12px; padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--error-bg); color: var(--error); }
.flash .close { margin-left: auto; background: none; border: 0; color: inherit; font-size: 18px; line-height: 1; padding: 0 2px; cursor: pointer; opacity: .7; }
.flash .close:hover { opacity: 1; }
.notice { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; background: var(--warn-bg); color: var(--warn); }
.notice.info { background: var(--accent-weak); color: #1d4f9e; }

/* --- Форми --- */
label { display: block; font-weight: 600; margin: 14px 0 4px; }
label:first-child { margin-top: 0; }
label.check { font-weight: normal; display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=search], select, textarea {
  width: 100%; max-width: 520px; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: 6px;
  font: inherit; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
textarea { min-height: 110px; resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0; }
.form-section { padding: 16px 0; border-top: 1px solid var(--border); }
.form-section:first-of-type { border-top: 0; padding-top: 0; }
.form-section > legend, .form-section h3 { font-weight: 700; font-size: 14px; margin-bottom: 4px; padding: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 24px; }
.input-group { display: flex; gap: 8px; max-width: 620px; }
.input-group input { flex: 1; max-width: none; }

button, .button {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; line-height: 1.4;
}
button:hover, .button:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
button.secondary, .button.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
button.secondary:hover, .button.secondary:hover { background: var(--surface-2); border-color: var(--muted); }
button.danger { background: var(--surface); border-color: #f0b4ae; color: var(--error); }
button.danger:hover { background: var(--error-bg); }
button.small, .button.small { padding: 3px 10px; font-size: 13px; }
button.link { background: none; border: none; color: var(--muted); padding: 0; }
button.link:hover { color: var(--text); background: none; }
button:disabled { opacity: .6; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=text], .toolbar input[type=search] { width: 240px; max-width: 100%; }
.page-head > .toolbar { flex-wrap: nowrap; }
form.inline { display: inline; }
.danger-zone { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }

/* --- Фільтри-«чипси» --- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 4px 12px; border: 1px solid var(--border-strong); border-radius: 999px; color: var(--text); background: var(--surface); font-size: 13px; }
.chip:hover { text-decoration: none; border-color: var(--muted); }
.chip.active { background: var(--text); border-color: var(--text); color: #fff; }
.chip .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.active .count { color: rgba(255,255,255,.75); }

/* --- Чекліст готовності --- */
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 2px 12px; align-items: start; padding: 10px 0; border-top: 1px solid var(--border); }
.checklist li:first-child { border-top: 0; padding-top: 0; }
.checklist .icon { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.checklist .ok .icon { background: var(--ok-bg); color: var(--ok); }
.checklist .warn .icon { background: var(--warn-bg); color: var(--warn); }
.checklist .title { font-weight: 600; }
.checklist .detail { color: var(--muted); font-size: 13px; }
.checklist .fix { margin-left: auto; white-space: nowrap; font-size: 13px; }

/* --- Смуги розподілу --- */
.bars { display: grid; grid-template-columns: max-content minmax(80px, 1fr) max-content; gap: 8px 12px; align-items: center; }
.bars .bar-track { height: 10px; }
.bars .bar { height: 10px; border-radius: 0 4px 4px 0; background: var(--accent); min-width: 2px; }
.bars .bar-value { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; white-space: nowrap; }

/* --- Хронологія подій --- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.timeline li::after { content: ""; position: absolute; left: 8.5px; top: 18px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline li.payment::before { background: var(--accent); }
.timeline li.payment_error::before { background: var(--error); }
.timeline li.callback::before { background: #8b5cf6; }
.timeline .when { color: var(--muted); font-size: 12px; }

/* --- Властивості --- */
dl.props { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; margin: 0; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.fact { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); }
.fact .label { color: var(--muted); font-size: 12px; }
.fact .value { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
pre { background: var(--bg); padding: 12px; border-radius: 6px; overflow-x: auto; font-size: 12px; margin: 8px 0 0; }
details > summary { cursor: pointer; color: var(--accent); }

/* --- Залишки --- */
.stock-wrap { max-height: calc(100vh - 260px); min-height: 320px; overflow: auto; }
.stock-wrap thead th { position: sticky; top: 0; z-index: 2; }
.stock-wrap .sticky-col { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.stock-wrap thead .sticky-col { z-index: 3; background: var(--surface-2); }
.stock-wrap th.seller { text-align: center; white-space: normal; min-width: 76px; text-transform: none; letter-spacing: 0; font-size: 12px; }
.stock-wrap th.seller .kind { display: block; font-weight: normal; color: var(--muted); font-size: 11px; }
.stock-wrap td { padding: 5px 8px; vertical-align: middle; }
.stock-wrap td.qty-cell { text-align: center; }
input.qty { width: 60px; padding: 4px 6px; text-align: right; font-variant-numeric: tabular-nums; }
input.qty.has { background: var(--ok-bg); border-color: #b7e0c6; }
input.qty.changed { background: #fff7d6; border-color: #e0b100; }
.save-bar {
  position: sticky; bottom: 0; z-index: 5; display: none; align-items: center; gap: 12px; justify-content: space-between;
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: var(--radius); margin-top: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
.save-bar.visible { display: flex; }
.save-bar button.secondary { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }

/* --- Мапа регіонів --- */
.map-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; color: var(--text); }
.legend-item:hover { text-decoration: none; }
.legend-item:hover b { text-decoration: underline; }
.store-swatch { background: var(--text); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--text); width: 10px; height: 10px; }
.map-wrap { position: relative; max-width: 960px; }
.map-wrap svg { width: 100%; height: auto; display: block; }
.map-wrap .oblast { stroke: #fff; stroke-width: 1.5; stroke-linejoin: round; cursor: pointer; transition: opacity .1s, fill .15s; }
.map-wrap .oblast:hover { opacity: .82; }
.map-wrap .oblast.static { cursor: default; }
.map-wrap .oblast.static:hover { opacity: 1; }
.map-wrap .oblast.other { fill-opacity: .35; }
.map-wrap .oblast:focus-visible { outline: none; stroke: var(--text); stroke-width: 2.5; }
.map-wrap text { font-family: inherit; paint-order: stroke; stroke: #fff; stroke-linejoin: round; pointer-events: none; }
.oblast-labels text { font-size: 10.5px; fill: #52514e; stroke-width: 3px; }
.region-labels text { font-size: 14px; fill: #0b0b0b; stroke-width: 4px; }
.region-labels .region-name { font-weight: 700; font-size: 16px; }
.stores rect { fill: #0b0b0b; stroke: #fff; stroke-width: 2px; pointer-events: none; }
.stores text { font-size: 12px; font-weight: 600; fill: #0b0b0b; stroke-width: 3px; }
.map-tip {
  position: absolute; z-index: 2; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; box-shadow: 0 4px 14px rgba(0,0,0,.12); font-size: 13px; max-width: 260px;
}
.map-tip .tip-title { font-weight: 700; margin-bottom: 2px; }
.oblast-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0 16px; }
.oblast-grid label.check { margin: 3px 0; align-items: flex-start; }
.oblast-grid label.check input { margin-top: 3px; }
.oblast-grid label.check .small { display: block; }
.cols-side .oblast-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

/* --- Вхід, сторінка оплати --- */
.center-box { max-width: 400px; margin: 72px auto; }
.center-box .logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; margin-bottom: 20px; }
.center-box .logo img { width: 32px; height: 32px; }
.center-box dl.props { grid-template-columns: 110px 1fr; }
.center-box input[type=text], .center-box input[type=password] { max-width: none; }
.center-box button[type=submit] { width: 100%; justify-content: center; }

@media (max-width: 900px) {
  .cols-2, .cols-side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  main { padding: 16px; }
  header.top { padding: 0 16px; gap: 0 12px; }
  header.top .brand { flex: 1; }
  header.top nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  header.top nav a { padding: 8px 6px; white-space: nowrap; }
  dl.props { grid-template-columns: 1fr; gap: 2px 0; }
  dl.props dd { margin-bottom: 8px; }
  .checklist li { grid-template-columns: 22px minmax(0, 1fr); }
  .checklist .fix { grid-column: 2; margin-left: 0; }
  header.top .brand { flex: 0 1 auto; }
  header.top .header-right { margin-left: auto; }
  .mode-pill .long { display: none; }
  .mode-pill .short { display: inline; }
}
