/* ═══════════════════════════════════════════════════════════════
   WS-VoIP - Estilos de la Aplicación
   Self-Hosted WhatsApp VoIP Client
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* Colores principales */
  --primary: #00a884;
  --primary-dark: #008f72;
  --primary-light: #00d4a0;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --info: #3b82f6;
  
  /* Colores de fondo */
  --bg-primary: #0b141a;
  --bg-secondary: #111b21;
  --bg-tertiary: #1f2c34;
  --bg-card: #202c33;
  --bg-hover: #2a3942;
  
  /* Colores de texto */
  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-muted: #667781;
  
  /* Bordes */
  --border: #2a3942;
  --border-light: #334155;
  
  /* Sombras */
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.4);
  
  /* Dimensiones */
  --header-height: 60px;
  --max-width: 480px;
  --radius: 12px;
  --radius-sm: 8px;
}

/* ─── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: var(--max-width);
  margin: 0 auto;
  position: relative;
}

/* ─── Header ────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-icon {
  font-size: 1.5rem;
}

.header-brand h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.header-badge {
  font-size: 0.65rem;
  background: var(--primary);
  color: white;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transition: background 0.3s;
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.status-dot.disconnected {
  background: var(--danger);
}

.status-dot.connecting {
  background: var(--warning);
  animation: pulse 1.5s infinite;
}

/* ─── Main Content ──────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

/* ─── Panels ────────────────────────────────────────────────── */
.panel {
  display: none;
  flex-direction: column;
  animation: fadeIn 0.3s ease-out;
}

.panel.active {
  display: flex;
}

.hidden {
  display: none !important;
}

/* ─── Panel: Conectar WhatsApp ──────────────────────────────── */
.panel-connect {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  gap: 20px;
}

.panel-icon {
  font-size: 4rem;
  margin-bottom: 8px;
}

.panel-connect h2 {
  font-size: 1.5rem;
  color: var(--text-primary);
}

.panel-description {
  color: var(--text-secondary);
  max-width: 360px;
  line-height: 1.6;
  font-size: 0.9rem;
}

.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin: 16px 0;
}

.qr-wrapper {
  position: relative;
  background: white;
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.qr-wrapper img {
  width: 256px;
  height: 256px;
  display: block;
}

.qr-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.95);
  border-radius: var(--radius);
  gap: 12px;
  color: var(--bg-primary);
  font-size: 0.85rem;
}

.qr-instructions {
  font-size: 0.8rem;
  color: var(--text-muted);
  max-width: 300px;
}

/* ─── Panel: Dashboard ──────────────────────────────────────── */
.panel-dashboard {
  gap: 20px;
}

.connection-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.user-avatar {
  font-size: 2.2rem;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border-radius: 50%;
}

.user-details {
  flex: 1;
}

.user-details h3 {
  font-size: 1rem;
  font-weight: 600;
}

.user-details p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ─── Dialer ────────────────────────────────────────────────── */
.dialer {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px 16px;
  border: 1px solid var(--border);
}

.phone-input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  text-align: center;
  letter-spacing: 1px;
  outline: none;
  transition: border-color 0.2s;
}

.phone-input:focus {
  border-color: var(--primary);
}

.phone-input::placeholder {
  color: var(--text-muted);
  font-size: 0.8rem;
  letter-spacing: 0;
}

.dialer-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.key {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 1.3rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  user-select: none;
}

.key small {
  font-size: 0.55rem;
  color: var(--text-muted);
  letter-spacing: 2px;
  font-weight: 400;
}

.key:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
}

.key:active {
  transform: scale(0.95);
  background: var(--primary);
}

.key-delete {
  font-size: 1.5rem;
}

.dialer-actions {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}

.btn-call {
  background: var(--success);
  color: white;
  border: none;
  padding: 14px 48px;
  border-radius: 50px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.btn-call:hover {
  background: #16a34a;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(34, 197, 94, 0.3);
}

.btn-call:active {
  transform: translateY(0);
}

/* ─── Call History ──────────────────────────────────────────── */
.call-history {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
}

.call-history h4 {
  font-size: 0.9rem;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.history-list {
  max-height: 200px;
  overflow-y: auto;
}

.history-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 20px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.history-item:last-child {
  border-bottom: none;
}

.history-item:hover {
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
}

.history-icon {
  font-size: 1.2rem;
}

.history-info {
  flex: 1;
}

.history-number {
  font-size: 0.9rem;
  font-weight: 500;
}

.history-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.history-badge {
  font-size: 0.6rem;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.history-badge.rejected {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.history-badge.timeout {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.history-duration {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ─── Panel: Incoming Call ──────────────────────────────────── */
.panel-incoming,
.panel-outgoing {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  gap: 16px;
  min-height: 70vh;
}

.call-animation {
  position: relative;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.call-avatar {
  font-size: 3rem;
  z-index: 2;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border-radius: 50%;
  border: 3px solid var(--primary);
}

.call-pulse {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--primary);
  animation: callPulse 2s infinite;
}

.incoming .call-pulse {
  border-color: var(--success);
}

.incoming .call-avatar {
  border-color: var(--success);
  animation: shake 0.5s infinite;
}

.outgoing .call-pulse {
  border-color: var(--info);
}

.call-number {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.call-type {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.incoming-actions {
  display: flex;
  gap: 40px;
  margin-top: 24px;
}

.outgoing-actions {
  margin-top: 24px;
}

/* ─── Panel: Active Call ────────────────────────────────────── */
.panel-active {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  gap: 20px;
  min-height: 70vh;
}

.active-call-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.active-anim .call-avatar {
  border-color: var(--success);
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.2);
}

.call-duration {
  font-size: 2rem;
  font-weight: 300;
  color: var(--primary-light);
  font-variant-numeric: tabular-nums;
}

.call-state {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.active-call-controls {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-top: 16px;
}

.btn-control {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 16px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  min-width: 72px;
}

.btn-control:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
}

.btn-control.active {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.btn-control span {
  font-size: 1.5rem;
}

.btn-control small {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.btn-control.active small {
  color: rgba(255, 255, 255, 0.8);
}

/* ─── Audio Bridge Status ───────────────────────────────────── */
.audio-bridge-status {
  margin-top: 12px;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.bridge-indicators {
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 8px;
}

.bridge-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.bridge-indicator small {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-indicator {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transition: background 0.3s;
}

.status-indicator.active {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.status-indicator.inactive {
  background: var(--text-muted);
  opacity: 0.5;
}

.status-packets {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  font-family: monospace;
}

/* ─── Audio Visualizer ──────────────────────────────────────── */
.audio-visualizer {
  margin-top: 16px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.audio-visualizer canvas {
  width: 100%;
  height: 60px;
  display: block;
}

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  user-select: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-dark);
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.btn-lg {
  padding: 16px 32px;
  font-size: 1.1rem;
}

.btn-round {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.btn-round span {
  font-size: 1.8rem;
}

.btn-round small {
  font-size: 0.65rem;
  font-weight: 500;
}

.btn-accept {
  background: var(--success);
  color: white;
}

.btn-accept:hover {
  background: #16a34a;
}

.btn-reject,
.btn-end-call {
  background: var(--danger);
  color: white;
}

.btn-reject:hover,
.btn-end-call:hover {
  background: var(--danger-dark);
}

.btn-icon {
  font-size: 1.2rem;
}

/* ─── Toast Notifications ───────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: calc(var(--max-width) - 32px);
  width: calc(100% - 32px);
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideUp 0.3s ease-out;
  font-size: 0.85rem;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error { border-left: 3px solid var(--danger); }
.toast.toast-warning { border-left: 3px solid var(--warning); }
.toast.toast-info { border-left: 3px solid var(--info); }

.toast-icon {
  font-size: 1.2rem;
}

/* ─── Spinner ───────────────────────────────────────────────── */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ─── Footer ────────────────────────────────────────────────── */
.footer {
  padding: 12px 16px;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.footer a {
  color: var(--warning);
  text-decoration: none;
}

/* ─── Animations ────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes callPulse {
  0% {
    transform: scale(0.8);
    opacity: 1;
  }
  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}

@keyframes shake {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(10deg); }
  75% { transform: rotate(-10deg); }
}

/* ─── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ─── Settings Panel ────────────────────────────────────────── */
.panel-settings {
  gap: 16px;
  padding: 16px 0;
}

.settings-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.settings-header h2 {
  font-size: 1.1rem;
}

.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.settings-section h4 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.settings-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.settings-item label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}

.settings-item small {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.settings-about {
  text-align: center;
}

.settings-about p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.text-muted {
  color: var(--text-muted) !important;
  font-size: 0.75rem !important;
}

/* ─── Toggle Switch ─────────────────────────────────────────── */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 24px;
  transition: 0.3s;
}

.toggle-slider::before {
  position: absolute;
  content: '';
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-muted);
  border-radius: 50%;
  transition: 0.3s;
}

.toggle input:checked + .toggle-slider {
  background-color: var(--primary);
  border-color: var(--primary);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background-color: white;
}

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 480px) {
  .dialer-pad {
    gap: 6px;
  }
  
  .key {
    padding: 12px;
    font-size: 1.1rem;
  }
  
  .incoming-actions {
    gap: 32px;
  }
}

@media (min-width: 768px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
