/* Единая дизайн-система админки assistant-hub. Свежий светлый интерфейс с
   аккуратной тёмной темой. Один источник токенов для всех разделов. */

:root {
  --pri: #2563eb;
  --pri-600: #1d4ed8;
  --pri-050: #eff6ff;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --card: #ffffff;
  --line: #e6eaf0;
  --line-strong: #d3dae4;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --txt: #0f172a;
  --ok: #16a34a;
  --ok-bg: #f0fdf4;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --sh-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --sh: 0 4px 16px rgba(15, 23, 42, .08);
  --sh-lg: 0 12px 40px rgba(15, 23, 42, .16);
  --sidebar: 248px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --pri: #3b82f6;
    --pri-600: #2563eb;
    --pri-050: #172033;
    --bg: #0b1220;
    --surface: #0f172a;
    --card: #131c2e;
    --line: #1e293b;
    --line-strong: #2b3a52;
    --muted: #94a3b8;
    --muted-2: #64748b;
    --txt: #e8eef7;
    --ok: #4ade80;
    --ok-bg: #0f2417;
    --warn: #fbbf24;
    --warn-bg: #2a2410;
    --danger: #f87171;
    --danger-bg: #2a1414;
    --sh-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --sh: 0 4px 16px rgba(0, 0, 0, .35);
    --sh-lg: 0 12px 40px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--txt);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ------------------------------ Layout ------------------------------ */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px 14px; font-weight: 700; font-size: 15px;
}
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--pri), #7c3aed);
  display: grid; place-items: center; color: #fff; font-size: 15px;
}
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }

.nav { padding: 6px 12px; overflow-y: auto; flex: 1; }
.nav .group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted-2); font-weight: 700; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--r-sm); color: var(--muted);
  font-weight: 500; margin-bottom: 2px; cursor: pointer;
  transition: background .12s, color .12s;
}
.nav a .ic { width: 18px; text-align: center; font-size: 15px; flex: none; }
.nav a:hover { background: var(--pri-050); color: var(--txt); }
.nav a.active { background: var(--pri); color: #fff; box-shadow: var(--sh-sm); }
.nav a .count { margin-left: auto; font-size: 11px; font-weight: 700;
  background: rgba(148,163,184,.18); color: var(--muted); padding: 1px 7px; border-radius: 20px; }
.nav a.active .count { background: rgba(255,255,255,.25); color: #fff; }

.sidebar .foot { padding: 12px; border-top: 1px solid var(--line); }
.userbox { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.userbox .av { width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: var(--pri-050); color: var(--pri); display: grid; place-items: center; font-weight: 700; }
.userbox .who { min-width: 0; flex: 1; }
.userbox .who b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.userbox .who span { font-size: 11px; color: var(--muted); }
.userbox .out { color: var(--muted); padding: 6px; border-radius: 8px; }
.userbox .out:hover { background: var(--danger-bg); color: var(--danger); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 28px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 6;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }
.topbar .sub { font-size: 12.5px; color: var(--muted); font-weight: 400; }
.content { padding: 24px 28px 60px; max-width: 1080px; width: 100%; }

/* ---- burger (mobile) ---- */
.burger { display: none; background: none; border: none; font-size: 20px; color: var(--txt); cursor: pointer; }

/* ------------------------------ Buttons ------------------------------ */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  border: 1px solid var(--line-strong); background: var(--card); color: var(--txt);
  padding: 9px 15px; border-radius: var(--r-sm); font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: filter .12s, background .12s, border-color .12s;
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.pri { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.pri:hover { background: var(--pri-600); }
.btn.danger { background: var(--danger-bg); border-color: transparent; color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--bg); color: var(--txt); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }

/* ------------------------------ Cards / table ------------------------------ */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--sh-sm); overflow: hidden; }
.card + .card { margin-top: 18px; }
.card .hd { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.card .hd input, .card .hd select { min-width: 0; }
.card .hd h2 { font-size: 14.5px; margin: 0; flex: 1; }
.card .hd .sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.card .bd { padding: 6px 0; }

.list-item {
  display: flex; align-items: center; gap: 14px; padding: 13px 18px;
  border-bottom: 1px solid var(--line); cursor: pointer; transition: background .1s;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--pri-050); }
.list-item .avatar {
  width: 38px; height: 38px; border-radius: 10px; flex: none; display: grid; place-items: center;
  font-size: 17px; background: var(--bg); border: 1px solid var(--line);
}
.list-item .meta { flex: 1; min-width: 0; }
.list-item .meta b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .meta span { font-size: 12px; color: var(--muted); }
.list-item .chev { color: var(--muted-2); font-size: 18px; }

/* ------------------------------ Badges / pills ------------------------------ */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600;
  padding: 3px 9px; border-radius: 20px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge.pri { background: var(--pri-050); color: var(--pri); border-color: transparent; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.badge.muted { opacity: .8; }

.chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px; border-radius: 20px;
  background: var(--pri-050); color: var(--pri); font-weight: 600; font-size: 13px; }
.chip .x { cursor: pointer; opacity: .6; font-weight: 700; }
.chip .x:hover { opacity: 1; }
.chip.ghost { background: var(--bg); color: var(--muted); border: 1px dashed var(--line-strong); }

/* ------------------------------ Forms ------------------------------ */
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field label .req { color: var(--danger); }
.field .hint { font-size: 11.5px; color: var(--muted-2); margin-top: 5px; }
input[type=text], input[type=password], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  font-size: 14px; background: var(--surface); color: var(--txt); font-family: inherit;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--pri); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pri) 18%, transparent);
}
textarea { min-height: 90px; resize: vertical; }
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 40px; height: 23px; border-radius: 20px; background: var(--line-strong); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: var(--sh-sm); }
.switch input:checked + .track { background: var(--pri); }
.switch input:checked + .track::after { transform: translateX(17px); }

/* ------------------------------ Drawer ------------------------------ */
.scrim { position: fixed; inset: 0; background: rgba(15,23,42,.45); opacity: 0; pointer-events: none; transition: opacity .18s; z-index: 40; }
.scrim.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 460px; max-width: 94vw;
  background: var(--bg); box-shadow: var(--sh-lg); z-index: 50;
  transform: translateX(100%); transition: transform .22s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
}
.drawer.show { transform: translateX(0); }
.drawer .dh { display: flex; align-items: center; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.drawer .dh h2 { font-size: 16px; margin: 0; flex: 1; }
.drawer .dh .x { font-size: 20px; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.drawer .dh .x:hover { background: var(--bg); }
.drawer .db { padding: 20px; overflow-y: auto; flex: 1; }
.drawer .df { padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface); display: flex; gap: 10px; }
.drawer .df .btn { flex: 1; }

.section-t { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2);
  font-weight: 700; margin: 22px 0 10px; }

/* ------------------------------ Empty / toast / skeleton ------------------------------ */
.empty { text-align: center; color: var(--muted); padding: 46px 20px; }
.empty .big { font-size: 34px; margin-bottom: 10px; opacity: .7; }
.empty p { margin: 4px 0; }
.toast-wrap { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #0f172a; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 13px; box-shadow: var(--sh-lg);
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
.skeleton { height: 62px; border-radius: var(--r); background: linear-gradient(90deg, var(--line) 25%, var(--bg) 37%, var(--line) 63%); background-size: 400% 100%; animation: sk 1.3s ease infinite; margin-bottom: 10px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.err { background: var(--danger-bg); color: var(--danger); padding: 10px 13px; border-radius: var(--r-sm); font-size: 13px; margin-bottom: 12px; font-weight: 500; }

/* ------------------------------ Dialogs ------------------------------ */
.content.flush { padding: 0; max-width: none; flex: 1; min-height: 0; }
.dlg { display: flex; height: calc(100vh - 61px); background: var(--surface); }
.dlg .list { width: 340px; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.dlg .filters { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.dlg .filters input, .dlg .filters select { padding: 8px 11px; }
.dlg .filters input { flex: 1; }
.dlg .convs { flex: 1; overflow-y: auto; }
.conv { display: flex; gap: 11px; padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background .1s; }
.conv:hover { background: var(--pri-050); }
.conv.active { background: var(--pri-050); box-shadow: inset 3px 0 0 var(--pri); }
.conv .ava { width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; }
.conv .body { flex: 1; min-width: 0; }
.conv .row1 { display: flex; align-items: center; gap: 6px; }
.conv .name { font-weight: 650; font-size: 14px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .time { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.conv .row2 { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.conv .prev { color: var(--muted); font-size: 12.5px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dlg .thread { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.dlg .thead { display: flex; align-items: center; gap: 11px; padding: 11px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.dlg .thead .back { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--txt); }
.dlg .thead .who { flex: 1; min-width: 0; }
.dlg .thead .who .n { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dlg .thead .who .s { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.bot { background: var(--ok); } .dot.human { background: var(--warn); }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 2px; }
.daysep { align-self: center; font-size: 11.5px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); padding: 3px 12px; border-radius: 20px; margin: 10px 0 6px; }
.m { display: flex; margin: 2px 0; max-width: 100%; }
.m .bub { max-width: 74%; padding: 9px 13px; border-radius: 16px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--sh-sm); }
.m.user { justify-content: flex-start; }
.m.user .bub { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.m.assistant { justify-content: flex-end; }
.m.assistant .bub { background: var(--pri-050); border-bottom-right-radius: 5px; }
.m.manager { justify-content: flex-end; }
.m.manager .bub { background: var(--pri); color: #fff; border-bottom-right-radius: 5px; }
.m .who { font-size: 11px; opacity: .75; margin-bottom: 2px; font-weight: 600; }
.m .tm { font-size: 10px; opacity: .6; margin-top: 3px; text-align: right; }
.composer { padding: 12px 14px; background: var(--surface); border-top: 1px solid var(--line); }
.composer .box { display: flex; gap: 9px; align-items: flex-end; background: var(--bg); border: 1px solid var(--line-strong); border-radius: 14px; padding: 6px 6px 6px 12px; }
.composer .box:focus-within { border-color: var(--pri); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pri) 14%, transparent); }
.composer textarea { flex: 1; resize: none; height: 24px; max-height: 130px; padding: 6px 0; border: none; background: none; font-size: 14px; font-family: inherit; outline: none; color: var(--txt); }
.composer .snd { border: none; background: var(--pri); color: #fff; width: 38px; height: 38px; border-radius: 11px; cursor: pointer; display: grid; place-items: center; flex: none; }
.composer .snd:hover { background: var(--pri-600); } .composer .snd:disabled { background: var(--muted-2); cursor: default; }
.dlg-state { margin: auto; text-align: center; color: var(--muted); padding: 40px 20px; }
.dlg-state .ico { font-size: 30px; opacity: .5; margin-bottom: 8px; }
@media (max-width: 760px) {
  .dlg .list { width: 100%; }
  .dlg[data-view="thread"] .list { display: none; }
  .dlg[data-view="list"] .thread { display: none; }
  .dlg .thead .back { display: block; }
}

/* ------------------------------ Widget builder ------------------------------ */
.wb { display: grid; grid-template-columns: 1fr 380px; gap: 18px; align-items: start; }
.wb .preview-col { position: sticky; top: 84px; }
.wb-stage { border: 1px solid var(--line); border-radius: var(--r-lg); height: 520px; position: relative; overflow: hidden; box-shadow: var(--sh-sm); }
.wb-launcher { position: absolute; bottom: 18px; padding: 12px 18px; border-radius: 26px; font-weight: 600; font-size: 14px; box-shadow: var(--sh); cursor: default; }
.wb-window { position: absolute; bottom: 18px; width: 320px; max-width: calc(100% - 36px); border-radius: 16px; overflow: hidden; box-shadow: var(--sh-lg); display: flex; flex-direction: column; height: 440px; }
.wb-whead { padding: 14px 16px; color: #fff; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.wb-wbody { flex: 1; background: #fff; padding: 14px; overflow-y: auto; }
.wb-bubble { max-width: 80%; padding: 9px 13px; border-radius: 14px; font-size: 13.5px; margin-bottom: 8px; background: #f1f5f9; color: #0f172a; }
.wb-wfoot { padding: 10px 12px; border-top: 1px solid #e6eaf0; background: #fff; font-size: 13px; color: #94a3b8; }
@media (max-width: 900px) { .wb { grid-template-columns: 1fr; } .wb .preview-col { position: static; } }

/* ------------------------------ Login ------------------------------ */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 70% -10%, color-mix(in srgb, var(--pri) 16%, transparent), transparent), var(--bg); }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--sh); padding: 30px; width: 380px; max-width: 100%; }
.login-card .brand { padding: 0 0 6px; font-size: 18px; }
.login-card p.lead { color: var(--muted); font-size: 13px; margin: 0 0 22px; }

/* ------------------------------ Responsive ------------------------------ */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 60; width: var(--sidebar); transform: translateX(-100%); transition: transform .2s; }
  .sidebar.show { transform: translateX(0); box-shadow: var(--sh-lg); }
  .burger { display: block; }
  .content { padding: 18px 16px 60px; }
  .topbar { padding: 14px 16px; }
}
