/* AI Hub owner page and sign-in, style «Диспетчерська»: dark control room. System fonts, no external files (CSP). */
:root {
  --bg: #0e1116; --bar: #0b0e12; --panel: #161b22; --panel-2: #1c2128; --line: #262d36; --line-soft: #1e242c; --line-strong: #363d46;
  --fg: #e6edf3; --muted: #8b96a3; --faint: #6e7681;
  --ok: #3fb950; --ok-fg: #56d364; --ok-bg: #12301b; --ok-line: #23472b;
  --run: #58a6ff; --run-fg: #79b8ff; --run-bg: #0f2a47; --run-line: #1f4d7a;
  --warn: #d29922; --warn-fg: #e3b341; --warn-bg: #2d2a1a;
  --bad: #f85149; --bad-fg: #ff7b72; --bad-bg: #3a1618; --bad-line: #5a2a2a;
  --idle-bg: #21262d;
  --primary: #238636; --primary-line: #2ea043;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.45 var(--sans); }
a { color: var(--run-fg); text-decoration: none; }
a:hover { color: #b3d4ff; }
code, pre, .mono { font-family: var(--mono); }
code { font-size: 12.5px; }
h1, h2, h3 { line-height: 1.25; }
.muted, .meta { color: var(--muted); }
.meta { font-size: 12.5px; }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.empty { color: var(--muted); margin: 6px 0; font-size: 13px; }
.tone-ok { color: var(--ok-fg); } .tone-bad { color: var(--bad-fg); } .tone-warn { color: var(--warn-fg); } .tone-run { color: var(--run-fg); }

/* ---- top bar: brand, sections, connection ---- */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bar); border-bottom: 1px solid var(--line); }
.topbar-row { display: flex; align-items: center; flex-wrap: wrap; gap: 0 22px; max-width: 1360px; margin: 0 auto; padding: 0 24px; min-height: 54px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font: 700 13px var(--mono); letter-spacing: .12em; color: var(--fg); text-transform: uppercase; }
.brand:hover { color: var(--fg); }
.logo { width: 18px; height: 18px; border: 2px solid var(--ok); border-radius: 4px; flex: none; }
.tabs { display: flex; gap: 2px; flex: 1 1 auto; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; font: 500 12px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 18px 12px 16px; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--fg); }
.tabs a.active { color: var(--fg); border-bottom-color: var(--ok); }
.conn { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font: 12px var(--mono); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { max-width: 1360px; margin: 0 auto; padding: 24px 24px 56px; }
.tab > * + * { margin-top: 16px; }
.section-title, .card-title, .sub-label, .field-label { font: 600 11px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.section-title { margin: 8px 0 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; }
.section-head .section-title { margin: 0; }

/* ---- panels ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .empty { padding: 14px 18px; }
.card + .card { margin-top: 16px; }
.card-title { margin: 0 0 12px; }
.card-title.pad { padding: 14px 18px 0; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; min-width: 0; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.card-head .card-title { margin: 0; flex: 1; }
.card > p.muted { margin: -4px 0 14px; font-size: 13px; }
.count { min-width: 22px; padding: 0 7px; border-radius: 4px; background: var(--idle-bg); color: var(--muted); font: 600 11px/18px var(--mono); text-align: center; }

/* tiles: one strip split by 1px lines */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tile { background: var(--panel); padding: 14px 18px; min-width: 0; }
.tile-value { font: 700 30px/1.15 var(--mono); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-label { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.tile.tone-ok .tile-value { color: var(--ok-fg); } .tile.tone-bad .tile-value { color: var(--bad-fg); }
.tile.tone-warn .tile-value { color: var(--warn-fg); } .tile.tone-run .tile-value { color: var(--run-fg); }

.node-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.batch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; align-items: start; }
.batch-grid .card + .card, .node-grid .card + .card, .two-col .card + .card, .stats-grid .card + .card, .split .card + .card, .side .card + .card { margin-top: 0; }

/* ---- node card ---- */
.node { display: flex; flex-direction: column; gap: 12px; }
.node .card-head { margin: 0; }
.node > .meta { margin-top: -8px; font-family: var(--mono); font-size: 11.5px; }
.node.is-offline .card-head h3 { color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--faint); flex: none; }
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot.paused { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.current { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; cursor: pointer; }
.current:hover, .current:focus-visible { border-color: var(--run-line); }
.current.idle { cursor: default; color: var(--muted); font-size: 13px; }
.current.idle:hover { border-color: var(--line); }
.current-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.current-title { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.current .bar { height: 4px; }
.sub-label { margin: 0 0 4px; }
.today { display: flex; gap: 22px; flex-wrap: wrap; border-top: 1px solid var(--line-soft); padding-top: 10px; }
.num.big { font-size: 18px; font-weight: 700; }
.more summary { cursor: pointer; color: var(--muted); font: 600 11px var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.more summary:hover { color: var(--fg); }
.more[open] summary { margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: minmax(90px, max-content) 1fr; gap: 7px 14px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; min-width: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.node .actions { border-top: 1px solid var(--line-soft); padding-top: 12px; margin-top: auto; }
.role { display: inline-flex; align-items: center; gap: 6px; margin-right: auto; }

/* ---- lists of jobs and batches ---- */
.rows > * + * { border-top: 1px solid var(--line-soft); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; cursor: pointer; }
.row:hover .row-title, .batch:hover .row-title { color: var(--run-fg); }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 500; overflow-wrap: anywhere; }
.reason { color: var(--warn-fg); font-size: 12.5px; overflow-wrap: anywhere; }
.batch { display: grid; gap: 6px; padding: 10px 0; cursor: pointer; }
.batch-grid .batch { padding: 0; }
.batch-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
[tabindex]:focus-visible { outline: 2px solid var(--run); outline-offset: 2px; border-radius: 6px; }

/* ---- state pills and tags ---- */
.pill { display: inline-block; padding: 2px 8px; border-radius: 4px; font: 600 11px/1.5 var(--mono); white-space: nowrap; font-variant-numeric: tabular-nums; }
.st-queued { color: var(--warn-fg); background: var(--warn-bg); }
.st-running { color: var(--run-fg); background: var(--run-bg); }
.st-done { color: var(--ok-fg); background: var(--ok-bg); }
.st-failed { color: var(--bad-fg); background: var(--bad-bg); }
.st-cancelled { color: var(--muted); background: var(--idle-bg); }
.tag { display: inline-block; padding: 0 6px; border: 1px solid var(--line-strong); border-radius: 4px; font: 11px/17px var(--mono); color: var(--muted); white-space: nowrap; margin-right: 4px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.tag-accent { color: var(--ok-fg); border-color: var(--ok-line); }
.tag-high { color: var(--bad-fg); border-color: var(--bad-line); }
.tag-low { color: var(--faint); }
.tag-cache { color: var(--ok-fg); border-color: var(--ok-line); }
.chip { display: inline-block; padding: 0 6px; margin: 1px 4px 1px 0; border-radius: 4px; background: var(--idle-bg); font: 11px/18px var(--mono); color: var(--fg); }

/* ---- progress bars ---- */
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 8px 0; display: flex; }
.bar-fill { height: 100%; background: var(--ok); transition: width .4s ease; }
.bar.run .bar-fill { background: var(--run); }
.bar.stack { margin: 2px 0; }
.seg { height: 100%; transition: width .4s ease; }
.seg-ok { background: var(--ok); } .seg-bad { background: var(--bad); } .seg-idle { background: var(--faint); } .seg-run { background: var(--run); }
.mini { height: 4px; background: var(--line); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.mini-fill { height: 100%; background: var(--run); }

/* ---- tables ---- */
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font: 600 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { text-align: left; padding: 10px 12px; border-top: 1px solid var(--line-soft); vertical-align: top; overflow-wrap: anywhere; }
tbody tr:first-child td { border-top: 0; }
th.num, td.num { text-align: right; }
td.right { text-align: right; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }
tr.selected td { background: var(--run-bg); }
tr.selected td:first-child { box-shadow: inset 2px 0 0 var(--run); }
table.jobs td:first-child, table.jobs th:first-child { width: 1%; white-space: nowrap; }
.card:not(.flush) table th:first-child, .card:not(.flush) table td:first-child { padding-left: 0; }
.card:not(.flush) table th:last-child, .card:not(.flush) table td:last-child { padding-right: 0; }
.error-line { color: var(--bad-fg); font-size: 12.5px; margin-top: 2px; }
td.name { font-weight: 500; }
td.barcell { min-width: 110px; }

/* ---- segmented control and filter bar ---- */
.segmented { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.segmented button { font: 500 12px var(--mono); padding: 6px 12px; border: 0; border-left: 1px solid var(--line-strong); border-radius: 0; background: transparent; color: var(--muted); cursor: pointer; min-height: 32px; }
.segmented button:first-child { border-left: 0; }
.segmented button:hover { color: var(--fg); background: var(--panel-2); }
.segmented button.active { background: var(--idle-bg); color: var(--fg); }
.segmented .n { color: var(--faint); margin-left: 6px; }
.segmented button.active .n { color: var(--muted); }
.filterbar { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; }
.filterbar .search { margin-left: auto; width: min(300px, 100%); }

/* ---- jobs: table + side panel ---- */
.split { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.side { position: sticky; top: 72px; }
.side .card { max-height: calc(100vh - 96px); overflow-y: auto; display: grid; gap: 12px; }
.side h2 { margin: 0; font-size: 17px; overflow-wrap: anywhere; }
.side .ids { font: 11.5px var(--mono); color: var(--muted); overflow-wrap: anywhere; }

/* ---- full job view ---- */
.crumb { font: 12px var(--mono); color: var(--muted); }
.job-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.job-head h1 { margin: 0; font-size: 24px; overflow-wrap: anywhere; min-width: 0; }
.job-head .actions { margin-left: auto; }
.prog-line { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px 16px; }
.big-pct { font: 700 40px/1.1 var(--mono); color: var(--run-fg); }
.big-pct.ok { color: var(--ok-fg); } .big-pct.bad { color: var(--bad-fg); } .big-pct.idle { color: var(--muted); } .big-pct.warn { color: var(--warn-fg); }
.job-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.job-grid > div { display: grid; gap: 16px; min-width: 0; }
.job-grid .card + .card { margin-top: 0; }
.file-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line-soft); font-size: 13px; flex-wrap: wrap; }
.file-row:first-child { border-top: 0; }
.file-row a { font-family: var(--mono); overflow-wrap: anywhere; }
.sha { font: 11px var(--mono); color: var(--faint); }
.note { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
pre.json { max-height: 220px; overflow: auto; font-size: 12px; }

/* ---- controls ---- */
button, .btn { font: 500 13px var(--sans); padding: 0 14px; min-height: 34px; border: 1px solid var(--line-strong); background: var(--idle-bg); color: var(--fg); border-radius: 6px; cursor: pointer; line-height: 1.3; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { border-color: #4a525c; background: #292f37; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--primary); border-color: var(--primary-line); color: #fff; }
.btn.primary:hover { background: #2a9a3f; }
.btn.danger { color: var(--bad-fg); border-color: var(--bad-line); }
.btn.danger:hover { background: var(--bad-bg); border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--fg); background: var(--idle-bg); }
.small-btn, .btn.small-btn { font-size: 12.5px; padding: 0 10px; min-height: 28px; }
input, select, textarea { font: inherit; font-size: 13px; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg); color: var(--fg); max-width: 100%; min-height: 34px; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--run); outline-offset: 1px; }
input[type="checkbox"] { padding: 0; min-height: 0; accent-color: var(--ok); width: 15px; height: 15px; vertical-align: -3px; }
.role select { padding: 3px 8px; font-size: 12.5px; min-height: 28px; }
textarea { width: 100%; resize: vertical; }
.form-grid { display: grid; gap: 14px; max-width: 720px; margin-bottom: 14px; }
.field { display: grid; gap: 6px; min-width: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; overflow-wrap: anywhere; font-family: var(--mono); font-size: 12.5px; }
.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.inline input { flex: 1 1 220px; }
.notice { margin-top: 14px; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--run-line); background: #0f1b2a; font-size: 13px; overflow-wrap: anywhere; }
.notice.warn { border-color: #5c4a1a; background: var(--warn-bg); }
pre { background: var(--bar); border: 1px solid var(--line); color: #c9d1d9; padding: 10px 12px; border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font-size: 12px; line-height: 1.6; }
.row-actions { display: inline-flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* switches for job types */
.switches { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.switch { justify-content: space-between; width: 100%; min-height: 40px; padding: 0 12px; background: var(--bg); border-color: var(--line); font: 12.5px var(--mono); text-align: left; }
.switch:hover { background: var(--panel-2); border-color: var(--line-strong); }
.switch .knob { width: 30px; height: 16px; border-radius: 8px; background: var(--line-strong); position: relative; flex: none; transition: background .15s; }
.switch .knob::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); transition: left .15s, background .15s; }
.switch[aria-checked="true"] { border-color: var(--ok-line); }
.switch[aria-checked="true"] .knob { background: var(--primary); }
.switch[aria-checked="true"] .knob::after { left: 16px; background: #fff; }

/* pairing a computer */
.copy { margin-top: 12px; }
.copy-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.notice .copy { margin-top: 0; }
.pair-code { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 14px; margin: 16px 0 4px; }
.code-big { font: 700 30px/1.2 var(--mono); letter-spacing: .14em; color: var(--ok-fg); }
.os-pick { margin-top: 12px; }
#key-out:empty, #code-out:empty { display: none; }
#clients { margin-top: 16px; }

/* ---- batch dialog ---- */
dialog { width: min(860px, calc(100vw - 24px)); max-height: calc(100vh - 32px); border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel); color: var(--fg); padding: 20px; box-shadow: 0 16px 48px rgba(0, 0, 0, .5); }
dialog::backdrop { background: rgba(1, 4, 9, .7); }
dialog > div { display: grid; gap: 10px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.dialog-head h2 { margin: 0; font-size: 18px; overflow-wrap: anywhere; min-width: 0; }
.dialog-foot { display: flex; justify-content: flex-end; margin-top: 16px; }
.error-box { padding: 10px 12px; border-radius: 6px; border: 1px solid var(--bad-line); background: var(--bad-bg); color: var(--bad-fg); font-size: 13px; overflow-wrap: anywhere; }
.error-box strong { font-family: var(--mono); }
pre.log { max-height: 320px; overflow-y: auto; }

/* ---- sign-in ---- */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 28px 24px; }
.login-card .brand { margin: 0; }
.login-card p { margin: 10px 0 22px; color: var(--muted); font-size: 13px; }
.login-card form { display: grid; gap: 8px; }
.login-card label { font: 600 11px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.login-card input { width: 100%; }
.login-card button { margin-top: 10px; width: 100%; }

/* ---- narrower screens ---- */
@media (max-width: 1100px) {
  .split, .job-grid { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
}
@media (max-width: 600px) {
  .hide-narrow { display: none; }
  main { padding: 16px 12px 40px; }
  .topbar-row { padding: 0 12px; gap: 0 14px; }
  .tabs { order: 3; flex-basis: 100%; margin: 0 -6px; }
  .tabs a { padding: 10px 8px 9px; }
  .node-grid, .two-col, .batch-grid, .stats-grid { grid-template-columns: minmax(0, 1fr); }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile-value { font-size: 24px; }
  .card { padding: 14px; }
  td, th { padding: 9px 8px; }
  dialog { padding: 16px; }
  .role { margin-right: 0; width: 100%; }
  .filterbar .search { margin-left: 0; width: 100%; }
  .job-head .actions { margin-left: 0; }
  .big-pct { font-size: 32px; }
}
.kv + .sub-label { margin-top: 14px; }
#stats-body > * + * { margin-top: 16px; }
@media (max-width: 600px) { .conn { margin-left: auto; } }
