:root {
  color-scheme: light dark;
  --bg: #f3f4f6; --surface: #ffffff; --surface-2: #f8fafc; --border: #d9dee6; --border-strong: #b8c0cc;
  --text: #111827; --text-2: #4b5563; --muted: #6b7280;
  --accent: #2563eb; --accent-text: #ffffff; --accent-soft: #e0eaff;
  --ok: #15803d; --ok-bg: #e3f6e9; --warn: #92400e; --warn-bg: #fff3d6; --err: #b91c1c; --err-bg: #fde6e6;
  --run: #1d4ed8; --run-bg: #e0eaff;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .06);
  --c1: #2563eb; --c2: #dc2626; --c3: #16a34a; --c4: #d97706; --c5: #7c3aed; --c6: #0891b2; --c7: #db2777; --c8: #65a30d;
  --radius: 8px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --surface: #181c25; --surface-2: #1d222d; --border: #2b3240; --border-strong: #3d4658;
    --text: #e6e9ef; --text-2: #aab2c0; --muted: #8b94a5;
    --accent: #5b8def; --accent-text: #0b1020; --accent-soft: #1f2d4d;
    --ok: #5fd68a; --ok-bg: #163324; --warn: #f0c36a; --warn-bg: #3a2f14; --err: #ff8a8a; --err-bg: #3d1a1d;
    --run: #8fb2ff; --run-bg: #1f2d4d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --c1: #6ea0ff; --c2: #ff7b72; --c3: #4fd18b; --c4: #f0b34a; --c5: #b794f6; --c6: #4dd0e1; --c7: #f472b6; --c8: #a3e635;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.25; }
h2 { font-size: 17px; } h3 { font-size: 14px; color: var(--text-2); margin-top: 1.2em; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 12.5px; }
pre { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: 12px; } .strong { font-weight: 600; } .right { text-align: right; }
.error { color: var(--err); } .boot { padding: 2rem; color: var(--muted); }
[hidden] { display: none !important; }

/* оболонка */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px; height: 46px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; font-size: 15px; }
.brand-sub { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; }
.logo::after { content: ""; position: absolute; inset: 5px 4px; border-left: 2px solid #fff; border-bottom: 2px solid #fff; transform: skewX(-25deg) scaleY(.7); opacity: .95; }
.topbar nav { display: flex; gap: 2px; flex: 1; }
.nav-link { padding: 6px 12px; border-radius: 6px; color: var(--text-2); text-decoration: none; font-weight: 500; }
.nav-link:hover { background: var(--surface-2); }
.nav-link[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.lang { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.lang-btn { border: 0; background: transparent; color: var(--text-2); padding: 4px 10px; cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; }
.lang-btn.active { background: var(--accent); color: var(--accent-text); }
main { max-width: 1280px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; outline: none; }

/* картки, кнопки, поля */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.section-head h2 { margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 200px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.section-head .actions, .results-head .actions { margin-top: 0; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--err); border-color: var(--err); }
.btn.small { padding: 2px 9px; font-size: 13px; }
.icon-btn { padding: 4px 6px; border-color: transparent; background: transparent; color: var(--text-2); }
.ico { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
input[type=text], input[type=number], select { font: inherit; padding: 5px 8px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--text); min-width: 0; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); margin: 0; }
.field-label { display: block; font-weight: 600; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); margin-left: 6px; }
td .badge, .row .badge { margin-left: 0; }
.badge.done, .badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.running, .badge.queued { background: var(--run-bg); color: var(--run); border-color: transparent; }
.badge.error { background: var(--err-bg); color: var(--err); border-color: transparent; }
.badge.cancelled { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.user { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.alert { padding: 10px 12px; border-radius: 6px; margin: 8px 0; border: 1px solid transparent; }
.alert.warn { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.alert.err { background: var(--err-bg); color: var(--err); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.errtext { margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; font-size: 12px; max-height: 240px; overflow: auto; }

/* дропзона */
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 34px 16px; border: 2px dashed var(--border-strong); border-radius: 10px; text-align: center; cursor: pointer; color: var(--text-2); transition: background .12s, border-color .12s; }
.dropzone .ico { width: 36px; height: 36px; color: var(--accent); }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.busy { opacity: .55; pointer-events: none; }
.dz-title { font-size: 17px; font-weight: 600; color: var(--text); }
.dz-sub { margin-bottom: 8px; }
.upload-status { margin-top: 12px; display: grid; gap: 6px; }
.local .field-label { margin-bottom: 8px; }

/* прогрес / метри */
.bar { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.bar.big { height: 14px; flex: 1; min-width: 200px; }
.bar .fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.pct { font-weight: 700; min-width: 3.5em; text-align: right; font-variant-numeric: tabular-nums; }
.progress .row { margin: 14px 0 8px; flex-wrap: nowrap; }
.file-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.file-head .ico { width: 32px; height: 32px; color: var(--accent); }
.file-head h2 { margin: 0; word-break: break-all; }

/* кандидати */
.cands { display: grid; gap: 8px; }
.cand { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; background: var(--surface); }
.cand:hover:not(.disabled) { border-color: var(--border-strong); background: var(--surface-2); }
.cand.selected { border-color: var(--accent); background: var(--accent-soft); }
.cand.disabled { opacity: .6; cursor: not-allowed; }
.cand-main { flex: 1; min-width: 0; display: grid; gap: 4px; }
.cand-name { font-weight: 600; }
.cand-score { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 3em; text-align: right; }
.meter { height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 99px; }
.meter-fill.shi { background: var(--ok); } .meter-fill.smid { background: #d97706; } .meter-fill.slo { background: var(--err); }
.manual { margin-top: 12px; }

/* списки */
.table-scroll { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--border); }
table.list td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list tr.clickable { cursor: pointer; }
table.list tbody tr:hover { background: var(--surface-2); }
.link { font-weight: 600; text-decoration: none; word-break: break-all; }
.link:hover { text-decoration: underline; }
.sha { cursor: help; color: var(--text-2); }
.sha-full { word-break: break-all; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; margin: 8px 0 0; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; }
tr.has-error td { background: var(--err-bg); }

/* результат */
.results { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.results-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.results-head h2 { margin: 0 0 2px; word-break: break-all; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border-strong); overflow-x: auto; overflow-y: hidden; padding-top: 2px; }
.tab { border: 1px solid transparent; border-bottom: 0; background: transparent; color: var(--text-2); padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer; border-radius: 6px 6px 0 0; white-space: nowrap; margin-bottom: -1px; }
.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--surface); color: var(--accent); border-color: var(--border-strong); border-bottom: 1px solid var(--surface); }
.tab .count { margin-left: 8px; font-size: 12px; font-weight: 500; color: var(--muted); }
.panels { background: var(--surface); border: 1px solid var(--border); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); box-shadow: var(--shadow); min-width: 0; }

/* таблиця даних */
.pager { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.pager-mid { margin: 0 6px; display: inline-flex; align-items: center; gap: 4px; }
.page-input { width: 5.5em; padding: 2px 6px; }
.grow-right { margin-left: auto; }
.grid-wrap { overflow: auto; max-height: calc(100vh - 290px); min-height: 200px; }
table.data { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 13px; }
table.data th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); border-bottom: 1px solid var(--border-strong); border-right: 1px solid var(--border); padding: 0; text-align: left; }
.th-btn { all: unset; box-sizing: border-box; display: flex; align-items: baseline; gap: 6px; width: 100%; padding: 6px 10px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.th-btn:hover { background: var(--accent-soft); }
.th-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.th-unit { color: var(--muted); font-weight: 400; font-size: 12px; }
.sort-ind { margin-left: auto; color: var(--accent); font-size: 10px; min-width: 10px; }
th.num .th-btn { justify-content: flex-end; } th.num .sort-ind { margin-left: 0; }
table.data td { padding: 3px 10px; border-bottom: 1px solid var(--border); border-right: 1px solid color-mix(in srgb, var(--border) 50%, transparent); white-space: nowrap; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12.5px; }
table.data tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
table.data tbody tr:hover td { background: var(--accent-soft); }
.rownum { color: var(--muted); text-align: right; font-size: 12px; padding: 3px 10px; background: var(--surface-2); position: sticky; left: 0; }
table.data th.rownum { z-index: 2; padding: 6px 10px; }

/* графік */
.chart-bar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.chart-bar label { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-weight: 500; }
.chart-body { display: flex; min-height: 440px; }
.chart-main { flex: 1; min-width: 0; padding: 10px; display: flex; flex-direction: column; }
.plot { flex: 1; min-height: 380px; min-width: 0; }
.chart .empty { padding: 60px 10px; text-align: center; color: var(--muted); }
.ychecks { width: 220px; flex: none; border-left: 1px solid var(--border); padding: 10px; overflow-y: auto; max-height: 560px; display: flex; flex-direction: column; gap: 2px; }
.ytitle { font-weight: 600; margin-bottom: 4px; }
.ycheck { display: flex; align-items: center; gap: 7px; padding: 3px 4px; border-radius: 4px; cursor: pointer; }
.ycheck:hover { background: var(--surface-2); }
.swatch { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--border-strong); flex: none; }
.u-legend { font-size: 12.5px; color: var(--text); }
.u-legend .u-label { color: var(--text); }
.u-select { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.u-legend th > * { vertical-align: middle; }
@media (max-width: 760px) { .chart-body { flex-direction: column; } .ychecks { width: auto; border-left: 0; border-top: 1px solid var(--border); max-height: 200px; } }

/* діалоги */
.dialog { border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); color: var(--text); padding: 20px; width: min(560px, 94vw); box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
.dialog::backdrop { background: rgba(10, 14, 22, .55); }
.dialog h2 { margin-bottom: 10px; }
fieldset { border: 1px solid var(--border); border-radius: 6px; margin: 0 0 10px; padding: 6px 12px 8px; }
legend { padding: 0 6px; font-weight: 600; color: var(--text-2); font-size: 13px; }
.opt { display: flex; align-items: flex-start; gap: 8px; padding: 3px 0; cursor: pointer; }
.opt input { margin-top: 3px; }
.radios.inline { display: flex; gap: 20px; }
.checks { max-height: 180px; overflow-y: auto; }

/* тости */
.toasts { position: fixed; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, 92vw); }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: 0 4px 16px rgba(0, 0, 0, .3); word-break: break-word; }
.toast.error { background: var(--err); color: #fff; } .toast.ok { background: var(--ok); color: #fff; }
@media (prefers-color-scheme: dark) { .toast.error, .toast.ok { color: #0b1020; } }
@media (max-width: 640px) { .brand-sub { display: none; } main { padding: 10px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* карта */
.mapview .map-layers { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.map-wrap { position: relative; }
.omap { height: clamp(420px, 68vh, 760px); background: var(--surface-2); color: var(--text); }
.omap.leaflet-container { font: inherit; font-size: 13px; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
.leaflet-container a.map-link { color: var(--accent); font-weight: 600; }
.leaflet-container .leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 80%, transparent); color: var(--text-2); }
.leaflet-container .leaflet-control-attribution a { color: var(--accent); }
.map-pop { min-width: 150px; }
.map-pop dl { display: grid; grid-template-columns: auto auto; gap: 2px 12px; margin: 6px 0 8px; }
.map-pop dt { color: var(--muted); } .map-pop dd { margin: 0; font-variant-numeric: tabular-nums; }
.map-note { padding: 6px 10px; background: var(--warn-bg); color: var(--warn); font-size: 13px; }
.map-legend { position: absolute; left: 10px; bottom: 28px; z-index: 500; background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid var(--border-strong); border-radius: 6px; padding: 6px 10px; width: 170px; font-size: 12px; }
.map-legend .lg-bar { height: 8px; border-radius: 4px; margin: 4px 0; }
.map-legend .lg-ends { display: flex; justify-content: space-between; color: var(--text-2); }
@media (prefers-color-scheme: dark) { .omap.osm .leaflet-tile-pane { filter: brightness(.72) contrast(1.05) saturate(.85); } }

/* вхід (веб-режим) */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 10px; }
.login-card input[type=password] { width: 100%; padding: 8px 10px; font: inherit; }
.login-brand { justify-content: center; }
.login-title { font-size: 18px; margin: 4px 0; text-align: center; }
.login-lang { align-self: center; margin-top: 6px; }
.logout-btn { margin-left: 8px; }
