:root {
  color-scheme: dark;
  --bg: #070b16;
  --card: #111827;
  --surface: #0f172a;
  --input: #0b1220;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --line: #263247;
  --accent: #60a5fa;
  --accent-strong: #3b82f6;
  --accent-soft: #172554;
  --danger: #ef4444;
  --danger-strong: #dc2626;
  --danger-soft: #3b1116;
  --ok: #22c55e;
  --ok-strong: #16a34a;
  --ok-soft: #12351f;
  --warn: #f59e0b;
  --warn-soft: #3a2606;
  --shadow: rgba(0, 0, 0, 0.42);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #111f3d 0, var(--bg) 34rem);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
  background: rgba(17, 24, 39, 0.96);
  border-bottom: 1px solid var(--line);
  padding: 0.85rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-left { display: flex; gap: 0.7rem; align-items: center; min-width: 0; }
.brand { font-weight: 800; color: var(--text); white-space: nowrap; }
nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.container { width: var(--app-width-percent, 96%); max-width: none; margin: 0 auto; padding: 1.5rem 0; }
.footer { color: var(--muted); text-align: center; padding: 2rem 1rem; font-size: 0.9rem; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.2rem;
  box-shadow: 0 14px 32px var(--shadow);
  margin-bottom: 1rem;
}
.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
.hero { padding: 2rem; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack-form, .compact { display: grid; gap: 0.8rem; }
label { display: grid; gap: 0.35rem; font-weight: 600; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  background: var(--input);
  color: var(--text);
  accent-color: var(--accent);
}
input::placeholder, textarea::placeholder { color: #64748b; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(96, 165, 250, 0.35);
  border-color: var(--accent);
}
textarea { resize: vertical; }
button, .button {
  border: 0;
  background: var(--accent-strong);
  color: white;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button:hover, .button:hover { filter: brightness(1.08); text-decoration: none; }
button.secondary, .button.secondary { background: var(--accent-soft); color: #bfdbfe; }
button.danger, .danger { background: var(--danger-strong); color: white; }
button.audio-connect-status.is-connected { background: var(--ok-strong); color: white; }
button.audio-connect-status.is-disconnected { background: var(--danger-strong); color: white; }
button.audio-connect-status.is-connecting { background: var(--warn); color: #111827; }
button:disabled { opacity: 0.6; cursor: not-allowed; }
.link-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0;
  font-weight: 500;
}
.small-button { padding: 0.45rem 0.65rem; font-size: 0.86rem; }
.inline-form { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; }
.actions { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.badge {
  display: inline-flex;
  background: var(--accent-soft);
  color: #bfdbfe;
  border: 1px solid #1d4ed8;
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  font-size: 0.75rem;
  font-weight: 700;
  vertical-align: middle;
}
.flash-stack { display: grid; gap: 0.5rem; margin-bottom: 1rem; }
.flash {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.flash.success { border-color: #166534; color: #86efac; background: var(--ok-soft); }
.flash.warning { border-color: #92400e; color: #fcd34d; background: var(--warn-soft); }
.flash.danger { border-color: #991b1b; color: #fca5a5; background: var(--danger-soft); }
.channel-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
.channel-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  align-items: center;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.7rem;
}
.channel-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.channel-head { display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.chat-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; }
.chat-card { min-height: 68vh; display: grid; grid-template-rows: auto 1fr auto; }
.messages {
  overflow-y: auto;
  min-height: 420px;
  max-height: 68vh;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  background: var(--surface);
}
.message {
  padding: 0.8rem;
  border-bottom: 1px solid var(--line);
}
.message:last-child { border-bottom: 0; }
.message-meta { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.25rem; }
.message-author { font-weight: 800; }
.message-time { color: var(--muted); font-size: 0.82rem; }
.message-content { white-space: pre-wrap; overflow-wrap: anywhere; }
.message-actions { display: flex; gap: 0.5rem; margin-top: 0.4rem; }
.message-toolbar { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.75rem; }
.message-select { display: none; align-items: center; gap: 0.35rem; font-size: 0.82rem; color: var(--muted); }
.message-select input { width: auto; }
.messages:not(.edit-mode) .message-actions { display: none; }
.messages.edit-mode .message-select { display: inline-flex; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 0.75rem; margin-top: 0.75rem; align-items: end; }
.side-panel { display: grid; gap: 0.75rem; align-content: start; }
.peer-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.peer-list li { padding: 0.45rem 0.6rem; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.file-transfers { display: grid; gap: 0.4rem; }
.file-card { padding: 0.6rem; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow-wrap: anywhere; }
.remote-audio { display: grid; gap: 0.5rem; margin-top: 1rem; }
.remote-audio audio { width: 100%; }
.verification-note { margin-top: 0.75rem; }
.peer-verification-code { margin-top: 0.35rem; }
.peer-verification-code code { font-weight: 800; letter-spacing: 0.04em; }
.admin-list { display: grid; gap: 0.8rem; }
.admin-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.admin-row.management-row,
.admin-row.channel-management-row {
  grid-template-columns: 1fr;
  align-items: stretch;
}
.admin-row.category-row {
  grid-template-columns: minmax(0, 1fr) auto;
}
.management-summary { display: grid; gap: 0.25rem; }
.management-form { display: grid; gap: 0.65rem; align-items: end; }
.management-form.channel-form { grid-template-columns: repeat(3, minmax(0, 1fr)) auto; }
.inline-limits { gap: 0.65rem; }
.inline-edit { display: flex; gap: 0.4rem; align-items: center; }
.password-edit { flex-wrap: wrap; }
.inline-check { display: inline-flex; width: auto; gap: 0.35rem; align-items: center; font-weight: 600; white-space: nowrap; }
.inline-check input { width: auto; }
.file-card progress { width: 100%; margin-top: 0.35rem; }
.transfer-title { font-weight: 800; }
.transfer-details, .transfer-status { margin-top: 0.25rem; }
.transfer-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; margin-top: 0.45rem; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 0.8rem; display: grid; gap: 0.7rem; }
legend { color: var(--muted); font-weight: 700; }

.page-title-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}
.page-title-row h1 { margin-top: 0; }
.compact-channel-head { padding: 0.85rem 1rem; }
.compact-channel-head h1 { margin: 0; font-size: 1.45rem; }
.compact-channel-head p { margin: 0.25rem 0 0; }
.settings-grid .card { margin-bottom: 0; }
.grid.two.admin-settings-grid {
  display: block;
  columns: 2 340px;
  column-gap: 1rem;
}
.admin-settings-grid .card {
  break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 1rem;
}
.settings-check { justify-content: start; }
.danger-zone { border-color: #991b1b; }
.peer-list li.presence-typing,
.message-author.presence-typing {
  background: #2b1d0c;
  border-color: #b45309;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}
.peer-list li.presence-speaking {
  background: var(--ok-soft);
  border-color: #16a34a;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}
.message-author.presence-typing {
  border-radius: 999px;
  padding: 0.05rem 0.35rem;
}
.transfer-actions a.button { text-decoration: none; }

.admin-section-grid .card { margin-bottom: 0; }
.admin-section-card { display: grid; gap: 0.75rem; align-content: start; }
.admin-section-card h2 { margin-bottom: 0; }
.admin-select-form { display: grid; gap: 0.65rem; }
.selected-management-form { margin-top: 0.85rem; }
.admin-detail-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.85rem; }
.peer-list li { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.peer-entry-label { overflow-wrap: anywhere; }
.peer-controls { display: inline-flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; }
.admin-audio-actions { margin-top: 0.75rem; }
.peer-list li.presence-muted { opacity: 0.82; }

.category-card-stack { display: grid; gap: 1rem; }
.channel-category-title h2 { margin-bottom: 0.2rem; }
.category-card { display: grid; gap: 0.85rem; }
.category-card-head { display: flex; justify-content: space-between; align-items: center; gap: 0.7rem; flex-wrap: wrap; }
.category-card-head h2 { margin: 0; }
.category-card .category-channel-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.category-channel-grid h3 { margin-top: 0; }
.bulk-delete-users-form { display: grid; gap: 0.85rem; }
.bulk-user-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.45rem 0.9rem; }
.bulk-user-option { white-space: normal; justify-content: start; }
.category-order-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; align-items: end; }
.category-order-form button { align-self: end; }


.icon-button,
button.icon-button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  line-height: 1;
}
.topbar-icon-link {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 2.25rem;
  height: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.topbar-icon-link:hover { text-decoration: none; filter: brightness(1.08); }
.app-frame {
  width: var(--app-width-percent, 96%);
  max-width: calc(100vw - 1rem);
  margin: 0 auto;
  padding: 1.5rem 0;
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
.app-frame .container { width: 100%; max-width: none; margin: 0; padding: 0; }
.app-sidebar {
  position: sticky;
  top: 4.8rem;
  max-height: calc(100vh - 5.4rem);
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem;
  box-shadow: 0 14px 32px var(--shadow);
}
.app-sidebar-head,
.users-pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
}
.app-channel-nav { display: grid; gap: 0.55rem; }
.sidebar-category {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.72);
  overflow: hidden;
}
.sidebar-category summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.8rem;
  padding: 0.65rem 0.75rem;
  list-style-position: inside;
}
.sidebar-channel {
  display: block;
  color: var(--text);
  padding: 0.45rem 0.75rem;
  border-top: 1px solid rgba(38, 50, 71, 0.7);
  overflow-wrap: anywhere;
}
.sidebar-channel:hover,
.sidebar-channel.active {
  background: var(--accent-soft);
  color: #dbeafe;
  text-decoration: none;
}
.sidebar-home { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.sidebar-empty { color: var(--muted); font-size: 0.85rem; margin: 0; padding: 0.55rem 0.75rem; }
.sidebar-lock { color: var(--muted); font-size: 0.72rem; }
.sidebar-dm-form { display: grid; gap: 0.45rem; padding: 0.65rem 0.75rem 0.75rem; border-top: 1px solid rgba(38, 50, 71, 0.7); }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
body.app-sidebar-collapsed .app-frame { grid-template-columns: minmax(0, 1fr); }
body.app-sidebar-collapsed .app-sidebar { display: none; }
.channel-page-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
  gap: 1rem;
  align-items: start;
}
body.users-pane-collapsed .channel-page-layout { grid-template-columns: minmax(0, 1fr); }
body.users-pane-collapsed .users-pane { display: none; }
.users-pane { position: sticky; top: 4.8rem; max-height: calc(100vh - 5.4rem); overflow-y: auto; }
.chat-card-head {
  border-bottom: 1px solid var(--line);
  margin: -0.2rem -0.2rem 0.8rem;
  padding: 0 0.2rem 0.8rem;
}
.chat-card-head h1 { margin: 0; font-size: 1.45rem; }
.chat-card-head p { margin: 0.25rem 0 0; }
.voice-card { display: grid; gap: 0.8rem; }
.private-member-list { margin-bottom: 0.75rem; }
.private-invite-form { margin-bottom: 0.75rem; }
.private-leave-form { margin: 0 0 0.85rem; }
.dm-voice-section {
  display: grid;
  gap: 0.7rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0.85rem 0;
  margin: 0.85rem 0;
}
.dm-voice-section h3 { margin: 0.25rem 0 0; }
.toast-stack {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 30;
  display: grid;
  gap: 0.6rem;
  max-width: min(380px, calc(100vw - 2rem));
}
.toast {
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  box-shadow: 0 14px 32px var(--shadow);
  color: var(--text);
  display: grid;
  gap: 0.25rem;
  text-align: left;
  cursor: pointer;
}
.toast:hover { filter: brightness(1.08); }
.toast-title { font-weight: 800; }
.toast-body { color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }
.toast-dismiss,
button.toast-dismiss {
  position: absolute;
  top: 0.35rem;
  right: 0.45rem;
  width: 1.65rem;
  height: 1.65rem;
  padding: 0;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
}
.toast { position: relative; padding-right: 2.4rem; }
.message { position: relative; padding-right: 5rem; }
.messages:not(.edit-mode) .message-actions { display: flex; }
.message-actions {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  display: flex;
  gap: 0.35rem;
  margin-top: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease-in-out;
}
.message-own:hover .message-actions,
.message-own:focus-within .message-actions {
  opacity: 1;
  pointer-events: auto;
}
.message-icon-button,
button.message-icon-button {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 8px;
  font-size: 0.95rem;
}

@media (max-width: 900px) {
  .grid.two, .grid.three, .chat-layout, .channel-page-layout { grid-template-columns: 1fr; }
  .grid.two.admin-settings-grid { columns: 1; }
  .admin-row, .management-form.channel-form, .bulk-user-list, .category-order-form { grid-template-columns: 1fr; }
  .composer { grid-template-columns: 1fr; }
  .app-frame { width: var(--app-width-percent, 96%); grid-template-columns: 1fr; }
  .app-sidebar, .users-pane { position: static; max-height: none; }
}

