* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: rgba(88,101,242,0.3); }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #36393f;
  color: #dcddde;
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

/* === Login === */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #5865f2 0%, #404eed 100%);
  padding: 16px;
}
.login-card {
  background: #36393f;
  padding: 40px;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  width: 420px; max-width: 100%;
  text-align: center;
}
.login-card h1 { color: #fff; margin-bottom: 8px; font-size: 28px; }
.login-card p { color: #b9bbbe; margin-bottom: 20px; }
.login-card input {
  width: 100%; padding: 12px;
  background: #202225; border: 1px solid #202225;
  border-radius: 4px; color: #fff; font-size: 16px; margin-bottom: 16px;
}
.login-card input:focus { outline: none; border-color: #5865f2; }
.login-card button {
  width: 100%; padding: 12px;
  background: #5865f2; color: #fff; border: none;
  border-radius: 4px; font-size: 16px; font-weight: 500; cursor: pointer;
}
.login-card button:hover { background: #4752c4; }

/* === App layout (ДЕСКТОП) === */
.app {
  display: grid;
  grid-template-columns: 72px 240px 1fr 240px;
  height: 100vh;
  position: relative;
}

#mobile-toggle { display: none; }

/* === Серверы === */
.col-servers {
  background: #202225;
  padding: 12px 0;
  display: flex; flex-direction: column; align-items: center;
  gap: 8px;
  overflow-y: auto;
}
.server {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: #36393f;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500; font-size: 15px;
  cursor: pointer;
  transition: border-radius 0.15s, background 0.15s;
  position: relative;
  flex-shrink: 0;
}
.server:hover { border-radius: 16px; }
.server.active { border-radius: 16px; }
.server.active::before {
  content: "";
  position: absolute; left: -16px; top: 12px;
  width: 4px; height: 24px;
  background: #fff; border-radius: 0 4px 4px 0;
}
.server-divider {
  width: 32px; height: 2px;
  background: #2f3136; border-radius: 1px;
  margin: 4px 0; flex-shrink: 0;
}
.add-server {
  background: #36393f; color: #3ba55c;
  font-size: 22px; font-weight: 400;
}
.add-server:hover { background: #3ba55c; color: #fff; border-radius: 16px; }

/* === Каналы === */
.col-channels {
  background: #2f3136;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.server-header {
  padding: 14px 16px;
  border-bottom: 1px solid #202225;
  font-weight: 500; color: #fff; font-size: 15px;
  height: 48px;
  display: flex; align-items: center;
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
}
.channels-scroll { flex: 1; overflow-y: auto; padding: 8px; }
.placeholder-text { padding: 24px 16px; text-align: center; color: #72767d; font-size: 13px; }
.category {
  padding: 18px 8px 4px 8px;
  font-size: 11px; color: #8e9297;
  letter-spacing: 0.5px; text-transform: uppercase;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 500;
}
.category span:last-child { font-size: 18px; cursor: pointer; color: #b9bbbe; padding: 0 4px; }
.category span:last-child:hover { color: #fff; }
.channel {
  padding: 6px 8px;
  border-radius: 4px;
  display: flex; align-items: center; gap: 6px;
  color: #8e9297; cursor: pointer;
  margin-bottom: 2px; font-size: 14px;
}
.channel:hover { background: #393c43; color: #dcddde; }
.channel.active { background: #42464d; color: #fff; }
.channel.active .hash { color: #fff; }
.hash { color: #8e9297; font-size: 18px; line-height: 1; }
.voice-icon { width: 16px; height: 16px; flex-shrink: 0; }
.voice-user {
  padding: 4px 8px 4px 32px;
  font-size: 13px; color: #dcddde;
  display: flex; align-items: center; gap: 6px;
  border-radius: 4px; margin: 1px 0;
}
.voice-user:hover { background: #393c43; }
.voice-user .mini-av {
  width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 10px; font-weight: 500; flex-shrink: 0;
}
.speaking-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; background: #3ba55c;
  margin-left: auto;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.3); }
}

/* === Панель пользователя === */
.user-panel {
  background: #292b2f; padding: 8px;
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid #202225;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500; font-size: 12px;
  flex-shrink: 0; position: relative;
}
.status {
  position: absolute; bottom: -2px; right: -2px;
  width: 12px; height: 12px; border-radius: 50%;
  border: 3px solid #292b2f;
}
.status.online { background: #3ba55c; }
.status.idle { background: #faa61a; }
.status.dnd { background: #ed4245; }
.status.offline { background: #747f8d; }
.user-info { flex: 1; min-width: 0; }
.username { color: #fff; font-weight: 500; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usertag { color: #b9bbbe; font-size: 11px; }
.controls { display: flex; gap: 2px; }
.ctrl-btn {
  width: 32px; height: 32px;
  background: transparent; border: none; border-radius: 4px;
  color: #b9bbbe; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.ctrl-btn:hover { background: #36393f; color: #fff; }
.ctrl-btn.muted { color: #ed4245; }

/* === Основная область === */
.col-main {
  display: flex; flex-direction: column;
  overflow: hidden; background: #36393f; min-width: 0;
}
.placeholder {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: #72767d; text-align: center; padding: 20px;
}
.placeholder h2 { margin-bottom: 8px; color: #dcddde; font-size: 20px; }
.channel-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.channel-header {
  padding: 12px 16px;
  border-bottom: 1px solid #202225;
  display: flex; align-items: center; gap: 12px;
  height: 48px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
  flex-shrink: 0;
}
.channel-type-icon { font-size: 22px; color: #8e9297; }
.channel-header h3 { font-size: 16px; color: #fff; font-weight: 500; }
.channel-header .topic {
  color: #b9bbbe; font-size: 13px;
  padding-left: 12px; border-left: 1px solid #4f545c;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.header-actions { margin-left: auto; display: flex; gap: 8px; }
.btn {
  padding: 6px 12px;
  border-radius: 4px; border: none;
  font-size: 13px; font-weight: 500; cursor: pointer;
  display: flex; align-items: center; gap: 6px; color: #fff;
}
.btn-green { background: #3ba55c; }
.btn-green:hover { background: #2d7d46; }
.btn-red { background: #ed4245; }
.btn-red:hover { background: #c03538; }
.btn-ghost { background: #4f545c; }
.btn-ghost:hover { background: #686d73; }
.btn-ghost.active { background: #5865f2; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === Видео === */
.video-area {
  background: #202225; padding: 12px;
  display: grid; gap: 8px;
  max-height: 45vh; overflow-y: auto; flex-shrink: 0;
}
.video-area:empty { display: none; }
.video-area.count-1 { grid-template-columns: 1fr; }
.video-area.count-2 { grid-template-columns: 1fr 1fr; }
.video-area.count-3 { grid-template-columns: repeat(3, 1fr); }
.video-area.count-many { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.video-area.has-screen { grid-template-columns: 2fr 1fr; grid-auto-rows: minmax(120px, 1fr); }

.tile {
  background: #2f3136; border-radius: 6px;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  aspect-ratio: 16 / 9; min-height: 120px;
}
.tile.screen-tile { aspect-ratio: auto; background: #000; grid-row: span 2; }
.tile video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.screen-tile video { object-fit: contain; }
.tile-avatar {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px; font-weight: 500;
}
.tile-label {
  position: absolute; bottom: 6px; left: 6px;
  background: rgba(0,0,0,0.75); color: #fff;
  padding: 3px 8px; border-radius: 4px; font-size: 11px;
  display: flex; align-items: center; gap: 4px;
}
.tile-label.sharing { background: #5865f2; }
.tile-label .mini-speaking { width: 6px; height: 6px; border-radius: 50%; background: #3ba55c; animation: pulse 1.2s ease-in-out infinite; }
.tile.speaking { box-shadow: inset 0 0 0 2px #3ba55c; }

/* === Чат === */
.chat-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 12px; }
.msg .avatar { width: 40px; height: 40px; font-size: 14px; }
.msg .status { display: none; }
.msg-body { flex: 1; min-width: 0; }
.msg-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 2px; }
.msg-author { color: #fff; font-weight: 500; font-size: 15px; }
.msg-time { color: #72767d; font-size: 11px; }
.msg-text { color: #dcddde; font-size: 14px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; }
.msg-text code { background: #2f3136; padding: 2px 5px; border-radius: 3px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; color: #ededed; }
.system-msg { color: #72767d; font-size: 13px; font-style: italic; text-align: center; padding: 4px 0; }

.chat-input-form {
  margin: 0 16px 16px;
  background: #40444b; border-radius: 8px; padding: 0 14px;
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.plus-btn {
  width: 22px; height: 22px; border-radius: 50%;
  background: #b9bbbe; color: #40444b; border: none;
  font-size: 18px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.chat-input-form input {
  flex: 1; background: transparent; border: none;
  color: #dcddde; font-size: 15px; padding: 12px 0;
}
.chat-input-form input:focus { outline: none; }

/* === Участники === */
.col-members { background: #2f3136; overflow-y: auto; }
.members-section { padding: 16px 8px; }
.members-header { font-size: 11px; color: #8e9297; letter-spacing: 0.5px; padding: 0 8px 6px; font-weight: 500; }
.member {
  padding: 6px 8px; border-radius: 4px;
  display: flex; align-items: center; gap: 8px;
  color: #b9bbbe; cursor: pointer; margin-bottom: 2px; font-size: 14px;
}
.member:hover { background: #393c43; color: #dcddde; }
.member .avatar { width: 24px; height: 24px; font-size: 10px; }
.member .status { width: 9px; height: 9px; border-width: 2px; }
.member-role-admin { color: #faa61a !important; }
.member-role-mod { color: #3ba55c !important; }

/* === Модалки === */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-content {
  background: #36393f; padding: 24px; border-radius: 8px;
  width: 420px; max-width: 90vw;
}
.modal-content h2 { color: #fff; margin-bottom: 16px; font-size: 20px; }
.modal-content input {
  width: 100%; padding: 10px 12px;
  background: #202225; border: 1px solid #202225; border-radius: 4px;
  color: #fff; font-size: 14px; margin-bottom: 16px;
}
.modal-content input:focus { outline: none; border-color: #5865f2; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions button {
  padding: 10px 20px; border: none; border-radius: 4px;
  cursor: pointer; font-size: 14px; font-weight: 500;
  background: #4f545c; color: #fff;
}
.modal-actions button.primary { background: #5865f2; }
.modal-actions button.primary:hover { background: #4752c4; }

.channel-type-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.type-tab {
  flex: 1; padding: 10px;
  background: #2f3136; border: 1px solid #202225; color: #b9bbbe;
  border-radius: 4px; cursor: pointer; font-size: 14px;
}
.type-tab.active { background: #5865f2; color: #fff; border-color: #5865f2; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #202225; color: #fff;
  padding: 12px 20px; border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  z-index: 200; font-size: 14px;
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #202225; border-radius: 4px; }

/* ============================================= */
/* ===== МОБИЛЬНАЯ ВЕРСИЯ (ниже 900px) ========== */
/* ============================================= */
@media (max-width: 900px) {
  .app {
    display: block;
    position: relative;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
  }

  /* Кнопка бургер слева сверху */
  #mobile-toggle {
    display: flex !important;
    position: fixed;
    top: 10px;
    left: 10px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #5865f2;
    color: #fff;
    border: none;
    z-index: 100;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    cursor: pointer;
  }
  .app.menu-open #mobile-toggle {
    left: auto;
    right: 10px;
    background: #2f3136;
  }

  /* Сайдбар: серверы + каналы рядом, выезжают вместе */
  .col-servers,
  .col-channels {
    position: fixed;
    top: 0;
    bottom: 0;
    height: 100vh;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .col-servers { left: 0; width: 72px; }
  .col-channels { left: 72px; width: calc(100vw - 72px); max-width: 280px; }

  .app.menu-open .col-servers,
  .app.menu-open .col-channels {
    transform: translateX(0);
  }

  /* Оверлей */
  .app.menu-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 80;
  }

  /* Участники справа */
  .col-members {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 240px; max-width: 80vw;
    z-index: 90;
    transform: translateX(100%);
    transition: transform 0.25s ease;
  }
  .app.members-open .col-members { transform: translateX(0); }
  .app.members-open::before {
    content: "";
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 80;
  }

  /* Основная область — всегда на весь экран */
  .col-main {
    width: 100vw;
    height: 100vh;
  }

  .placeholder { padding: 60px 20px 20px; }
  .channel-header { padding-left: 60px; }
  .channel-header .topic { display: none; }
  .video-area { max-height: 45vh; }
}

/* === Форма аутентификации === */
.auth-error {
  background: rgba(237, 66, 69, 0.15);
  color: #f87171;
  padding: 10px 12px;
  border-radius: 4px;
  margin-bottom: 12px;
  font-size: 13px;
  border: 1px solid rgba(237, 66, 69, 0.3);
}
.auth-switch {
  margin-top: 16px;
  font-size: 13px;
  color: #b9bbbe;
}
.auth-switch a {
  color: #5865f2;
  text-decoration: none;
  margin-left: 6px;
  font-weight: 500;
  cursor: pointer;
}
.auth-switch a:hover { text-decoration: underline; }

.member.offline { opacity: 0.5; }
