:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #182033;
  --muted: #667085;
  --line: #d8deea;
  --accent: #2557d6;
  --danger: #b42318;
  --ok: #067647;
  --warn: #b54708;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
  background: var(--card);
  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: 2;
}
.brand { font-weight: 800; color: var(--text); }
nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.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 8px 22px rgba(16, 24, 40, 0.05);
  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: white;
}
textarea { resize: vertical; }
button, .button {
  border: 0;
  background: var(--accent);
  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(0.96); text-decoration: none; }
button.secondary, .button.secondary { background: #e8edff; color: var(--accent); }
button.danger, .danger { background: var(--danger); color: white; }
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: #eef2ff;
  color: #3538cd;
  border: 1px solid #c7d7fe;
  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: white;
}
.flash.success { border-color: #abefc6; color: var(--ok); background: #ecfdf3; }
.flash.warning { border-color: #fedf89; color: var(--warn); background: #fffaeb; }
.flash.danger { border-color: #fecdca; color: var(--danger); background: #fef3f2; }
.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: 1fr auto; }
.messages {
  overflow-y: auto;
  min-height: 420px;
  max-height: 68vh;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  background: #fbfcff;
}
.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; }
.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: #f8faff; border: 1px solid var(--line); border-radius: 10px; }
.file-transfers { display: grid; gap: 0.4rem; }
.file-card { padding: 0.6rem; background: #f8faff; 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%; }
.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: #fbfcff;
}
.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; }
.settings-check { justify-content: start; }
.danger-zone { border-color: #fecdca; }
.peer-list li.presence-typing,
.message-author.presence-typing {
  background: #fff7ed;
  border-color: #fdba74;
  box-shadow: 0 0 0 2px rgba(253, 186, 116, 0.25);
}
.peer-list li.presence-speaking {
  background: #ecfdf3;
  border-color: #86efac;
  box-shadow: 0 0 0 2px rgba(134, 239, 172, 0.25);
}
.message-author.presence-typing {
  border-radius: 999px;
  padding: 0.05rem 0.35rem;
}
.transfer-actions a.button { text-decoration: none; }

@media (max-width: 900px) {
  .grid.two, .grid.three, .chat-layout { grid-template-columns: 1fr; }
  .admin-row { grid-template-columns: 1fr; }
  .composer { grid-template-columns: 1fr; }
}
