/* ============================================================
   CargadorCursos — Sistema de diseño
   Tipografía: Inter (UI) + Plus Jakarta Sans (display)
   ============================================================ */

:root {
  /* Marca */
  --brand: #0b5cab;
  --brand-2: #1570ef;
  --brand-ink: #08427e;
  --accent: #12b76a;
  --accent-2: #039855;
  --danger: #d92d20;
  --danger-2: #b42318;
  --amber: #b54708;

  /* Neutros */
  --bg: #eaeef5;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --surface-3: #eef2f8;
  --border: #e6eaf1;
  --border-strong: #d5dce7;
  --txt: #0f1728;
  --txt-2: #475467;
  --txt-3: #98a2b3;

  /* Formas */
  --r-lg: 20px;
  --r: 14px;
  --r-sm: 10px;
  --pill: 999px;

  /* Sombras */
  --sh-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --sh: 0 8px 24px -10px rgba(16, 24, 40, 0.18), 0 2px 6px -2px rgba(16, 24, 40, 0.07);
  --sh-lg: 0 28px 56px -18px rgba(16, 24, 40, 0.32);
  --ring: 0 0 0 4px rgba(21, 112, 239, 0.16);

  /* Tipos */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --display: 'Plus Jakarta Sans', var(--font);

  --topbar-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #121a2b;
    --surface-2: #0f1826;
    --surface-3: #1a2438;
    --border: #24304a;
    --border-strong: #2d3a57;
    --txt: #eaf0fb;
    --txt-2: #9fb0cc;
    --txt-3: #6b7c9c;
    --sh: 0 10px 30px -12px rgba(0, 0, 0, 0.6), 0 2px 8px -2px rgba(0, 0, 0, 0.5);
    --sh-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --sh-lg: 0 30px 60px -18px rgba(0, 0, 0, 0.75);
  }
}

* { box-sizing: border-box; }
/* El atributo hidden debe ganar siempre, aunque el componente defina display:flex.
   (Aplica a #toast, #topbar y los botones de la barra que se togglean con hidden.) */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--txt);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

/* Fondo con degradado sutil tipo aurora */
.bg-aurora {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60% 45% at 12% 0%, rgba(21, 112, 239, 0.16), transparent 60%),
    radial-gradient(50% 40% at 100% 8%, rgba(18, 183, 106, 0.12), transparent 60%),
    radial-gradient(70% 50% at 50% 100%, rgba(11, 92, 171, 0.08), transparent 70%);
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  min-height: var(--topbar-h);
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: linear-gradient(120deg, var(--brand-2), var(--brand) 70%, var(--brand-ink));
  color: #fff;
  box-shadow: 0 6px 20px -10px rgba(11, 92, 171, 0.7);
}
.topbar-title {
  flex: 1; text-align: center;
  font-family: var(--display); font-weight: 700; font-size: 17px; letter-spacing: -0.01em;
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; flex-shrink: 0;
  background: rgba(255, 255, 255, 0.16); color: #fff;
  border: none; border-radius: 11px; cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.3); transform: scale(0.94); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- Layout ---------- */
.app {
  max-width: 640px; margin: 0 auto;
  padding: 18px 16px calc(40px + env(safe-area-inset-bottom));
}

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--sh-sm);
  margin-bottom: 14px;
}
.card h2 {
  font-family: var(--display); font-weight: 700; font-size: 19px;
  letter-spacing: -0.015em; margin: 0 0 4px; color: var(--txt);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card .muted { color: var(--txt-2); font-size: 13.5px; line-height: 1.45; }

/* ---------- Formularios ---------- */
label {
  display: block; font-size: 12.5px; font-weight: 600; color: var(--txt-2);
  margin: 14px 0 6px; letter-spacing: 0.01em;
}
label .opt { color: var(--txt-3); font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 12px 14px; font-size: 16px; font-family: var(--font);
  color: var(--txt); background: var(--surface);
  border: 1.5px solid var(--border-strong); border-radius: 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none; appearance: none;
}
input::placeholder { color: var(--txt-3); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-2); box-shadow: var(--ring);
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
  padding-right: 40px;
}
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

.field-msg { font-size: 12.5px; margin-top: 6px; min-height: 16px; font-weight: 600; display: flex; align-items: center; gap: 5px; }
.field-msg.ok { color: var(--accent-2); }
.field-msg.err { color: var(--danger); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  width: 100%; padding: 13px 18px; margin-top: 10px;
  font-family: var(--font); font-size: 15.5px; font-weight: 600; letter-spacing: 0.01em;
  border: none; border-radius: 13px; cursor: pointer;
  background: linear-gradient(120deg, var(--brand-2), var(--brand));
  color: #fff; box-shadow: 0 8px 18px -8px rgba(11, 92, 171, 0.6);
  transition: transform 0.1s, box-shadow 0.15s, filter 0.15s;
}
.btn:active { transform: translateY(1px) scale(0.992); filter: brightness(0.97); }
.btn svg { width: 20px; height: 20px; }

.btn.secondary {
  background: var(--surface-3); color: var(--brand); box-shadow: none;
  border: 1px solid var(--border);
}
.btn.ghost {
  background: transparent; color: var(--brand); box-shadow: none;
  border: 1.5px solid var(--border-strong);
}
.btn.verde {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 18px -8px rgba(4, 152, 85, 0.55);
}
.btn.rojo {
  background: #fdecec; color: var(--danger-2); box-shadow: none;
  border: 1px solid #f8cfca;
}
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-grid .btn { margin-top: 0; }

/* ---------- Listas ---------- */
.list-item {
  display: flex; align-items: center; gap: 13px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 13px 14px; margin-bottom: 10px;
  box-shadow: var(--sh-sm); cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, border-color 0.15s;
}
.list-item:active { transform: scale(0.99); border-color: var(--border-strong); box-shadow: var(--sh); }
.list-item .info { flex: 1; min-width: 0; }
.list-item .info .titulo {
  font-weight: 600; font-size: 15px; color: var(--txt);
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
}
.list-item .info .sub {
  color: var(--txt-2); font-size: 12.5px; margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chev { flex-shrink: 0; color: var(--txt-3); display: flex; }
.chev svg { width: 20px; height: 20px; }

/* Avatar / icono redondo */
.avatar {
  width: 44px; height: 44px; border-radius: 13px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-weight: 700; font-size: 15px; color: #fff;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  box-shadow: 0 6px 14px -6px rgba(11, 92, 171, 0.55);
}
.avatar.ico svg { width: 22px; height: 22px; }

/* ---------- Buscador ---------- */
.search { position: relative; margin-top: 12px; }
.search > svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 19px; height: 19px; color: var(--txt-3); pointer-events: none; }
.search input { padding-left: 42px; }

/* ---------- Paginador ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.pager label { margin: 0; font-size: 13px; color: var(--txt-2); display: flex; align-items: center; gap: 8px; font-weight: 500; }
.pager select { width: auto; padding: 8px 34px 8px 12px; font-size: 14px; border-radius: 10px; }
.pnav { display: flex; align-items: center; gap: 6px; }
.pnav .info { font-size: 13px; color: var(--txt-2); min-width: 90px; text-align: center; font-variant-numeric: tabular-nums; }
.pg-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  background: var(--surface); color: var(--brand); border: 1px solid var(--border-strong);
  transition: background 0.15s, transform 0.1s;
}
.pg-btn:active { transform: scale(0.94); }
.pg-btn:disabled { color: var(--txt-3); opacity: 0.5; cursor: not-allowed; }
.pg-btn svg { width: 20px; height: 20px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.01em;
  padding: 3px 10px; border-radius: var(--pill);
  background: var(--surface-3); color: var(--txt-2);
}
.badge svg { width: 13px; height: 13px; }
.badge.ok { background: #e6f6ee; color: var(--accent-2); }
.badge.err { background: #fdecec; color: var(--danger-2); }
.badge.abierto { background: #e7f0fd; color: var(--brand); }
.badge.cerrado { background: var(--surface-3); color: var(--txt-2); }
.badge.ocr { background: #efeafc; color: #6b46c1; }

/* ---------- Estados vacíos ---------- */
.empty { text-align: center; color: var(--txt-2); padding: 30px 16px; }
.empty .big { margin-bottom: 12px; }
.empty .big svg { width: 84px; height: 84px; }
.empty .t { font-family: var(--display); font-weight: 700; color: var(--txt); font-size: 16px; margin-bottom: 4px; }

/* ---------- Errores / avisos ---------- */
.err-list { margin: 6px 0 0; padding-left: 18px; color: var(--danger); font-size: 13px; }
.warn {
  color: var(--amber); font-size: 13px; line-height: 1.45;
  background: #fef6ee; border: 1px solid #fde6cf; border-radius: 12px;
  padding: 10px 12px; margin-top: 8px;
}

/* ---------- Cámara ---------- */
.cam-wrap {
  position: relative; background: #05121f; border-radius: var(--r);
  overflow: hidden; aspect-ratio: 3/2; box-shadow: var(--sh);
}
.cam-wrap video, .cam-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-guide {
  position: absolute; inset: 10% 7%; border: 2px dashed rgba(255, 255, 255, 0.75);
  border-radius: 12px; pointer-events: none;
}
.cam-hint { text-align: center; color: var(--txt-2); font-size: 13px; margin: 12px 0 2px; min-height: 18px; }

/* ---------- Efecto de escaneo láser ---------- */
.scan-wrap {
  position: relative; width: 100%; aspect-ratio: 3/2;
  border-radius: var(--r); overflow: hidden; background: #05121f; box-shadow: var(--sh);
}
.scan-img { width: 100%; height: 100%; object-fit: cover; display: block; filter: brightness(0.9) contrast(1.05); }
.scan-grid {
  position: absolute; inset: 0; pointer-events: none; mix-blend-mode: screen;
  background-image: repeating-linear-gradient(0deg, rgba(56, 247, 176, 0.1) 0, rgba(56, 247, 176, 0.1) 1px, transparent 1px, transparent 6px);
}
.scan-line {
  position: absolute; left: 0; right: 0; top: 3%; height: 2px; pointer-events: none;
  background: linear-gradient(90deg, transparent, #38f7b0 30%, #eafff6 50%, #38f7b0 70%, transparent);
  box-shadow: 0 0 14px 3px rgba(56, 247, 176, 0.8), 0 0 44px 10px rgba(56, 247, 176, 0.35);
  animation: scanline 1.6s ease-in-out infinite alternate;
}
.scan-line::after {
  content: ''; position: absolute; left: 0; right: 0; top: 2px; height: 48px;
  background: linear-gradient(180deg, rgba(56, 247, 176, 0.35), transparent);
}
.scan-frame { position: absolute; inset: 8px; border-radius: 8px; pointer-events: none; box-shadow: inset 0 0 0 2px rgba(56, 247, 176, 0.22); }
.scan-frame::before, .scan-frame::after { content: ''; position: absolute; width: 28px; height: 28px; border: 3px solid #38f7b0; }
.scan-frame::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; border-top-left-radius: 8px; }
.scan-frame::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; border-bottom-right-radius: 8px; }
.scan-status { text-align: center; color: var(--accent-2); font-size: 14px; font-weight: 600; margin-top: 14px; letter-spacing: 0.02em; }
.scan-status .spinner { display: inline-block; vertical-align: middle; margin-right: 8px; }
@keyframes scanline { 0% { top: 3%; } 100% { top: 97%; } }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16, 24, 40, 0.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fade 0.15s ease;
}
.modal { max-width: 420px; width: 100%; margin: 0; box-shadow: var(--sh-lg); animation: pop 0.18s ease; }
.modal h2 { margin-top: 0; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #101828; color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 500; z-index: 200; box-shadow: var(--sh-lg);
  max-width: 90%; display: flex; align-items: center; gap: 8px;
  animation: toastin 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.toast.err { background: linear-gradient(120deg, #e8493f, var(--danger-2)); }
.toast.ok { background: linear-gradient(120deg, var(--accent), var(--accent-2)); }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Spinner ---------- */
.spinner {
  width: 22px; height: 22px; border: 3px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite;
}
.spinner.dark { border-color: rgba(11, 92, 171, 0.22); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }
.center { display: flex; justify-content: center; align-items: center; gap: 10px; padding: 28px; color: var(--txt-2); }

/* ---------- Utilidades ---------- */
.section-title {
  font-size: 12px; font-weight: 700; color: var(--txt-3);
  text-transform: uppercase; letter-spacing: 0.06em; margin: 20px 4px 10px;
}
.hr { height: 1px; background: var(--border); margin: 18px 0; border: 0; }

/* ---------- Marca / Login ---------- */
.brand { text-align: center; margin: 34px 0 22px; }
.brand-mark {
  width: 76px; height: 76px; margin: 0 auto 16px; border-radius: 22px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brand-2), var(--brand) 65%, var(--brand-ink));
  box-shadow: 0 18px 40px -14px rgba(11, 92, 171, 0.7);
}
.brand-mark svg { width: 42px; height: 42px; }
.brand .logo {
  font-family: var(--display); font-size: 27px; font-weight: 800;
  color: var(--txt); letter-spacing: -0.02em;
}
.brand .logo b { color: var(--brand); }
.brand .tag { color: var(--txt-2); font-size: 14px; margin-top: 6px; line-height: 1.4; }
.ver-tag { text-align: center; color: var(--txt-3); font-size: 11px; margin-top: 18px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
