/* ─────────────────────────────────────────────
   GrupIA Dashboard — Design System
   Dark Mode · WhatsApp Green + AI Violet
   Font: Inter (Google Fonts)
───────────────────────────────────────────── */

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

/* ── Tokens ──────────────────────────────── */
:root {
  --bg-base:       #0a0e1a;
  --bg-surface:    #111827;
  --bg-card:       #1a2235;
  --bg-hover:      #1e2d44;
  --border:        #243047;

  --wa-green:      #25D366;
  --wa-green-dim:  #1a9e4a;
  --ai-violet:     #7C3AED;
  --ai-violet-dim: #5b21b6;
  --accent-blue:   #3B82F6;
  --accent-amber:  #F59E0B;
  --danger:        #EF4444;

  --text-primary:  #F0F4FF;
  --text-secondary:#8B9EC7;
  --text-muted:    #4A5578;

  --radius-sm:  8px;
  --radius-md:  12px;
  --radius-lg:  16px;
  --radius-xl:  24px;

  --shadow-card: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-glow-green:  0 0 32px rgba(37,211,102,0.25);
  --shadow-glow-violet: 0 0 32px rgba(124,58,237,0.25);

  --transition: 0.22s cubic-bezier(.4,0,.2,1);
}

/* ── Reset & Base ────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; width: 100%; overflow-x: hidden; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  width: 100%;
  display: flex;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; }

/* ── Layout ──────────────────────────────── */
#app { display: flex; width: 100%; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────── */
.sidebar {
  width: 240px;
  min-height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  transition: transform var(--transition);
}
.sidebar-logo {
  padding: 24px 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--wa-green), var(--ai-violet));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.sidebar-logo .logo-text {
  font-size: 18px; font-weight: 800;
  background: linear-gradient(135deg, var(--wa-green), var(--ai-violet));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.sidebar-logo .logo-sub {
  font-size: 10px; color: var(--text-muted);
  font-weight: 500; letter-spacing: 0.05em;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-section-label {
  font-size: 10px; font-weight: 600;
  color: var(--text-muted); letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 12px 8px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(37,211,102,0.15), rgba(124,58,237,0.15));
  color: var(--text-primary);
  border: 1px solid rgba(37,211,102,0.2);
}
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 10px; font-weight: 700;
  padding: 1px 6px;
  border-radius: 99px;
  min-width: 18px; text-align: center;
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--border);
}
.user-pill {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
}
.user-pill:hover { background: var(--bg-hover); }
.user-avatar {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--ai-violet), var(--accent-blue));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role {
  font-size: 10px; color: var(--text-muted);
  text-transform: capitalize;
}
.user-logout {
  font-size: 14px; color: var(--text-muted);
  transition: color var(--transition);
}
.user-logout:hover { color: var(--danger); }

/* ── Main content ────────────────────────── */
.main {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0; /* previene desbordamiento en flex child */
  width: 100%;
}
.topbar {
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  background: var(--bg-surface);
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 20px; font-weight: 700; flex: 1; }
.topbar-subtitle { font-size: 13px; color: var(--text-secondary); }

.content { padding: 28px 32px; flex: 1; }

/* ── Cards ───────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-card);
}
.card-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px;
}
.card-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.card-icon.green  { background: rgba(37,211,102,0.15); }
.card-icon.violet { background: rgba(124,58,237,0.15); }
.card-icon.blue   { background: rgba(59,130,246,0.15); }
.card-icon.amber  { background: rgba(245,158,11,0.15); }
.card-icon.red    { background: rgba(239,68,68,0.15); }

.card-title { font-size: 16px; font-weight: 700; }
.card-subtitle { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ── Stats grid ──────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-card); }
.stat-value { font-size: 28px; font-weight: 800; margin-bottom: 4px; }
.stat-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }

/* ── Buttons ─────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  transition: all var(--transition);
  cursor: pointer;
}
.btn-primary {
  background: linear-gradient(135deg, var(--wa-green), var(--ai-violet));
  color: #fff;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-surface); }
.btn-danger {
  background: rgba(239,68,68,0.15);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.3);
}
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Status badge ────────────────────────── */
.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 12px; font-weight: 600;
}
.status-badge.connected    { background: rgba(37,211,102,0.15); color: var(--wa-green); }
.status-badge.disconnected { background: rgba(239,68,68,0.15);  color: var(--danger); }
.status-badge.connecting   { background: rgba(245,158,11,0.15); color: var(--accent-amber); }
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
}
.status-dot.pulse {
  animation: pulse-dot 1.5s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.7); }
}

/* ── QR Section ──────────────────────────── */
.qr-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 32px;
}
.qr-frame {
  position: relative;
  background: #fff;
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-glow-green);
}
.qr-frame canvas { display: block; }
.qr-ring {
  position: absolute;
  inset: -8px;
  border-radius: calc(var(--radius-md) + 8px);
  border: 2px solid transparent;
  background: linear-gradient(135deg, var(--wa-green), var(--ai-violet)) border-box;
  -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: destination-out;
  mask-composite: exclude;
  animation: ring-pulse 2s ease-in-out infinite;
}
@keyframes ring-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}
.qr-label {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 280px;
  line-height: 1.6;
}
.qr-label strong { color: var(--text-primary); }
.qr-placeholder {
  width: 256px; height: 256px;
  background: var(--bg-surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px;
  color: var(--text-muted);
  font-size: 13px;
}
.qr-placeholder .ph-icon { font-size: 40px; }

/* ── Groups list ─────────────────────────── */
.groups-list { display: flex; flex-direction: column; gap: 12px; }
.group-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex; align-items: center; gap: 16px;
  cursor: pointer;
  transition: all var(--transition);
}
.group-row:hover {
  background: var(--bg-hover);
  border-color: rgba(37,211,102,0.3);
  transform: translateX(4px);
}
.group-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--wa-green-dim), var(--ai-violet-dim));
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700;
  flex-shrink: 0;
}
.group-info { flex: 1; min-width: 0; }
.group-name { font-size: 15px; font-weight: 600; }
.group-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.group-badges { display: flex; gap: 8px; align-items: center; }
.badge {
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px; font-weight: 600;
}
.badge-green  { background: rgba(37,211,102,0.15); color: var(--wa-green); }
.badge-violet { background: rgba(124,58,237,0.15); color: #a78bfa; }
.badge-amber  { background: rgba(245,158,11,0.15); color: var(--accent-amber); }

/* ── Providers grid ──────────────────────── */
.providers-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.provider-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: all var(--transition);
}
.provider-card.is-default {
  border-color: var(--wa-green);
  box-shadow: var(--shadow-glow-green);
}
.provider-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.provider-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.provider-name { font-size: 15px; font-weight: 700; }
.provider-model { font-size: 12px; color: var(--text-muted); }
.provider-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Form ────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color var(--transition);
  outline: none;
}
.form-input:focus { border-color: var(--wa-green); }
.form-input::placeholder { color: var(--text-muted); }
.form-select { appearance: none; cursor: pointer; }

/* ── Table ───────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px; font-weight: 600;
  color: var(--text-muted); letter-spacing: 0.06em; text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 14px 16px; border-bottom: 1px solid rgba(36,48,71,0.5); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-hover); }

/* ── Login page ──────────────────────────── */
.login-wrapper {
  min-height: 100vh; width: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-base);
  position: relative;
  overflow: hidden;
}
.login-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(37,211,102,0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(124,58,237,0.1) 0%, transparent 60%);
}
.login-card {
  position: relative; z-index: 1;
  width: calc(100% - 40px); max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px;
  box-shadow: var(--shadow-card);
}
.login-logo {
  text-align: center; margin-bottom: 32px;
}
.login-logo .logo-big {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--wa-green), var(--ai-violet));
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; margin: 0 auto 12px;
}
.login-logo h1 { font-size: 26px; font-weight: 800; }
.login-logo p { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.login-error {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px; color: var(--danger);
  margin-bottom: 16px;
}

/* ── Alerts / Toast ──────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 999;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  font-size: 14px;
  display: flex; align-items: center; gap: 10px;
  animation: slide-in 0.3s ease-out;
}
.toast.success { border-color: var(--wa-green); }
.toast.error   { border-color: var(--danger); }
@keyframes slide-in {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Skeleton loader ─────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Utilities ───────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-20 { gap: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.mb-4  { margin-bottom: 4px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mt-16 { margin-top: 16px; }
.text-sm    { font-size: 13px; }
.text-xs    { font-size: 11px; }
.text-muted { color: var(--text-secondary); }
.text-green { color: var(--wa-green); }
.text-violet{ color: #a78bfa; }
.font-bold  { font-weight: 700; }
.full-width { width: 100%; }

/* ── Scrollbar ───────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ──────────────────────────── */
.mobile-menu-toggle {
  display: none;
  font-size: 20px;
  color: var(--text-primary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.mobile-menu-toggle:hover {
  background: var(--bg-hover);
}

.responsive-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.8); }
  .main { margin-left: 0; width: 100%; }
  .topbar { padding: 16px 20px; }
  .content { padding: 16px 20px; }
  .card { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .responsive-grid { grid-template-columns: 1fr; }
  .mobile-menu-toggle { display: block; }
  .qr-placeholder { width: 100%; max-width: 256px; }
  #qr-div { max-width: 100%; }
  .qr-frame { width: 100%; max-width: 290px; }
  
  /* Ajustar grid de columnas internas por si quedó algún estilo en línea */
  div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns:1fr 340px"] {
    grid-template-columns: 1fr !important;
  }
}
/* ─── Toggle Switch ─── */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 24px;
}

.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-color);
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
}

input:checked + .slider {
  background-color: var(--primary-color);
}

input:focus + .slider {
  box-shadow: 0 0 1px var(--primary-color);
}

input:checked + .slider:before {
  transform: translateX(16px);
}

.slider.round {
  border-radius: 24px;
}

.slider.round:before {
  border-radius: 50%;
}

/* ─── Inactive Group ─── */
.inactive-group {
  opacity: 0.6;
  filter: grayscale(100%);
  transition: all 0.2s ease;
}

.inactive-group:hover {
  opacity: 0.85;
  filter: grayscale(50%);
}
