:root {
  --bg-primary: #0a0f1a;
  --bg-secondary: #111827;
  --bg-tertiary: #1a2332;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --success: #00cec9;
  --danger: #e74c3c;
  --warning: #f39c12;
  --border: #2d3748;
  --shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
  --radius: 20px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  user-select: none;
}

.app-container {
  width: 100%;
  height: 100dvh;
  max-width: 1400px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column; /* Susunan Vertikal */
  border-radius: 0;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

@media (min-width: 768px) {
  .app-container {
    border-radius: var(--radius);
    height: calc(100dvh - 40px);
    margin: 20px;
  }
}

/* === SIDEBAR === */
.sidebar {
  width: 100%;
  height: 100%;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 2;
  transition: transform var(--transition);
}

.sidebar.hidden {
  display: none;
}

.sidebar-header {
  padding: 25px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.user-name {
  font-weight: 600;
  font-size: 1rem;
}
.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
}
.logout-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.search-box {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
}
.search-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border var(--transition);
}
.search-input:focus {
  border-color: var(--accent);
}

.contact-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.contact-item {
  padding: 15px 20px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: background 0.2s;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.contact-item:hover, .contact-item.active {
  background: var(--bg-tertiary);
}

.contact-avatar {
  width: 48px;
  height: 48px;
  border-radius: 15px;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: var(--accent-light);
  flex-shrink: 0;
  font-size: 1.2rem;
  border: 2px solid var(--border);
}
.contact-details {
  flex: 1;
  text-align: left;
}
.contact-name {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-last-msg {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.add-contact-btn {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.85rem;
}

/* === CHAT AREA === */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  position: relative;
  overflow: hidden;
  display: none; /* Sembunyikan Chat di awal */
}

.chat-area.active {
  display: flex;
}

.chat-header {
  padding: 20px 25px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 25px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.message {
  max-width: 70%;
  padding: 12px 18px;
  border-radius: 18px;
  font-size: 0.9rem;
  position: relative;
  word-wrap: break-word;
}
.message.sent {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 6px;
}
.message.received {
  align-self: flex-start;
  background: var(--bg-tertiary);
  border-bottom-left-radius: 6px;
}

.chat-input-area {
  padding: 20px 25px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  background: var(--bg-secondary);
}

/* === AUTH SCREEN === */
.auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100%;
  padding: 20px;
  background: var(--bg-primary);
}
.auth-form {
  background: var(--bg-secondary);
  padding: 40px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.auth-input {
  width: 100%;
  padding: 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 12px;
  margin: 10px 0;
  outline: none;
}
.auth-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  border: none;
  color: white;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 15px;
}

.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-primary);
  margin-right: 15px;
  cursor: pointer;
  padding: 5px;
  border-radius: 50%;
}

@media (max-width: 768px) {
  .chat-header {
    padding: 15px;
  }
}

/* === CALL UI === */
.call-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  margin-left: 8px;
}

.call-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.call-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at center, var(--bg-tertiary) 0%, var(--bg-primary) 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 99999;
  backdrop-filter: blur(10px);
}

.call-box {
  background: transparent;
  width: 100%;
  max-width: 400px;
  padding: 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.caller-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: 700;
  color: white;
  margin-bottom: 10px;
  box-shadow: 0 0 0 10px rgba(108, 92, 231, 0.1);
}

.caller-name {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
}

.call-type {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.circle-btn {
  width: 65px;
  height: 65px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, background 0.3s;
  color: white;
}

.circle-btn:active {
  transform: scale(0.9);
}

.circle-btn.accept { background: var(--success); }
.circle-btn.reject { background: var(--danger); }

.circle-btn.toggle-off {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.circle-btn.toggle-on {
  background: var(--bg-tertiary);
  color: var(--accent-light);
  border: 1px solid var(--accent);
}

.pulse {
  animation: pulse-animation 2s infinite;
}

@keyframes pulse-animation {
  0% { box-shadow: 0 0 0 0 rgba(0, 206, 201, 0.7); }
  70% { box-shadow: 0 0 0 20px rgba(0, 206, 201, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 206, 201, 0); }
}

.video-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 9998;
}

.video-wrapper {
  width: 100%;
  height: 100%;
  position: relative;
}

.remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.local-video {
  position: absolute;
  top: 25px;
  right: 25px;
  width: 110px;
  aspect-ratio: 3/4;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.3);
  object-fit: cover;
  z-index: 10001;
  box-shadow: 0 10px 20px rgba(0,0,0,0.5);
}

.video-controls {
  position: absolute;
  bottom: 50px;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  z-index: 10002;
}

.control-buttons-row {
  display: flex;
  gap: 30px;
}

.volume-panel {
  width: 80%;
  max-width: 300px;
  background: rgba(0, 0, 0, 0.5);
  padding: 15px;
  border-radius: 15px;
  backdrop-filter: blur(5px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.playlist-info {
  width: 80%;
  max-width: 300px;
  background: rgba(0, 0, 0, 0.6);
  padding: 12px;
  border-radius: 15px;
  backdrop-filter: blur(5px);
  margin-bottom: 5px;
  font-size: 0.8rem;
  text-align: left;
  border: 1px solid rgba(255,255,255,0.1);
}

.volume-slider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
  font-size: 0.8rem;
}

.volume-slider input {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

@media (max-width: 480px) {
  .local-video {
    width: 90px;
    top: 15px;
    right: 15px;
  }
  .video-controls {
    bottom: 30px;
  }
  .circle-btn {
    width: 60px;
    height: 60px;
  }
  .caller-avatar {
    width: 100px;
    height: 100px;
    font-size: 2.5rem;
  }
}