:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2e38;
  --text: #e8e9ec;
  --muted: #9096a3;
  --accent: #5b8def;
  --danger: #e5586a;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --border: #e1e3e8;
    --text: #1b1e24;
    --muted: #5c6270;
    --accent: #3b6fd6;
    --danger: #c9364a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}

.card h1 {
  margin: 0 0 1.25rem;
  font-size: 1.25rem;
}

select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
}

input[type="password"], input[type="text"] {
  width: 100%;
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background-color 0.12s, border-color 0.12s, opacity 0.12s, transform 0.08s;
}

button:active {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
  width: 100%;
  margin-top: 0.75rem;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg);
}

.btn-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: white;
}

input, select {
  transition: border-color 0.12s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

.empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 1rem;
}

a { color: var(--accent); }

/* Modal (admin panel) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
  animation: backdrop-in 0.15s ease-out;
}

@keyframes backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  animation: modal-in 0.16s ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h1 {
  margin: 0;
  font-size: 1.15rem;
}

.modal-subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
}

.icon-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.modal-body {
  padding: 1.25rem 1.5rem 1.5rem;
  overflow-y: auto;
}

.modal-section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin: 1.25rem 0 0.6rem;
}

.add-user-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.admin-users-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}

.user-row .avatar {
  width: 32px;
  height: 32px;
  font-size: 0.85rem;
}

.user-row .user-info {
  flex: 1;
  min-width: 0;
}

.user-row .user-name {
  font-weight: 600;
}

.user-row .user-username {
  color: var(--muted);
  font-size: 0.78rem;
}

.admin-badge {
  background: var(--accent);
  color: white;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.role-select {
  width: auto;
  flex-shrink: 0;
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
}

.admin-toast {
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  background: rgba(63, 202, 107, 0.12);
  color: #3fca6b;
  border: 1px solid rgba(63, 202, 107, 0.3);
  animation: msg-in 0.15s ease-out;
}

.admin-toast.error {
  background: rgba(229, 88, 106, 0.12);
  color: var(--danger);
  border-color: rgba(229, 88, 106, 0.3);
}

.user-row-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.password-row {
  display: flex;
  gap: 0.4rem;
  padding: 0 0.6rem;
}

.password-row input {
  flex: 1;
}

.password-row button {
  width: auto;
  margin-top: 0;
}

/* Discord-like layout */
.discord-app {
  display: flex;
  height: 100vh;
}

.channels-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.channels-sidebar .brand {
  font-size: 1.05rem;
  font-weight: 700;
}

.channels-sidebar h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin: 0;
}

.channel-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.channel-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.channel-btn {
  flex: 1;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
  border-radius: 6px;
}

.channel-btn:hover {
  background: var(--bg);
}

.channel-btn.active {
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
}

.channel-delete {
  background: transparent;
  color: var(--muted);
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
}

.channel-delete:hover {
  color: var(--danger);
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.chat-header h1 {
  font-size: 1.1rem;
  margin: 0;
}

.chat-header .meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.chat-row {
  display: flex;
  gap: 0.85rem;
  padding: 0.15rem 0.5rem;
  border-radius: 8px;
  animation: msg-in 0.15s ease-out;
}

.chat-row:hover {
  background: var(--panel);
}

.chat-row.grouped {
  margin-top: 0;
}

.chat-row:not(.grouped) {
  margin-top: 0.85rem;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.avatar {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: white;
}

.avatar-spacer {
  width: 38px;
  flex-shrink: 0;
}

.chat-row-body {
  min-width: 0;
  flex: 1;
}

.chat-row .sender {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.1rem;
}

.chat-row .sender .time {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--muted);
  margin-left: 0.4rem;
}

.text-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.text-row .text {
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
}

.text-row .delete-link {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.75rem;
  text-decoration: underline;
  opacity: 0;
  transition: opacity 0.1s;
}

.chat-row:hover .delete-link {
  opacity: 1;
}

.action-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.3rem 0.5rem;
  margin: 0.4rem 0;
  font-style: italic;
  color: var(--muted);
  font-size: 0.88rem;
  border-radius: 8px;
}

.action-row:hover {
  background: var(--panel);
}

.action-row .delete-link {
  cursor: pointer;
  font-size: 0.75rem;
  text-decoration: underline;
  opacity: 0;
  transition: opacity 0.1s;
}

.action-row:hover .delete-link {
  opacity: 1;
}

.system-message {
  padding: 0.4rem 0.5rem;
  margin: 0.3rem 0;
  font-size: 0.85rem;
  color: var(--muted);
  border-left: 2px solid var(--border);
  padding-left: 0.75rem;
  white-space: pre-line;
}

.chat-input {
  display: flex;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.chat-input input {
  flex: 1;
}

.chat-input button {
  width: auto;
  margin-top: 0;
}

.announce-notice {
  padding: 0.85rem 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.voice-room {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 1.5rem;
}

.voice-participants {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
}

.voice-participant {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.voice-participant .avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.2rem;
  border: 3px solid transparent;
}

.voice-participant .avatar.speaking {
  border-color: #3fca6b;
  box-shadow: 0 0 0 3px rgba(63, 202, 107, 0.25);
}

.voice-participant .avatar.muted::after {
  content: "🔇";
  position: relative;
  top: 18px;
  left: 18px;
  font-size: 0.8rem;
}

.voice-participant .name {
  font-size: 0.85rem;
  color: var(--muted);
}

.voice-controls {
  display: flex;
  gap: 0.75rem;
}

@media (max-width: 640px) {
  .channels-sidebar {
    width: 84px;
    padding: 0.75rem 0.4rem;
  }
  .channels-sidebar .brand,
  .channels-sidebar h2,
  #addChannelForm {
    display: none !important;
  }
  .channel-btn {
    text-align: center;
    font-size: 0.75rem;
    padding: 0.5rem 0.2rem;
  }
  .channel-delete {
    display: none;
  }
  .chat-header {
    padding: 0.75rem 1rem;
  }
  .chat-header .meta {
    display: none;
  }
  .chat-messages {
    padding: 0.75rem;
  }
}
