/* ===================================================================
   BotStudio Admin Panel — Dark Mode con gradientes del Home
   Paleta: #2563EB · #7C3AED · #0F172A
   Tipografía: Poppins
   =================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800&display=swap');

/* ===== Variables ===================================================== */
:root {
  --blue:        #2563EB;
  --purple:      #7C3AED;
  --purple2:     #9f5cf5;
  --dark:        #0F172A;
  --gradient:    linear-gradient(135deg, #2563EB 0%, #7C3AED 100%);

  --bg:          #0d0f1a;
  --bg2:         #141626;
  --bg3:         #1c1f35;

  --border:      rgba(255,255,255,.08);
  --border-mid:  rgba(255,255,255,.12);

  --text:        #E2E8F0;
  --text-dim:    #64748B;
  --text-light:  #475569;

  --accent:      var(--purple);
  --accent2:     #60A5FA;
  --success:     #10B981;
  --danger:      #EF4444;
  --warning:     #F59E0B;

  --sidebar-w:   240px;
  --radius:      12px;
  --radius-lg:   16px;
  --transition:  .2s ease;

  --shadow-sm:   0 2px 8px rgba(0,0,0,.3);
  --shadow:      0 6px 24px rgba(0,0,0,.4);
  --shadow-lg:   0 16px 48px rgba(0,0,0,.5);
  --shadow-glow: 0 4px 20px rgba(124,58,237,.35);
}

/* ===== Reset ========================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: 'Poppins', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  background-image:
    radial-gradient(ellipse at 15% 40%, rgba(37,99,235,.18) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 15%, rgba(124,58,237,.15) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 90%, rgba(37,99,235,.08) 0%, transparent 50%);
}
a { text-decoration: none; color: inherit; }
input, textarea, select, button { font-family: inherit; }
code {
  background: var(--bg3);
  border: 1px solid var(--border-mid);
  padding: 2px 7px; border-radius: 5px;
  font-family: 'Courier New', monospace;
  font-size: .85em;
  color: #94D3FC;
}

/* ===== Utilities ===================================================== */
.hidden { display: none !important; }
.screen { width: 100%; min-height: 100vh; }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* ===== Buttons ======================================================= */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px; border-radius: 10px; font-size: 14px;
  font-weight: 600; cursor: pointer; border: none;
  transition: all var(--transition);
  letter-spacing: .3px;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  background: var(--gradient);
  color: #fff;
  box-shadow: var(--shadow-glow);
}
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 24px rgba(124,58,237,.5);
}

.btn-ghost {
  background: rgba(255,255,255,.05);
  color: var(--text-dim);
  border: 1.5px solid var(--border-mid);
}
.btn-ghost:hover:not(:disabled) {
  border-color: rgba(124,58,237,.5);
  color: #C084FC;
  background: rgba(124,58,237,.08);
}

.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }

.btn-icon {
  padding: 7px; border-radius: 8px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  cursor: pointer; color: var(--text-dim); font-size: 15px;
  transition: all var(--transition);
}
.btn-icon:hover {
  background: var(--gradient);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-glow);
}

/* ===== Login ========================================================= */
#login-screen {
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  width: 100%; max-width: 400px; padding: 44px 40px;
  background: rgba(20, 22, 38, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 24px;
  border: 1px solid var(--border-mid);
  box-shadow: var(--shadow-lg), 0 0 60px rgba(124,58,237,.08);
  animation: slide-in .35s ease;
}
@keyframes slide-in { from { opacity:0; transform: translateY(24px); } }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-form { display: flex; flex-direction: column; gap: 18px; }

/* ===== Fields ======================================================== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: rgba(255,255,255,.65); }
.field input, .field select, .field textarea {
  background: rgba(255,255,255,.05);
  border: 1.5px solid var(--border-mid);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 14px; font-size: 14px; outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: rgba(124,58,237,.6);
  background: rgba(124,58,237,.06);
  box-shadow: 0 0 0 3px rgba(124,58,237,.15);
}
.field input::placeholder { color: var(--text-light); }
.field select option { background: var(--bg2); color: var(--text); }
.field small { color: var(--text-dim); font-size: 12px; }
.field-inline { flex-direction: row; align-items: center; gap: 8px; }
.field-inline label { cursor: pointer; margin: 0; color: var(--text); font-weight: 500; }
.field textarea { resize: vertical; min-height: 100px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.color-field { display: flex; gap: 10px; align-items: center; }
.color-field input[type="color"] {
  width: 42px; height: 42px; padding: 3px;
  border-radius: 10px; cursor: pointer;
  border: 1.5px solid var(--border-mid);
  background: var(--bg3);
}
.color-field input[type="text"] { flex: 1; }

/* API Key field */
.api-key-field {
  display: flex; gap: 8px; align-items: center;
}
.api-key-field input {
  flex: 1;
  background: rgba(255,255,255,.05);
  border: 1.5px solid var(--border-mid);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 14px; font-size: 14px; outline: none;
  transition: border-color var(--transition);
  font-family: monospace;
}
.api-key-field input:focus {
  border-color: rgba(124,58,237,.6);
  box-shadow: 0 0 0 3px rgba(124,58,237,.15);
}
.toggle-key-btn {
  background: rgba(255,255,255,.06);
  border: 1.5px solid var(--border-mid);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 15px;
  transition: all var(--transition);
  flex-shrink: 0;
}
.toggle-key-btn:hover {
  background: rgba(124,58,237,.15);
  border-color: rgba(124,58,237,.5);
  color: #C084FC;
}

/* ===== Layout ======================================================== */
#dashboard-screen { display: flex; height: 100vh; overflow: hidden; }

/* ─ Sidebar ─ */
.sidebar {
  width: var(--sidebar-w);
  background: rgba(13, 15, 26, 0.75);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 0; flex-shrink: 0;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-nav {
  padding: 16px 12px;
  display: flex; flex-direction: column;
  gap: 4px; flex: 1;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 10px;
  color: rgba(255,255,255,.45);
  font-size: 14px; font-weight: 500;
  transition: all var(--transition);
}
.nav-item:hover {
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.85);
}
.nav-item.active {
  background: var(--gradient);
  color: #fff;
  box-shadow: var(--shadow-glow);
}
.nav-icon { font-size: 16px; }
.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--border);
}
.sidebar-footer .btn-ghost { width: 100%; justify-content: center; }

/* ─ Main Content ─ */
.main-content {
  flex: 1; overflow-y: auto; padding: 32px 36px;
  background: transparent;
}
.main-content::-webkit-scrollbar { width: 5px; }
.main-content::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 4px; }

.view { display: none; animation: slide-in .2s ease; }
.view.active { display: block; }

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 28px;
}
.page-header h2 { font-size: 22px; font-weight: 700; color: #F1F5F9; }
.page-header .subtitle { color: var(--text-dim); font-size: 14px; margin-top: 4px; }

/* ─ Stat Cards ─ */
.stats-row { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.stat-card {
  flex: 1; min-width: 140px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
  transition: all var(--transition);
  backdrop-filter: blur(8px);
}
.stat-card:hover {
  background: rgba(255,255,255,.06);
  border-color: rgba(124,58,237,.25);
  transform: translateY(-2px);
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 2px;
  background: var(--gradient);
}
.stat-card .stat-label { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; font-weight: 500; }
.stat-card .stat-value { font-size: 28px; font-weight: 800; color: #F1F5F9; }
.stat-card .stat-sub { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

/* ─ Card / Table ─ */
.card {
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
}
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead {
  background: rgba(255,255,255,.04);
  border-bottom: 1px solid var(--border-mid);
}
th {
  text-align: left; padding: 14px 16px;
  color: var(--text-dim);
  font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .6px;
  white-space: nowrap;
}
td { padding: 14px 16px; border-top: 1px solid var(--border); vertical-align: middle; }
td div[style*="font-weight:600"] { color: #E2E8F0; }
tr:hover td { background: rgba(255,255,255,.02); }
.loading-row { text-align: center; color: var(--text-dim); padding: 48px !important; }

/* ─ Badges ─ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
}
.badge-green {
  background: rgba(16,185,129,.12);
  color: #34D399;
  border: 1px solid rgba(16,185,129,.2);
}
.badge-red {
  background: rgba(239,68,68,.12);
  color: #F87171;
  border: 1px solid rgba(239,68,68,.2);
}
.badge-blue {
  background: rgba(37,99,235,.12);
  color: #60A5FA;
  border: 1px solid rgba(37,99,235,.2);
  font-size: 11px;
}

/* ─ Actions ─ */
.action-cell { display: flex; gap: 6px; align-items: center; }

/* ===== Analíticas ===================================================== */
.analytics-controls {
  display: flex; gap: 10px; align-items: center;
}
.analytics-select {
  background: rgba(255,255,255,.05);
  border: 1.5px solid var(--border-mid);
  border-radius: 10px;
  color: var(--text);
  padding: 8px 14px;
  font-size: 13px;
  font-family: 'Poppins', sans-serif;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
}
.analytics-select:focus {
  border-color: rgba(124,58,237,.6);
}
.analytics-select option { background: var(--bg2); }

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 0;
}
.chart-card { overflow: visible; }
.chart-header {
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--border);
}
.chart-header h3 {
  font-size: 15px; font-weight: 700; color: #F1F5F9;
  margin-bottom: 4px;
}
.chart-subtitle { font-size: 12px; color: var(--text-dim); }
.chart-container {
  padding: 16px 20px 20px;
  height: 260px;
  position: relative;
}

/* ===== Modal ========================================================= */
.modal-overlay {
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity:0; } }

.modal-card {
  background: rgba(20, 22, 38, 0.97);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-mid);
  border-radius: 20px;
  padding: 28px;
  width: 100%; max-width: 640px;
  animation: slide-in .25s ease;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg), 0 0 80px rgba(124,58,237,.08);
  position: relative;
}
.modal-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--gradient);
  border-radius: 20px 20px 0 0;
}

/* Modal ancho para el formulario con live preview */
.modal-wide {
  max-width: 1060px;
  padding: 28px;
  overflow: hidden; /* el scroll se maneja en modal-layout */
}

.modal-layout {
  display: flex;
  gap: 28px;
  align-items: flex-start;
  max-height: calc(90vh - 100px);
}

.modal-form-col {
  flex: 1;
  overflow-y: auto;
  max-height: calc(90vh - 110px);
  padding-right: 8px;
}
.modal-form-col::-webkit-scrollbar { width: 4px; }
.modal-form-col::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 4px; }

.modal-preview-col {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: sticky;
  top: 0;
}

.modal-sm { max-width: 480px; }
.modal-card::-webkit-scrollbar { width: 4px; }
.modal-card::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 4px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
}
.modal-header h3 { font-size: 18px; font-weight: 700; color: #F1F5F9; }
.modal-close {
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 16px; cursor: pointer; padding: 6px 9px;
  border-radius: 8px; transition: all var(--transition); line-height: 1;
}
.modal-close:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.modal-form { display: flex; flex-direction: column; gap: 20px; }
.modal-actions {
  display: flex; gap: 12px; justify-content: flex-end;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ===== Live Preview — Phone Frame ==================================== */
.preview-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  text-align: center;
}

.phone-frame {
  width: 240px;
  height: 480px;
  background: #111827;
  border-radius: 36px;
  border: 6px solid #374151;
  position: relative;
  box-shadow:
    0 0 0 1px rgba(255,255,255,.06),
    0 20px 60px rgba(0,0,0,.6),
    inset 0 0 0 1px rgba(255,255,255,.04);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Botones laterales del teléfono */
.phone-frame::before {
  content: '';
  position: absolute;
  left: -9px; top: 90px;
  width: 4px; height: 32px;
  background: #374151;
  border-radius: 2px 0 0 2px;
  box-shadow: 0 44px 0 #374151;
}
.phone-frame::after {
  content: '';
  position: absolute;
  right: -9px; top: 110px;
  width: 4px; height: 50px;
  background: #374151;
  border-radius: 0 2px 2px 0;
}

.phone-notch {
  width: 80px; height: 20px;
  background: #111827;
  border-radius: 0 0 14px 14px;
  margin: 0 auto;
  position: relative;
  z-index: 10;
  border: 4px solid #374151;
  border-top: none;
}

.phone-screen {
  flex: 1;
  background: #f1f5f9;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.phone-home-bar {
  height: 16px;
  background: #111827;
  display: flex;
  align-items: center;
  justify-content: center;
}
.phone-home-bar::after {
  content: '';
  width: 60px; height: 4px;
  background: #374151;
  border-radius: 2px;
}

/* ── Widget Preview ── */
.widget-preview {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  font-family: 'Poppins', sans-serif;
  background: #f8f9fb;
  transition: background var(--transition);
}

.wp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: #7C3AED;
  flex-shrink: 0;
  transition: background var(--transition);
}
.wp-header-left { display: flex; align-items: center; gap: 8px; }
.wp-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  overflow: hidden;
}
.wp-avatar img { width: 100%; height: 100%; object-fit: cover; }
.wp-name { font-size: 11px; font-weight: 700; color: #fff; line-height: 1.2; }
.wp-status { font-size: 9px; color: rgba(255,255,255,.75); }
.wp-close-btn {
  width: 20px; height: 20px;
  background: rgba(255,255,255,.2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: #fff; cursor: pointer;
}

.wp-body {
  flex: 1;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
  background: #f8f9fb;
  transition: background var(--transition);
}

.wp-bubble {
  max-width: 85%;
  padding: 7px 10px;
  border-radius: 12px;
  font-size: 9.5px;
  line-height: 1.4;
  word-break: break-word;
  transition: background var(--transition), color var(--transition);
}
.wp-bubble.bot {
  background: #ffffff;
  color: #1a1a2e;
  border-radius: 2px 12px 12px 12px;
  align-self: flex-start;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.wp-bubble.user {
  background: #7C3AED;
  color: #ffffff;
  border-radius: 12px 12px 2px 12px;
  align-self: flex-end;
  transition: background var(--transition);
}

.wp-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  background: #fff;
  border-top: 1px solid rgba(0,0,0,.08);
  flex-shrink: 0;
}
.wp-input {
  flex: 1;
  background: #f1f5f9;
  border-radius: 16px;
  padding: 5px 10px;
  font-size: 9px;
  color: #94a3b8;
}
.wp-send {
  width: 24px; height: 24px;
  background: #7C3AED;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: #fff;
  cursor: pointer;
  transition: background var(--transition);
}

/* Botón flotante */
.wp-fab {
  position: absolute;
  bottom: 56px;
  right: 10px;
  width: 36px; height: 36px;
  background: #7C3AED;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(124,58,237,.5);
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition);
  display: none; /* Se muestra solo cuando el widget está "cerrado" en el preview */
}

/* ===== Code block ==================================================== */
.code-block {
  position: relative;
  background: rgba(0,0,0,.4);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 70px 16px 16px;
  margin: 12px 0 24px;
}
.code-block pre {
  font-family: 'Courier New', monospace; font-size: 13px;
  color: #94D3FC; white-space: pre-wrap; word-break: break-all;
}
.copy-btn {
  position: absolute; top: 10px; right: 10px;
  background: var(--gradient);
  color: #fff; border: none;
  border-radius: 6px; padding: 5px 12px; font-size: 12px;
  cursor: pointer; transition: opacity var(--transition);
  font-weight: 600; box-shadow: var(--shadow-glow);
}
.copy-btn:hover { opacity: .85; }

/* ===== Docs ========================================================== */
.docs-card { padding: 28px; }
.docs-card h3 {
  font-size: 15px; font-weight: 700; margin-bottom: 8px;
  color: var(--accent2);
  display: flex; align-items: center; gap: 8px;
}
.docs-card h3::before {
  content: '';
  display: inline-block;
  width: 4px; height: 16px;
  background: var(--gradient);
  border-radius: 2px;
}
.docs-card p { color: var(--text-dim); font-size: 14px; margin-bottom: 4px; }

/* ===== Toast ========================================================= */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(20, 22, 38, 0.95);
  backdrop-filter: blur(16px);
  color: var(--text);
  padding: 12px 24px; border-radius: 30px;
  font-size: 14px; font-weight: 500; z-index: 99999;
  box-shadow: var(--shadow-lg);
  animation: toast-in .3s ease;
  white-space: nowrap;
  border: 1px solid var(--border-mid);
}
@keyframes toast-in { from { opacity:0; transform: translate(-50%, 16px); } }
.toast.success { border-color: rgba(16,185,129,.4); }
.toast.error   { border-color: rgba(239,68,68,.4); }

/* ===== Status containers (logo/icono/pdf/scrape) ===================== */
#logo-status-container,
#icono-status-container,
#pdf-status-container,
#scrape-status-container {
  background: rgba(255,255,255,.04) !important;
  border: 1px solid var(--border-mid) !important;
  color: var(--text) !important;
}
#logo-status-container a,
#icono-status-container a,
#pdf-status-container a {
  color: #C084FC !important;
}

/* ===== Responsive ===================================================== */
@media (max-width: 900px) {
  .modal-layout { flex-direction: column; }
  .modal-preview-col { width: 100%; align-items: center; }
  .modal-wide { max-width: 95vw; }
  .charts-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { padding: 20px 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-row { flex-wrap: wrap; }
  .analytics-controls { flex-wrap: wrap; gap: 8px; }
}
