/* ── Variables ── */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --border: #e0e0e0;
  --primary: #4f8ef7;
  --primary-dark: #3a75d4;
  --text: #1a1a1a;
  --muted: #6b7280;
  --bubble-self-bg: #4f8ef7;
  --bubble-self-text: #ffffff;
  --bubble-other-bg: #f0f2f5;
  --bubble-other-text: #1a1a1a;
  --sidebar-w: 220px;
  --radius: 12px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); height: 100dvh; overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; }

/* ── Utilities ── */
.hidden { display: none !important; }
.form-error { color: #e53e3e; font-size: 0.85rem; margin-top: 6px; }

/* ── Panels ── */
.panel { display: flex; align-items: center; justify-content: center; height: 100dvh; }

/* ── Auth card ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: min(400px, 90vw);
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
}
.card h1 { font-size: 1.6rem; margin-bottom: .35rem; }
.card .subtitle { color: var(--muted); font-size: .9rem; margin-bottom: 1.5rem; }
.card label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .3rem; color: var(--muted); }
.card input {
  display: block; width: 100%; padding: .65rem .85rem;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 1rem; outline: none; margin-bottom: 1rem;
  transition: border-color .15s;
}
.card input:focus { border-color: var(--primary); }
.card button[type=submit] {
  width: 100%; padding: .7rem; border: none; border-radius: 8px;
  background: var(--primary); color: #fff; font-size: 1rem; font-weight: 600;
  transition: background .15s;
}
.card button[type=submit]:hover { background: var(--primary-dark); }
.switch-link { margin-top: 1rem; font-size: .875rem; color: var(--muted); text-align: center; }

/* ── Admin panel ── */
.admin-toggle-wrap {
  margin-top: 1.5rem;
  border-top: 1px solid var(--border);
  padding-top: .85rem;
  text-align: center;
}
.admin-toggle {
  background: none; border: none;
  font-size: .78rem; color: var(--muted);
  cursor: pointer; text-decoration: underline; padding: 0;
}
.admin-toggle:hover { color: #e53e3e; }
.admin-section {
  margin-top: .85rem;
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: 8px;
  padding: .85rem;
}
.admin-section label { color: #c53030; }
.admin-section input {
  display: block; width: 100%; padding: .55rem .75rem;
  border: 1.5px solid #feb2b2; border-radius: 6px;
  font-size: .9rem; outline: none; margin-bottom: .75rem;
}
.admin-section input:focus { border-color: #e53e3e; }
.btn-danger {
  width: 100%; padding: .6rem; border: none; border-radius: 6px;
  background: #e53e3e; color: #fff; font-size: .88rem; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.btn-danger:hover { background: #c53030; }

/* ── Chat layout ── */
#view-chat { display: block; height: 100dvh; }
.chat-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
}

/* ── Sidebar ── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-section {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-section h3 {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: .6rem;
}
.sidebar-section ul { list-style: none; }
.sidebar-section li {
  font-size: .875rem;
  padding: .3rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .35rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-section li .user-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-remove-user {
  background: none; border: none; padding: 0 2px;
  color: var(--muted); font-size: .85rem; line-height: 1;
  cursor: pointer; opacity: 0; flex-shrink: 0;
  transition: opacity .15s, color .15s;
}
.sidebar-section li:hover .btn-remove-user { opacity: 1; }
.btn-remove-user:hover { color: #e53e3e; }

.sidebar-section li.online::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  background: #22c55e;
  border-radius: 50%;
  margin-right: 6px;
}
.sidebar-section a { color: var(--text); font-size: .82rem; }
.sidebar-section a:hover { color: var(--primary); }
.sidebar-footer {
  margin-top: auto;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .8rem;
  color: var(--muted);
}
.btn-ghost {
  background: none; border: none; color: var(--muted);
  font-size: .8rem; padding: 0; text-decoration: underline;
}
.btn-ghost:hover { color: #e53e3e; }

/* ── Chat main ── */
.chat-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Messages ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.msg-row { display: flex; flex-direction: column; max-width: 70%; }
.msg-row.self { align-self: flex-end; align-items: flex-end; }
.msg-row.other { align-self: flex-start; align-items: flex-start; }
.msg-meta {
  font-size: .72rem;
  color: var(--muted);
  margin-bottom: 2px;
}
.bubble {
  padding: .55rem .85rem;
  border-radius: 16px;
  font-size: .92rem;
  line-height: 1.45;
  word-break: break-word;
}
.msg-row.self .bubble {
  background: var(--bubble-self-bg);
  color: var(--bubble-self-text);
  border-bottom-right-radius: 4px;
}
.msg-row.other .bubble {
  background: var(--bubble-other-bg);
  color: var(--bubble-other-text);
  border-bottom-left-radius: 4px;
}
.bubble-file {
  display: flex; align-items: center; gap: .5rem;
}
.bubble-file svg { flex-shrink: 0; }
.bubble-file a { color: inherit; text-decoration: underline; font-size: .88rem; }
.msg-row.self .bubble-file a { color: rgba(255,255,255,.9); }

/* System events (join/leave) */
.msg-system {
  align-self: center;
  font-size: .78rem;
  color: var(--muted);
  background: var(--border);
  border-radius: 999px;
  padding: .2rem .75rem;
  margin: .25rem 0;
}

/* ── Upload progress ── */
.upload-progress {
  padding: .4rem 1rem;
  background: #eff6ff;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .82rem;
  color: var(--primary);
}
.progress-bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width .2s;
}

/* ── Input bar ── */
.input-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.attach-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%; cursor: pointer; color: var(--muted);
  transition: background .15s;
  flex-shrink: 0;
}
.attach-btn:hover { background: var(--bg); color: var(--primary); }
.attach-btn input[type=file] { display: none; }
.input-bar input[type=text] {
  flex: 1;
  padding: .6rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: .95rem;
  outline: none;
  transition: border-color .15s;
}
.input-bar input[type=text]:focus { border-color: var(--primary); }
.input-bar button[type=submit] {
  padding: .6rem 1.1rem;
  border: none; border-radius: 999px;
  background: var(--primary); color: #fff;
  font-size: .9rem; font-weight: 600;
  transition: background .15s;
}
.input-bar button[type=submit]:hover { background: var(--primary-dark); }

/* ── Disclaimer toast ── */
.disclaimer-toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  background: #1e293b;
  color: #f1f5f9;
  border-radius: 10px;
  padding: .75rem 1rem;
  max-width: min(520px, 92vw);
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  font-size: .83rem;
  line-height: 1.5;
  z-index: 9999;
  animation: toast-in .2s ease;
}
.disclaimer-toast strong { color: #ffffff; }
.disclaimer-toast svg { margin-top: 1px; color: #facc15; }
#disclaimer-close {
  background: none; border: none; color: #94a3b8;
  font-size: 1.1rem; line-height: 1; cursor: pointer;
  margin-left: auto; padding: 0 0 0 .5rem; flex-shrink: 0;
}
#disclaimer-close:hover { color: #f1f5f9; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Responsive ── */
@media (max-width: 600px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
}
