:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --line: #e3e6eb;
  --text: #1b1f24;
  --muted: #6a7280;
  --accent: #1f9d68;
  --accent-ink: #ffffff;
  --accent-soft: #e3f4ec;
  --danger: #d23f3f;
  --danger-soft: #fbe7e7;
  --warn: #b7791f;
  --warn-soft: #fbf1dc;
  --info: #2f6fd6;
  --info-soft: #e5eefc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #171b21;
    --panel-2: #1c2128;
    --line: #2a3039;
    --text: #e6e9ee;
    --muted: #8d96a3;
    --accent: #2bb77c;
    --accent-ink: #06140d;
    --accent-soft: #143325;
    --danger: #f06262;
    --danger-soft: #3a1b1d;
    --warn: #e0a84a;
    --warn-soft: #3a2d15;
    --info: #6aa0ff;
    --info-soft: #182a47;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
.hidden { display: none !important; }
a { color: var(--info); }
code, pre { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 10px; font-weight: 650; }
h3 { font-size: 14px; margin: 14px 0 6px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 10px; }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; }
.brand b { display: block; font-size: 16px; }
.brand small { color: var(--muted); }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); position: relative; flex: none; }
.logo::after { content: ""; position: absolute; inset: 6px 9px; border: 2px solid var(--accent-ink); border-radius: 3px; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; margin-bottom: 2px;
}
#nav a:hover { background: var(--panel-2); }
#nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#nav a .ico { width: 18px; text-align: center; opacity: .85; }
#nav { flex: 1; min-height: 0; overflow-y: auto; }
.nav-h { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 10px 4px; cursor: default; user-select: none; }
.nav-h.fold { cursor: pointer; }
.side-foot { margin-top: 8px; display: grid; gap: 6px; flex: none; }
details.info { margin: 0 0 12px; font-size: 12.5px; color: var(--muted); }
details.info > summary { cursor: pointer; user-select: none; width: fit-content; }
details.info > div { margin-top: 6px; line-height: 1.5; }

.who { padding: 8px 10px; border-radius: 8px; background: var(--panel-2); font-size: 13px; }
.who b { display: block; }
main { padding: 22px 26px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 13px; }

/* ---------- елементи ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 14px; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 7px 12px; border-radius: 8px; font: inherit; cursor: pointer; display: inline-flex; gap: 6px;
  align-items: center; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn.xs { padding: 2px 7px; font-size: 12px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
textarea { width: 100%; min-height: 70px; resize: vertical; }
textarea.code { font-family: var(--mono); font-size: 12.5px; min-height: 220px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
label.fld { display: grid; gap: 4px; font-size: 13px; }
label.fld > span { color: var(--muted); }
label.fld .req { color: var(--danger); }
.hint { font-size: 12px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px;
  font-size: 12px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.badge.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.err { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip { display: inline-block; padding: 1px 7px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); font-size: 12px; margin: 1px 2px 1px 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; }
.stat.sel { outline: 2px solid var(--accent); }
.stat b { font-size: 22px; display: block; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12.5px; }

/* ---------- таблиці ---------- */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th, table.t td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.t th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover { background: var(--panel-2); }
table.t tr.sel { background: var(--accent-soft); }
table.t td.w1 { width: 1%; white-space: nowrap; }
/* «Телефони»: щільна таблиця, обмежена по ширині, довгі тексти обрізаються (повний — у title) */
.stats.compact { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-bottom: 10px; }
.stats.compact .stat { padding: 7px 12px; display: flex; align-items: baseline; gap: 8px; }
.stats.compact .stat b { font-size: 18px; display: inline; }
.stat.warn b { color: var(--danger); }
.phones-wrap { max-width: none; }
table.t.phones th, table.t.phones td, table.t.dense th, table.t.dense td { padding: 6px 10px; }
table.t.phones td, table.t.dense td { max-width: 0; }
table.t.phones td.w1, table.t.dense td.w1 { max-width: none; }
table.t.phones th:nth-child(2) { width: 22%; } table.t.phones th:nth-child(3) { width: 14%; }
table.t.phones th:nth-child(4) { width: 36%; } table.t.phones th:nth-child(5) { width: 22%; }
table.t.phones tr.bad td:first-child, table.t.dense tr.bad td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
table.t.phones tr.busy td:first-child, table.t.dense tr.busy td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.t.dense tbody tr.click { cursor: pointer; }
.clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-cell small.clip { display: block; }
.prog-cell .clip { white-space: normal; overflow: visible; }
.prog-cell { display: grid; grid-template-columns: 130px 1fr; gap: 10px; align-items: center; }
.prog-cell .progress { height: 8px; }
.name-cell b { display: block; }
.name-cell small { color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Картка = ширина --wsw (під висоту вікна: ціла картка влазить без прокрутки; 250–380px). Плеєр просять намалювати екран саме під цю ширину
   (width у /phone/start = ширина картки − 20: по 10px поля з боків), тож нічого не обрізається. Змінив розмір вікна — «⟳» на картці підганяє наново. */
.ws-grid { --wsw: clamp(250px, calc((100vh - 190px) / 2), 380px); display: grid; grid-template-columns: repeat(auto-fill, var(--wsw)); gap: 12px; justify-content: start; }
.ws-cell { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); display: flex; flex-direction: column; }
/* Шапка: ім'я телефона завжди читається повністю; кнопки справа в тому ж рядку, а коли тісно (вузька картка) — переносяться другим рядком */
.ws-head { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; padding: 6px 8px; border-bottom: 1px solid var(--line); min-width: 0; border-radius: var(--radius) var(--radius) 0 0; }
.ws-head b { min-width: 0; }
.ws-btns { display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; margin-left: auto; }
.ws-body { height: calc(var(--wsw) * 2 - 40px); display: flex; align-items: center; justify-content: center; background: var(--panel-2); border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }
.ws-body iframe { width: 100%; height: 100%; border: 0; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { width: 240px; }
.bulk {
  position: sticky; top: 8px; z-index: 5; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--text); color: var(--bg); padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px; box-shadow: var(--shadow);
}
.bulk .btn { background: transparent; color: var(--bg); border-color: color-mix(in srgb, var(--bg) 30%, transparent); }
.bulk .btn:hover { background: color-mix(in srgb, var(--bg) 12%, transparent); }
.bulk .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- модалки, шухляда, тости ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 20, .45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow: auto; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: min(640px, 100%); border: 1px solid var(--line); }
.modal.wide { width: min(920px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 16px 18px; max-height: 70vh; overflow: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--panel); }
.drawer-ov { position: fixed; inset: 0; background: rgba(10, 14, 20, .35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--panel); z-index: 41; box-shadow: var(--shadow); display: flex; flex-direction: column; border-left: 1px solid var(--line); }
.drawer .modal-body { max-height: none; flex: 1; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 420px; }
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--accent); color: var(--accent-ink); }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv > div:nth-child(odd) { color: var(--muted); }
.kv > div { overflow-wrap: anywhere; }
.shot { max-width: 100%; border-radius: 10px; border: 1px solid var(--line); display: block; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { background: none; border: 0; padding: 8px 12px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--text); border-color: var(--accent); font-weight: 600; }

/* ---------- API-провідник ---------- */
.api-layout { display: grid; grid-template-columns: 300px 1fr; gap: 14px; align-items: start; }
.api-tree { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; position: sticky; top: 12px; max-height: calc(100vh - 110px); overflow: auto; }
.api-tree input { width: 100%; margin-bottom: 8px; }
.api-tree details { margin: 2px 0; }
.api-tree summary { cursor: pointer; padding: 5px 6px; border-radius: 6px; font-weight: 600; font-size: 13px; list-style: none; }
.api-tree summary::before { content: "▸ "; color: var(--muted); }
.api-tree details[open] > summary::before { content: "▾ "; }
.api-tree summary:hover { background: var(--panel-2); }
.api-tree .sub { padding-left: 10px; }
.api-tree .sub > summary { font-weight: 500; color: var(--muted); }
.api-tree a { display: block; padding: 4px 8px 4px 20px; border-radius: 6px; color: var(--text); text-decoration: none; font-size: 13px; }
.api-tree a:hover { background: var(--panel-2); }
.api-tree a.on { background: var(--accent-soft); color: var(--accent); }
.json { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto; max-height: 520px; white-space: pre-wrap; word-break: break-word; margin: 0; }
.json .k { color: var(--info); }
.json .s { color: var(--accent); }
.json .n { color: var(--warn); }
.json .b { color: var(--danger); }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 12.5px; display: block; overflow: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--panel-2); }
.md pre { background: var(--panel-2); padding: 10px; border-radius: 8px; overflow: auto; border: 1px solid var(--line); }
.md code { background: var(--panel-2); padding: 1px 4px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md h2 { margin-top: 18px; }
.field-desc { max-height: 3.2em; overflow: hidden; cursor: pointer; }
.field-desc.open { max-height: none; }

/* ---------- вхід ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: min(380px, 100%); padding: 26px; box-shadow: var(--shadow); }
.auth h1 { margin-bottom: 4px; }
.auth form { display: grid; gap: 12px; margin-top: 18px; }

.notice { padding: 10px 12px; border-radius: 8px; background: var(--info-soft); color: var(--text); font-size: 13px; border: 1px solid transparent; }
.notice.warn { background: var(--warn-soft); }
.notice.err { background: var(--danger-soft); }
.progress { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .2s; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.pick-list { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.pick-list label { display: flex; gap: 8px; align-items: center; padding: 3px 4px; border-radius: 6px; }
.pick-list label:hover { background: var(--panel-2); }

/* ---------- конструктор потоків ---------- */
.flow-list { display: grid; gap: 8px; }
.flow-children { border-left: 2px solid var(--accent); margin-left: 10px; padding-left: 12px; margin-top: 8px; }
.flow-block { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.flow-block.container { background: var(--accent-soft); border-color: transparent; }
.flow-block-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.flow-block-head .t { font-weight: 600; }
.flow-block-head .num { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.flow-block .grid2 { gap: 8px; }
.filter-row { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; gap: 8px; align-items: center; }
  .brand { padding: 0 8px 0 0; }
  #nav { display: flex; flex-wrap: nowrap; gap: 2px; overflow-x: auto; overflow-y: hidden; flex: 1 1 100%; order: 3; }
  #nav a { white-space: nowrap; }
  .nav-h { display: none; }
  .side-foot { margin: 0; display: flex; }
  .who { display: none; }
  main { padding: 16px; }
  .api-layout { grid-template-columns: 1fr; }
  .api-tree { position: static; max-height: 300px; }
  .toolbar input[type=search] { width: 100%; }
}

/* DEBUG-діагностика */
.notice.ok { background: var(--accent-soft); }
tr.hl { background: var(--accent-soft); }
tr.hl td { font-weight: 500; }
pre.code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; white-space: pre-wrap; word-break: break-word; margin: 6px 0 0; }

/* меню «⋯» у рядках */
details.more { position: relative; display: inline-block; }
details.more > summary { list-style: none; cursor: pointer; }
details.more > summary::-webkit-details-marker { display: none; }
.more-list { position: absolute; right: 0; top: 100%; z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; display: grid; min-width: 190px; }
.more-list .btn { justify-content: flex-start; }
.cols2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); gap: 14px; align-items: start; }

/* Профіль-набір (Робоче поле): плаваюче вікно з даними для копіювання й фото на телефон */
.prof-sec { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 10px 0 2px; }
.prof-row { display: grid; grid-template-columns: 112px 1fr auto; gap: 6px 8px; align-items: start; padding: 3px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.prof-row .k { color: var(--muted); }
.prof-v { cursor: copy; overflow-wrap: anywhere; }
.prof-chip { cursor: copy; }
.prof-photos { display: flex; gap: 14px; flex-wrap: wrap; }
.prof-ph { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.prof-ph img { border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); object-fit: cover; }
