/* DM-Zentrale. One accent (teal), zinc neutrals, light + dark via prefers-color-scheme.
   Shapes: panels 12px, inputs/buttons 8px, chips and quick replies full pill. */
:root {
  --bg: #f6f6f7;
  --surface: #ffffff;
  --surface-2: #f0f0f2;
  --line: #e2e2e6;
  --text: #18181b;
  --muted: #5f5f69;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #ccfbf1;
  --warn: #9a3412;
  --warn-soft: #ffedd5;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --good: #15803d;
  --bubble-them: #ececf0;
  --bubble-us: #0f766e;
  --shadow: 0 1px 2px rgb(24 24 27 / 0.06), 0 4px 16px rgb(24 24 27 / 0.05);
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1a1a1d;
    --surface-2: #232327;
    --line: #2f2f35;
    --text: #ececef;
    --muted: #a1a1aa;
    --accent: #2dd4bf;
    --accent-ink: #062e2a;
    --accent-soft: #123b37;
    --warn: #fdba74;
    --warn-soft: #3b2412;
    --bad: #fca5a5;
    --bad-soft: #3b1515;
    --good: #86efac;
    --bubble-them: #2a2a30;
    --bubble-us: #0f766e;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 88px;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
h4 { font-size: 13px; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.pad { padding: 24px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  height: 60px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.switch { display: flex; gap: 4px; padding: 3px; background: var(--surface-2); border-radius: 999px; }
.switch button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 550;
  padding: 6px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.switch button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.top-status { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.tabs {
  position: sticky; top: 60px; z-index: 19;
  display: flex; gap: 2px; padding: 0 20px; overflow-x: auto;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.tabs button {
  border: 0; background: none; font: inherit; color: var(--muted); font-weight: 550;
  padding: 12px 12px 10px; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
main { max-width: 1440px; margin: 0 auto; padding: 24px 20px; }

/* ---------- basics ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.stack { display: grid; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
button.btn, a.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 13.5px; text-decoration: none;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap;
  transition: transform 0.12s ease, background 0.15s ease;
}
button.btn:active, a.btn:active { transform: translateY(1px); }
button.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); padding: 6px 8px; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
  padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.good { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
@media (prefers-color-scheme: dark) { .badge.good { color: var(--accent); } }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field .help { font-size: 12px; color: var(--muted); }
input[type="text"], input[type="number"], input[type="url"], textarea, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
textarea { resize: vertical; min-height: 64px; line-height: 1.45; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.counter { font-size: 11.5px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.counter.over { color: var(--bad); font-weight: 700; }
.field.invalid input, .field.invalid textarea { border-color: var(--bad); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 12px; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text); cursor: pointer;
}
.variant { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: start; }
.variant + .variant { margin-top: 8px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 550; }

/* ---------- overview ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12.5px; color: var(--muted); }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.data td { padding: 9px 10px; vertical-align: middle; }
table.data tr + tr td { border-top: 1px solid color-mix(in srgb, var(--line) 55%, transparent); }
table.data td.n { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: var(--surface-2); }
.funnel { display: flex; height: 8px; width: 160px; border-radius: 999px; overflow: hidden; gap: 2px; }
.funnel span { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.c-delivered { background: var(--accent); }
.c-need_follow { background: #d97706; }
.c-offered { background: #a1a1aa; }
.c-pending { background: #6366f1; }
.c-failed { background: #dc2626; }
.problems { display: grid; gap: 8px; }
.problem { display: grid; grid-template-columns: 120px 1fr; gap: 12px; font-size: 13px; }

/* ---------- keywords ---------- */
.kw-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.kw-list { position: sticky; top: 124px; max-height: calc(100dvh - 140px); overflow: auto; padding: 8px; }
.kw-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; width: 100%; text-align: left;
  font: inherit; color: inherit; background: none; border: 0; border-radius: 8px; padding: 8px 10px; cursor: pointer;
}
.kw-item:hover { background: var(--surface-2); }
.kw-item[aria-current="true"] { background: var(--accent-soft); }
.kw-item b { font-weight: 650; }
.kw-item .t { grid-column: 1 / -1; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kw-preview { position: sticky; top: 124px; }

/* ---------- phone preview ---------- */
.phone {
  background: var(--surface); border: 1px solid var(--line); border-radius: 28px; padding: 14px 12px 18px;
  box-shadow: var(--shadow); max-width: 360px;
}
.phone-head { display: flex; justify-content: space-between; align-items: center; padding: 2px 6px 10px; border-bottom: 1px solid var(--line); margin-bottom: 10px; font-size: 13px; font-weight: 650; }
.chat { display: grid; gap: 6px; max-height: calc(100dvh - 260px); overflow: auto; padding: 2px; }
.sep { text-align: center; font-size: 11.5px; color: var(--muted); margin: 8px 0 2px; }
.bubble { max-width: 82%; padding: 8px 12px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; font-size: 13.5px; line-height: 1.4; }
.bubble.them { background: var(--bubble-them); justify-self: start; border-bottom-left-radius: 6px; }
.bubble.us { background: var(--bubble-us); color: #fff; justify-self: end; border-bottom-right-radius: 6px; }
.comment { justify-self: start; font-size: 13px; background: var(--surface-2); padding: 8px 12px; border-radius: 12px; max-width: 90%; }
.comment b { font-weight: 650; }
.comment.reply { margin-left: 18px; }
.quicks { justify-self: end; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 90%; }
.quick { font-size: 12.5px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--accent); color: var(--accent); background: var(--surface); }
.card { justify-self: end; width: 78%; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: var(--surface); }
.card .img { aspect-ratio: 1 / 1; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.card .img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .body { padding: 8px 12px; }
.card .body b { display: block; font-size: 13.5px; }
.card .body span { display: block; font-size: 12.5px; color: var(--muted); }
.card .cbtn { border-top: 1px solid var(--line); text-align: center; padding: 8px; font-size: 13px; font-weight: 600; color: var(--accent); }
.toggle { display: flex; gap: 4px; padding: 3px; background: var(--surface-2); border-radius: 999px; }
.toggle button { border: 0; background: none; font: inherit; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 10px; border-radius: 999px; cursor: pointer; }
.toggle button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- flow ---------- */
.flow { display: grid; gap: 0; justify-items: center; }
.flow-triggers { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; width: 100%; }
.trigger { background: var(--surface-2); border: 1px dashed var(--line); border-radius: 12px; padding: 12px 14px; }
.trigger h4 { margin-bottom: 4px; }
.trigger p { font-size: 12.5px; color: var(--muted); }
.connector { width: 2px; height: 28px; background: var(--line); position: relative; }
.connector::after { content: ""; position: absolute; left: -4px; bottom: -2px; border: 5px solid transparent; border-top-color: var(--line); }
.node {
  width: min(640px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; display: grid; gap: 10px; box-shadow: var(--shadow); text-align: left; font: inherit; color: inherit;
}
.node.selected { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.node .head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.node .desc { font-size: 13px; color: var(--muted); }
.node .mini { display: grid; gap: 6px; padding: 10px; background: var(--bg); border-radius: 10px; }
.gate {
  padding: 10px 18px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-weight: 650; border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.branches { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; width: 100%; max-width: 1100px; position: relative; }
.branch { display: grid; justify-items: center; align-content: start; }
.branch .blabel { font-size: 12px; font-weight: 650; color: var(--muted); margin: 6px 0 0; }
.flow-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 440px; gap: 20px; align-items: start; }
.drawer { position: sticky; top: 124px; max-height: calc(100dvh - 140px); overflow: auto; }
.drawer .group + .group { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }

/* ---------- live / diff / log ---------- */
pre.log, pre.diff {
  font: 12px/1.5 var(--mono); background: var(--surface-2); border-radius: 10px; padding: 12px 14px;
  overflow: auto; max-height: 420px; margin: 0; white-space: pre-wrap;
}
pre.diff .add { color: var(--good); }
pre.diff .del { color: var(--bad); }
pre.diff .gap { color: var(--muted); }

/* ---------- bottom bar + toast ---------- */
.dirty {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 30;
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  background: var(--text); color: var(--bg); border-radius: 14px; padding: 10px 12px 10px 18px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.25); max-width: calc(100vw - 32px);
}
.dirty .btn { border-color: transparent; }
.dirty .btn.ghostinv { background: transparent; color: var(--bg); border-color: color-mix(in srgb, var(--bg) 35%, transparent); }
.errors { position: fixed; right: 16px; bottom: 84px; z-index: 31; width: min(520px, calc(100vw - 32px)); max-height: 60dvh; overflow: auto; }
.errors ul { margin: 8px 0 0; padding-left: 18px; display: grid; gap: 4px; font-size: 13px; }
.toast {
  position: fixed; top: 72px; right: 20px; z-index: 40; max-width: 420px;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); font-size: 13.5px;
}
.toast.bad { border-left-color: var(--bad); }

.notice { padding: 10px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.notice.info { background: var(--surface-2); color: var(--muted); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } * { transition: none !important; } }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .kw-layout { grid-template-columns: 240px minmax(0, 1fr); }
  .kw-preview { grid-column: 2; position: static; }
  .flow-wrap { grid-template-columns: 1fr; }
  .drawer { position: static; max-height: none; }
}
@media (max-width: 780px) {
  .top { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .tabs { top: 0; position: static; }
  .top-status { margin-left: 0; width: 100%; }
  main { padding: 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kw-layout, .grid-2, .branches { grid-template-columns: 1fr; }
  .kw-list, .kw-preview { position: static; max-height: none; grid-column: auto; }
  .funnel { width: 90px; }
  .problem { grid-template-columns: 1fr; gap: 0; }
  .hide-sm { display: none; }
}

/* login page (online version) */
.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-box { width: min(380px, 100%); }
.login-box .btn { width: 100%; justify-content: center; }
