/* ===================================================== casca do aplicativo */
#root { display: contents; }

.app {
  height: 100%;
  display: grid;
  grid-template-columns: var(--rail-w) var(--sidebar-w) minmax(0, 1fr) auto;
  background: var(--bg-void);
  position: relative;
  animation: fade-in .3s var(--ease);
}

/* ------------------------------------------------------------------ rail */
.rail {
  grid-column: 1;
  background: var(--bg-rail);
  display: flex; flex-direction: column; align-items: center;
  padding: 12px 0 10px;
  gap: 10px;
  border-right: 1px solid var(--line);
}
.rail-badge {
  width: 48px; height: 48px; border-radius: var(--r-lg);
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 45%, var(--purple)));
  color: var(--accent-ink); font-weight: 800; font-size: 19px; letter-spacing: -.03em;
  box-shadow: 0 10px 26px -12px var(--accent);
  overflow: hidden; position: relative; flex: none;
  transition: border-radius var(--med), transform var(--med);
}
.rail-badge:hover { border-radius: var(--r-md); transform: translateY(-1px); }
.rail-badge img { width: 100%; height: 100%; object-fit: cover; }
.rail-sep { width: 28px; height: 2px; border-radius: 2px; background: var(--line-strong); flex: none; }
.rail-spacer { flex: 1 1 auto; }
.rail .icon-btn { width: 44px; height: 44px; border-radius: var(--r-md); }

/* --------------------------------------------------------------- sidebar */
.sidebar {
  grid-column: 2;
  background: var(--bg-sidebar);
  display: flex; flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
}
.sidebar-head {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  position: relative; z-index: 2;
}
.sidebar-head h1 { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.sidebar-body { flex: 1 1 auto; min-height: 0; padding: 10px 8px 12px; }

.cat { margin-top: 14px; }
.cat:first-child { margin-top: 2px; }
.cat-head {
  display: flex; align-items: center; gap: 4px;
  padding: 2px 6px 4px; width: 100%;
  color: var(--text-faint);
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  transition: color var(--fast);
}
.cat-head:hover { color: var(--text-soft); }
.cat-head .caret { width: 12px; height: 12px; transition: transform var(--med); }
.cat[data-collapsed="true"] .cat-head .caret { transform: rotate(-90deg); }
.cat[data-collapsed="true"] .chan:not(.active):not(.has-voice) { display: none; }
.cat-head .add { margin-left: auto; opacity: 0; transition: opacity var(--fast); }
.cat:hover .cat-head .add { opacity: 1; }

.chan {
  display: flex; align-items: center; gap: 7px;
  width: 100%; padding: 7px 8px; margin-bottom: 1px;
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: 14.5px; font-weight: 500;
  transition: background var(--fast), color var(--fast);
  position: relative; text-align: left;
}
.chan:hover { background: var(--bg-hover); color: var(--text-soft); }
.chan.active { background: var(--bg-active); color: var(--text); font-weight: 600; }
.chan.active::before {
  content: ""; position: absolute; left: -8px; top: 50%; translate: 0 -50%;
  width: 4px; height: 20px; border-radius: 0 4px 4px 0; background: var(--accent);
}
.chan .glyph { width: 18px; height: 18px; flex: none; opacity: .8; }
.chan .name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan .count { font-size: 11px; font-weight: 700; color: var(--text-faint); }
.chan .unread {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.chan .tools { display: flex; gap: 2px; opacity: 0; transition: opacity var(--fast); }
.chan:hover .tools { opacity: 1; }
.chan .tools .icon-btn { width: 22px; height: 22px; border-radius: var(--r-sm); }
.chan .tools .icon-btn svg { width: 14px; height: 14px; }

/* Lista de quem está numa sala de voz */
.voice-members { padding: 2px 0 6px 22px; display: flex; flex-direction: column; gap: 1px; }
.voice-member {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: var(--r-sm);
  font-size: 13.5px; color: var(--text-muted);
  transition: background var(--fast);
  width: 100%; text-align: left;
}
.voice-member:hover { background: var(--bg-hover); }
.voice-member .avatar { --size: 22px; }
.voice-member.speaking .avatar { box-shadow: 0 0 0 2px var(--green); }
.voice-member .name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-member .flags { display: flex; gap: 3px; color: var(--text-faint); }
.voice-member .flags svg { width: 14px; height: 14px; }
.voice-member .flags .on { color: var(--accent-text); }
.voice-member .flags .off { color: var(--red); }

/* ---------------------------------------------------- painéis de rodapé */
.sidebar-foot { flex: none; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg-void) 45%, var(--bg-sidebar)); }

.voice-status {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--line);
  animation: slide-up .22s var(--ease);
}
.voice-status .top { display: flex; align-items: center; gap: 8px; }
.voice-status .state { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.voice-status .state strong { font-size: 13px; color: var(--green); display: flex; align-items: center; gap: 6px; }
.voice-status .state strong .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); animation: pulse-ring 2s infinite; }
.voice-status .state span { font-size: 12px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-status[data-quality="poor"] .state strong { color: var(--yellow); }
.voice-status[data-quality="poor"] .state strong .dot { background: var(--yellow); }
.voice-status .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 9px; }

.user-panel { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 10px; }
.user-panel .who { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; text-align: left; padding: 2px 4px; border-radius: var(--r-sm); transition: background var(--fast); }
.user-panel .who:hover { background: var(--bg-hover); }
.user-panel .who b { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-panel .who span { font-size: 11.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-panel .icon-btn { width: 30px; height: 30px; }
.user-panel .icon-btn svg { width: 17px; height: 17px; }
.user-panel .icon-btn.on { color: var(--red); background: color-mix(in srgb, var(--red) 14%, transparent); }

/* ------------------------------------------------------------------ main */
.main { grid-column: 3; display: flex; flex-direction: column; min-width: 0; background: var(--bg-main); }
.main-head {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-main) 82%, transparent);
  backdrop-filter: blur(12px);
  position: relative; z-index: 3;
}
.main-head .glyph { width: 20px; height: 20px; color: var(--text-faint); flex: none; }
.main-head .title { font-size: 15px; font-weight: 700; }
.main-head .topic {
  color: var(--text-faint); font-size: 13px; padding-left: 12px; margin-left: 4px;
  border-left: 1px solid var(--line-strong);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.main-head .spacer { flex: 1 1 auto; }

/* --------------------------------------------------------------- membros */
.members {
  grid-column: 4;
  width: var(--members-w);
  background: var(--bg-sidebar);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
  transition: width var(--med), opacity var(--med);
}
.members[hidden] { display: none; }
.members-body { flex: 1 1 auto; min-height: 0; padding: 12px 8px; }
.members .eyebrow { padding: 12px 10px 6px; }
.members .eyebrow:first-child { padding-top: 0; }
.member {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 6px 8px; border-radius: var(--r-md);
  transition: background var(--fast); text-align: left;
}
.member:hover { background: var(--bg-hover); }
.member[data-offline="true"] { opacity: .42; }
.member .avatar { --size: 30px; --dot-ring: var(--bg-sidebar); }
.member .info { min-width: 0; flex: 1 1 auto; }
.member .info b { display: block; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .info small { display: block; font-size: 11.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .owner-mark { color: var(--yellow); width: 13px; height: 13px; flex: none; }

/* --------------------------------------------------------------- estados */
.empty {
  flex: 1 1 auto; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: var(--text-faint); text-align: center; padding: 40px;
}
.empty .art {
  width: 72px; height: 72px; border-radius: var(--r-xl);
  display: grid; place-items: center;
  background: var(--bg-raised); border: 1px solid var(--line); color: var(--text-muted);
}
.empty .art svg { width: 32px; height: 32px; }
.empty h3 { font-size: 17px; color: var(--text-soft); font-weight: 700; }
.empty p { max-width: 380px; font-size: 14px; line-height: 1.6; }

/* ---------------------------------------------------------------- toasts */
.toasts {
  position: fixed; right: 18px; bottom: 18px; z-index: 300;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  min-width: 240px; max-width: 380px;
  padding: 11px 14px;
  border-radius: var(--r-md);
  background: var(--bg-raised); border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  animation: slide-up .26s var(--ease);
}
.toast.leaving { animation: fade-in .18s var(--ease) reverse forwards; }
.toast .bar { width: 3px; align-self: stretch; border-radius: 3px; background: var(--accent); flex: none; }
.toast[data-kind="error"] .bar { background: var(--red); }
.toast[data-kind="success"] .bar { background: var(--green); }
.toast[data-kind="warn"] .bar { background: var(--yellow); }
.toast .toast-text { flex: 1 1 auto; min-width: 0; line-height: 1.4; }
.toast button { color: var(--text-faint); }
.toast button:hover { color: var(--text); }

/* -------------------------------------------------------------- conexão */
.link-banner {
  position: fixed; top: 12px; left: 50%; translate: -50% 0; z-index: 320;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; border-radius: var(--r-pill);
  background: var(--bg-raised); border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg); font-size: 13.5px; font-weight: 600;
  animation: slide-up .24s var(--ease);
}
.link-banner[data-state="offline"] { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.link-banner[data-state="connecting"] { color: var(--yellow); }

/* ------------------------------------------------------------ responsivo */
.mobile-only { display: none; }

@media (max-width: 1240px) {
  :root { --members-w: 200px; --sidebar-w: 224px; }
}
@media (max-width: 1020px) {
  /* Espaço curto: a lista de membros vira sobreposição em vez de comer o chat. */
  /* grid-column: 1 / -1 faz o bloco de contenção do absoluto ser a área
     inteira da grade — sem isso o "right: 0" seria relativo à coluna 4. */
  .members {
    position: absolute; grid-column: 1 / -1;
    right: 0; top: 0; bottom: 0; left: auto;
    z-index: 40; width: 232px; box-shadow: var(--shadow-lg);
  }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail, .sidebar {
    position: absolute; grid-column: 1 / -1;
    top: 0; bottom: 0; z-index: 50; transition: transform var(--med);
  }
  .rail { left: 0; right: auto; width: var(--rail-w); transform: translateX(calc(-1 * (var(--rail-w) + var(--sidebar-w)))); }
  .sidebar { left: var(--rail-w); right: auto; width: var(--sidebar-w); transform: translateX(calc(-1 * (var(--rail-w) + var(--sidebar-w)))); }
  .app[data-drawer="true"] .rail, .app[data-drawer="true"] .sidebar { transform: none; }
  .app[data-drawer="true"]::after {
    content: ""; position: absolute; inset: 0; z-index: 45;
    background: rgba(0,0,0,.5); animation: fade-in .2s var(--ease);
  }
  .main { grid-column: 1; }
  .mobile-only { display: inline-flex; }
  .members { width: min(280px, 82vw); }
}
