/* ===== RESET Y BASE ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #e0e7ff;
  --secondary: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --sidebar-w: 260px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); }

/* ===== LAYOUT ===== */
#app { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w); background: #1e1b4b; color: white;
  display: flex; flex-direction: column; position: fixed; height: 100vh;
  overflow-y: auto; z-index: 100;
}

.sidebar-header { padding: 24px 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.1); }

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 28px; }
.logo-text { font-size: 18px; font-weight: 700; color: #e0e7ff; }

.client-selector { padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.client-selector label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: #a5b4fc; display: block; margin-bottom: 8px; }
.client-selector select {
  width: 100%; padding: 8px 10px; background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2); border-radius: 8px;
  color: white; font-size: 14px; cursor: pointer;
}
.client-selector select option { background: #1e1b4b; }
.btn-new-client {
  margin-top: 8px; width: 100%; padding: 6px; background: transparent;
  border: 1px dashed rgba(255,255,255,0.3); border-radius: 8px;
  color: #a5b4fc; font-size: 13px; cursor: pointer; transition: all 0.2s;
}
.btn-new-client:hover { background: rgba(255,255,255,0.1); color: white; }

.sidebar-nav { padding: 12px 12px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: 8px; color: #a5b4fc; text-decoration: none;
  font-size: 14px; font-weight: 500; transition: all 0.2s; margin-bottom: 2px;
}
.nav-icon { font-size: 18px; width: 24px; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,0.1); color: white; }
.nav-item.active { background: var(--primary); color: white; }

/* ===== MAIN CONTENT ===== */
.main-content { margin-left: var(--sidebar-w); flex: 1; padding: 32px; min-height: 100vh; }

/* ===== PÁGINAS ===== */
.page { display: none; }
.page.active { display: block; }

/* ===== CARDS ===== */
.card {
  background: var(--bg-card); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow); border: 1px solid var(--border);
  margin-bottom: 20px;
}
.card-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; color: var(--text); }

/* ===== GRID DE MÉTRICAS ===== */
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.metric-card {
  background: var(--bg-card); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.metric-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px; }
.metric-value { font-size: 28px; font-weight: 700; color: var(--text); }
.metric-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.metric-icon { font-size: 32px; float: right; margin-top: -8px; }

/* ===== BOTONES ===== */
.btn {
  padding: 10px 20px; border-radius: 8px; font-size: 14px; font-weight: 600;
  cursor: pointer; border: none; transition: all 0.2s; display: inline-flex;
  align-items: center; gap: 8px;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none !important; }

/* ===== FORMULARIOS ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; color: var(--text); background: var(--bg-card);
  transition: border-color 0.2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.form-textarea { min-height: 100px; resize: vertical; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== GRID DE 2 COLUMNAS ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ===== TABLA ===== */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); padding: 12px 16px; border-bottom: 2px solid var(--border); }
td { padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
tr:hover td { background: var(--bg); }
.td-actions { display: flex; gap: 8px; }

/* ===== BADGES ===== */
.badge { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-paused { background: #fef3c7; color: #92400e; }
.badge-meta { background: #dbeafe; color: #1e40af; }
.badge-google { background: #fef9c3; color: #713f12; }
.badge-tiktok { background: #fce7f3; color: #9d174d; }

/* ===== RESULTADO DE IA ===== */
.ai-result {
  background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-top: 20px; white-space: pre-wrap; font-size: 14px;
  line-height: 1.7; color: var(--text); display: none;
}
.ai-result.visible { display: block; }
.ai-result-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.ai-result-title { font-weight: 700; color: var(--primary); }

/* ===== LOADING SPINNER ===== */
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: white;
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: none; align-items: center; justify-content: center; z-index: 1000;
}
.modal-overlay.visible { display: flex; }
.modal-box {
  background: white; border-radius: var(--radius); padding: 32px;
  width: 90%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-title { font-size: 20px; font-weight: 700; margin-bottom: 24px; }
.modal-footer { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 24px; right: 24px; padding: 14px 20px;
  border-radius: 10px; color: white; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg); display: none; z-index: 2000;
  animation: slideIn 0.3s ease;
}
.toast.visible { display: block; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ===== ENCABEZADO DE PÁGINA ===== */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; }
.page-title { font-size: 26px; font-weight: 800; color: var(--text); }
.page-subtitle { font-size: 14px; color: var(--text-muted); margin-top: 4px; }

/* ===== ESTADO VACÍO ===== */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--text); margin-bottom: 8px; }

/* ===== CONFIGURACIÓN DE API ===== */
.api-banner {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: var(--radius); padding: 20px 24px; color: white;
  margin-bottom: 24px; display: flex; justify-content: space-between; align-items: center;
}
.api-banner h3 { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.api-banner p { font-size: 13px; opacity: 0.85; }

/* ===== BOTÓN HAMBURGUESA ===== */
.hamburger {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 300;
  background: var(--primary); color: white; border: none; border-radius: 10px;
  width: 42px; height: 42px; font-size: 20px; cursor: pointer;
  align-items: center; justify-content: center; box-shadow: var(--shadow-lg);
}

/* ===== OVERLAY PARA CERRAR SIDEBAR ===== */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 99;
}
.sidebar-overlay.visible { display: block; }

/* ===== BARRA INFERIOR MÓVIL ===== */
.mobile-bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  background: white; border-top: 1px solid var(--border);
  z-index: 200; padding: 6px 0 8px;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
}
.mobile-bottom-nav .bottom-nav-items {
  display: flex; justify-content: space-around; align-items: center;
}
.mobile-bottom-nav .bnav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 10px; border-radius: 10px; cursor: pointer;
  color: var(--text-muted); font-size: 10px; font-weight: 600;
  border: none; background: none; min-width: 52px;
}
.mobile-bottom-nav .bnav-item .bnav-icon { font-size: 22px; }
.mobile-bottom-nav .bnav-item.active { color: var(--primary); }
.mobile-bottom-nav .bnav-item.active .bnav-icon { transform: scale(1.15); }

/* ===== RESPONSIVE MÓVIL ===== */
@media (max-width: 768px) {

  /* Sidebar oculta por defecto, desliza desde izquierda */
  .sidebar {
    transform: translateX(-100%); transition: transform 0.28s ease;
    z-index: 100; width: 260px;
  }
  .sidebar.open { transform: translateX(0); }

  /* Botón hamburguesa visible */
  .hamburger { display: flex; }

  /* Contenido ocupa toda la pantalla */
  .main-content {
    margin-left: 0; padding: 16px; padding-top: 64px; padding-bottom: 80px;
  }

  /* Barra inferior */
  .mobile-bottom-nav { display: block; }

  /* Grids: una columna */
  .form-grid { grid-template-columns: 1fr !important; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }

  /* Encabezados de página */
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .page-header .btn { width: 100%; justify-content: center; }

  /* Cards más compactas */
  .card { padding: 16px; }

  /* Tablas: scroll horizontal */
  .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 600px; }
  td, th { padding: 10px 12px; white-space: nowrap; }

  /* Modales: casi pantalla completa */
  .modal-box {
    width: 96%; padding: 20px; max-height: 92vh;
    border-radius: 16px; margin: 0 auto;
  }
  .modal-title { font-size: 17px; }
  .modal-footer { flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; justify-content: center; }

  /* Página nuevo cliente: una columna */
  #page-new-client > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Pestañas de plataforma */
  .platform-tab { gap: 6px; }
  .platform-tab button { padding: 8px 12px; font-size: 12px; }

  /* Resultados IA */
  .ai-result { padding: 14px; font-size: 13px; }
  .ai-result-header { flex-direction: column; gap: 8px; align-items: flex-start; }

  /* Métricas */
  .metric-card { padding: 14px; }
  .metric-value { font-size: 22px; }

  /* Steps bar de campaña */
  .steps-bar { gap: 0; }
  .step-label { font-size: 9px; }
  .step-circle { width: 28px; height: 28px; font-size: 13px; }
  .step-line { min-width: 16px; }

  /* Objetivos en grid */
  div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Botones de acción en tablas */
  .td-actions { flex-direction: column; gap: 4px; }
  .td-actions .btn { width: 100%; justify-content: center; font-size: 11px; }

  /* Toast más grande */
  .toast { left: 12px; right: 12px; bottom: 90px; text-align: center; }

  /* Logo en sidebar abierta */
  .logo-text { display: block; }
  .client-selector label { display: block; }
  .btn-new-client { display: block; }
}

/* Pantallas muy pequeñas */
@media (max-width: 380px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .main-content { padding: 12px; padding-top: 60px; padding-bottom: 76px; }
  .mobile-bottom-nav .bnav-item { min-width: 44px; font-size: 9px; padding: 4px 6px; }
}
