/* ===== CSS Variables (Light theme default) ===== */
:root {
  --bg: #f5f6fa;
  --bg-card: #ffffff;
  --bg-input: #f0f1f5;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --primary: #4F6EF7;
  --primary-hover: #3d5ce5;
  --accent: #FF6B6B;
  --online: #22c55e;
  --offline: #ef4444;
  --msg-self: #4F6EF7;
  --msg-self-text: #ffffff;
  --msg-other: #e8eaf0;
  --msg-other-text: #1a1a2e;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 10px;
  --transition: 0.2s ease;
}

/* ===== Dark theme ===== */
.dark {
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-input: #252540;
  --text: #e5e7eb;
  --text-secondary: #9ca3af;
  --border: #2d2d45;
  --msg-other: #252540;
  --msg-other-text: #e5e7eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* ===== Views ===== */
.view { display: flex; flex-direction: column; height: 100vh; }
.view.hidden { display: none; }

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
}
.slogan { font-size: 0.8rem; color: var(--text-secondary); flex: 1; }

/* ===== Buttons ===== */
.btn, .btn-icon, .btn-text {
  cursor: pointer; border: none; outline: none;
  transition: all var(--transition);
  font-family: inherit;
}
.btn {
  padding: 8px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  background: var(--bg-input);
  color: var(--text);
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-icon {
  font-size: 1.2rem;
  background: none;
  padding: 4px 8px;
  border-radius: 6px;
}
.btn-icon:hover { background: var(--bg-input); }
.btn-text {
  background: none;
  color: var(--primary);
  font-size: 0.85rem;
  padding: 4px 8px;
}
.btn-text:hover { opacity: 0.8; }

/* ===== Lobby ===== */
.nickname-section {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.nickname-section input { flex: 1; }

input[type="text"], textarea {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border var(--transition);
}
input[type="text"]:focus, textarea:focus {
  border-color: var(--primary);
}

.room-list-section {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-header h2, .section-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.room-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.empty-hint {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 30px 0;
}

.room-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}
.room-card:hover { border-color: var(--primary); }
.room-card .room-name { font-weight: 600; font-size: 0.95rem; }
.room-card .room-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.room-card .room-meta .count { color: var(--online); font-weight: 600; }

.action-section {
  padding: 16px 20px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ===== Footer ===== */
.footer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.dot.connected { background: var(--online); }
.dot.disconnected { background: var(--offline); }
.sep { color: var(--border); }

/* ===== Room View ===== */
.room-header { gap: 8px; }
.room-info { flex: 1; }
.room-info h2 { font-size: 1.1rem; }
.room-info span { font-size: 0.75rem; color: var(--text-secondary); }

.room-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Chat area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.message {
  max-width: 75%;
  padding: 8px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.message.self {
  align-self: flex-end;
  background: var(--msg-self);
  color: var(--msg-self-text);
  border-bottom-right-radius: 4px;
}
.message.other {
  align-self: flex-start;
  background: var(--msg-other);
  color: var(--msg-other-text);
  border-bottom-left-radius: 4px;
}
.message.system {
  align-self: center;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.75rem;
  max-width: 90%;
}
.message .msg-sender {
  font-size: 0.7rem;
  font-weight: 600;
  margin-bottom: 2px;
  opacity: 0.8;
}
.message.self .msg-sender { color: rgba(255,255,255,0.8); }
.message .msg-time {
  font-size: 0.65rem;
  opacity: 0.5;
  margin-top: 2px;
  text-align: right;
}
.message.failed {
  border: 1px solid var(--offline);
}
.message.failed::after {
  content: " ⚠️";
  font-size: 0.7rem;
  color: var(--offline);
}

/* Input area */
.input-area {
  padding: 10px 16px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.input-area textarea {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 120px;
}
.input-actions { display: flex; gap: 6px; }

/* Sidebar */
.sidebar {
  width: 200px;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
  flex-shrink: 0;
  transition: width 0.2s ease, padding 0.2s ease, border 0.2s ease;
}
.sidebar.hidden {
  width: 0;
  padding: 0;
  border-left: none;
  overflow: hidden;
}
.member-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}
.member-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
}
.member-item .role-icon { font-size: 0.9rem; }
.member-item .member-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.member-item .is-you { color: var(--primary); font-size: 0.65rem; font-weight: 600; }
.member-item.speaking { background: var(--bg-input); }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .sidebar { display: none; }
  .slogan { display: none; }
  .message { max-width: 90%; }
}

/* ===== Custom Alert Modal ===== */
.alert-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}
.alert-overlay.hidden { display: none; }

.alert-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  min-width: 280px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  text-align: center;
  animation: slideUp 0.2s ease;
}

.alert-box p {
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 20px;
  color: var(--text);
}

.alert-box .btn { min-width: 80px; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
