/* Site Assistant admin — neutral tokens, light by default, dark by system */
:root {
  --bg: oklch(0.985 0.002 260);
  --surface: oklch(1 0 0);
  --sidebar: oklch(0.97 0.004 260);
  --hover: oklch(0.955 0.006 260);
  --line: oklch(0.915 0.006 260);
  --line-2: oklch(0.86 0.008 260);
  --ink: oklch(0.21 0.01 260);
  --ink-2: oklch(0.44 0.012 260);
  --ink-3: oklch(0.56 0.01 260);
  --brand: oklch(0.55 0.2 262);
  --brand-ink: oklch(0.48 0.19 262);
  --brand-soft: oklch(0.955 0.03 262);
  --on-brand: oklch(0.99 0 0);
  --critical: oklch(0.55 0.2 27);
  --critical-soft: oklch(0.965 0.022 25);
  --warning-ink: oklch(0.5 0.12 65);
  --warning-soft: oklch(0.97 0.035 85);
  --ok: oklch(0.52 0.13 155);
  --ok-soft: oklch(0.965 0.03 155);
  --shadow: 0 1px 2px oklch(0.2 0 0 / 0.05), 0 8px 24px -8px oklch(0.2 0 0 / 0.12);
  --shadow-lg: 0 24px 64px -16px oklch(0.2 0 0 / 0.28);
  --radius: 8px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  --ease: cubic-bezier(0.25, 1, 0.5, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(0.17 0.006 260);
    --surface: oklch(0.205 0.008 260);
    --sidebar: oklch(0.155 0.006 260);
    --hover: oklch(0.25 0.01 260);
    --line: oklch(0.29 0.01 260);
    --line-2: oklch(0.36 0.012 260);
    --ink: oklch(0.95 0.004 260);
    --ink-2: oklch(0.76 0.008 260);
    --ink-3: oklch(0.64 0.008 260);
    --brand: oklch(0.68 0.16 262);
    --brand-ink: oklch(0.76 0.13 262);
    --brand-soft: oklch(0.28 0.06 262);
    --on-brand: oklch(0.17 0.02 262);
    --critical: oklch(0.7 0.17 25);
    --critical-soft: oklch(0.27 0.06 25);
    --warning-ink: oklch(0.82 0.13 80);
    --warning-soft: oklch(0.28 0.05 75);
    --ok: oklch(0.76 0.14 155);
    --ok-soft: oklch(0.26 0.04 155);
    --shadow: 0 1px 2px oklch(0 0 0 / 0.4), 0 8px 24px -8px oklch(0 0 0 / 0.5);
    --shadow-lg: 0 24px 64px -16px oklch(0 0 0 / 0.7);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand-ink); }
h1 { font-size: 22px; line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 620; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 620; }
p { margin: 0 0 8px; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* layout */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { background: var(--sidebar); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 8px 14px; }
.brand i { width: 28px; height: 28px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; color: var(--on-brand); font-style: normal; font-size: 15px; }
.side select { width: 100%; margin-bottom: 8px; }
.nav { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 6px; color: var(--ink-2); text-decoration: none; font-weight: 500; }
.nav:hover { background: var(--hover); color: var(--ink); }
.nav.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.nav .cnt { margin-left: auto; font-size: 11.5px; background: var(--brand); color: var(--on-brand); border-radius: 999px; padding: 0 7px; font-weight: 600; }
.side .sep { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); padding: 14px 10px 4px; }
.side .bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.main { padding: 28px 32px 64px; max-width: 1240px; width: 100%; }
.head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head .grow p { margin: 4px 0 0; }
.banner { background: var(--warning-soft); color: var(--warning-ink); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; }

/* controls */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font: 500 13.5px var(--font); cursor: pointer; text-decoration: none; white-space: nowrap; transition: background 0.15s var(--ease); }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { filter: brightness(1.06); background: var(--brand); }
.btn.danger { color: var(--critical); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: default; }
input, select, textarea { font: 14px var(--font); color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 7px 10px; min-height: 34px; width: 100%; }
textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
input[type=checkbox] { width: 16px; height: 16px; min-height: 0; accent-color: var(--brand); }
input[type=color] { padding: 2px; width: 48px; height: 34px; }
input[type=range] { padding: 0; accent-color: var(--brand); }
label.f { display: grid; gap: 4px; font-weight: 500; font-size: 13px; }
label.f .hint { font-weight: 400; color: var(--ink-3); font-size: 12px; }
label.chk { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13px; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 14px; font: 500 13.5px var(--font); color: var(--ink-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--brand); }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat b { display: block; font-size: 24px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat span { color: var(--ink-2); font-size: 12.5px; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 90px; margin-top: 8px; }
.bars div { flex: 1; background: var(--brand-soft); border-top: 2px solid var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars div:hover::after { content: attr(data-t); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); font-size: 11px; padding: 2px 6px; border-radius: 4px; white-space: nowrap; margin-bottom: 4px; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-weight: 500; color: var(--ink-3); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.t tr:hover td { background: var(--hover); }
.t tr.click { cursor: pointer; }
.t .title { font-weight: 500; max-width: 460px; overflow: hidden; text-overflow: ellipsis; }
.t .url { color: var(--ink-3); font-size: 12px; max-width: 460px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 550; padding: 1px 8px; border-radius: 999px; background: var(--hover); color: var(--ink-2); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warning-soft); color: var(--warning-ink); }
.pill.bad { background: var(--critical-soft); color: var(--critical); }
.pill.brand { background: var(--brand-soft); color: var(--brand-ink); }
.empty { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 0; }
.run { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.run:last-child { border-bottom: 0; }
.kv { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.kv b { color: var(--ink); font-weight: 600; }
pre.code { background: var(--sidebar); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; margin: 0; }
.hit { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-top: 8px; }
.hit pre { white-space: pre-wrap; font-family: var(--font); font-size: 13px; margin: 6px 0 0; color: var(--ink-2); max-height: 140px; overflow: auto; }

/* questions */
.q { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 10px; }
.q .qt { font-weight: 600; font-size: 14.5px; }
.q .bot { color: var(--ink-2); font-size: 13px; margin: 6px 0 10px; border-left: 2px solid var(--line-2); padding-left: 10px; white-space: pre-wrap; }

/* dialogs */
.split { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.clist { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; max-height: calc(100vh - 210px); overflow-y: auto; }
.citem { padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; gap: 3px; }
.citem:hover { background: var(--hover); }
.citem.on { background: var(--brand-soft); }
.citem .pv { color: var(--ink-2); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 420px; }
.chat .ch { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.chat .cm { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat .cf { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; align-items: flex-end; }
.chat .cf textarea { min-height: 40px; height: 40px; }
.bub { max-width: 78%; padding: 9px 13px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.bub.user { align-self: flex-end; background: var(--brand); color: var(--on-brand); }
.bub.assistant { align-self: flex-start; background: var(--hover); }
.bub.manager { align-self: flex-end; background: var(--ok-soft); color: var(--ink); border: 1px solid var(--ok); }
.bub.note { align-self: center; background: none; color: var(--ink-3); font-size: 12px; padding: 0; }
.bub .meta { font-size: 11px; opacity: 0.75; margin-top: 4px; white-space: normal; }
.bub .meta a { color: inherit; }
.bub img { max-width: 220px; max-height: 180px; border-radius: 8px; display: block; margin-bottom: 6px; }

/* appearance */
.look { display: grid; grid-template-columns: minmax(0, 1fr) 440px; gap: 20px; align-items: start; }
.look iframe { width: 100%; height: 720px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); position: sticky; top: 20px; }

/* drawer, toasts, login */
.drawer-bg { position: fixed; inset: 0; background: oklch(0.2 0 0 / 0.35); opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 40; }
.drawer-bg.on { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100vw); background: var(--surface); box-shadow: var(--shadow-lg); transform: translateX(100%); transition: transform 0.25s var(--ease); z-index: 50; display: flex; flex-direction: column; }
.drawer.on { transform: none; }
.drawer .dh { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: center; }
.drawer .db { padding: 20px; overflow-y: auto; flex: 1; }
.drawer .df { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 70; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); box-shadow: var(--shadow-lg); font-weight: 500; max-width: 520px; }
.toast.err { background: var(--critical); color: #fff; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 360px; display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.skel { height: 14px; border-radius: 4px; background: var(--hover); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

@media (max-width: 1100px) { .look { grid-template-columns: 1fr; } .look iframe { position: static; height: 640px; } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .main { padding: 20px 16px 48px; }
  .split, .grid2, .grid3 { grid-template-columns: 1fr; }
  .chat { height: 70vh; }
}

/* ---------------------------------------------------------------- manager cabinet */
.mc-body { height: 100dvh; overflow: hidden; }
.mc { display: grid; grid-template-rows: auto 1fr; height: 100dvh; }
.mc-top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--surface); }
.mc-top .brand { padding: 0; }
.mc-top select { width: auto; max-width: 220px; }
.mc-main { display: grid; grid-template-columns: 360px 1fr; min-height: 0; }
.mc-side { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--sidebar); }
.mc-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; padding: 8px; }
.mc-tabs button { border: 0; background: none; border-radius: 6px; padding: 7px 4px; font: 500 12.5px var(--font); color: var(--ink-2); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.mc-tabs button b { font-size: 16px; color: var(--ink); font-variant-numeric: tabular-nums; }
.mc-tabs button.on { background: var(--surface); box-shadow: var(--shadow); color: var(--ink); }
.mc-tabs button.alert b { color: var(--critical); }
.mc-search { padding: 0 8px 8px; }
.mc-list { overflow-y: auto; flex: 1; }
.mc-item { padding: 11px 14px; border-top: 1px solid var(--line); cursor: pointer; display: grid; gap: 2px; position: relative; }
.mc-item:hover { background: var(--hover); }
.mc-item.on { background: var(--brand-soft); }
.mc-item .pv { color: var(--ink-2); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-item .site { font-size: 11.5px; color: var(--ink-3); }
.mc-ch { margin-left: 6px; padding: 0 6px; border-radius: 6px; font-size: 10.5px; font-weight: 600; color: #fff; background: var(--ink-3); }
.mc-ch.ch-telegram { background: #2a9fd8; }
.mc-ch.ch-viber { background: #7360f2; }
.mc-ch.ch-whatsapp { background: #1f9e55; }
.mc-ch.ch-instagram { background: #c13584; }
.mc-ch.ch-messenger { background: #0866ff; }
.mc-item.need::before { content: ""; position: absolute; left: 4px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--critical); }
.mc-chat { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.mc-head { display: flex; gap: 10px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.mc-head .who { flex: 1; min-width: 160px; }
.mc-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.mc-msgs .bub { max-width: min(78%, 620px); }
.mc-msgs .bub.event { align-self: center; background: var(--brand-soft); color: var(--brand-ink); font-size: 12.5px; padding: 4px 12px; border-radius: 999px; }
.mc-msgs .bub .who { font-size: 11px; font-weight: 600; opacity: 0.8; margin-bottom: 2px; }
.mc-comp { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.mc-comp textarea { min-height: 42px; height: 42px; max-height: 160px; resize: none; }
.mc-join { padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mc-back { display: none; }
.mc-empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--ink-2); padding: 24px; }
@media (max-width: 860px) {
  .mc-main { grid-template-columns: 1fr; }
  .mc-main.chat-open .mc-side { display: none; }
  .mc-main:not(.chat-open) .mc-chat { display: none; }
  .mc-back { display: inline-flex; }
  .mc-top .hide-sm { display: none; }
}
.mc-visitor { padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); display: grid; gap: 3px; max-height: 240px; overflow-y: auto; }
.mc-canned { border-top: 1px solid var(--line); background: var(--surface); padding: 8px 12px; display: grid; gap: 4px; max-height: 280px; overflow-y: auto; }
.mc-canned button:not(.btn) { border: 0; background: none; text-align: left; padding: 6px 8px; border-radius: 6px; cursor: pointer; font: 13px var(--font); color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-canned button:not(.btn):hover { background: var(--hover); }
.mc-emo { height: 28px; font-size: 12.5px; padding: 0 6px; max-width: 180px; }
