:root {
  --bg: #1e1f24;
  --bg-side: #16171b;
  --bg-panel: #111216;
  --bg-input: #2a2c33;
  --bg-hover: #2a2c33;
  --bg-active: #33363f;
  --text: #e6e7ea;
  --muted: #8e9199;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --speak: #3ba55d;
  --danger: #ed4245;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }

/* ---- login ---- */
.login-screen { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.login-screen form { display: grid; gap: 14px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--bg-active); }
.card {
  width: min(380px, 100%);
  background: var(--bg-side);
  padding: 28px;
  border-radius: 12px;
  display: grid;
  gap: 14px;
}
.card h1 { margin: 0; font-size: 22px; }
.card p { margin: 0; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, select {
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 12px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
input[type="range"] { padding: 0; accent-color: var(--accent); }
label.check { display: flex; align-items: flex-start; gap: 10px; color: var(--text); font-size: 14px; }
label.check input { margin: 3px 0 0; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
label.check .small { color: var(--muted); }
button { cursor: pointer; }
.primary {
  background: var(--accent);
  border: 0;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-weight: 600;
  color: #fff;
}
.primary:hover { background: var(--accent-hover); }
.primary:disabled { opacity: .6; cursor: default; }
.secondary {
  background: var(--bg-active);
  border: 0;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-weight: 600;
}
.secondary:hover { background: #3d4049; }
.secondary:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--muted); font-size: 13px; text-decoration: underline; }
.link:hover { color: var(--text); }
.danger, .link.danger { color: var(--danger); }
.icon:disabled { opacity: .5; cursor: not-allowed; }
input:disabled { opacity: .6; }
.badge { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border: 1px solid var(--bg-active); border-radius: 4px; padding: 0 4px; }
.banner { display: flex; align-items: center; gap: 12px; margin: 12px 16px 0; padding: 10px 12px; background: var(--bg-active); border-radius: var(--radius); font-size: 14px; }
.banner span { flex: 1; }
.banner .primary { padding: 6px 12px; white-space: nowrap; }

/* ---- app layout ---- */
#app { display: flex; height: 100%; }
#sidebar {
  width: 260px;
  flex: none;
  background: var(--bg-side);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#serverName { padding: 16px; font-weight: 700; border-bottom: 1px solid #0006; }
#channels { flex: 1; overflow-y: auto; padding: 10px 8px; }

.channel-name {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 7px 8px;
  color: var(--muted);
  text-align: left;
}
.channel-name svg { width: 18px; height: 18px; flex: none; }
.channel-name:hover { background: var(--bg-hover); color: var(--text); }
.channel.active .channel-name { background: var(--bg-active); color: var(--text); }
.channel ul { list-style: none; margin: 2px 0 8px; padding: 0 0 0 28px; }
.channel li { display: flex; align-items: center; gap: 8px; padding: 3px 4px; font-size: 14px; }
.uname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

.avatar {
  --h: 230;
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: hsl(var(--h) 45% 45%);
  box-shadow: 0 0 0 2px transparent;
  transition: box-shadow .08s;
}
.speaking .avatar, .avatar.speaking { box-shadow: 0 0 0 2px var(--speak); }
#meAvatar { width: 32px; height: 32px; font-size: 14px; }

.status-icon, .icon { position: relative; display: inline-grid; place-items: center; }
.status-icon { width: 16px; height: 16px; color: var(--danger); }
.status-icon svg { grid-area: 1 / 1; width: 16px; height: 16px; }

/* ---- me panel ---- */
#mePanel { background: var(--bg-panel); padding: 8px; display: grid; gap: 8px; }
.me-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.me-info { display: flex; align-items: center; gap: 8px; min-width: 0; }
.me-info > div { min-width: 0; }
#meName { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#connState.bad { color: var(--danger); }
.controls { display: flex; gap: 2px; }
.icon {
  width: 34px;
  height: 34px;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
}
.icon:hover { background: var(--bg-hover); color: var(--text); }
.icon svg { grid-area: 1 / 1; width: 20px; height: 20px; }
.slash { display: none; }
.icon.off, .status-icon { color: var(--danger); }
.icon.off .slash, .status-icon .slash { display: block; }

#pttBtn {
  border: 0;
  border-radius: var(--radius);
  padding: 12px;
  background: var(--bg-active);
  font-weight: 600;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#pttBtn.down { background: var(--speak); color: #fff; }

/* ---- chat ---- */
main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#channelTitle { padding: 16px; font-weight: 700; border-bottom: 1px solid #0006; min-height: 55px; }
#messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.msg .who { --h: 230; font-weight: 600; color: hsl(var(--h) 70% 70%); margin-right: 8px; }
.msg time { color: var(--muted); font-size: 12px; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
#chatForm { padding: 0 16px 16px; }
#chatInput { width: 100%; }

/* ---- settings ---- */
dialog {
  background: var(--bg-side);
  color: var(--text);
  border: 0;
  border-radius: 12px;
  padding: 0;
  width: min(420px, calc(100% - 32px));
}
dialog::backdrop { background: #000a; }
.settings { padding: 24px; display: grid; gap: 16px; }
.settings h2 { margin: 0; font-size: 18px; }
.settings p { margin: 0; }
.settings h3 { margin: 0 0 4px; font-size: 14px; }
.tab-panel { display: grid; gap: 16px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--bg-active); }
.tabs button {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 8px 10px;
  color: var(--muted);
  font-weight: 600;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 6px; }
.list > li { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--bg-input); border-radius: 6px; padding: 8px 10px; }
.list > li.muted { background: none; padding: 0; }
.members { max-height: 50vh; overflow-y: auto; }
.members > li { display: grid; gap: 6px; justify-content: stretch; }
.member-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.perms { display: flex; flex-wrap: wrap; gap: 4px 14px; }
label.check.inline { align-items: center; gap: 6px; font-size: 13px; }
label.check.inline input { margin: 0; }
.member-actions { display: flex; gap: 14px; }
.member-actions:empty { display: none; }
.add-member { display: flex; gap: 8px; }
.add-member input { flex: 1; min-width: 0; }
.row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
#pttBind { background: var(--bg-input); border: 0; border-radius: 6px; padding: 6px 14px; min-width: 80px; }
.meter { position: relative; height: 8px; background: var(--bg-input); border-radius: 4px; overflow: hidden; }
#meterFill { height: 100%; width: 0; background: var(--muted); }
#meterFill.hot { background: var(--speak); }
#meterMark { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); }

/* ---- phone ---- */
@media (max-width: 700px) {
  #app { flex-direction: column; }
  #sidebar { width: auto; max-height: 55%; }
  #channels { padding: 6px 8px; }
  #channelTitle { padding: 12px 16px; min-height: 0; }
}
