:root {
  --bg-900: #0b0f1a;
  --bg-800: #11182a;
  --bg-700: #1a2440;
  --card: rgba(255, 255, 255, 0.06);
  --card-strong: rgba(255, 255, 255, 0.12);
  --text: #e6ecff;
  --muted: #9fb0d0;
  --accent: #00f5d4;
  --accent-2: #ff9f1c;
  --danger: #ff4d6d;
  --success: #2dd4bf;
  --ring: rgba(0, 245, 212, 0.4);
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

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

body {
  font-family: "Space Grotesk", "Sora", sans-serif;
  background: radial-gradient(1200px 600px at 10% 10%, #12203a 0%, transparent 60%),
    radial-gradient(900px 700px at 90% 20%, #1c2c52 0%, transparent 55%),
    linear-gradient(160deg, var(--bg-900) 0%, var(--bg-800) 100%);
  color: var(--text);
  min-height: 100dvh;
  overflow: hidden;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }
.screen { width: 100%; height: 100%; }
.screen.active { display: flex; justify-content: center; align-items: center; }

/* Preloader */
#preloader {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 26, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(10px);
}
.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Login */
.login-container {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 2rem;
  border-radius: var(--radius-lg);
  width: min(420px, 92vw);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  animation: rise 0.5s ease;
}
.login-container h1 {
  font-size: 2rem;
  letter-spacing: 0.5px;
  margin-bottom: 1.2rem;
}
.form-group { margin-bottom: 1rem; }
.form-group label {
  font-size: 0.9rem;
  color: var(--muted);
}
.form-group input, select {
  width: 100%;
  padding: 0.85rem 0.9rem;
  margin-top: 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  outline: none;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}
.form-group input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--ring);
}
.btn-primary {
  width: 100%;
  padding: 1rem;
  background: linear-gradient(135deg, var(--accent) 0%, #30a9ff 100%);
  border: none;
  color: #02111b;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-weight: 700;
  letter-spacing: 0.3px;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(0, 245, 212, 0.25); }
.btn-secondary {
  width: 100%;
  padding: 0.9rem 1rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
#toggle-key {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--text);
  padding: 0 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* Chat Layout */
.chat-header {
  height: 64px;
  background: rgba(0, 0, 0, 0.25);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
}
.brand {
  font-weight: 700;
  letter-spacing: 0.3px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.connection-status {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
}
.user-profile {
  justify-self: end;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
}

.chat-main {
  height: calc(100dvh - 100px);
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  padding: 16px;
}
.sidebar {
  background: var(--card);
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 220px;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
}
.video-area {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  height: 100%;
}

/* User List */
.user-list {
  overflow: auto;
  padding-right: 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.user-item {
  padding: 10px;
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: transform 0.12s ease, background 0.2s ease, border 0.2s ease;
}
.user-item:hover, .user-item.selected {
  background: rgba(0, 245, 212, 0.12);
  border-color: rgba(0, 245, 212, 0.3);
}
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #465173;
  color: #fff;
  font-weight: 700;
}
.user-avatar.male { background: #2b59ff; }
.user-avatar.female { background: #ff6ea8; }
.user-details .user-name { font-weight: 600; }
.user-status-text { font-size: 0.8rem; color: var(--muted); }
.empty-state { color: var(--muted); padding: 12px; text-align: center; }

/* Video */
.video-container {
  background: #05070d;
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
video { width: 100%; height: 100%; object-fit: cover; }
.video-label {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
}
.video-placeholder, .video-error { position: absolute; color: #7b86a6; }

/* Controls */
.video-controls {
  position: absolute;
  bottom: 14px;
  left: 14px;
  display: flex;
  gap: 10px;
  background: rgba(0, 0, 0, 0.45);
  padding: 8px 10px;
  border-radius: 999px;
}
.btn-control {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: #3b4257;
  color: white;
  transition: transform 0.15s ease, background 0.2s ease;
}
.btn-control.active { background: var(--accent); color: #02111b; }
.btn-control.inactive { background: var(--danger); }

.call-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  gap: 12px;
}
.btn-success {
  background: var(--success);
  padding: 10px 26px;
  border: none;
  color: #02111b;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}
.btn-danger {
  background: var(--danger);
  padding: 10px 26px;
  border: none;
  color: #fff;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Incoming Call */
.incoming-call {
  position: absolute;
  background: rgba(5, 7, 13, 0.85);
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  gap: 12px;
  text-align: center;
  backdrop-filter: blur(6px);
}
.status-dot { width: 10px; height: 10px; background: var(--danger); border-radius: 50%; display: inline-block; }
.status-dot.connected { background: var(--success); }

/* Status Bar */
.status-bar {
  height: 36px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: rgba(0, 0, 0, 0.35);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
#call-status-text { color: var(--muted); font-size: 0.9rem; }

@keyframes rise {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Tablet */
@media (max-width: 1024px) {
  .chat-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: calc(100dvh - 100px);
  }
  .sidebar {
    flex-direction: column;
  }
  .user-list {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 4px;
  }
  .user-item {
    min-width: 200px;
    flex: 0 0 auto;
  }
  .video-area {
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(240px, 1fr);
  }
}

/* Phone */
@media (max-width: 720px) {
  .chat-header {
    grid-template-columns: 1fr auto;
    gap: 8px;
  }
  .user-profile { display: none; }
  .chat-main {
    padding: 10px;
    gap: 10px;
  }
  .sidebar {
    padding: 10px;
  }
  .user-item {
    min-width: 160px;
    padding: 8px;
  }
  .user-details .user-status-text { display: none; }
  .video-area {
    position: relative;
    grid-template-columns: 1fr;
  }
  .video-container.remote {
    height: 54vh;
  }
  .video-container.local {
    position: absolute;
    width: 38vw;
    height: 28vw;
    min-width: 140px;
    min-height: 100px;
    bottom: 12px;
    right: 12px;
    z-index: 5;
    border: 2px solid rgba(255, 255, 255, 0.2);
  }
  .call-controls {
    left: 12px;
    right: auto;
    bottom: 12px;
    flex-direction: column;
    gap: 8px;
  }
  .video-controls {
    top: 12px;
    bottom: auto;
    left: 12px;
  }
  .status-bar { height: 32px; }
}
