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

/* ── Variables ────────────────────────────────────────────── */
:root {
  /* Tema claro */
  --bg-base:        #f1f5f9;   /* slate-100 */
  --bg-surface:     #ffffff;   /* sidebar y cabeceras */
  --bg-card:        #ffffff;   /* cards */
  --bg-elevated:    #f8fafc;   /* inputs / hover */
  --border:         #e2e8f0;   /* gris claro visible */
  --border-hover:   #94a3b8;   /* gris medio */
  --accent:         #0284c7;   /* sky-600, más oscuro para contrastar */
  --accent-dim:     rgba(2,132,199,0.10);
  --accent-2:       #6366f1;   /* indigo-500 */
  --success:        #059669;   /* emerald-600 */
  --warning:        #d97706;   /* amber-600 */
  --danger:         #dc2626;   /* red-600 */
  --text-primary:   #0f172a;   /* slate-900 */
  --text-secondary: #475569;   /* slate-600 */
  --text-muted:     #94a3b8;   /* slate-400 */
  --sidebar-w:      260px;
  --radius:         14px;
  --radius-sm:      8px;
  --shadow:         0 2px 8px rgba(15,23,42,0.06), 0 1px 3px rgba(15,23,42,0.04);
  --transition:     0.2s cubic-bezier(0.4,0,0.2,1);
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body { font-family: 'Outfit', sans-serif; background: var(--bg-base); color: var(--text-primary); min-height: 100vh; -webkit-font-smoothing: antialiased; overflow-x: hidden; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* ── Layout ───────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; max-width: 100vw; overflow-x: hidden; }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 0 24px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.brand-icon {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.brand-text { font-size: 1rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.brand-sub { font-size: 0.7rem; color: var(--text-muted); }

.nav-section { padding: 0 12px; margin-bottom: 8px; }
.nav-label { font-size: 0.65rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; padding: 8px 12px 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 0.9rem; font-weight: 500;
  transition: all var(--transition); margin-bottom: 2px;
}
.nav-item:hover { background: var(--accent-dim); color: var(--accent); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.nav-item .icon { font-size: 1.1rem; width: 20px; text-align: center; }

.sidebar-footer {
  margin-top: auto; padding: 16px 24px 0;
  border-top: 1px solid var(--border);
}
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--bg-card);
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; color: white; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 0.82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.68rem; color: var(--text-muted); }
.btn-logout { background: none; border: none; color: var(--text-muted); font-size: 1rem; padding: 4px; border-radius: 6px; transition: color var(--transition); }
.btn-logout:hover { color: var(--danger); }

/* ── Main Content ─────────────────────────────────────────── */
.main-content { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; width: calc(100% - var(--sidebar-w)); max-width: calc(100% - var(--sidebar-w)); min-width: 0; overflow-x: hidden; }
.page-header { padding: 28px 16px 0; }
.page-title { font-size: 1.6rem; font-weight: 800; color: var(--text-primary); }
.page-subtitle { font-size: 0.85rem; color: var(--text-secondary); margin-top: 4px; }
.page-body { padding: 24px 16px 40px; flex: 1; min-width: 0; max-width: 100%; overflow-x: hidden; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: border-color var(--transition);
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}
.card:hover { border-color: var(--border-hover); }
.card-title { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 16px; }

/* ── KPI Cards ────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; position: relative; overflow: hidden; transition: all var(--transition); }
.kpi-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.kpi-card:hover { transform: translateY(-2px); border-color: var(--border-hover); box-shadow: var(--shadow); }
.kpi-label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.kpi-value { font-size: 2rem; font-weight: 800; color: var(--text-primary); line-height: 1; }
.kpi-sub { font-size: 0.75rem; color: var(--text-secondary); margin-top: 6px; }
.kpi-card.danger::before { background: linear-gradient(90deg, var(--danger), #f97316); }
.kpi-card.success::before { background: linear-gradient(90deg, var(--success), #34d399); }
.kpi-card.warning::before { background: linear-gradient(90deg, var(--warning), #fbbf24); }

/* ── Charts Grid ──────────────────────────────────────────── */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.chart-card canvas { max-height: 280px; }

/* ── Filters ──────────────────────────────────────────────── */
.filters-bar {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 20px;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
}
.filter-group { display: flex; flex-direction: column; gap: 5px; min-width: 150px; flex: 1; }
.filter-group label { font-size: 0.72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.filter-group select, .filter-group input {
  background: #ffffff; border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  padding: 8px 10px; font-size: 0.85rem;
  transition: border-color var(--transition); outline: none;
}
.filter-group select:focus, .filter-group input:focus { border-color: var(--accent); }
.filter-group select option { background: #ffffff; color: var(--text-primary); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-size: 0.85rem; font-weight: 600; border: none;
  transition: all var(--transition); white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #ffffff; }
.btn-primary:hover { background: #0369a1; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(2,132,199,0.25); }
.btn-ghost { background: #ffffff; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--border-hover); color: var(--text-primary); }
.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 12px; font-size: 0.78rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ── Table ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-card); }
table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
thead th { background: #f1f5f9; color: var(--text-secondary); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; padding: 12px 14px; text-align: left; white-space: nowrap; border-bottom: 2px solid var(--border); }
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 11px 14px; color: var(--text-secondary); vertical-align: middle; }
tbody td strong { color: var(--text-primary); }
.table-empty { text-align: center; padding: 48px; color: var(--text-muted); }

/* ── Status Pills ─────────────────────────────────────────── */
.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 0.72rem; font-weight: 600; white-space: nowrap; }
.pill-success { background: rgba(5,150,105,0.12); color: var(--success); border: 1px solid rgba(5,150,105,0.25); }
.pill-warning { background: rgba(217,119,6,0.12); color: var(--warning); border: 1px solid rgba(217,119,6,0.25); }
.pill-danger  { background: rgba(220,38,38,0.10);  color: var(--danger); border: 1px solid rgba(220,38,38,0.25); }
.pill-neutral { background: rgba(148,163,184,0.15); color: var(--text-secondary); border: 1px solid rgba(148,163,184,0.30); }
.pill-accent  { background: rgba(2,132,199,0.10);  color: var(--accent); border: 1px solid rgba(2,132,199,0.25); }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.06em; }
.form-control {
  width: 100%; background: #ffffff; border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary); padding: 10px 14px;
  font-size: 0.88rem; outline: none; transition: border-color var(--transition);
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56,189,248,0.1); }
.form-control::placeholder { color: var(--text-muted); }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.45); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: all var(--transition);
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; width: 90%; max-width: 540px; max-height: 90vh; overflow-y: auto;
  transform: scale(0.95); transition: transform var(--transition);
}
.modal-overlay.open .modal { transform: scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.3rem; padding: 4px; border-radius: 6px; transition: color var(--transition); }
.modal-close:hover { color: var(--danger); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* ── Loader ───────────────────────────────────────────────── */
.page-loader { position: fixed; inset: 0; background: var(--bg-base); z-index: 9999; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 16px; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--bg-elevated); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { font-size: 0.85rem; color: var(--text-muted); }

/* ── Toast ────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 18px; font-size: 0.85rem; display: flex; align-items: center; gap: 10px;
  animation: slideIn 0.3s ease; min-width: 280px; box-shadow: var(--shadow);
}
.toast.success { border-color: rgba(16,185,129,0.4); }
.toast.error   { border-color: rgba(239,68,68,0.4); }
.toast.info    { border-color: rgba(56,189,248,0.4); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Pagination ───────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.pagination-info { font-size: 0.8rem; color: var(--text-muted); margin-right: auto; }

/* ── Glow BG ──────────────────────────────────────────────── */
.bg-glow { position: fixed; top: -200px; left: 50%; transform: translateX(-50%); width: 800px; height: 400px; background: radial-gradient(ellipse, rgba(2,132,199,0.04) 0%, transparent 70%); pointer-events: none; z-index: 0; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .charts-grid { grid-template-columns: 1fr; }
}
