:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-2: #1d2b39;
  --hover: #202b36;
  --border: #101921;
  --text: #e9edf0;
  --muted: #7d8e9e;
  --accent: #2b9ae8;
  --accent-2: #3390ec;
  --bubble-out: #2b5278;
  --bubble-in: #182533;
  --danger: #e8534f;
  --ok: #4dba87;
  --warn: #e0a644;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; }

/* ---------- flashes ---------- */
.flashes {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 1000; width: min(440px, 92vw); display: flex; flex-direction: column; gap: 8px;
}
.flash {
  padding: 10px 14px; border-radius: 10px; font-size: 14px;
  background: var(--panel-2); border: 1px solid var(--border); box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.flash-danger { border-color: var(--danger); }
.flash-success { border-color: var(--ok); }
.flash-warning { border-color: var(--warn); }
.flash-info { border-color: var(--accent); }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(380px, 94vw); background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px 26px; box-shadow: 0 10px 40px rgba(0,0,0,.45);
}
.auth-card h1 { margin: 0 0 4px; font-size: 24px; }
.auth-card .sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 11px 13px; border-radius: 10px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); outline: none;
}
.field input:focus { border-color: var(--accent); }
.btn {
  width: 100%; padding: 12px; border: none; border-radius: 10px; color: #fff;
  background: var(--accent-2); font-weight: 600;
}
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--panel-2); }
.auth-links { margin-top: 16px; display: flex; justify-content: space-between; font-size: 14px; }
.brand { font-weight: 700; letter-spacing: .3px; }

/* ---------- chat layout ---------- */
.app { display: grid; grid-template-columns: 320px 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; }
.sidebar-head { padding: 12px; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--border); }
.sidebar-head .me { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: transparent; border: none; color: var(--muted); font-size: 18px; padding: 6px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.search { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.search input { width: 100%; padding: 9px 12px; border-radius: 18px; background: var(--bg); border: 1px solid var(--border); color: var(--text); outline: none; }
.conv-list { flex: 1; overflow-y: auto; }
.conv {
  display: flex; gap: 10px; padding: 10px 12px; cursor: pointer; align-items: center;
  border-bottom: 1px solid rgba(255,255,255,.02);
}
.conv:hover { background: var(--hover); }
.conv.active { background: var(--bubble-out); }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, #2b9ae8, #6b5be8); color: #fff; font-weight: 600; position: relative;
}
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--panel); background: var(--muted); }
.dot.online { background: var(--ok); }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; }
.conv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { color: var(--muted); font-size: 12px; flex: none; }
.conv-bottom { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.conv-preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--accent-2); color: #fff; font-size: 12px; border-radius: 11px; min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center; }

/* ---------- chat panel ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; background:
  linear-gradient(rgba(14,22,33,.92), rgba(14,22,33,.92)); }
.chat-head { padding: 10px 16px; display: flex; gap: 12px; align-items: center; border-bottom: 1px solid var(--border); background: var(--panel); }
.chat-head .title { flex: 1; min-width: 0; }
.chat-head .name { font-weight: 600; }
.chat-head .status { font-size: 12px; color: var(--muted); }
.chat-head .status.online { color: var(--ok); }
.messages { flex: 1; overflow-y: auto; padding: 18px 14% 18px; display: flex; flex-direction: column; gap: 4px; }
@media (max-width: 900px) { .messages { padding: 16px 12px; } }
.msg { max-width: 70%; padding: 7px 11px; border-radius: 14px; background: var(--bubble-in); align-self: flex-start; word-wrap: break-word; }
.msg.out { align-self: flex-end; background: var(--bubble-out); }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }
.msg.out .meta .ticks { color: #9fd1ff; }
.msg img.att { max-width: 320px; max-height: 320px; border-radius: 10px; display: block; cursor: pointer; }
.msg video.att { max-width: 320px; border-radius: 10px; display: block; }
.msg audio.att { width: 260px; }
.msg .file { display: flex; gap: 10px; align-items: center; }
.msg .file .fi { width: 38px; height: 38px; border-radius: 8px; background: var(--accent-2); display: grid; place-items: center; flex: none; }
.msg .file a { color: inherit; }
.day-sep { align-self: center; background: rgba(0,0,0,.3); color: var(--muted); font-size: 12px; padding: 3px 10px; border-radius: 10px; margin: 8px 0; }
.typing { color: var(--muted); font-size: 13px; padding: 0 14% 6px; min-height: 18px; }

.composer { padding: 10px 14px; display: flex; gap: 10px; align-items: center; border-top: 1px solid var(--border); background: var(--panel); }
.composer textarea { flex: 1; resize: none; min-height: 44px; max-height: 140px; padding: 11px 16px; line-height: 20px; border-radius: 22px; background: var(--bg); border: 1px solid var(--border); color: var(--text); outline: none; overflow-y: auto; }
.composer textarea:focus { border-color: var(--accent); }
.composer .send { background: var(--accent-2); color: #fff; border: none; width: 44px; height: 44px; border-radius: 50%; font-size: 18px; flex: none; }
.composer .send:disabled { opacity: .5; }

.empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; }

/* ---------- call overlay ---------- */
.call-overlay { position: fixed; inset: 0; background: rgba(8,12,18,.96); z-index: 2000; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.call-overlay.show { display: flex; }
.call-videos { position: relative; width: min(900px, 94vw); height: min(64vh, 620px); background: #000; border-radius: 16px; overflow: hidden; }
.call-videos video { width: 100%; height: 100%; object-fit: cover; }
.call-videos .local { position: absolute; right: 14px; bottom: 14px; width: 180px; height: 120px; border-radius: 10px; border: 2px solid rgba(255,255,255,.2); object-fit: cover; background: #111; }
.call-info { text-align: center; }
.call-info .who { font-size: 20px; font-weight: 600; }
.call-info .state { color: var(--muted); }
.call-btns { display: flex; gap: 16px; }
.call-btns button { width: 60px; height: 60px; border-radius: 50%; border: none; font-size: 22px; color: #fff; background: var(--panel-2); }
.call-btns .hangup { background: var(--danger); }
.call-btns .accept { background: var(--ok); }
.call-btns.toggled { background: #fff; }
.call-btns button.muted { background: #fff; color: #111; }

.hidden { display: none !important; }

/* ---------- admin ---------- */
.admin { max-width: 1000px; margin: 0 auto; padding: 24px; }
.admin h1 { font-size: 22px; }
.admin-nav { display: flex; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.admin-nav a { padding: 8px 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; color: var(--text); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 12px; margin-bottom: 24px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.card .num { font-size: 28px; font-weight: 700; }
.card .lbl { color: var(--muted); font-size: 13px; }
table.tbl { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 12px; overflow: hidden; }
table.tbl th, table.tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.tbl th { color: var(--muted); font-weight: 600; font-size: 13px; }
.btn-sm { padding: 6px 12px; border-radius: 8px; border: none; color: #fff; font-size: 13px; }
.btn-sm.ok { background: var(--ok); }
.btn-sm.no { background: var(--danger); }
.btn-sm.gray { background: var(--panel-2); }
.inline { display: inline; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 8px; background: var(--panel-2); }
.tag.ok { background: rgba(77,186,135,.2); color: var(--ok); }
.tag.no { background: rgba(232,83,79,.2); color: var(--danger); }
