/* ====== RESET & BASE ====== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0a0a1a;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.08);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(124, 58, 237, 0.5);
  --text-primary: #f0f0f5;
  --text-secondary: #8888aa;
  --text-muted: #555577;
  --accent-purple: #7c3aed;
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-orange: #f59e0b;
  --gradient-main: linear-gradient(135deg, #667eea, #764ba2);
  --gradient-glow: linear-gradient(135deg, rgba(124, 58, 237, 0.3), rgba(6, 182, 212, 0.3));
  --shadow-glow: 0 0 30px rgba(124, 58, 237, 0.2);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --header-h: 60px;
  --panel-w: 340px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

input, button, textarea {
  font-family: inherit;
  outline: none;
  border: none;
}

input::placeholder { color: var(--text-muted); }

/* ====== SCROLLBAR ====== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ====== VIEW SYSTEM ====== */
.view { display: none; width: 100%; height: 100%; position: absolute; top: 0; left: 0; }
.view.active { display: flex; }

/* ====== HOME VIEW ====== */
#home-view {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0a0a1a 0%, #1a0a2e 50%, #0a0a1a 100%);
}

.home-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
  animation: float 20s ease-in-out infinite;
}

.orb-1 { width: 500px; height: 500px; background: #7c3aed; top: -10%; left: -10%; animation-delay: 0s; }
.orb-2 { width: 400px; height: 400px; background: #06b6d4; bottom: -15%; right: -10%; animation-delay: -7s; }
.orb-3 { width: 300px; height: 300px; background: #10b981; top: 50%; left: 50%; animation-delay: -14s; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(50px, -50px) scale(1.1); }
  66% { transform: translate(-30px, 30px) scale(0.9); }
}

.home-card {
  position: relative;
  z-index: 1;
  background: var(--bg-card);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 48px 40px 36px;
  width: 400px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 25px 60px rgba(0,0,0,0.5);
  animation: cardIn 0.6s ease-out;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.logo { margin-bottom: 32px; }

.logo-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  background: var(--gradient-main);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.logo-icon.small {
  width: 32px;
  height: 32px;
  font-size: 14px;
  border-radius: 10px;
  margin: 0;
  display: inline-flex;
}

.logo h1 {
  font-size: 36px;
  font-weight: 800;
  background: var(--gradient-main);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -1px;
}

.tagline {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
  font-weight: 400;
}

.username-section {
  margin-bottom: 20px;
  text-align: left;
}

.username-section label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.username-section input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 15px;
  transition: border 0.2s;
}

.username-section input:focus {
  border-color: var(--accent-purple);
}

/* ====== BUTTONS ====== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.btn-primary {
  width: 100%;
  background: var(--gradient-main);
  color: #fff;
  padding: 14px;
  font-size: 16px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.3);
  margin-bottom: 16px;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(124, 58, 237, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.12);
  border-color: var(--text-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 14px;
  font-size: 13px;
}

.btn-ghost:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
  padding: 8px 16px;
  font-size: 13px;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: var(--gradient-main);
  color: #fff;
  flex-shrink: 0;
}

.btn-icon:hover {
  transform: scale(1.1);
}

.btn-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  padding: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 18px;
  backdrop-filter: blur(12px);
}

.btn-circle:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.btn-circle.active {
  background: var(--accent-green);
  border-color: var(--accent-green);
  color: #fff;
}

.btn-circle.danger {
  background: var(--accent-red);
  border-color: var(--accent-red);
  color: #fff;
}

.btn-tiny {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
}

.btn-tiny:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* ====== DIVIDER ====== */
.divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 8px 0 16px;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

/* ====== JOIN SECTION ====== */
.join-section {
  display: flex;
  gap: 10px;
}

.join-section input {
  flex: 1;
  padding: 12px 16px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 4px;
  transition: border 0.2s;
}

.join-section input:focus {
  border-color: var(--accent-purple);
}

.error-msg {
  color: var(--accent-red);
  font-size: 13px;
  margin-top: 12px;
  min-height: 20px;
}

/* ====== CONNECTION STATUS ====== */
.conn-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-red);
  transition: background 0.3s;
}

.conn-dot.connected { background: var(--accent-green); box-shadow: 0 0 8px rgba(16, 185, 129, 0.5); }
.conn-dot.connecting { background: var(--accent-orange); animation: blink 1s ease-in-out infinite; }
.conn-dot.disconnected { background: var(--accent-red); }

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.home-footer {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 28px;
  color: var(--text-muted);
  font-size: 12px;
}

.home-footer span {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ====== ROOM VIEW ====== */
#room-view {
  flex-direction: column;
}

.room-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(20px);
  flex-shrink: 0;
  z-index: 10;
}

.header-left, .header-center, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-title {
  font-weight: 700;
  font-size: 16px;
  background: var(--gradient-main);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.room-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.06);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-cyan);
  letter-spacing: 1px;
}

#member-count {
  color: var(--text-secondary);
  font-size: 13px;
}

/* ====== ROOM MAIN LAYOUT ====== */
.room-main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ====== MAP ====== */
.map-container {
  flex: 1;
  position: relative;
  min-width: 0;
}

#map {
  width: 100%;
  height: 100%;
  z-index: 1;
}

.map-overlay-top {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-label {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 6px;
}

.map-overlay-bottom {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  gap: 12px;
}

/* Custom Leaflet styles */
.leaflet-container {
  background: #0a0a1a;
}

.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-color) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-card-hover) !important;
}

.leaflet-control-attribution {
  background: rgba(10, 10, 26, 0.8) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: var(--text-secondary) !important;
}

/* ====== SIDE PANEL ====== */
.side-panel {
  width: var(--panel-w);
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border-left: 1px solid var(--border-color);
  flex-shrink: 0;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  padding: 12px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
}

.tab:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.tab.active {
  color: var(--accent-purple);
  border-bottom-color: var(--accent-purple);
}

.tab-content {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}

.tab-content.active {
  display: flex;
}

/* ====== CHAT ====== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  gap: 12px;
}

.msg-placeholder i {
  font-size: 40px;
  opacity: 0.3;
}

.msg-system {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 0;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 85%;
  animation: msgIn 0.2s ease-out;
}

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

.msg-own { align-self: flex-end; }
.msg-other { align-self: flex-start; }

.msg-username {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0 4px;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.msg-own .msg-bubble {
  background: var(--gradient-main);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-other .msg-bubble {
  background: rgba(255,255,255,0.08);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 6px;
}

.msg-own .msg-time { text-align: right; }

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.chat-input-area input {
  flex: 1;
  padding: 10px 14px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  color: var(--text-primary);
  font-size: 14px;
  transition: border 0.2s;
}

.chat-input-area input:focus {
  border-color: var(--accent-purple);
}

/* ====== MEMBERS LIST ====== */
.members-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}

.member-item:hover {
  background: var(--bg-card-hover);
}

.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.member-info {
  flex: 1;
  min-width: 0;
}

.member-name {
  font-size: 14px;
  font-weight: 500;
}

.member-status {
  font-size: 11px;
  color: var(--text-muted);
}

.member-voice {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.member-voice.on { color: var(--accent-green); }
.member-voice.off { color: var(--text-muted); }

/* ====== TOASTS ====== */
#toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 14px;
  animation: slideIn 0.3s ease-out;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.toast.info { border-left: 3px solid var(--accent-cyan); }
.toast.success { border-left: 3px solid var(--accent-green); }
.toast.error { border-left: 3px solid var(--accent-red); }

/* ====== RESPONSIVE ====== */
@media (max-width: 900px) {
  .room-main {
    flex-direction: column;
  }
  .side-panel {
    width: 100%;
    height: 40vh;
    border-left: none;
    border-top: 1px solid var(--border-color);
  }
  .home-card {
    padding: 32px 24px;
  }
  .room-header {
    padding: 0 12px;
  }
  .header-title { display: none; }
}

@media (max-width: 480px) {
  .home-card {
    padding: 24px 16px;
  }
  .logo h1 { font-size: 28px; }
  .join-section {
    flex-direction: column;
  }
}
