/* Адмінка «Чати кураторів». Без залежностей. Теми — через custom properties. */
:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --surface-3: #e8e8e4;
  --border: #e1e0db;
  --border-strong: #c9c8c2;
  --text: #17171a;
  --text-2: #55545a;
  --text-3: #85848a;
  --accent: #2563c9;
  --accent-ink: #ffffff;
  --accent-soft: #e6eefb;
  --good: #1d7a3e;   --good-soft: #e3f3e8;
  --warn: #946200;   --warn-soft: #fbf0d6;
  --bad: #b8322f;    --bad-soft: #fbe5e4;
  --info: #5b4bc4;   --info-soft: #ecebfb;
  --series-client: #2a78d6;
  --series-staff: #eb6834;
  --bubble-client: #ffffff;
  --bubble-staff: #eef4fd;
  --bubble-bot: #f3f1fb;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  --radius: 8px;
  --radius-sm: 6px;
  --side-w: 220px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141416;
    --surface: #1c1c1f;
    --surface-2: #232327;
    --surface-3: #2c2c31;
    --border: #2f2f34;
    --border-strong: #45454c;
    --text: #ececef;
    --text-2: #b4b3ba;
    --text-3: #85848c;
    --accent: #5b93ec;
    --accent-ink: #0d1424;
    --accent-soft: #1d2a40;
    --good: #5ec27f;   --good-soft: #17301f;
    --warn: #e0b04f;   --warn-soft: #33290f;
    --bad: #ef7b78;    --bad-soft: #3a1c1c;
    --info: #a69bf0;   --info-soft: #25223f;
    --series-client: #3987e5;
    --series-staff: #d95926;
    --bubble-client: #222226;
    --bubble-staff: #1c2638;
    --bubble-bot: #24213a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 18px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141416; --surface: #1c1c1f; --surface-2: #232327; --surface-3: #2c2c31;
  --border: #2f2f34; --border-strong: #45454c; --text: #ececef; --text-2: #b4b3ba; --text-3: #85848c;
  --accent: #5b93ec; --accent-ink: #0d1424; --accent-soft: #1d2a40;
  --good: #5ec27f; --good-soft: #17301f; --warn: #e0b04f; --warn-soft: #33290f;
  --bad: #ef7b78; --bad-soft: #3a1c1c; --info: #a69bf0; --info-soft: #25223f;
  --series-client: #3987e5; --series-staff: #d95926;
  --bubble-client: #222226; --bubble-staff: #1c2638; --bubble-bot: #24213a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 18px rgba(0,0,0,.35);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 620; }
h3 { font-size: 14px; font-weight: 620; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- логін ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 28px 24px; box-shadow: var(--shadow); display: grid; gap: 14px;
}
.login-card .sub { color: var(--text-2); }
.login-error { color: var(--bad); background: var(--bad-soft); padding: 8px 10px; border-radius: var(--radius-sm); }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; letter-spacing: .5px;
}
.brand-mark.sm { width: 26px; height: 26px; border-radius: 7px; font-size: 11px; }

/* ---------- каркас ---------- */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
}
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--text); }
.brand:hover { text-decoration: none; }
.menu-btn { display: none; }
.nav { display: flex; flex-direction: column; padding: 4px 8px 12px; gap: 1px; flex: 1; }
.nav a {
  color: var(--text-2); padding: 7px 10px; border-radius: var(--radius-sm); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav-group {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3);
  padding: 14px 10px 4px; font-weight: 600;
}
.side-user {
  margin-top: auto; border-top: 1px solid var(--border); padding: 12px 10px 4px; display: grid; gap: 6px;
  color: var(--text-2); font-size: 13px;
}
.side-user strong { color: var(--text); }
.main { padding: 22px 28px 60px; min-width: 0; outline: none; }

@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; z-index: 20; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .side-top { padding: 10px 16px; }
  .menu-btn { display: inline-flex; }
  .nav { display: none; padding: 0 8px 10px; max-height: 70vh; overflow-y: auto; }
  .nav.open { display: flex; }
  .main { padding: 16px 16px 48px; }
}

/* ---------- шапка сторінки ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 16px; }
.page-head h1 { margin-right: auto; }
.page-head .crumbs { width: 100%; font-size: 13px; color: var(--text-3); }
.lead { color: var(--text-2); margin: -8px 0 16px; max-width: 70ch; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.stack { display: grid; gap: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 16px; align-items: start; }

/* ---------- картки, плитки ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.card > h2, .card > .card-head { margin-bottom: 12px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.card-head h2 { margin-right: auto; }
.card.flush { padding: 0; }
.card.flush > .card-head { padding: 14px 16px 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: grid; gap: 4px; color: var(--text);
}
a.tile:hover { border-color: var(--border-strong); text-decoration: none; }
.tile .label { color: var(--text-2); font-size: 13px; }
.tile .value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tile .hint { color: var(--text-3); font-size: 12px; }
.tile.bad .value { color: var(--bad); }
.tile.warn .value { color: var(--warn); }

/* ---------- кнопки та форми ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 550; font-size: 13.5px; line-height: 1;
  padding: 8px 12px; min-height: 34px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 8px; min-height: 28px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn.busy { pointer-events: none; opacity: .65; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 7px 9px; min-height: 34px; width: 100%; max-width: 100%;
}
textarea { min-height: 90px; resize: vertical; line-height: 1.45; }
textarea.code { font-family: var(--mono); font-size: 13px; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; min-height: 0; padding: 0; accent-color: var(--accent); margin: 0; }
input[type=color] { padding: 2px; width: 44px; height: 34px; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-2); }
.f { display: grid; gap: 5px; min-width: 0; }
.f > span:first-child { font-weight: 550; font-size: 13px; color: var(--text); }
.f .hint, .hint { color: var(--text-3); font-size: 12.5px; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 12px; }
.toolbar .f { flex: 1 1 160px; }
.toolbar .f.narrow { flex: 0 1 150px; }
.toolbar .f.search { flex: 2 1 220px; }
.inline-group { display: flex; flex-wrap: wrap; gap: 8px; }
.inline-group .f { flex: 1 1 110px; }
.weekdays { display: flex; flex-wrap: wrap; gap: 6px; }
.weekdays label {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 6px 10px; cursor: pointer;
}
.weekdays label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; min-width: 0; }
legend { padding: 0 6px; font-weight: 600; font-size: 13px; }

/* ---------- мультивибір ---------- */
.ms { position: relative; }
.ms-btn {
  width: 100%; text-align: left; justify-content: space-between; font-weight: 400;
  min-height: 34px; overflow: hidden;
}
.ms-btn .ms-val { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-btn .ms-val.placeholder { color: var(--text-3); }
.ms-pop {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 100%; width: max-content; max-width: min(340px, 90vw);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px; display: grid; gap: 4px;
}
.ms-pop input[type=search] { min-height: 30px; }
.ms-list { max-height: 260px; overflow-y: auto; display: grid; }
.ms-list label { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 4px; cursor: pointer; }
.ms-list label:hover { background: var(--surface-2); }
.ms-item {
  all: unset; box-sizing: border-box; display: block; width: 100%; cursor: pointer; padding: 6px 8px; border-radius: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ms-item:hover, .ms-item:focus-visible { background: var(--surface-2); }
.ms-item .sub { color: var(--text-3); font-size: 12px; }
.ms-list .count { margin-left: auto; color: var(--text-3); font-size: 12px; padding-left: 10px; }

/* ---------- таблиці ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.card .table-wrap { border-radius: var(--radius-sm); }
.card.flush .table-wrap { border: 0; border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th {
  font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface-2);
  position: sticky; top: 0; white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
tr.clickable { cursor: pointer; }
tr.selected td { background: var(--accent-soft) !important; }
td.check-col, th.check-col { width: 34px; padding-right: 0; }
td .sub { color: var(--text-3); font-size: 12px; }
.empty { padding: 28px 16px; text-align: center; color: var(--text-3); }
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; justify-content: space-between; padding: 10px 2px 0; color: var(--text-2); font-size: 13px; }

/* ---------- чіпи, бейджі ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; line-height: 18px; background: var(--surface-3); color: var(--text); white-space: nowrap;
  border: 1px solid transparent;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--text-3)); flex: none; }
.chip.crm { background: transparent; border: 1px dashed var(--border-strong); color: var(--text-2); }
.chip.crm::after {
  content: "CRM"; font-size: 9px; font-weight: 700; letter-spacing: .04em; color: var(--text-3);
  border-left: 1px solid var(--border-strong); padding-left: 5px; margin-left: 1px;
}
.chip button { all: unset; cursor: pointer; color: var(--text-3); font-size: 14px; line-height: 1; padding: 0 1px; }
.chip button:hover { color: var(--bad); }
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 550; line-height: 18px; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- вкладки ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button {
  all: unset; cursor: pointer; padding: 8px 12px; color: var(--text-2); font-weight: 550; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs button .n { color: var(--text-3); font-weight: 500; margin-left: 4px; font-variant-numeric: tabular-nums; }

/* ---------- прогрес, мітри ---------- */
.progress { height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; min-width: 80px; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.progress.bad > i { background: var(--bad); }
.meter { display: inline-flex; align-items: center; gap: 8px; }
.meter .progress { width: 70px; }

/* ---------- банери ---------- */
.banner {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); margin-bottom: 16px;
}
.banner.good { background: var(--good-soft); border-color: transparent; }
.banner.warn { background: var(--warn-soft); border-color: transparent; }
.banner.info { background: var(--info-soft); border-color: transparent; }
.banner.bad { background: var(--bad-soft); border-color: transparent; }
.banner strong { display: block; margin-bottom: 2px; }
.note { font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; }
.note code { background: var(--surface-3); padding: 0 4px; border-radius: 3px; }

/* ---------- повідомлення ---------- */
.msgs { display: grid; gap: 8px; max-height: 620px; overflow-y: auto; padding: 4px 2px; }
.msg {
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 11px; max-width: 86%;
  background: var(--bubble-client); justify-self: start; overflow-wrap: anywhere;
}
.msg.staff { background: var(--bubble-staff); justify-self: end; border-color: color-mix(in srgb, var(--accent) 25%, var(--border)); }
.msg.bot { background: var(--bubble-bot); justify-self: end; border-style: dashed; border-color: color-mix(in srgb, var(--info) 40%, var(--border)); }
.msg .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--text-3); margin-bottom: 3px; }
.msg .meta b { color: var(--text-2); font-weight: 600; }
.msg .text { white-space: pre-wrap; }

/* ---------- графік ---------- */
.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; width: 100%; height: auto; min-width: 420px; }
.chart .axis { fill: var(--text-3); font-size: 10px; font-family: var(--font); }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .c-client { fill: var(--series-client); }
.chart .c-staff { fill: var(--series-staff); }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: color-mix(in srgb, var(--text) 6%, transparent); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--text-2); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* ---------- кнопки розсилки (редактор рядків) ---------- */
.btn-rows { display: grid; gap: 8px; }
.btn-row { display: grid; gap: 6px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 8px; }
.btn-cell { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto; gap: 6px; }
@media (max-width: 560px) { .btn-cell { grid-template-columns: 1fr; } }

/* ---------- кандидати FAQ ---------- */
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.preview-box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.sample-list { max-height: 180px; overflow-y: auto; font-size: 13px; columns: 2 200px; column-gap: 16px; }
.sample-list div { break-inside: avoid; padding: 1px 0; }

/* ---------- модалка ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 50; background: rgba(10,10,14,.45);
  display: grid; place-items: center; padding: 16px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); width: 100%; max-width: 560px;
  padding: 18px 18px 16px; display: grid; gap: 14px; max-height: calc(100vh - 32px); overflow-y: auto;
}
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; gap: 8px; }
.modal-head h2 { margin-right: auto; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.secret { display: flex; gap: 6px; }
.secret input { font-family: var(--mono); }

/* ---------- тости ---------- */
.toasts { position: fixed; z-index: 60; right: 16px; bottom: 16px; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: 13.5px; animation: tin .18s ease-out; overflow-wrap: anywhere;
}
.toast.error { background: var(--bad); color: #fff; }
.toast.ok { background: var(--good); color: #fff; }
@keyframes tin { from { transform: translateY(6px); opacity: 0; } }

.loading { padding: 40px 0; color: var(--text-3); text-align: center; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; background: var(--c, var(--surface-3)); border: 1px solid var(--border); }

@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }
