/* ============================================================
   ChatApp — Estilos globales
   ============================================================ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg:          #0a0e1a;
  --sidebar:     #111827;
  --card:        #1a2235;
  --accent:      #6366f1;
  --accent2:     #8b5cf6;
  --text:        #e2e8f0;
  --muted:       #64748b;
  --border:      #1e293b;
  --danger:      #ef4444;
  --success:     #22c55e;
  --warning:     #f59e0b;
  --radius:      12px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── AUTH ─────────────────────────────────────────────────── */
.auth-page { overflow: auto; }
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.auth-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 44px 40px;
  width: 380px;
  max-width: 100%;
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
}
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-icon { font-size: 52px; line-height: 1; margin-bottom: 10px; }
.auth-logo h1 {
  font-size: 26px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.auth-logo p { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* ── FORMS ───────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .7px;
  margin-bottom: 7px;
}
.form-group input,
.create-form input,
.create-chat-form input,
.create-chat-form select,
#new-chat-members {
  width: 100%;
  padding: 11px 15px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
  font-family: inherit;
}
.form-group input:focus,
.create-form input:focus,
.create-chat-form input:focus,
.create-chat-form select:focus { border-color: var(--accent); }
.error-msg { color: #fca5a5; font-size: 12px; margin-top: 8px; min-height: 16px; }
.session-bar {
  background: rgba(99,102,241,.1);
  border: 1px solid rgba(99,102,241,.25);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 12px;
  color: #a5b4fc;
  text-align: center;
  margin-top: 16px;
}

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn {
  display: block;
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  text-align: center;
  text-decoration: none;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
}
.btn-primary:hover { opacity: .88; transform: translateY(-1px); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .88; }
.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); }
.btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: auto;
  padding: 7px 14px;
  font-size: 12px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: all .2s;
  font-family: inherit;
}
.btn-del {
  background: rgba(239,68,68,.15);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,.2);
}
.btn-del:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ── TOP BAR ─────────────────────────────────────────────── */
.topbar {
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 10;
}
.topbar-left  { display: flex; align-items: center; gap: 14px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-logo {
  font-size: 20px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.tabs { display: flex; gap: 3px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab {
  padding: 6px 18px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  background: none;
  border: none;
  transition: all .2s;
  font-family: inherit;
  font-weight: 500;
}
.tab.active { background: var(--accent); color: #fff; }
.timer-badge {
  background: rgba(99,102,241,.15);
  border: 1px solid rgba(99,102,241,.3);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  min-width: 80px;
  text-align: center;
}
.timer-badge.warning {
  background: rgba(239,68,68,.15);
  border-color: rgba(239,68,68,.3);
  color: #fca5a5;
}
.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
}
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}
.logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  transition: all .2s;
  font-weight: 500;
}
.logout-btn:hover { border-color: var(--danger); color: var(--danger); }

/* ── LAYOUT ──────────────────────────────────────────────── */
.main-layout { display: flex; flex: 1; overflow: hidden; }

/* ── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
  width: 300px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header { padding: 14px 14px 10px; border-bottom: 1px solid var(--border); }
.sidebar-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 10px;
}
.search-box { position: relative; }
.search-box input {
  padding-left: 32px !important;
  font-size: 13px;
}
.search-box::before {
  content: '🔍';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  pointer-events: none;
}
.sidebar-list { flex: 1; overflow-y: auto; padding: 8px; }
.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
  margin-bottom: 2px;
  position: relative;
  text-decoration: none;
  color: inherit;
}
.chat-item:hover  { background: var(--card); }
.chat-item.active { background: var(--accent); }
.chat-item.active .chat-name,
.chat-item.active .chat-preview { color: #fff; }
.chat-item.active .chat-preview { opacity: .75; }
.chat-info { flex: 1; min-width: 0; }
.chat-name  { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
.chat-item.active .unread-badge { background: #fff; color: var(--accent); }
.online-dot {
  width: 9px;
  height: 9px;
  background: var(--success);
  border-radius: 50%;
  position: absolute;
  bottom: 8px;
  left: 32px;
  border: 2px solid var(--sidebar);
}
.chat-item.active .online-dot { border-color: var(--accent); }
.group-tag {
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 8px;
  background: rgba(99,102,241,.2);
  color: #a5b4fc;
  font-weight: 600;
  vertical-align: middle;
  margin-left: 4px;
}
.chat-item.active .group-tag { background: rgba(255,255,255,.2); color: #fff; }
.chat-ts { font-size: 10px; color: var(--muted); white-space: nowrap; }

/* ── CHAT AREA ───────────────────────────────────────────── */
.chat-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.chat-header {
  padding: 12px 20px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.chat-header-info { display: flex; align-items: center; gap: 12px; }
.chat-header-text h3 { font-size: 15px; font-weight: 700; }
.chat-header-text p  { font-size: 12px; color: var(--muted); margin-top: 2px; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg { display: flex; flex-direction: column; max-width: 66%; }
.msg.me    { align-self: flex-end;   align-items: flex-end; }
.msg.other { align-self: flex-start; align-items: flex-start; }
.msg-sender { font-size: 11px; color: var(--muted); margin-bottom: 3px; padding: 0 4px; }
.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.me    .msg-bubble { background: var(--accent);  color: #fff; border-bottom-right-radius: 4px; }
.msg.other .msg-bubble { background: var(--card); color: var(--text); border-bottom-left-radius: 4px; }
.msg-time { font-size: 10px; color: var(--muted); margin-top: 3px; padding: 0 4px; }
.msg-date {
  align-self: center;
  background: var(--card);
  padding: 4px 14px;
  border-radius: 10px;
  font-size: 11px;
  color: var(--muted);
  margin: 10px 0;
  font-weight: 600;
}

.chat-input-area {
  padding: 14px 18px;
  background: var(--sidebar);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}
.msg-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 16px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  resize: none;
  max-height: 120px;
  font-family: inherit;
  transition: border-color .2s;
  line-height: 1.5;
}
.msg-input:focus { border-color: var(--accent); }
.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all .2s;
}
.send-btn:hover { background: var(--accent2); transform: scale(1.05); }

.empty-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 14px;
}
.empty-icon { font-size: 72px; opacity: .2; }

/* ── ADMIN ───────────────────────────────────────────────── */
#admin-panel {
  flex: 1;
  overflow-y: auto;
}
.admin-inner { padding: 24px; max-width: 1100px; margin: 0 auto; }
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.stat-num {
  font-size: 36px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1;
}
.stat-label { font-size: 13px; color: var(--muted); margin-top: 6px; font-weight: 500; }
.admin-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
}
.admin-section h3 { font-size: 15px; font-weight: 700; margin-bottom: 16px; }
.create-form,
.create-chat-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.create-form input,
.create-chat-form input,
.create-chat-form select { flex: 1; min-width: 140px; }
#new-chat-members { min-width: 200px; }
#new-chat-members option { background: var(--card); padding: 4px; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
td {
  padding: 11px 12px;
  font-size: 13px;
  border-bottom: 1px solid rgba(30,41,59,.6);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(99,102,241,.04); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.badge-admin   { background: rgba(99,102,241,.2);  color: #a5b4fc; }
.badge-user    { background: rgba(100,116,139,.2); color: var(--muted); }
.badge-online  { background: rgba(34,197,94,.2);  color: var(--success); }
.badge-offline { background: rgba(100,116,139,.15); color: var(--muted); }

.actions { display: flex; gap: 6px; }

/* ── MODAL ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px;
  width: 420px;
  max-width: 92vw;
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
}
.modal h3 { font-size: 18px; font-weight: 800; margin-bottom: 8px; }
.modal p  { color: var(--muted); font-size: 14px; margin-bottom: 22px; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

/* ── TOAST ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  right: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  animation: slideUp .3s ease;
  box-shadow: 0 8px 32px rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── MISC ────────────────────────────────────────────────── */
.loading-spinner { color: var(--muted); font-size: 13px; text-align: center; padding: 24px; }
.no-data         { color: var(--muted); font-size: 13px; text-align: center; padding: 18px; }

/* Scrollbar global */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Responsive */
@media (max-width: 640px) {
  .sidebar { width: 220px; }
  .msg { max-width: 85%; }
  .admin-inner { padding: 12px; }
}
