:root {
  --bg: #0f1216;
  --surface: #161a1f;
  --surface2: #1b2027;
  --surface3: #222831;
  --line: #262c35;
  --line2: #323945;
  --text: #e8ebef;
  --muted: #8b95a3;
  --faint: #626c79;
  --accent: #3b82f6;
  --accent-bg: #1a2a44;
  --red: #f26d6d;
  --red-bg: #2a1b1e;
  --green: #45c47a;
  --amber: #e3b341;
  --r: 8px;
  --r-lg: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 "Inter", -apple-system, "Segoe UI", Roboto, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
code { background: var(--surface3); padding: 2px 6px; border-radius: 5px; font-size: 12px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--line2); background-clip: padding-box; }

input[type=search], input:not([type]) { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 9px 12px; outline: none; }
input::placeholder { color: var(--faint); }
input:focus { border-color: var(--accent); }
.check { display: flex; gap: 7px; align-items: center; color: var(--muted); font-size: 13px; white-space: nowrap; cursor: pointer; }
.check input { accent-color: var(--accent); }
.primary { background: var(--accent); color: #fff; padding: 9px 16px; border-radius: var(--r); font-weight: 600; }
.primary:hover { background: #2f6fe0; }
.ghost { color: var(--muted); padding: 7px 11px; border-radius: 7px; }
.ghost:hover { background: var(--surface3); color: var(--text); }
.btn { background: var(--surface3); border: 1px solid var(--line2); padding: 6px 11px; border-radius: 7px; font-size: 13px; }
.btn:hover { border-color: var(--accent); }
.more { display: block; margin: 12px auto; color: var(--accent); padding: 8px 14px; }

.brand { display: flex; align-items: center; gap: 9px; }
.brand img { width: 26px; height: 26px; }
.wordmark { font-weight: 600; font-size: 16px; }
.wordmark b { color: var(--accent); }
.wordmark .sub { color: var(--faint); font-weight: 400; font-size: 12px; margin-left: 6px; }

.login { height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { max-width: 420px; width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 36px 32px; text-align: center; }
.login-card img { width: 60px; height: 60px; margin-bottom: 16px; }
.login-card h1 { margin: 0 0 8px; font-size: 24px; font-weight: 600; }
.login-card h1 b { color: var(--accent); }
.login-card p { color: var(--muted); margin: 8px 0; line-height: 1.6; }

.app { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 16px; padding: 11px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.stats-bar { display: flex; gap: 8px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.stats-bar::-webkit-scrollbar { display: none; }
.stat-chip { display: flex; align-items: center; gap: 7px; background: var(--surface2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.stat-chip b { color: var(--text); font-size: 14px; font-weight: 600; }
.stat-chip.accent b { color: var(--accent); }
.me { display: flex; align-items: center; gap: 10px; color: var(--muted); white-space: nowrap; font-size: 13px; }

.tabs { display: flex; gap: 2px; padding: 6px 16px; border-bottom: 1px solid var(--line); background: var(--surface); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { padding: 7px 14px; border-radius: 7px; color: var(--muted); white-space: nowrap; font-weight: 500; }
.tabs button:hover { color: var(--text); background: var(--surface2); }
.tabs button.active { color: var(--text); background: var(--surface3); }

.view { flex: 1; min-height: 0; overflow: auto; }
.view.three { display: grid; grid-template-columns: 300px 320px 1fr; overflow: hidden; }
.col { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.col-msgs { border-right: 0; background: var(--bg); }
.col-users, .col-chats { background: var(--surface); }
.col-head { padding: 12px; display: flex; flex-direction: column; gap: 9px; border-bottom: 1px solid var(--line); }
.col-head.small { padding: 9px 12px; }
.list { overflow-y: auto; flex: 1; padding: 5px; }
.chips { display: flex; gap: 6px; }
.chip { padding: 5px 11px; border-radius: 7px; background: var(--surface2); border: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }

.item { display: flex; gap: 10px; align-items: center; padding: 9px 11px; border-radius: var(--r); cursor: pointer; margin-bottom: 1px; }
.item:hover { background: var(--surface2); }
.item.active { background: var(--accent-bg); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 15px; flex: none; position: relative; color: #fff; }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--surface); background: #5a6472; }
.avatar .dot.on { background: var(--green); }
.item-main { min-width: 0; flex: 1; }
.item-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--surface3); color: var(--muted); white-space: nowrap; }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.green { background: #16301f; color: var(--green); }

.user-card { padding: 15px; border-bottom: 1px solid var(--line); position: relative; }
.user-card.empty { color: var(--faint); text-align: center; padding: 36px 15px; }
.user-card h4 { margin: 0 0 3px; font-size: 16px; }
.user-card .meta { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.user-card .badges { display: flex; gap: 6px; flex-wrap: wrap; }

.chat-head { display: flex; align-items: center; gap: 11px; padding: 11px 16px; border-bottom: 1px solid var(--line); background: var(--surface); min-height: 58px; }
.chat-head.empty .chat-title { color: var(--faint); }
.chat-title { font-weight: 600; flex: 1; min-width: 0; }
.chat-title small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; margin-top: 1px; }
.back { display: none; font-size: 19px; padding: 4px 8px; color: var(--muted); }
.msgs { flex: 1; overflow-y: auto; padding: 16px 18px 30px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; background: var(--surface2); border: 1px solid var(--line); color: var(--muted); font-size: 12px; padding: 3px 11px; border-radius: 7px; margin: 10px 0 4px; }
.bubble { max-width: min(580px, 84%); background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 6px; align-self: flex-start; }
.bubble.out { background: var(--accent-bg); border-color: #294063; align-self: flex-end; }
.bubble.deleted { background: var(--red-bg); border-color: #4a2626; }
.bubble.hl { border-color: var(--amber); }
.b-from { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.b-text { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.b-meta { display: flex; gap: 8px; justify-content: flex-end; align-items: center; font-size: 11px; color: var(--faint); margin-top: 3px; flex-wrap: wrap; }
.b-meta .del { color: var(--red); font-weight: 600; }
.b-meta .send { cursor: pointer; opacity: .55; }
.b-meta .send:hover { opacity: 1; }
.media { margin: 2px -5px 4px; }
.media img, .media video { display: block; max-width: 100%; max-height: 420px; border-radius: 8px; background: #000; }
.media img { cursor: zoom-in; }
.media video.round { width: 230px; height: 230px; border-radius: 50%; object-fit: cover; }
.media audio { width: 280px; max-width: 100%; }
.media .sticker { max-width: 170px; background: transparent; }
.filecard { display: flex; gap: 10px; align-items: center; background: var(--surface3); border-radius: 8px; padding: 9px 11px; }
.filecard .ico { font-size: 22px; }
.filecard .fn { font-weight: 600; word-break: break-all; }
.placeholder { background: var(--surface3); border: 1px dashed var(--line2); border-radius: 8px; padding: 12px; color: var(--muted); font-size: 13px; }
.empty-state { color: var(--muted); text-align: center; margin: auto; padding: 48px 22px; }
.empty-state .spark { width: 48px; height: 48px; margin: 0 auto 12px; border-radius: 12px; background: var(--accent-bg); border: 1px solid var(--accent); display: grid; place-items: center; font-size: 22px; color: var(--accent); }
.empty-state .muted { margin-top: 4px; }

.pad { padding: 20px; max-width: 1100px; margin: 0 auto; }
.pad.narrow { max-width: 820px; }
.search-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.results { display: flex; flex-direction: column; gap: 10px; }
.result { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 11px 13px; cursor: pointer; }
.result:hover { border-color: var(--accent); }
.result .ctx { font-size: 12px; color: var(--muted); margin-bottom: 7px; }
.result .bubble { max-width: 100%; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 15px; }
.stat .v { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; }
.panel h3 { margin: 0 0 11px; font-size: 15px; }
.chart { display: flex; align-items: flex-end; gap: 5px; height: 160px; }
.chart .bar { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 3px; position: relative; }
.chart .bar span { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--faint); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 15px; }
.kv div:nth-child(odd) { color: var(--muted); }
.table { display: flex; flex-direction: column; }
.tr { display: grid; grid-template-columns: 150px 120px 1fr auto; gap: 11px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; align-items: center; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal-box { background: var(--surface); border: 1px solid var(--line2); border-radius: 12px; padding: 18px; max-width: 92vw; max-height: 90vh; overflow: auto; position: relative; min-width: 280px; }
.modal-box img { max-width: 88vw; max-height: 80vh; display: block; border-radius: 8px; }
.modal-x { position: absolute; top: 9px; right: 11px; color: var(--muted); font-size: 16px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--surface3); border: 1px solid var(--line2); padding: 10px 16px; border-radius: 8px; z-index: 30; }

@media (max-width: 920px) {
  .top { flex-wrap: wrap; gap: 9px; }
  .stats-bar { order: 3; flex-basis: 100%; }
  .view.three { grid-template-columns: 1fr; }
  .view.three .col { display: none; border-right: 0; }
  .view.three[data-pane=users] .col-users,
  .view.three[data-pane=chats] .col-chats,
  .view.three[data-pane=msgs] .col-msgs { display: flex; }
  .back { display: inline-block; }
  .grid2 { grid-template-columns: 1fr; }
  .tr { grid-template-columns: 1fr; gap: 2px; }
}
