@import url('https://fonts.googleapis.com/css2?family=gg+sans:wght@400;500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg-primary: #313338;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #1e1f22;
  --bg-modifier: #35373c;
  --bg-modifier-hover: #3f4147;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #23a559;
  --red: #f23f43;
  --text-normal: #dbdee1;
  --text-muted: #949ba4;
  --text-link: #00a8fc;
  --header-primary: #f2f3f5;
  --interactive-normal: #b5bac1;
  --interactive-hover: #dbdee1;
  --channel-icon: #80848e;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'gg sans', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-tertiary);
  color: var(--text-normal);
  overflow: hidden;
  user-select: none;
}
button { font-family: inherit; cursor: pointer; border: none; background: transparent; color: inherit; }
input { font-family: inherit; }
.hidden { display: none !important; }

/* ========== LOGIN ========== */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e1f22 0%, #2b2d31 100%);
}
.login-card {
  background: var(--bg-secondary);
  padding: 32px;
  border-radius: 8px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.login-logo {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 20px;
  color: var(--header-primary);
}
.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  color: var(--header-primary);
  margin-bottom: 8px;
}
.login-sub {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 16px;
}
.field { margin-bottom: 20px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}
.field input {
  width: 100%;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 4px;
  padding: 12px;
  color: var(--text-normal);
  font-size: 16px;
  outline: none;
}
.field input:focus { outline: 2px solid var(--accent); }
.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  font-size: 16px;
  padding: 12px;
  border-radius: 4px;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: transparent;
  color: var(--text-normal);
  padding: 10px 16px;
  border-radius: 4px;
  font-weight: 500;
}
.btn-secondary:hover { text-decoration: underline; }
.btn-secondary.full { width: 100%; background: var(--bg-modifier); margin-top: 8px; }
.btn-secondary.full:hover { background: var(--bg-modifier-hover); text-decoration: none; }
.login-hint {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.4;
}

/* ========== APP LAYOUT ========== */
.app {
  display: flex;
  height: 100vh;
}

/* ===== SERVERS RAIL ===== */
.servers-rail {
  width: 72px;
  background: var(--bg-tertiary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
  flex-shrink: 0;
  overflow-y: auto;
}
.server-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-normal);
  transition: border-radius 0.15s, background 0.15s;
  cursor: pointer;
  position: relative;
}
.server-icon:hover,
.server-icon.active {
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
}
.server-icon.home { background: var(--bg-primary); }
.server-icon.home.active,
.server-icon.home:hover { background: var(--accent); }
.server-icon.add {
  background: var(--bg-primary);
  color: var(--green);
  font-size: 28px;
  font-weight: 300;
}
.server-icon.add:hover {
  background: var(--green);
  color: #fff;
  border-radius: 16px;
}
.server-separator {
  width: 32px;
  height: 2px;
  background: var(--bg-primary);
  border-radius: 1px;
  margin: 4px 0;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 240px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  height: 48px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
  font-weight: 600;
  font-size: 16px;
  color: var(--header-primary);
}
.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.4px;
  padding: 12px 8px 4px;
  text-transform: uppercase;
}
.channel, .friend-item, .dm-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  color: var(--channel-icon);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  margin: 1px 0;
  transition: 0.1s;
}
.channel:hover, .friend-item:hover, .dm-item:hover {
  background: var(--bg-modifier);
  color: var(--interactive-hover);
}
.channel.active, .friend-item.active, .dm-item.active {
  background: var(--bg-modifier);
  color: var(--header-primary);
}
.channel span, .friend-item .status-dot {
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.friend-item .avatar-small,
.dm-item .avatar-small {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
}
.status-dot.online { background: var(--green); }

.voice-members {
  padding-left: 28px;
  margin-top: 4px;
}
.voice-member {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  font-size: 13px;
  color: var(--text-muted);
  border-radius: 4px;
}
.voice-member.speaking { color: var(--header-primary); }
.voice-member .mini-av {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
}

/* USER PANEL */
.user-panel {
  height: 52px;
  background: #232428;
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 4px;
}
.user-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px;
  border-radius: 4px;
  cursor: pointer;
}
.user-info:hover { background: var(--bg-modifier); }
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}
.user-meta { min-width: 0; }
.username {
  font-size: 14px;
  font-weight: 600;
  color: var(--header-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status {
  font-size: 12px;
  color: var(--text-muted);
}
.user-controls {
  display: flex;
  gap: 2px;
}
.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--interactive-normal);
  transition: 0.1s;
}
.icon-btn:hover { background: var(--bg-modifier); color: var(--interactive-hover); }
.icon-btn.off { color: var(--red); }
.icon-btn.danger { color: var(--red); }
.icon-btn.danger:hover { background: var(--red); color: #fff; }
.icon-btn.small { width: 28px; height: 28px; font-size: 18px; }

/* ===== MAIN CONTENT ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  min-width: 0;
  position: relative;
}
.main-header {
  height: 48px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
  z-index: 2;
}
.channel-name {
  font-weight: 600;
  font-size: 16px;
  color: var(--header-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-actions { display: flex; gap: 8px; }
.h-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--interactive-normal);
  border-radius: 4px;
}
.h-btn:hover { color: var(--interactive-hover); }
.h-btn.active { color: var(--green); }

/* CHAT */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.msg {
  display: flex;
  gap: 16px;
  padding: 4px 0;
  border-radius: 4px;
}
.msg:hover { background: rgba(0,0,0,0.06); }
.msg .msg-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
  margin-top: 2px;
}
.msg-body { flex: 1; min-width: 0; }
.msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.msg-author {
  font-weight: 500;
  font-size: 16px;
  color: var(--header-primary);
}
.msg-time {
  font-size: 12px;
  color: var(--text-muted);
}
.msg-content {
  font-size: 16px;
  line-height: 1.375;
  color: var(--text-normal);
  word-break: break-word;
}
.msg.sys {
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 8px 0;
}
.msg.sys:hover { background: transparent; }

.message-input-area {
  padding: 0 16px 24px;
}
.input-wrapper {
  background: var(--bg-modifier);
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
}
.input-wrapper input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 14px 0;
  color: var(--text-normal);
  font-size: 16px;
  outline: none;
}
.attach-btn, .send-btn {
  font-size: 20px;
  color: var(--interactive-normal);
  padding: 4px;
  border-radius: 4px;
}
.attach-btn:hover, .send-btn:hover { color: var(--interactive-hover); }

/* CALL OVERLAY */
.call-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-primary);
  z-index: 10;
  display: flex;
  flex-direction: column;
}
.call-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 24px 100px;
  position: relative;
  overflow: hidden;
}
.avatar-grid, .video-grid {
  flex: 1;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-content: center;
  min-height: 0;
}
.video-grid { display: none; }
.video-grid.show { display: grid; }

.voice-tile {
  background: var(--bg-secondary);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 160px;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.voice-tile.speaking { border-color: var(--green); }
.big-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
  color: #fff;
}
.name-tag {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(0,0,0,0.6);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}

.video-wrap {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
}
.video-wrap.speaking { border-color: var(--green); }
.video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.video-wrap .tag {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(0,0,0,0.6);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}
.video-wrap.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  border-radius: 0;
  border: none;
}

.sharing-banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(35,165,89,0.2);
  border: 1px solid var(--green);
  color: var(--green);
  padding: 8px 16px;
  border-radius: 24px;
  font-weight: 600;
  font-size: 14px;
  display: none;
  align-items: center;
  gap: 12px;
  z-index: 5;
}
.sharing-banner button {
  background: rgba(255,255,255,0.1);
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}

.call-controls {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  background: rgba(0,0,0,0.6);
  padding: 12px;
  border-radius: 32px;
  backdrop-filter: blur(12px);
}
.ctrl-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-modifier);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: 0.15s;
}
.ctrl-btn:hover { background: #4e5058; }
.ctrl-btn.active { background: rgba(35,165,89,0.2); color: var(--green); }
.ctrl-btn.off { background: rgba(242,63,67,0.2); color: var(--red); }
.ctrl-btn.hangup { background: var(--red); color: #fff; }
.ctrl-btn.hangup:hover { background: #da373c; }

.close-fullscreen {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 20px;
  display: none;
  align-items: center;
  justify-content: center;
}
.close-fullscreen.visible { display: flex; }

/* MODALS */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: var(--bg-primary);
  padding: 24px;
  border-radius: 8px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.modal-content h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--header-primary);
  margin-bottom: 8px;
}
.modal-content p {
  color: var(--text-muted);
  margin-bottom: 16px;
  font-size: 14px;
}
.modal-content input {
  width: 100%;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 4px;
  padding: 12px;
  color: var(--text-normal);
  font-size: 16px;
  margin-bottom: 20px;
  outline: none;
}
.modal-content input:focus { outline: 2px solid var(--accent); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}
.or-divider {
  text-align: center;
  color: var(--text-muted);
  margin: 16px 0;
  font-size: 14px;
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb {
  background: #1a1b1e;
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 700px) {
  .servers-rail { width: 56px; }
  .sidebar { width: 200px; }
  .server-icon { width: 40px; height: 40px; font-size: 16px; }
}