:root {
  --bg: #0b1020;
  --bg-2: #0f172a;
  --panel: rgba(17, 24, 39, 0.75);
  --panel-solid: #111827;
  --panel-2: #1b2436;
  --text: #e5edf7;
  --muted: #94a3b8;
  --accent: #22c55e;
  --accent-2: #38bdf8;
  --me: #14532d;
  --me-border: #1f6f3f;
  --border: rgba(148, 163, 184, 0.16);
  --danger: #f87171;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at -10% -10%, rgba(56, 189, 248, 0.18), transparent 60%),
    radial-gradient(900px 500px at 110% 0%, rgba(34, 197, 94, 0.16), transparent 55%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.error {
  color: #fecaca;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.25);
  padding: 10px 12px;
  border-radius: 10px;
  margin: 12px 0 0;
}

/* Login */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.card {
  width: min(440px, 100%);
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.logo {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; font-size: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #062016; font-weight: 700;
}
.card h1 { margin: 0; font-size: 1.6rem; }
.subtitle { margin: 4px 0 0; }
.form { display: flex; flex-direction: column; gap: 14px; margin-top: 22px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.92rem; color: var(--muted); }
input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.7);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input::placeholder { color: #64748b; }
input:focus {
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
  background: rgba(15, 23, 42, 0.95);
}
button {
  padding: 12px 16px;
  border-radius: 12px;
  border: 0;
  background: linear-gradient(135deg, var(--accent), #16a34a);
  color: #052012;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: transform .08s ease, filter .15s ease;
}
button:hover { filter: brightness(1.05); }
button:active { transform: translateY(1px); }
.hint { margin-top: 16px; font-size: 0.85rem; color: var(--muted); text-align: center; }

/* Chat */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.7);
  backdrop-filter: blur(10px);
}
.room-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.room-badge {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: rgba(56, 189, 248, 0.15); color: var(--accent-2); font-weight: 700;
}
.room-meta { display: flex; flex-direction: column; line-height: 1.2; }
.room-meta strong { font-size: 1rem; }
.room-meta span { font-size: 0.85rem; color: var(--muted); }
.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 3px rgba(255,255,255,0.04) inset; }
.dot.on { background: #22c55e; box-shadow: 0 0 0 4px rgba(34,197,94,0.15); }
.dot.off { background: #ef4444; box-shadow: 0 0 0 4px rgba(239,68,68,0.12); }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 240px 1fr; }
.sidebar {
  border-right: 1px solid var(--border);
  padding: 16px;
  background: rgba(15, 23, 42, 0.35);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar h2 {
  font-size: 0.8rem; margin: 0 0 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
}
.sidebar ul { list-style: none; padding: 0; margin: 0; overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.user-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 10px;
  background: rgba(148, 163, 184, 0.06); border: 1px solid var(--border);
  font-size: 0.95rem;
}
.user-pill .avatar {
  width: 26px; height: 26px; border-radius: 8px; flex: 0 0 26px;
  display: grid; place-items: center; font-size: 0.75rem; font-weight: 700;
  background: linear-gradient(135deg, #334155, #1e293b); color: #cbd5e1;
}
.user-pill.me-pill { border-color: rgba(34,197,94,0.25); background: rgba(34,197,94,0.08); }
.sidebar-footer { padding-top: 12px; margin-top: 12px; border-top: 1px solid var(--border); }
.leave {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 0.92rem; padding: 6px 2px;
}
.leave:hover { color: #fca5a5; text-decoration: none; }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.messages {
  list-style: none; margin: 0; padding: 18px 18px 8px;
  overflow: auto; flex: 1; min-height: 0;
  display: flex; flex-direction: column; gap: 10px;
}
.msg {
  max-width: min(70%, 680px);
  padding: 10px 12px;
  border-radius: 16px 16px 16px 6px;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
}
.msg.me {
  align-self: flex-end;
  background: linear-gradient(180deg, rgba(20,83,45,0.95), rgba(20,83,45,0.75));
  border-color: var(--me-border);
  border-radius: 16px 16px 6px 16px;
}
.msg .meta { font-size: 0.78rem; color: #b7c3d1; margin-bottom: 4px; }
.msg.me .meta { color: #bbf7d0; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; line-height: 1.4; }
.msg.system {
  align-self: center; max-width: none;
  background: rgba(148,163,184,0.08); border: 1px dashed rgba(148,163,184,0.2);
  color: var(--muted); font-size: 0.85rem; padding: 6px 12px; border-radius: 999px; box-shadow: none;
}

.composer {
  display: flex; gap: 10px; align-items: center;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.6);
  backdrop-filter: blur(8px);
}
.composer input { flex: 1; border-radius: 999px; padding: 12px 16px; }
.composer button { border-radius: 999px; padding: 12px 18px; white-space: nowrap; }

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar {
    flex-direction: row; align-items: center; gap: 10px;
    border-right: 0; border-bottom: 1px solid var(--border);
    padding: 10px 12px; overflow: hidden;
  }
  .sidebar h2 { margin: 0; }
  .sidebar ul { flex-direction: row; overflow: auto; flex: 1; gap: 8px; }
  .user-pill { padding: 6px 10px; white-space: nowrap; }
  .sidebar-footer { margin: 0; padding: 0; border: 0; }
  .messages { padding: 14px 12px 8px; }
  .msg { max-width: 88%; }
  .composer { padding: 10px; }
}

/* --- additions: auth/admin --- */
.userbar { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-top:18px; padding:10px 12px; border:1px solid var(--border); border-radius:12px; background:rgba(148,163,184,0.06); }
.inline-form { display:inline; margin:0; }
.actions-row { display:flex; gap:10px; margin-top:18px; }
.button-link { flex:1; text-align:center; padding:12px 16px; border-radius:12px; background:linear-gradient(135deg,var(--accent),#16a34a); color:#052012; font-weight:700; text-decoration:none; }
.button-link.secondary { background:rgba(148,163,184,0.12); color:var(--text); border:1px solid var(--border); }
.button-link:hover { text-decoration:none; filter:brightness(1.05); }
.btn-secondary { background:rgba(148,163,184,0.12); color:var(--text); border:1px solid var(--border); padding:10px 14px; border-radius:10px; font-weight:600; cursor:pointer; display:inline-flex; align-items:center; justify-content:center; text-decoration:none; }
.btn-secondary:hover { background:rgba(148,163,184,0.18); text-decoration:none; }
.btn-danger { background:rgba(248,113,113,0.15); color:#fecaca; border:1px solid rgba(248,113,113,0.3); padding:10px 14px; border-radius:10px; font-weight:600; cursor:pointer; }
.btn-danger:hover { background:rgba(248,113,113,0.22); }
.btn-sm { padding:6px 10px; font-size:0.85rem; border-radius:8px; }
.full { display:flex; width:100%; margin-top:10px; }
.badge { display:inline-block; padding:2px 8px; border-radius:999px; background:rgba(56,189,248,0.18); color:#7dd3fc; font-size:0.75rem; margin-left:6px; vertical-align:middle; }
.topbar-actions { display:flex; align-items:center; gap:12px; }
.load-more-wrap { padding:8px 16px 0; text-align:center; }

.admin-wrap { max-width:1100px; margin:0 auto; padding:24px; }
.admin-topbar { display:flex; justify-content:space-between; align-items:center; gap:16px; margin-bottom:18px; }
.admin-topbar h1 { margin:0; font-size:1.6rem; }
.admin-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(160px,1fr)); gap:12px; margin-bottom:18px; }
.stat-card { background:var(--panel); border:1px solid var(--border); border-radius:14px; padding:16px; }
.stat-card .stat-label { color:var(--muted); font-size:0.85rem; display:block; margin-bottom:6px; }
.stat-card strong { font-size:1.6rem; }
.panel { background:var(--panel); border:1px solid var(--border); border-radius:16px; padding:16px; margin-bottom:16px; }
.panel h2 { margin:0 0 12px; font-size:1.1rem; }
.table-wrap { overflow:auto; }
table { width:100%; border-collapse:collapse; }
th, td { text-align:left; padding:10px 8px; border-bottom:1px solid var(--border); font-size:0.95rem; }
th { color:var(--muted); font-weight:600; font-size:0.85rem; text-transform:uppercase; letter-spacing:.04em; }
.row-actions { display:flex; gap:6px; flex-wrap:wrap; align-items:center; }
.room-list { list-style:none; padding:0; margin:0; display:flex; flex-direction:column; gap:8px; }
.room-list li { display:flex; justify-content:space-between; align-items:center; gap:12px; padding:10px 12px; border:1px solid var(--border); border-radius:10px; background:rgba(148,163,184,0.04); }
.composer button:disabled { opacity:0.5; cursor:not-allowed; }

/* media, dm, composer icons */
.section-title { font-size:0.95rem; margin:18px 0 8px; color:var(--muted); text-transform:uppercase; letter-spacing:.06em; }
.dm-list { list-style:none; padding:0; margin:8px 0 0; display:flex; flex-direction:column; gap:8px; max-height:220px; overflow:auto; }
.dm-link { display:flex; align-items:center; gap:10px; padding:10px 12px; border:1px solid var(--border); border-radius:12px; color:var(--text); text-decoration:none; background:rgba(148,163,184,0.05); }
.dm-link:hover { background:rgba(148,163,184,0.1); text-decoration:none; }
.avatar.sm { width:28px; height:28px; border-radius:8px; display:inline-grid; place-items:center; background:linear-gradient(135deg,#334155,#1e293b); font-weight:700; font-size:0.8rem; text-transform:uppercase; }
.icon-btn { width:40px; height:40px; padding:0; border-radius:12px; background:rgba(148,163,184,0.12); border:1px solid var(--border); font-size:1.1rem; display:inline-grid; place-items:center; cursor:pointer; color:var(--text); flex:0 0 40px; }
.icon-btn:hover { background:rgba(148,163,184,0.2); }
.msg-image { max-width:100%; max-height:320px; border-radius:10px; display:block; margin-top:4px; }
.msg-audio { width:100%; max-width:320px; margin-top:4px; }
.rec-indicator { padding:8px 16px; color:#fecaca; font-size:0.9rem; text-align:center; background:rgba(239,68,68,0.08); }

/* replies */
.reply-quote { border-left:3px solid #22c55e; padding:4px 8px; margin:4px 0; background:rgba(15,23,42,0.55); border-radius:6px; max-width:100%; }
.reply-quote .reply-author { font-size:0.75rem; font-weight:700; color:#86efac; }
.reply-quote .reply-text { font-size:0.85rem; color:#cbd5e1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
