:root {
  --bg: #0a0f1d;
  --bg-2: #0e1426;
  --panel: #151c2f;
  --panel-2: #1b2339;
  --panel-3: #232c46;
  --border: #29324d;
  --text: #e9edf6;
  --text-2: #b4bdd2;
  --muted: #7d88a3;
  --accent: #1a82ff;
  --accent-2: #3d97ff;
  --good: #22c55e;
  --warn: #f5a524;
  --bad: #ef4444;
  --bad-soft: #3a1822;
  --series-1: #3987e5;
  --series-2: #d95926;
  --radius: 14px;
  --nav-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  overflow-x: hidden;
}
a { color: var(--accent-2); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; font-weight: 700; }
h2 { font-size: 16px; margin: 0; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; color: var(--text-2); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bad-text { color: #ff8a9a; }
.good-text { color: #6ee7a0; }
.warn-text { color: #f7c46c; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  min-height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--panel-3); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: #ff8a8a; border-color: #5a2630; background: #2a1520; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { width: 38px; padding: 0; }
.btn.sm.icon { width: 32px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.block { width: 100%; }

.input, select.input, textarea.input {
  width: 100%; min-height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-2); outline: none; transition: border-color .15s;
}
textarea.input { padding: 10px 12px; resize: none; }
.input:focus { border-color: var(--accent); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.error-text { color: #ff8a8a; font-size: 13px; min-height: 18px; margin: 4px 0 10px; }
.check { display: flex; gap: 10px; align-items: center; padding: 8px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 17px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.chip.active { background: #24305a; border-color: #3a4f8f; color: var(--text); }
.chip.alert.active { background: var(--bad-soft); border-color: #6b2333; }
.count {
  min-width: 22px; height: 20px; padding: 0 7px; border-radius: 10px; background: var(--panel-3);
  font-size: 12px; display: inline-grid; place-items: center; color: var(--text-2); font-variant-numeric: tabular-nums;
}
.count.blue { background: var(--accent); color: #fff; }
.count.red { background: var(--bad); color: #fff; }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 16px 12px; border-right: 1px solid var(--border);
  background: #0c1222; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 8px 16px; }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--text-2);
  font-weight: 500; cursor: pointer;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); }
.nav-item .ico { width: 20px; text-align: center; font-size: 16px; }
.nav-item .count { margin-left: auto; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 14px 12px 6px; }
.sidebar .spacer { flex: 1; }
.me-box { padding: 10px 12px; border-top: 1px solid var(--border); margin-top: 8px; font-size: 13px; }
.ws-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); display: inline-block; }
.ws-dot.on { background: var(--good); }

.main { min-width: 0; }
.page { padding: 22px 24px 32px; max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }

.mobile-top { display: none; }
.tabbar { display: none; }

/* ---------- карточки ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.card.pad { padding: 16px; }
.section { margin-top: 20px; }
.section > .head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.section > .head h2 { flex: 1; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.tile { padding: 14px 16px; cursor: default; }
.tile.link { cursor: pointer; }
.tile.link:hover { border-color: #3a4a74; }
.tile .label { font-size: 12.5px; color: var(--text-2); font-weight: 600; }
.tile .value { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tile .value.sm { font-size: 22px; }
.tile .delta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.tile .delta b.up { color: var(--good); }
.tile .delta b.down { color: #ff6b81; }
.tile.alert { border-color: #6b2333; background: linear-gradient(180deg, #2a1520, var(--panel)); }
.tile.alert .value { color: #ff8a9a; }

.hr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.hr-card { padding: 14px; display: flex; flex-direction: column; gap: 10px; cursor: pointer; }
.hr-card:hover { border-color: #3a4a74; }
.hr-card.problem { border-color: #6b2333; }
.hr-card .top { display: flex; gap: 10px; align-items: center; }
.hr-card .name { font-weight: 600; }
.hr-card .sub { font-size: 12px; color: var(--muted); }
.mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.mini-stats div { background: var(--panel-2); border-radius: 10px; padding: 6px 8px; }
.mini-stats b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.mini-stats span { font-size: 11px; color: var(--muted); }
.mini-stats .red b { color: #ff8a9a; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: 14px; color: #fff;
}
.avatar.sm { width: 36px; height: 36px; font-size: 13px; }
.status { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; font-size: 13px; }
.status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.status.active::before { background: var(--good); }
.status.error::before, .status.pending::before { background: var(--warn); }
.status.banned::before, .status.unauthorized::before { background: var(--bad); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: #22305a; font-size: 12px; color: #c9d6ff; white-space: nowrap; }
.tag.gray { background: var(--panel-3); color: var(--text-2); }
.tag.red { background: var(--bad-soft); color: #ff8a9a; }
.tag.warn { background: #3a2c12; color: #f7c46c; }
.tag .status { font-size: 12px; margin-right: 5px; vertical-align: 1px; }
.tag .status::before { width: 7px; height: 7px; }
.list-item.dim { opacity: .6; }
/* iPhone увеличивает страницу, если шрифт в поле меньше 16px, — на телефоне поля крупнее */
@media (max-width: 899px) {
  .input, select.input, textarea.input { font-size: 16px; }
}
.hr-item .grow { min-width: 0; }
@media (max-width: 899px) {
  .hr-item { flex-wrap: wrap; }
  .hr-item .grow { flex: 1 1 200px; }
  .hr-item .actions { width: 100%; justify-content: flex-end; }
}

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: separate; border-spacing: 0 6px; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2);
  font-weight: 600; padding: 6px 10px; white-space: nowrap;
}
.table td { padding: 10px; background: var(--panel-2); vertical-align: middle; white-space: nowrap; }
.table tr td:first-child { border-radius: 10px 0 0 10px; }
.table tr td:last-child { border-radius: 0 10px 10px 0; }
.table tbody tr.click { cursor: pointer; }
.table tbody tr.click:hover td { background: var(--panel-3); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.acc-cell { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.acc-cell .name { font-weight: 600; }
.acc-cell .sub { font-size: 12px; color: var(--muted); }

/* ---------- чаты ---------- */
.chats {
  display: grid; grid-template-columns: 380px minmax(0, 1fr); height: 100vh; overflow: hidden;
}
.chats-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.chats-list .head { padding: 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.chats-list .head .chips { flex-wrap: wrap; overflow: visible; }
.crit-row { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--border); }
.crit-row .grow { min-width: 200px; }
.crit-row .seg { margin-left: auto; }
.crit-row:last-child { border-bottom: none; }
.crit-row .ico { font-size: 18px; width: 24px; text-align: center; }
.crit-row .evidence { font-size: 12px; color: var(--muted); margin-top: 3px; font-style: italic; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; flex: none; }
.seg button { border: none; background: var(--panel-2); padding: 6px 9px; cursor: pointer; font-size: 13px; color: var(--text-2); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: #24305a; color: var(--text); }
.crit-sum { display: inline-flex; gap: 6px; align-items: center; }
.chats-list .scroll { overflow-y: auto; flex: 1; min-height: 0; }
.chat-item { display: flex; gap: 10px; padding: 11px 12px; cursor: pointer; border-bottom: 1px solid rgba(41, 50, 77, .6); }
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: #1f2a4c; }
.chat-item .body { flex: 1; min-width: 0; }
.chat-item .row1 { display: flex; gap: 8px; align-items: baseline; }
.chat-item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.chat-item .time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.chat-item .row2 { display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.chat-item .preview { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.chat-item .meta { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; align-items: center; }
.chat-item .acc { font-size: 11px; color: var(--muted); }

.conv { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg-2); }
.conv-empty { display: grid; place-items: center; height: 100%; color: var(--muted); padding: 20px; text-align: center; }
.conv-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--panel); }
.conv-head .who { flex: 1; min-width: 0; }
@media (min-width: 900px) { #c-back { display: none; } }
.conv-head .who .t { font-weight: 600; }
.conv-tools { display: flex; gap: 8px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--panel); flex-wrap: wrap; }
.conv-tools select.input { width: auto; min-height: 32px; height: 32px; }
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); padding: 3px 10px; border-radius: 10px; margin: 10px 0; }
.msg { max-width: min(560px, 82%); padding: 8px 12px 6px; border-radius: 14px; background: var(--panel-2); align-self: flex-start; word-wrap: break-word; white-space: pre-wrap; }
.msg.out { align-self: flex-end; background: #1d4f99; }
.msg.panel { background: #3b2f86; }
.msg .info { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg.out .info { color: #a9c3ee; }
.msg.deleted { outline: 1px dashed #a3384a; opacity: .78; }
.msg .del-label { color: #ff8a9a; font-weight: 600; }
.msg .media { font-size: 12px; color: #c9d6ff; display: block; margin-bottom: 2px; }
.msg audio.voice { display: block; width: min(280px, 62vw); height: 36px; margin: 2px 0 4px; }
.msg video.vnote { display: block; width: 180px; height: 180px; border-radius: 50%; object-fit: cover; background: #000; margin: 2px 0 4px; }
.msg .transcript { font-size: 13px; font-style: italic; color: var(--text-2); background: rgba(0,0,0,.18); border-radius: 8px; padding: 6px 8px; margin: 2px 0 4px; white-space: pre-wrap; }
.msg.out .transcript { color: #dbe6fb; }
.msg .tr-btn { margin: 0 0 4px; padding: 0 8px; min-height: 28px; font-size: 12px; }
.msg .fwd { display: block; font-size: 12px; color: #c9d6ff; border-left: 2px solid #5b7bd6; padding-left: 7px; margin: 0 0 4px; }
.msg .fwd.bad { color: #ffd0d6; border-left-color: var(--bad); background: rgba(239, 68, 68, .18); border-radius: 0 6px 6px 0; padding: 3px 7px; font-weight: 600; }
.msg .by { font-size: 11px; color: #d6ccff; display: block; margin-bottom: 2px; font-weight: 600; }
.reply-time { align-self: flex-end; font-size: 11px; color: var(--muted); margin: -2px 4px 4px; }
.reply-time.late { color: #ff8a9a; }
.composer { display: flex; gap: 10px; padding: 10px 14px calc(10px + var(--safe-b)); border-top: 1px solid var(--border); background: var(--panel); align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 160px; }
.readonly-note { padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--border); background: var(--panel); color: var(--muted); text-align: center; font-size: 13px; }
.load-more { align-self: center; margin-bottom: 8px; }

/* ---------- статистика ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filters > * { flex: 1 1 180px; max-width: 280px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 14px; }
.chart-card { padding: 16px; min-width: 0; }
.chart-card .chart-box { position: relative; height: 240px; margin-top: 10px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
details.data-table summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 8px; }
.status-chips { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- списки настроек ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.list-item.click { cursor: pointer; }
.list-item.click:hover { background: var(--panel-2); }
.copy-box { display: flex; gap: 8px; align-items: center; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 6px 6px 6px 12px; }
.copy-box code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-2); cursor: pointer; }
.days input { display: none; }
.days label:has(input:checked), .days label.on { background: #24305a; border-color: #3a4f8f; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- модалки, тосты, вход ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(3, 6, 15, .72); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: 100%; max-width: 480px; background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 20px; max-height: 92vh; overflow-y: auto; }
.modal h2 { margin-bottom: 14px; }
.modal .buttons { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.modal .buttons .left { margin-right: auto; }
.steps { display: flex; gap: 6px; margin-bottom: 16px; }
.steps span { flex: 1; height: 4px; border-radius: 2px; background: var(--panel-3); }
.steps span.on { background: var(--accent); }
.notice { background: #1b2847; border: 1px solid #2c3f6e; padding: 10px 12px; border-radius: 10px; font-size: 13px; color: var(--text-2); margin-bottom: 14px; }
.notice.warn { background: #2e2414; border-color: #5c4519; color: #f3d39a; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--panel-3); border: 1px solid var(--border); padding: 10px 14px; border-radius: 10px; max-width: 360px; box-shadow: 0 8px 30px rgba(0,0,0,.35); }
.toast.error { border-color: #6b2333; background: #2a1520; }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; padding: 26px; }
.auth-card .brand { padding: 0 0 18px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 16px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- телефон ---------- */
@media (max-width: 899px) {
  .shell { display: block; }
  .sidebar { display: none; }
  .mobile-top {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20; height: 54px; padding: 0 14px;
    background: rgba(10, 15, 29, .92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
  }
  .mobile-top .title { flex: 1; font-weight: 700; font-size: 17px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    background: rgba(12, 18, 34, .97); border-top: 1px solid var(--border); backdrop-filter: blur(10px);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 11px; position: relative; }
  .tabbar a .ico { font-size: 20px; line-height: 1; }
  .tabbar a.active { color: var(--text); }
  .tabbar a .count { position: absolute; top: 6px; left: 52%; height: 17px; min-width: 17px; font-size: 10px; padding: 0 5px; }
  .main { padding-bottom: calc(var(--nav-h) + var(--safe-b)); }
  .page { padding: 14px 14px 24px; }
  .page-head h1 { display: none; }
  .page-head > select.input { flex: 1; min-width: 0 !important; }
  .page-head .spacer { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile .value { font-size: 24px; }
  .hr-grid { grid-template-columns: 1fr; }
  .charts { grid-template-columns: 1fr; }
  .chart-card .chart-box { height: 210px; }
  .filters > * { max-width: none; flex: 1 1 140px; }
  .chats { display: block; height: auto; }
  .chats-list { border-right: none; min-height: calc(100vh - 54px - var(--nav-h)); }
  .chats-list .scroll { overflow: visible; }
  .chats .conv { display: none; }
  .chats.show-conv .chats-list { display: none; }
  .chats.show-conv .conv {
    display: flex; position: fixed; inset: 0; z-index: 40; height: 100dvh;
  }
  .modal-back { place-items: end center; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 90vh; padding-bottom: calc(20px + var(--safe-b)); }
  #toasts { left: 12px; right: 12px; bottom: calc(var(--nav-h) + 12px + var(--safe-b)); }
  .toast { max-width: none; }
  .two { grid-template-columns: 1fr; }
  .msg { max-width: 88%; }
}
