:root {
  --bg-darkest: #18191c;
  --bg-sidebar: #1e1f22;
  --bg-chat: #2b2d31;
  --bg-input: #1a1b1e;
  --bg-elevated: #35373c;
  --bg-hover: #3f4249;
  --border-subtle: #3f4147;
  --text-primary: #f2f3f5;
  --text-muted: #949ba4;
  --accent-blue: #5865f2;
  --accent-green: #23a55a;
  --accent-red: #da373c;
  --ease-out-back: cubic-bezier(0.34, 1.45, 0.64, 1);
  --ease-smooth: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-darkest);
  color: var(--text-primary);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }

button, .panel-hdr, .section-hdr, .channel-row, .voice-peer-row, .member-row, .user-row, .sidebar-footer {
  user-select: none;
  -webkit-user-select: none;
}

/* AUTH */
.auth-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg-darkest);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 24px;
  animation: popIn 0.18s var(--ease-out-back);
}

.auth-logo { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.auth-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.tab-btn {
  padding: 9px;
  border: none;
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
  font-weight: 600;
  transition: background 0.14s var(--ease-smooth);
}
.tab-btn.active { background: var(--accent-blue); color: #fff; }

.field-label {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  margin: 10px 0 4px;
}

.field-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}
.field-input:focus { border-color: var(--accent-blue); }

.btn {
  padding: 10px 14px;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.12s var(--ease-out-back), filter 0.14s var(--ease-smooth);
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent-blue); color: #fff; }
.btn.secondary { background: var(--bg-elevated); color: var(--text-primary); }
.btn.secondary.active-red { background: var(--accent-red); color: #fff; }
.btn.danger { background: var(--accent-red); color: #fff; }
.btn.full { width: 100%; margin-top: 16px; }

.banner.error {
  background: #441c1e;
  border: 1px solid var(--accent-red);
  color: #ffbebe;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.banner.margin { margin: 8px 14px 0; }

/* APP SHELL */
.app-shell {
  height: 100%;
  display: grid;
  grid-template-columns: 256px 1fr 220px;
  position: relative;
}

.sidebar {
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  border-right: 1px solid var(--bg-darkest);
}
.right-sidebar {
  border-right: none;
  border-left: 1px solid var(--bg-darkest);
}

.panel-hdr {
  height: 48px;
  min-height: 48px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--bg-darkest);
}
.panel-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ws-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
}
.ws-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-red); }
.ws-pill.online { color: var(--accent-green); }
.ws-pill.online .dot { background: var(--accent-green); }
.ws-pill.offline { color: var(--accent-red); }

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
}

.section-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px 4px;
}
.section-hdr.spaced { margin-top: 14px; }

.mini-icon-btn {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: none;
  border-radius: 4px;
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-weight: 700;
}

.channel-list { display: flex; flex-direction: column; gap: 2px; }

.channel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 9px;
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s var(--ease-smooth), color 0.12s var(--ease-smooth);
}
.channel-row:hover { background: var(--bg-hover); color: var(--text-primary); }
.channel-row.selected { background: var(--bg-elevated); color: var(--text-primary); font-weight: 600; }

.channel-row-left {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  overflow: hidden;
}
.channel-row-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-row-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.badge {
  background: var(--accent-red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 99px;
  padding: 1px 6px;
}
.badge.danger { background: var(--accent-red); }

.del-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  padding: 0 4px;
  font-size: 14px;
}
.del-btn:hover { color: var(--accent-red); }

.voice-peer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-left: 16px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.12s var(--ease-smooth);
}
.voice-peer-row:hover { background: var(--bg-hover); }
.voice-peer-left { display: flex; align-items: center; gap: 7px; min-width: 0; }
.voice-peer-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voice-peer-name.speaking { color: var(--accent-green); font-weight: 600; }
.voice-peer-flags { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.voice-peer-flags.srv-muted { color: var(--accent-red); font-weight: 600; }

.avatar {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar.sm { width: 26px; height: 26px; font-size: 13px; }
.avatar.xs { width: 20px; height: 20px; font-size: 11px; }
.avatar.md { width: 34px; height: 34px; font-size: 16px; }
.avatar.speaking { box-shadow: 0 0 0 2px var(--accent-green); }

/* FOOTER */
.sidebar-footer {
  background: var(--bg-darkest);
  padding: 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.voice-box {
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.voice-status-row { display: flex; align-items: center; justify-content: space-between; }
.voice-status-title { color: var(--accent-green); font-size: 12px; font-weight: 700; }
.voice-status-sub { color: var(--text-muted); font-size: 12px; }
.voice-media-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.user-row { display: flex; align-items: center; gap: 8px; }
.user-meta { flex: 1; min-width: 0; }
.user-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-sub { color: var(--text-muted); font-size: 11px; }
.user-sub.danger { color: var(--accent-red); }

.controls-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  min-width: 34px;
  padding: 0 8px;
  border: none;
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
  transition: transform 0.12s var(--ease-out-back), background 0.14s var(--ease-smooth);
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--bg-hover); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn.wide { width: 100%; }
.icon-btn.danger { background: var(--accent-red); color: #fff; }
.icon-btn.active-green { background: var(--accent-green); color: #fff; }

.small-btn {
  padding: 4px 9px;
  border: none;
  border-radius: 5px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 12px;
  cursor: pointer;
}
.small-btn:hover { background: var(--bg-hover); }

/* CENTER WORKSPACE */
.center-pane {
  background: var(--bg-chat);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.center-hdr {
  height: 48px;
  min-height: 48px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--bg-darkest);
}
.hdr-left, .hdr-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.muted-small { color: var(--text-muted); font-size: 12px; }

.mobile-nav-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
}
.mobile-nav-btn svg { width: 18px; height: 18px; }

.video-stage {
  background: #111214;
  border-bottom: 1px solid var(--bg-darkest);
  padding: 10px;
  max-height: 44vh;
  overflow-y: auto;
}
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.video-tile {
  position: relative;
  background: #0b0c0e;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}
.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.video-tile-label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: rgba(14, 15, 18, 0.78);
  color: #fff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
}
.video-tile-fs {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: rgba(14, 15, 18, 0.8);
  color: #fff;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  font-size: 11px;
  padding: 3px 7px;
  cursor: pointer;
}

.messages-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  min-height: 0;
}
.load-older-wrap { margin-bottom: 10px; }
.messages-list { display: flex; flex-direction: column; gap: 3px; }

.msg-group-start {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}
.msg-group-start:first-child { margin-top: 0; }
.msg-grouped {
  padding-left: 46px;
}
.msg-col { flex: 1; min-width: 0; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-author { font-weight: 700; color: var(--text-primary); }
.msg-time { font-size: 11px; color: var(--text-muted); }

.msg-body-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 6px;
  margin: 0 -6px;
  border-radius: 4px;
}
.msg-body-row:hover { background: rgba(255, 255, 255, 0.03); }
.msg-text-wrap {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  min-width: 0;
  line-height: 1.4;
  word-break: break-word;
  user-select: text;
  -webkit-user-select: text;
}
.msg-edited-icon {
  display: inline-flex;
  color: var(--text-muted);
  opacity: 0.85;
}
.msg-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  flex-shrink: 0;
  transition: opacity 0.12s var(--ease-smooth);
}
.msg-body-row:hover .msg-actions,
.msg-body-row:focus-within .msg-actions { opacity: 1; }
.msg-act-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 22px;
  border: none;
  border-radius: 4px;
  background: var(--bg-sidebar);
  color: var(--text-muted);
  cursor: pointer;
}
.msg-act-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.msg-act-btn.del:hover { color: var(--accent-red); }
.msg-act-btn svg { width: 13px; height: 13px; }

.msg-edit-form { display: flex; gap: 6px; width: 100%; margin: 2px 0; }
.msg-edit-input {
  flex: 1;
  padding: 6px 9px;
  border-radius: 5px;
  border: 1px solid var(--accent-blue);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
}

.msg-att-img {
  max-width: min(380px, 100%);
  max-height: 260px;
  border-radius: 6px;
  margin-top: 4px;
  cursor: zoom-in;
  display: block;
}
.msg-att-file {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 6px 10px;
  margin-top: 4px;
  font-size: 13px;
}

/* COMPOSER */
.composer-wrap {
  padding: 8px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg-chat);
  border-top: 1px solid var(--bg-darkest);
}
.pending-upload {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  border-radius: 5px;
  padding: 5px 10px;
  margin-bottom: 6px;
  font-size: 13px;
}
.composer-row { display: flex; align-items: center; gap: 8px; }
.composer-input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}
.composer-input:focus { border-color: var(--accent-blue); }
.send-btn { height: 38px; padding: 0 16px; }

/* MEMBERS */
.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 7px;
  border-radius: 5px;
  cursor: pointer;
}
.member-row:hover { background: var(--bg-hover); }
.member-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.member-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-name.offline { color: var(--text-muted); }
.admin-tag { color: var(--accent-blue); font-size: 10px; font-weight: 700; }

/* MODALS */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}
.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 18px;
  animation: popIn 0.16s var(--ease-out-back);
}
.modal-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 14px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.user-modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.slider-row { display: flex; align-items: center; justify-content: space-between; }
.range-input { width: 100%; margin: 6px 0 12px; accent-color: var(--accent-blue); }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.admin-box { border-top: 1px solid var(--border-subtle); margin-top: 14px; padding-top: 10px; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.invite-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.invite-code {
  flex: 1;
  background: var(--bg-input);
  padding: 7px 10px;
  border-radius: 5px;
  font-size: 14px;
  letter-spacing: 1px;
}
.note-box { margin-top: 14px; line-height: 1.4; }
.lightbox-img { max-width: 94vw; max-height: 90vh; border-radius: 8px; }

@keyframes popIn {
  from { opacity: 0; transform: scale(0.94) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* MOBILE DRAWER LAYOUT */
@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .mobile-nav-btn { display: inline-flex; }
  .hide-mobile { display: none; }
  .msg-actions { opacity: 1; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    width: min(290px, 84vw);
    z-index: 50;
    transition: transform 0.2s var(--ease-smooth);
  }
  .left-sidebar {
    left: 0;
    transform: translateX(-105%);
  }
  .left-sidebar.open { transform: translateX(0); }

  .right-sidebar {
    right: 0;
    transform: translateX(105%);
  }
  .right-sidebar.open { transform: translateX(0); }

  .mobile-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 45;
  }

  .icon-btn { height: 40px; min-width: 40px; }
}
