/* Linea — панель управления */
:root {
  --bg: #F6F7F9; --surface: #FFFFFF; --surface2: #EFF1F5;
  --ink: #1A1C22; --muted: #667085; --line: #E4E7EC;
  --accent: #2E4BE8; --accent-ink: #FFFFFF; --accent-soft: #EEF1FE;
  --ok: #12915E; --warn: #B7791F; --danger: #D64533;
  --shadow: 0 1px 2px rgba(16,18,22,.05), 0 8px 24px rgba(16,18,22,.06);
  --r: 12px; --r-sm: 9px;
  --sidebar-w: 232px;
}
html[data-theme="dark"] {
  --bg: #101216; --surface: #171A20; --surface2: #1F2229;
  --ink: #E9EBF0; --muted: #8B93A3; --line: #262B35;
  --accent: #6D83FF; --accent-ink: #0E1120; --accent-soft: #1E2440;
  --ok: #3BC98A; --warn: #E0A93E; --danger: #F0705F;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14.5px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
::placeholder { color: var(--muted); opacity: .8; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- логотип: слово + линия ---------- */
.logo { display: flex; align-items: baseline; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: .04em; user-select: none; }
.logo::after { content: ""; flex: 1; height: 2px; background: linear-gradient(90deg, var(--accent), transparent); border-radius: 2px; transform: translateY(-4px); }

/* ---------- layout ---------- */
#app { min-height: 100%; }
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 22px 14px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .logo { padding: 0 10px 18px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: var(--r-sm);
  color: var(--muted); font-weight: 600; border: none; background: none; width: 100%; text-align: left;
  position: relative;
}
.nav-item:hover { background: var(--surface2); color: var(--ink); }
.nav-item.active { color: var(--accent); background: var(--accent-soft); }
.nav-item.active::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--accent); }
.nav-item svg { width: 19px; height: 19px; flex-shrink: 0; }
.nav-item .nbadge { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 9px; min-width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; padding: 0 5px; }
.sidebar .spacer { flex: 1; }
.sidebar .whoami { padding: 10px 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.sidebar .whoami b { color: var(--ink); display: block; }

.main { padding: 26px 30px 60px; max-width: 1200px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; font-weight: 800; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

/* ---------- элементы ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card.pad { padding: 20px; }
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px;
}
.btn:hover { background: var(--surface2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 8px 0; }
.switch input { display: none; }
.switch .track { width: 38px; height: 22px; border-radius: 11px; background: var(--line); position: relative; transition: background .15s; flex-shrink: 0; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.badge.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge.muted { background: var(--surface2); color: var(--muted); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--surface2); }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty b { display: block; color: var(--ink); margin-bottom: 6px; font-size: 16px; }

/* ---------- логин ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 380px; max-width: 100%; }
.login-card .logo { font-size: 26px; margin-bottom: 6px; }
.login-card .tag { color: var(--muted); margin-bottom: 26px; font-size: 14px; }

/* ---------- дашборд ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { padding: 18px; }
.stat .num { font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stat.hl .num { color: var(--accent); }
.chart { display: flex; align-items: flex-end; gap: 10px; height: 140px; padding: 18px 18px 8px; }
.chart .bar { flex: 1; background: var(--accent-soft); border-radius: 6px 6px 0 0; position: relative; min-height: 4px; }
.chart .bar i { position: absolute; bottom: 0; left: 0; right: 0; background: var(--accent); border-radius: 6px 6px 0 0; }
.chart-lbls { display: flex; gap: 10px; padding: 0 18px 14px; }
.chart-lbls span { flex: 1; text-align: center; font-size: 11px; color: var(--muted); }

/* ---------- диалоги ---------- */
.dlg-layout { display: grid; grid-template-columns: 340px 1fr; gap: 16px; height: calc(100vh - 130px); min-height: 420px; }
.dlg-list { overflow-y: auto; display: flex; flex-direction: column; }
.dlg-filters { padding: 12px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; position: sticky; top: 0; background: var(--surface); z-index: 2; border-radius: var(--r) var(--r) 0 0; }
.dlg-filters input, .dlg-filters select { padding: 7px 10px; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: var(--surface); outline: none; font-size: 13px; }
.dlg-filters input { flex: 1; min-width: 110px; }
.chip { padding: 6px 12px; border-radius: 20px; border: 1px solid var(--line); background: none; color: var(--muted); font-size: 13px; font-weight: 600; }
.chip.act { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.dlg-item { display: flex; gap: 11px; padding: 13px 14px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: flex-start; border-left: 3px solid transparent; }
.dlg-item:hover { background: var(--surface2); }
.dlg-item.act { background: var(--accent-soft); border-left-color: var(--accent); }
.ava { width: 38px; height: 38px; border-radius: 50%; background: var(--surface2); color: var(--muted); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; font-size: 15px; }
.dlg-item.unread .ava { background: var(--accent); color: var(--accent-ink); }
.dlg-item .di-body { flex: 1; min-width: 0; }
.dlg-item .di-top { display: flex; justify-content: space-between; gap: 8px; }
.dlg-item .di-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dlg-item .di-time { font-size: 11.5px; color: var(--muted); flex-shrink: 0; }
.dlg-item .di-site { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dlg-item .di-unread { background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 9px; min-width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; padding: 0 5px; margin-top: 3px; }

.chat { display: flex; flex-direction: column; overflow: hidden; }
.chat-head { padding: 13px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chat-head .ch-info { flex: 1; min-width: 0; }
.chat-head .ch-name { font-weight: 700; }
.chat-head .ch-meta { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-body { flex: 1; overflow-y: auto; padding: 18px; background: var(--bg); display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 70%; padding: 9px 13px; border-radius: 14px; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.visitor { background: var(--surface); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 5px; }
.msg.operator { background: var(--accent); color: var(--accent-ink); align-self: flex-end; border-bottom-right-radius: 5px; }
.msg.system { align-self: center; background: none; color: var(--muted); font-size: 12px; padding: 2px; }
.msg-meta { font-size: 11px; color: var(--muted); margin: -4px 4px 0; }
.msg-meta.op { align-self: flex-end; }
.chat-input { display: flex; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); align-items: flex-end; }
.chat-input textarea { flex: 1; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: var(--surface); resize: none; padding: 9px 12px; outline: none; max-height: 120px; }
.chat-input textarea:focus { border-color: var(--accent); }
.back-btn { display: none; }

/* ---------- модалка ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10,12,18,.5); display: flex; align-items: center; justify-content: center; padding: 18px; z-index: 100; }
.modal { width: 560px; max-width: 100%; max-height: 92vh; overflow-y: auto; padding: 24px; }
.modal h2 { font-size: 18px; margin-bottom: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- код вставки ---------- */
.code { background: var(--surface2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 13px 14px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; position: relative; }

/* ---------- тосты ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--r-sm); padding: 12px 16px; box-shadow: var(--shadow); max-width: 340px; font-size: 13.5px; animation: t-in .2s ease; cursor: pointer; }
.toast b { display: block; }
.toast.danger { border-left-color: var(--danger); }
@keyframes t-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- предпросмотр виджета ---------- */
.wprev { border-radius: var(--r); border: 1px dashed var(--line); padding: 18px; display: flex; justify-content: flex-end; background: var(--bg); }
.wprev .pv { width: 280px; border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.wprev .pv-head { padding: 13px 15px; color: #fff; }
.wprev .pv-title { font-weight: 700; font-size: 14.5px; }
.wprev .pv-sub { font-size: 11.5px; opacity: .85; }
.wprev .pv-body { padding: 14px; font-size: 13px; min-height: 90px; }
.wprev .pv-msg { border-radius: 11px; border-bottom-left-radius: 4px; padding: 8px 11px; max-width: 90%; display: inline-block; }

.sites-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.site-card { padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.site-card .sc-name { font-weight: 700; font-size: 16px; }
.site-card .sc-domain { color: var(--muted); font-size: 13px; }
.site-card .sc-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.seg button { border: none; background: none; padding: 7px 13px; color: var(--muted); font-weight: 600; font-size: 13px; }
.seg button.act { background: var(--accent); color: var(--accent-ink); }

/* ---------- мобильная версия ---------- */
.mob-top { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: auto 0 0 0; height: auto; flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-right: none; border-top: 1px solid var(--line); z-index: 50; justify-content: space-around; }
  .sidebar .logo, .sidebar .spacer, .sidebar .whoami, .sidebar .nav-label { display: none; }
  .nav-item { flex-direction: column; gap: 3px; font-size: 10.5px; padding: 7px 4px; flex: 1; align-items: center; text-align: center; }
  .nav-item.active::before { display: none; }
  .nav-item .nbadge { position: absolute; top: 2px; right: 50%; margin-right: -20px; margin-left: 0; }
  .main { padding: 16px 14px 96px; }
  .mob-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; }
  .mob-top .logo { font-size: 17px; }
  .dlg-layout { grid-template-columns: 1fr; height: calc(100vh - 210px); }
  .dlg-layout.chat-open .dlg-list { display: none; }
  .dlg-layout:not(.chat-open) .chat { display: none; }
  .back-btn { display: inline-flex; }
  .row2 { grid-template-columns: 1fr; }
  .msg { max-width: 86%; }
}
