/* ============================================================
   APOLO PREMIA — Hoja de Estilos Principal
   Fuentes: Outfit (títulos) + DM Sans (cuerpo) + JetBrains Mono (códigos)
   Colores: #c51319 (rojo primario) | #011b35 (azul profundo)
   ============================================================ */

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

/* ---- Variables ------------------------------------------ */
:root {
  --primary:       #c51319;
  --primary-dark:  #a00f14;
  --primary-light: #e8373d;
  --secondary:     #011b35;
  --secondary-mid: #02305c;

  /* Light mode */
  --bg:            #f3f5f8;
  --bg-card:       #ffffff;
  --bg-input:      #f0f2f5;
  --bg-sidebar:    #011b35;
  --text:          #0d1520;
  --text-muted:    #5a6780;
  --text-light:    #8a96aa;
  --border:        #e0e5ee;
  --shadow:        0 2px 16px rgba(1,27,53,.08);
  --shadow-md:     0 6px 32px rgba(1,27,53,.13);
  --radius:        14px;
  --radius-sm:     8px;
  --transition:    .22s cubic-bezier(.4,0,.2,1);

  --success:  #18a761;
  --warning:  #e08d00;
  --danger:   #c51319;
  --info:     #0b72cf;
}

[data-theme="dark"] {
  --bg:         #060e1c;
  --bg-card:    #0c1a2e;
  --bg-input:   #0f2240;
  --bg-sidebar: #040c18;
  --text:       #e8edf5;
  --text-muted: #7a90b0;
  --text-light: #4a6080;
  --border:     #162640;
  --shadow:     0 2px 20px rgba(0,0,0,.35);
  --shadow-md:  0 8px 40px rgba(0,0,0,.50);
}

/* ---- Reset & Base --------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
}

h1,h2,h3,h4,h5 {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  line-height: 1.25;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-light); }

img { max-width: 100%; display: block; }

code, .mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: .88em;
}

/* ---- Layout Shell --------------------------------------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar -------------------------------------------- */
.sidebar {
  width: 240px;
  min-height: 100vh;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 200;
  transition: transform var(--transition);
}

.sidebar-logo {
  padding: 24px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.sidebar-logo .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
}

.sidebar-logo .brand-icon {
  width: 38px; height: 38px;
  background: var(--primary);
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 20px;
}

.sidebar-logo .brand-name {
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 1.1rem;
  line-height: 1.2;
  letter-spacing: -.3px;
}

.sidebar-logo .brand-sub {
  font-size: .68rem;
  color: rgba(255,255,255,.45);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.nav-label {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: rgba(255,255,255,.3);
  padding: 10px 10px 4px;
  margin-top: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.6);
  font-size: .9rem;
  font-weight: 500;
  transition: all var(--transition);
  margin-bottom: 2px;
  cursor: pointer;
}

.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .nav-icon { font-size: 1.1rem; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid rgba(255,255,255,.06);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.05);
}

.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary);
  display: grid; place-items: center;
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: .85rem;
  color: #fff;
  flex-shrink: 0;
}

.user-info { overflow: hidden; }
.user-name { color: #fff; font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: rgba(255,255,255,.4); font-size: .7rem; }

/* ---- Main Content --------------------------------------- */
.main-content {
  flex: 1;
  margin-left: 240px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0; z-index: 100;
  transition: background var(--transition), border-color var(--transition);
}

.topbar-title { font-family: 'Outfit', sans-serif; font-weight: 700; font-size: 1.1rem; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.page-body { padding: 28px; flex: 1; }

/* ---- Cards ---------------------------------------------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.card-sm { padding: 16px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.card-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 700;
}

/* ---- Stat Cards ----------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  transition: all var(--transition);
}

.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.stat-icon {
  width: 50px; height: 50px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-icon.red   { background: rgba(197,19,25,.12); color: var(--primary); }
.stat-icon.blue  { background: rgba(1,27,53,.10); color: var(--secondary-mid); }
.stat-icon.green { background: rgba(24,167,97,.12); color: var(--success); }
.stat-icon.amber { background: rgba(224,141,0,.12); color: var(--warning); }

[data-theme="dark"] .stat-icon.blue { background: rgba(2,48,92,.5); color: #4a9eff; }

.stat-num {
  font-family: 'Outfit', sans-serif;
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.5px;
}

.stat-label { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

/* ---- Buttons -------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); color: #fff; box-shadow: 0 4px 16px rgba(197,19,25,.35); }

.btn-secondary {
  background: var(--secondary);
  color: #fff;
}
.btn-secondary:hover { background: var(--secondary-mid); color: #fff; }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a00f14; color: #fff; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #138550; color: #fff; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-input); color: var(--text); }

.btn-lg { padding: 13px 26px; font-size: 1rem; border-radius: 10px; }
.btn-sm { padding: 6px 13px; font-size: .8rem; }
.btn-icon { padding: 9px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ---- Forms --------------------------------------------- */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: .92rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(197,19,25,.12);
}

.form-control::placeholder { color: var(--text-light); }

.input-group { position: relative; }
.input-group .form-control { padding-left: 42px; }
.input-group .input-icon {
  position: absolute;
  left: 13px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  font-size: 1rem;
  pointer-events: none;
}

/* ---- Tables -------------------------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}

thead th {
  padding: 11px 14px;
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  background: var(--bg-input);
  border-bottom: 1.5px solid var(--border);
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(197,19,25,.03); }

/* ---- Badges -------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
}

.badge-red    { background: rgba(197,19,25,.12); color: var(--primary); }
.badge-green  { background: rgba(24,167,97,.12); color: var(--success); }
.badge-blue   { background: rgba(11,114,207,.12); color: var(--info); }
.badge-amber  { background: rgba(224,141,0,.12); color: var(--warning); }
.badge-gray   { background: var(--bg-input); color: var(--text-muted); }

/* ---- Alert Banner -------------------------------------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 18px;
}

.alert-success { background: rgba(24,167,97,.1); border-left: 3px solid var(--success); color: var(--success); }
.alert-error   { background: rgba(197,19,25,.08); border-left: 3px solid var(--primary); color: var(--primary); }
.alert-warning { background: rgba(224,141,0,.1); border-left: 3px solid var(--warning); color: var(--warning); }
.alert-info    { background: rgba(11,114,207,.1); border-left: 3px solid var(--info); color: var(--info); }

/* ---- Theme Toggle -------------------------------------- */
.theme-toggle {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 1rem;
  color: var(--text-muted);
  transition: all var(--transition);
}
.theme-toggle:hover { border-color: var(--primary); color: var(--primary); }

/* ---- QR Display --------------------------------------- */
.qr-container {
  text-align: center;
  padding: 28px;
}

.qr-frame {
  display: inline-block;
  padding: 18px;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 8px 40px rgba(0,0,0,.18);
  position: relative;
}

.qr-frame::before,
.qr-frame::after {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  border-color: var(--primary);
  border-style: solid;
}

.qr-frame::before {
  top: 6px; left: 6px;
  border-width: 3px 0 0 3px;
  border-radius: 4px 0 0 0;
}

.qr-frame::after {
  bottom: 6px; right: 6px;
  border-width: 0 3px 3px 0;
  border-radius: 0 0 4px 0;
}

#qr-canvas { display: block; border-radius: 8px; }

.qr-label {
  margin-top: 14px;
  font-size: .78rem;
  color: var(--text-light);
  font-family: 'Outfit', sans-serif;
  letter-spacing: .5px;
  text-transform: uppercase;
}

.qr-id {
  font-family: 'JetBrains Mono', monospace;
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: 4px;
  background: var(--bg-input);
  padding: 4px 12px;
  border-radius: 100px;
  display: inline-block;
}

/* ---- Folio Chips --------------------------------------- */
.folio-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.folio-chip {
  font-family: 'JetBrains Mono', monospace;
  font-size: .82rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  color: var(--secondary);
  letter-spacing: 1px;
  transition: all var(--transition);
}

[data-theme="dark"] .folio-chip { color: var(--primary-light); border-color: rgba(197,19,25,.3); }

.folio-chip:hover { border-color: var(--primary); background: rgba(197,19,25,.06); }

/* ---- Scanner UI ---------------------------------------- */
#scanner-box {
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: #000;
  min-height: 280px;
  position: relative;
}

#html5-qrcode-button-camera-permission,
#html5-qrcode-button-camera-start,
#html5-qrcode-button-camera-stop,
#html5-qrcode-anchor-scan-type-change {
  display: none !important;
}

.scan-result-card {
  border-left: 4px solid var(--primary);
  animation: slideIn .3s ease;
}

@keyframes slideIn {
  from { opacity:0; transform: translateY(10px); }
  to   { opacity:1; transform: translateY(0); }
}

/* ---- Auth Pages ---------------------------------------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--secondary);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(197,19,25,.2) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 50%, rgba(2,48,92,.4) 0%, transparent 60%);
  padding: 24px;
}

.auth-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 80px rgba(0,0,0,.4);
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo .logo-icon {
  width: 64px; height: 64px;
  background: var(--primary);
  border-radius: 18px;
  display: inline-grid;
  place-items: center;
  font-size: 2rem;
  margin-bottom: 10px;
  box-shadow: 0 8px 24px rgba(197,19,25,.4);
}

.auth-logo h1 {
  font-size: 1.6rem;
  letter-spacing: -.5px;
}

.auth-logo p {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ---- Client Dashboard Page (no sidebar) ---------------- */
.client-page {
  min-height: 100vh;
  background: var(--bg);
}

.client-topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
}

.client-body { padding: 24px 20px; max-width: 500px; margin: 0 auto; }

/* ---- Hero QR Card -------------------------------------- */
.hero-qr {
  background: linear-gradient(135deg, var(--secondary) 0%, var(--secondary-mid) 100%);
  border-radius: 20px;
  overflow: hidden;
  padding: 30px 24px;
  margin-bottom: 20px;
  position: relative;
}

.hero-qr::before {
  content: '⛽';
  position: absolute;
  right: 20px; top: 20px;
  font-size: 5rem;
  opacity: .06;
}

.hero-qr .greeting {
  font-family: 'Outfit', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.hero-qr .sub {
  font-size: .8rem;
  color: rgba(255,255,255,.5);
  margin-bottom: 20px;
}

.hero-qr .qr-frame {
  margin: 0 auto 12px;
}

.hero-qr .qr-label { color: rgba(255,255,255,.5); }
.hero-qr .qr-id { background: rgba(255,255,255,.08); color: rgba(255,255,255,.5); }

/* ---- Responsive ---------------------------------------- */
.hamburger {
  display: none;
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.hamburger span { display: block; width: 18px; height: 2px; background: var(--text); border-radius: 2px; }

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 30px rgba(0,0,0,.4);
  }
  .main-content { margin-left: 0; }
  .hamburger { display: flex; }
  .page-body { padding: 20px 16px; }
  .topbar { padding: 0 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .auth-card { padding: 28px 22px; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
}

/* ---- Overlay for mobile sidebar ----------------------- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 190;
}
.sidebar-overlay.active { display: block; }

/* ---- Loader ------------------------------------------- */
.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(197,19,25,.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- PDF / Print Grid ---------------------------------- */
@media print {
  body { background: white; color: black; }
  .no-print { display: none !important; }
}

/* ---- Utilities ---------------------------------------- */
.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .82rem; }
.text-xs { font-size: .72rem; }
.font-bold { font-weight: 700; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.w-full  { width: 100%; }
.hidden  { display: none; }
.grid { display: grid; }
.col-2 { grid-template-columns: 1fr 1fr; gap: 16px; }
