:root {
  --bg: #0f1419;
  --bg-2: #171c24;
  --bg-3: #1f2630;
  --line: #2a323d;
  --text: #e6e9ee;
  --muted: #9aa6b2;
  --accent: #4f8cff;
  --accent-2: #3a6fd0;
  --danger: #e5484d;
  --ok: #46c08a;
  --radius: 10px;
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }
button { font: inherit; cursor: pointer; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg-3);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
label { display: block; margin: 10px 0; font-size: 13px; color: var(--muted); }
label input { margin-top: 5px; }

.btn { background: var(--bg-3); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 14px; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-block { width: 100%; margin-top: 8px; }
.btn.danger, .ctrl.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.link { background: none; border: none; color: var(--accent); padding: 0; }
.link:hover { text-decoration: underline; }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100%; background: radial-gradient(1200px 600px at 50% -10%, #1c2942, var(--bg)); }
.login-card { width: 360px; max-width: 92vw; background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.brand { text-align: center; }
.brand h1 { margin: 12px 0 2px; font-size: 22px; }
.brand-logo { width: 52px; height: 52px; border-radius: 14px; background: linear-gradient(135deg, var(--accent), #7a5cff); color: #fff; font-weight: 800; font-size: 26px; display: grid; place-items: center; margin: 0 auto; }
.brand.small { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.brand.small .brand-logo { width: 32px; height: 32px; font-size: 18px; border-radius: 9px; }
.brand.small span { font-weight: 700; }

/* App shell */
.app-shell { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
.sidebar { background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px; gap: 12px; }
.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.nav-item { text-align: left; background: none; border: none; color: var(--muted); padding: 10px 12px; border-radius: 8px; }
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--bg-3); color: var(--text); font-weight: 600; }
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.me { display: flex; gap: 10px; align-items: center; }
.me-name { font-weight: 600; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-2); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: 0 0 auto; }

.content { overflow: hidden; }
.view { height: 100vh; }

/* Chat */
.chat { display: grid; grid-template-columns: 280px 1fr; height: 100%; }
.room-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.room-list .hd { display: flex; justify-content: space-between; align-items: center; padding: 14px; border-bottom: 1px solid var(--line); }
.room-list .scroll { overflow-y: auto; }
.room { display: flex; gap: 10px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--bg-3); }
.room:hover { background: var(--bg-2); }
.room.active { background: var(--bg-3); }
.room .r-main { min-width: 0; flex: 1; }
.room .r-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room .r-last { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #556; flex: 0 0 auto; }
.dot.on { background: var(--ok); }
.badge { background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }

.chat-main { display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 70%; }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg .bubble { background: var(--bg-3); padding: 9px 12px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.msg.mine { align-self: flex-end; }
.msg.mine .bubble { background: var(--accent-2); }
.composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.composer textarea { resize: none; height: 44px; }
.typing { font-size: 12px; color: var(--muted); padding: 0 16px 6px; height: 16px; }
.empty { color: var(--muted); display: grid; place-items: center; height: 100%; text-align: center; }

/* Files */
.files { display: flex; flex-direction: column; height: 100%; }
.files-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.breadcrumb { display: flex; gap: 6px; align-items: center; flex: 1; flex-wrap: wrap; }
.breadcrumb a { color: var(--accent); cursor: pointer; }
.tabs { display: flex; gap: 8px; }
.tab { background: none; border: 1px solid var(--line); color: var(--muted); padding: 6px 12px; border-radius: 999px; }
.tab.active { color: var(--text); border-color: var(--accent); }
.file-table { overflow-y: auto; flex: 1; }
.file-row { display: grid; grid-template-columns: 1fr 130px 90px 160px; gap: 10px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--bg-3); }
.file-row:hover { background: var(--bg-2); }
.file-row .nm { display: flex; gap: 10px; align-items: center; cursor: pointer; min-width: 0; }
.file-row .nm span.t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 6px; padding: 4px 7px; }
.icon-btn:hover { background: var(--bg-3); border-color: var(--line); }
.dropzone.drag { outline: 2px dashed var(--accent); outline-offset: -8px; }

/* Admin */
.admin { padding: 18px; overflow-y: auto; height: 100%; }
.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--bg-3); }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-actions { display: flex; gap: 6px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg-3); }
.tag.ok { color: var(--ok); } .tag.off { color: var(--danger); }

/* Call overlay */
.call-overlay { position: fixed; inset: 0; background: #0b0e13; z-index: 50; display: flex; flex-direction: column; }
.call-header { padding: 12px 16px; color: var(--muted); }
.video-grid { flex: 1; display: grid; gap: 10px; padding: 12px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); align-content: center; }
.video-tile { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 16/9; }
.video-tile video { width: 100%; height: 100%; object-fit: cover; }
.video-tile .label { position: absolute; bottom: 8px; left: 8px; background: rgba(0,0,0,.55); padding: 3px 9px; border-radius: 8px; font-size: 13px; }
.call-controls { display: flex; gap: 14px; justify-content: center; padding: 18px; }
.ctrl { width: 54px; height: 54px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg-3); font-size: 22px; }
.ctrl.off { background: var(--danger); border-color: var(--danger); }

/* Modal + toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 60; }
.modal-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: 440px; max-width: 92vw; max-height: 86vh; overflow-y: auto; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--bg-3); border: 1px solid var(--line); padding: 11px 16px; border-radius: 10px; z-index: 70; }
.toast.err { border-color: var(--danger); }

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; height: auto; }
  .sidebar .nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .chat, .file-row { grid-template-columns: 1fr; }
}
