:root {
  --bg-1: #1e1f22;
  --bg-2: #2b2d31;
  --bg-3: #313338;
  --bg-4: #383a40;
  --bg-input: #383a40;
  --text: #dbdee1;
  --text-dim: #949ba4;
  --blurple: #5865f2;
  --blurple-hover: #4752c4;
  --green: #23a55a;
  --green-hover: #1f8b4d;
  --red: #da373c;
  --red-hover: #a12828;
  --mention: #404249;
  --my-msg-bg: #2b5a3a;
  --my-msg-text: #ffffff;
}

:root[data-theme="light"] {
  --bg-1: #f2f3f5;
  --bg-2: #e3e5e8;
  --bg-3: #f7f8fa;
  --bg-4: #dcdee1;
  --bg-input: #e6e7e9;
  --text: #313338;
  --text-dim: #6c6f78;
  --mention: #dbdee1;
  --my-msg-bg: #d9f2e2;
  --my-msg-text: #1d422c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "gg sans", "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-1);
  color: var(--text);
  overflow: hidden;
  font-size: 15px;
}

button { font-family: inherit; }
svg { width: 20px; height: 20px; }

.app { display: flex; height: 100vh; }

/* ---------- Rail de ícones ---------- */
.icons-rail {
  width: 72px;
  background: var(--bg-1);
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.rail-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--bg-3);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-radius .15s, background .15s, color .15s;
}

.rail-btn:hover { border-radius: 16px; background: var(--blurple); color: #fff; }
.rail-btn.active { border-radius: 16px; background: var(--blurple); color: #fff; }
.rail-divider { width: 32px; height: 2px; background: var(--bg-3); border-radius: 1px; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px;
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.server-header {
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
  cursor: default;
  white-space: nowrap;
  overflow: hidden;
}

.server-banner {
  margin: 0 8px 8px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-dim);
  background: var(--bg-3);
  border-radius: 8px;
  user-select: all;
  word-break: break-all;
}

.sidebar-section { padding: 0 8px; }

.section-title {
  padding: 18px 8px 4px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .02em;
  color: var(--text-dim);
}
.section-title.spaced { padding-top: 14px; }

.channel-list { list-style: none; }

.channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  margin: 2px 0;
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  transition: background .1s, color .1s;
}

.channel-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.channel-item:hover { background: var(--bg-3); color: var(--text); }
.channel-item.online { color: var(--text); }

.add-friend { display: flex; gap: 6px; padding: 8px; }
.add-friend input {
  flex: 1;
  min-width: 0;
  background: var(--bg-1);
  border: none;
  outline: none;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
}
.add-friend input::placeholder { color: var(--text-dim); }
.add-friend button {
  border: none;
  background: var(--blurple);
  color: #fff;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}
.add-friend button:hover { background: var(--blurple-hover); }

.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; }
.status-dot.on { background: var(--green); }

.friend-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.friend-actions { display: none; gap: 4px; flex-shrink: 0; }
.channel-item:hover .friend-actions { display: flex; }

.mini-btn {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 6px;
  background: var(--bg-4);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.mini-btn svg { width: 14px; height: 14px; }
.mini-btn:hover { color: var(--text); background: var(--mention); }
.mini-btn.danger:hover { color: #fff; background: var(--red); }

.sidebar-spacer { flex: 1; }

/* ---------- User panel ---------- */
.user-panel {
  height: 52px;
  background: var(--bg-1);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  flex-shrink: 0;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--blurple);
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.avatar.small { width: 24px; height: 24px; font-size: 12px; }
.avatar.big { width: 72px; height: 72px; font-size: 28px; }

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-id { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.user-id:hover { text-decoration: underline; }

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--bg-4); color: var(--text); }

/* ---------- Chat ---------- */
.chat-area { flex: 1; background: var(--bg-3); display: flex; flex-direction: column; min-width: 0; }

.chat-header {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
  flex-shrink: 0;
}

.chat-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; min-width: 0; }
.chat-title svg { width: 18px; height: 18px; color: var(--text-dim); flex-shrink: 0; }
.chat-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.typing {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
  animation: blink 1.2s ease-in-out infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.chat-hint { font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ping-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-2);
  border: 1px solid var(--bg-4);
  border-radius: 12px;
  padding: 3px 10px;
  flex-shrink: 0;
  cursor: default;
  transition: background .2s;
}
.ping-chip::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.ping-chip.great::before, .ping-chip.good::before { background: var(--green); box-shadow: 0 0 6px var(--green); }
.ping-chip.fair::before { background: #f0b232; }
.ping-chip.bad::before { background: #edad3f; }
.ping-chip.worst::before { background: #ed4245; }

.ping-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  margin-left: 2px;
  flex-shrink: 0;
}
.ping-badge .dot-ping {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.ping-badge.great .dot-ping, .ping-badge.good .dot-ping { background: var(--green); }
.ping-badge.fair .dot-ping { background: #f0b232; }
.ping-badge.bad .dot-ping { background: #edad3f; }
.ping-badge.worst .dot-ping { background: #ed4245; }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 4px; }

.system-msg {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 8px 0;
  user-select: none;
}

.msg { display: flex; gap: 10px; padding: 4px 8px; align-items: flex-start; }
.msg-avatar { width: 36px; height: 36px; font-size: 15px; flex-shrink: 0; }
.msg-body { min-width: 0; max-width: min(70%, 520px); }
.msg-bubble {
  background: var(--bg-2);
  border-radius: 8px 8px 8px 2px;
  padding: 8px 12px;
}
.msg-meta { display: flex; align-items: baseline; gap: 8px; }
.msg-author { font-weight: 600; }
.msg-time { font-size: 11px; color: var(--text-dim); }
.msg-text { word-break: break-word; white-space: pre-wrap; }

.my-msg {
  flex-direction: row-reverse;
}
.my-msg .msg-body { display: flex; flex-direction: column; align-items: flex-end; }
.my-msg .msg-bubble {
  background: var(--my-msg-bg);
  color: var(--my-msg-text);
  border-radius: 8px 8px 2px 8px;
}
.my-msg .msg-author { color: var(--blurple); }
.my-msg .msg-meta { flex-direction: row-reverse; }
.my-msg .msg-text { color: inherit; }

.msg-status {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* ---------- Reazioni ---------- */
.msg-body { position: relative; }
.msg-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  min-height: 24px;
}
.my-msg .msg-foot { flex-direction: row-reverse; }

.msg-reactions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.react-chip {
  border: none;
  background: var(--bg-4);
  color: var(--text);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  gap: 4px;
  align-items: center;
  transition: background .12s;
}
.react-chip:hover { background: var(--mention); }
.react-chip.mine { outline: 1px solid var(--blurple); }

.react-btn {
  visibility: hidden;
  opacity: 0;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 8px;
  background: var(--bg-4);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .12s, background .12s;
  flex-shrink: 0;
}
.react-btn svg { width: 15px; height: 15px; }
.msg:hover .react-btn { visibility: visible; opacity: 1; }
.react-btn:hover { background: var(--mention); color: var(--text); }

.emoji-picker {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: 5;
  background: var(--bg-2);
  border: 1px solid var(--bg-4);
  border-radius: 12px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
}
.my-msg .emoji-picker { left: auto; right: 0; }
.emoji-picker button {
  border: none;
  background: transparent;
  font-size: 20px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
}
.emoji-picker button:hover { background: var(--bg-4); }

/* ---------- Composer ---------- */
.composer { padding: 0 16px 24px; display: flex; gap: 8px; align-items: center; }
.composer input {
  flex: 1;
  background: var(--bg-input);
  border: none;
  outline: none;
  color: var(--text);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 15px;
}
.composer input::placeholder { color: var(--text-dim); }

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: none;
  background: var(--blurple);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.btn-send:hover:not(:disabled) { background: var(--blurple-hover); }
.btn-send:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Members ---------- */
.members { width: 240px; background: var(--bg-2); padding: 16px 8px; overflow-y: auto; flex-shrink: 0; }

.members-title { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-dim); padding: 0 8px 8px; }

.member { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px; }
.member:hover { background: var(--bg-3); }
.member-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.me { background: var(--green); }
.dot.online { background: var(--green); }
.dot.offline { background: var(--text-dim); }

.members-empty { color: var(--text-dim); font-size: 13px; padding: 8px; }

/* ---------- Call overlay ---------- */
.call-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.85);
  backdrop-filter: blur(6px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  z-index: 50;
}
.call-overlay.open { display: flex; }

.video-grid { display: flex; gap: 16px; align-items: center; justify-content: center; flex-wrap: wrap; width: min(1100px, 94vw); }

.video-tile {
  position: relative;
  width: min(760px, 100%);
  aspect-ratio: 16/9;
  background: var(--bg-1);
  border-radius: 12px;
  overflow: hidden;
}
.video-tile video { width: 100%; height: 100%; object-fit: cover; }
.video-tile video.hidden { display: none; }

.video-tile.small {
  width: min(240px, 26vw);
  aspect-ratio: 16/10;
  border: 2px solid var(--bg-4);
  align-self: flex-end;
}

#screenTile { display: none; }
#screenTile.open { display: block; }

.ctrl-btn.hidden { display: none; }
.ctrl-btn.cinema-active { background: var(--green); color: #fff; }
.ctrl-btn.cinema-active:hover { background: var(--green-hover); }

.call-overlay.cinema .video-grid { position: fixed; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; max-width: none; background: #000; }
.call-overlay.cinema .video-tile:not(.small) { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 0; background: #000; }
.call-overlay.cinema .video-tile:not(.small) video { object-fit: cover; }
.call-overlay.cinema .video-tile.small { position: fixed; left: 16px; bottom: 92px; width: 200px; z-index: 2; border: none; box-shadow: 0 2px 14px rgba(0,0,0,.6); border-radius: 8px; transition: opacity .25s ease, transform .25s ease; }
.call-overlay.cinema #remoteTile.small { left: calc(16px + 210px); }
.call-overlay.cinema .call-controls { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 3; transition: opacity .25s ease, transform .25s ease; }
.call-overlay.cinema.hide-ui { cursor: none; }
.call-overlay.cinema.sharing-fs .video-tile.small { display: none; }
.call-overlay.cinema.hide-ui .video-tile.small,
.call-overlay.cinema.hide-ui .call-controls { opacity: 0; pointer-events: none; transform: translateY(14px); }

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.video-placeholder.hidden { display: none; }
.video-name { font-size: 18px; font-weight: 700; }
.video-status { font-size: 14px; color: var(--text-dim); max-width: 80%; text-align: center; }

.tile-label {
  position: absolute;
  left: 12px;
  bottom: 12px;
  font-size: 13px;
  font-weight: 600;
  background: rgba(0,0,0,.6);
  padding: 4px 10px;
  border-radius: 8px;
}

.call-controls {
  display: flex;
  gap: 16px;
  background: var(--bg-2);
  padding: 12px 20px;
  border-radius: 20px;
}

.call-net {
  font-size: 12px;
  color: var(--text-dim);
  background: rgba(0,0,0,.55);
  padding: 4px 12px;
  border-radius: 12px;
  user-select: none;
}

.tab-audio {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-2);
  padding: 8px 14px;
  border-radius: 16px;
  margin-top: 10px;
  max-width: 320px;
}

.tab-audio-label {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

.tab-audio .ctrl-btn.small {
  width: 32px;
  height: 32px;
  font-size: 14px;
  padding: 0;
}

.tab-audio input[type='range'] {
  flex: 1;
  min-width: 90px;
  accent-color: var(--accent, #7289da);
}

.ctrl-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--bg-4);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, transform .1s;
}
.ctrl-btn:hover { background: var(--bg-4); }
.ctrl-btn:active { transform: scale(.92); }
.ctrl-btn.danger { background: var(--red); color: #fff; }
.ctrl-btn.danger:hover { background: var(--red-hover); }
.ctrl-btn.accept { background: var(--green); color: #fff; }
.ctrl-btn.accept:hover { background: var(--green-hover); }
.ctrl-btn.off .mic-on, .ctrl-btn.off .cam-on, .ctrl-btn.off .share-on { display: none; }
.ctrl-btn.off { background: var(--bg-4); color: var(--red); }
.ctrl-btn .mic-off, .ctrl-btn .cam-off, .ctrl-btn .share-off { display: none; }
.ctrl-btn.off .mic-off, .ctrl-btn.off .cam-off, .ctrl-btn.off .share-off { display: block; }
.sharing { background: var(--green); color: #fff; }
.sharing:hover { background: var(--green-hover); }

/* ---------- Incoming call ---------- */
.incoming-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
}
.incoming-overlay.open { display: flex; }

.incoming-card {
  background: var(--bg-3);
  border-radius: 16px;
  padding: 40px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 300px;
  animation: pop .2s ease;
}

@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.incoming-title { color: var(--text-dim); font-size: 14px; }
.incoming-name { font-size: 24px; font-weight: 700; }
.incoming-type { color: var(--text-dim); font-size: 14px; }

.incoming-actions { display: flex; gap: 24px; margin-top: 12px; }
.incoming-actions .ctrl-btn { width: 60px; height: 60px; }

/* ---------- Impostazioni ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 90;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-3);
  border-radius: 14px;
  padding: 22px;
  width: min(440px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  animation: pop .18s ease;
}

.modal-head { display: flex; align-items: center; justify-content: space-between; font-size: 18px; }
.modal-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .02em;
  color: var(--text-dim);
  font-weight: 700;
  margin-bottom: 8px;
}
.modal-hint { margin-top: 8px; font-size: 12px; color: var(--text-dim); }

.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1;
  border: 1px solid var(--bg-4);
  background: var(--bg-2);
  color: var(--text);
  padding: 8px 4px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background .12s, color .12s;
}
.seg button:hover { background: var(--bg-4); }
.seg button.active { background: var(--blurple); border-color: var(--blurple); color: #fff; }
.seg button.active:hover { background: var(--blurple-hover); }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--bg-4);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  animation: slideIn .2s ease;
  max-width: 320px;
}
.toast.error { border-color: var(--red); }

@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---------- Callout quando está em chamada de voz ---------- */
.call-badge {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-2);
  border: 1px solid var(--bg-4);
  padding: 10px 18px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 40;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

@media (max-width: 900px) {
  .members { display: none; }
  .icons-rail { width: 56px; }
  .video-tile.small { width: 110px; }
}