/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --ink: #171a21;
  --muted: #5b6472;
  --line: #e3e6eb;
  --accent: #2453ff;
  --accent-ink: #ffffff;
  --accent-soft: #eaf0ff;
  --ok: #1a8a54;
  --ok-soft: #e7f6ee;
  --warn: #b3690a;
  --warn-soft: #fdf1e3;
  --danger: #c62b3a;
  --danger-soft: #fbe9eb;
  --demo: #b3690a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 24, 33, .04), 0 8px 24px rgba(20, 24, 33, .06);
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015;
    --surface: #161922;
    --ink: #eef0f4;
    --muted: #a2a9b6;
    --line: #2a2f3b;
    --accent: #6b8bff;
    --accent-ink: #0e1015;
    --accent-soft: #1c2340;
    --ok-soft: #10281d;
    --warn-soft: #2c2010;
    --danger-soft: #2c1418;
  }
}

/* =============================================================
   2. Reset & base
   ============================================================= */
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; tab-size: 2; scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
img, svg, video { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
p { text-wrap: pretty; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.15; letter-spacing: -0.01em; font-family: var(--serif); }
ul { list-style: none; padding: 0; }
::selection { background: var(--accent); color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.skip-link {
  position: fixed; top: -100px; left: 1rem; padding: .6rem 1rem;
  background: var(--ink); color: var(--bg); z-index: 9999; border-radius: 8px; font-weight: 600;
}
.skip-link:focus { top: 1rem; }

/* =============================================================
   3. Utilities
   ============================================================= */
.container { width: min(1120px, 92%); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.muted { color: var(--muted); }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; } .mt-4 { margin-top: 2.5rem; }

/* =============================================================
   4. Typography
   ============================================================= */
h1 { font-size: clamp(2.1rem, 4.5vw, 3.4rem); }
h2 { font-size: clamp(1.6rem, 3vw, 2.3rem); }
h3 { font-size: 1.2rem; }
.eyebrow {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft); padding: .35rem .7rem; border-radius: 99px;
}

/* =============================================================
   5. Components
   ============================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .8rem 1.4rem; border-radius: 10px; font-weight: 600; font-size: .96rem;
  transition: transform .15s var(--ease-out), background .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { box-shadow: 0 6px 20px rgba(36,83,255,.28); }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: .5rem .9rem; font-size: .85rem; border-radius: 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.75rem;
}

.badge {
  display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; font-weight: 700;
  padding: .3rem .65rem; border-radius: 99px;
}
.badge-demo { background: var(--warn-soft); color: var(--demo); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-tipo { background: var(--accent-soft); color: var(--accent); text-transform: none; font-weight: 600; }

.notice {
  border-radius: var(--radius-sm); padding: .9rem 1.1rem; font-size: .92rem; display: flex; gap: .6rem; align-items: flex-start;
}
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-danger { background: var(--danger-soft); color: var(--danger); }
.notice-ok { background: var(--ok-soft); color: var(--ok); }

.toast-stack {
  position: fixed; top: 1rem; right: 1rem; z-index: 1000; display: flex; flex-direction: column; gap: .6rem;
  max-width: min(360px, 90vw);
}
.toast {
  background: var(--ink); color: var(--bg); padding: .8rem 1rem; border-radius: 10px; font-size: .9rem;
  box-shadow: var(--shadow); animation: toast-in .25s var(--ease-out);
}
.toast-danger { background: var(--danger); color: #fff; }
.toast-ok { background: var(--ok); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10,12,18,.55); display: grid; place-items: center;
  padding: 1.5rem; z-index: 900;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 2rem; width: min(440px, 100%);
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); position: relative;
}
.modal-close {
  position: absolute; top: 1rem; right: 1rem; width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center; color: var(--muted);
}
.modal-close:hover { background: var(--bg); }
.field { margin-top: 1rem; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .35rem; }
.field input {
  width: 100%; padding: .7rem .85rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit;
}
.field input:focus { border-color: var(--accent); }
.field-error { color: var(--danger); font-size: .82rem; margin-top: .3rem; min-height: 1.1em; }
.form-switch { margin-top: 1.2rem; font-size: .88rem; text-align: center; color: var(--muted); }
.form-switch button { color: var(--accent); font-weight: 600; }

/* =============================================================
   6. Sections — marketing
   ============================================================= */
.nav {
  position: sticky; top: 0; z-index: 500; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.nav-row { display: flex; align-items: center; justify-content: space-between; padding: 1rem 0; }
.logo { font-family: var(--serif); font-weight: 600; font-size: 1.2rem; display: flex; align-items: center; gap: .5rem; }
.logo svg { width: 24px; height: 24px; }
.nav-links { display: none; gap: 1.6rem; font-size: .92rem; font-weight: 500; }
.nav-actions { display: flex; align-items: center; gap: .7rem; }
@media (min-width: 720px) { .nav-links { display: flex; } }

.hero { padding: 4.5rem 0 3rem; }
.hero-grid { display: grid; gap: 2.5rem; align-items: center; }
@media (min-width: 960px) { .hero-grid { grid-template-columns: 1.05fr .95fr; gap: 3rem; } }
.hero h1 { margin-top: 1rem; }
.hero-sub { margin-top: 1.1rem; font-size: 1.1rem; color: var(--muted); max-width: 46ch; }
.hero-cta { display: flex; flex-wrap: wrap; gap: .9rem; margin-top: 1.8rem; }
.hero-trust { margin-top: 1.6rem; font-size: .85rem; color: var(--muted); }

/* Before/after visual */
.baf { position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); background: var(--surface); }
.baf-doc { display: block; width: 100%; height: auto; }
.baf-slider {
  position: absolute; inset: 0; width: 100%; height: 100%; appearance: none; background: transparent;
  cursor: ew-resize; margin: 0; z-index: 5;
}
.baf-slider::-webkit-slider-thumb {
  appearance: none; width: 40px; height: 40px; border-radius: 50%; background: var(--surface);
  border: 3px solid var(--accent); box-shadow: var(--shadow); margin-top: 0;
}
.baf-after { position: absolute; inset: 0; overflow: hidden; }
.baf-after svg { position: absolute; inset: 0; }
.baf-handle-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); pointer-events: none; }
.baf-label { position: absolute; top: 10px; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: .3rem .6rem; border-radius: 99px; background: rgba(0,0,0,.65); color: #fff; }
.baf-label.left { left: 10px; }
.baf-label.right { right: 10px; }

.section { padding: 4rem 0; }
.section-head { max-width: 640px; margin-bottom: 2.4rem; }
.section-head p { color: var(--muted); margin-top: .7rem; }

.steps { display: grid; gap: 1.2rem; counter-reset: step; }
@media (min-width: 720px) { .steps { grid-template-columns: repeat(4, 1fr); } }
.step { position: relative; padding-top: 2.6rem; }
.step::before {
  counter-increment: step; content: counter(step);
  position: absolute; top: 0; left: 0; width: 2.1rem; height: 2.1rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-family: var(--sans);
}
.step h3 { margin-top: .2rem; }
.step p { margin-top: .4rem; color: var(--muted); font-size: .95rem; }

.audience-grid { display: grid; gap: 1.2rem; }
@media (min-width: 720px) { .audience-grid { grid-template-columns: repeat(3, 1fr); } }
.audience-card h3 { margin-bottom: .4rem; }
.audience-card p { color: var(--muted); font-size: .93rem; }

.tipos-grid { display: flex; flex-wrap: wrap; gap: .6rem; }

.pricing-grid { display: grid; gap: 1.4rem; }
@media (min-width: 860px) { .pricing-grid { grid-template-columns: repeat(3, 1fr); } }
.plan { display: flex; flex-direction: column; }
.plan.destacado { border-color: var(--accent); box-shadow: 0 10px 34px rgba(36,83,255,.18); position: relative; }
.plan.destacado::before {
  content: "Más elegido"; position: absolute; top: -12px; left: 1.75rem; background: var(--accent);
  color: var(--accent-ink); font-size: .7rem; font-weight: 700; padding: .3rem .7rem; border-radius: 99px;
}
.plan-precio { display: flex; align-items: baseline; gap: .3rem; margin: .8rem 0 .2rem; }
.plan-precio strong { font-family: var(--serif); font-size: 2.4rem; }
.plan-precio span { color: var(--muted); font-size: .9rem; }
.plan-creditos { font-size: .88rem; color: var(--muted); margin-bottom: 1rem; }
.plan ul { display: flex; flex-direction: column; gap: .55rem; margin: 1.1rem 0 1.4rem; font-size: .9rem; }
.plan li { display: flex; gap: .5rem; align-items: flex-start; }
.plan li svg { flex-shrink: 0; margin-top: .15rem; color: var(--ok); }
.pricing-note { text-align: center; margin-top: 1.6rem; font-size: .85rem; color: var(--muted); }

.faq { display: grid; gap: .8rem; max-width: 760px; }
.faq details { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 1rem 1.2rem; background: var(--surface); }
.faq summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 1rem; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; font-size: 1.3rem; color: var(--accent); }
.faq details[open] summary::after { content: "–"; }
.faq p { margin-top: .7rem; color: var(--muted); font-size: .93rem; }

.footer { border-top: 1px solid var(--line); padding: 2.5rem 0; font-size: .88rem; color: var(--muted); }
.footer-row { display: flex; flex-wrap: wrap; gap: 1.2rem; justify-content: space-between; align-items: center; }
.footer-links { display: flex; gap: 1.2rem; flex-wrap: wrap; }

/* =============================================================
   7. App shell (app.html / cuenta.html)
   ============================================================= */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .85rem 1.4rem; border-bottom: 1px solid var(--line); background: var(--surface);
}
.topbar-left { display: flex; align-items: center; gap: 1.4rem; }
.credits-pill {
  display: inline-flex; align-items: center; gap: .4rem; background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: .9rem; padding: .4rem .8rem; border-radius: 99px; transition: transform .2s var(--ease-out);
}
.credits-pill.bump { transform: scale(1.12); }
.topbar-right { display: flex; align-items: center; gap: .7rem; }
.account-menu { position: relative; }
.account-btn { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; }
.account-dropdown {
  position: absolute; right: 0; top: 46px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); min-width: 180px; padding: .4rem; z-index: 50;
}
.account-dropdown[hidden] { display: none; }
.account-dropdown a, .account-dropdown button {
  display: block; width: 100%; text-align: left; padding: .6rem .7rem; border-radius: 8px; font-size: .9rem;
}
.account-dropdown a:hover, .account-dropdown button:hover { background: var(--bg); }

.demo-bar {
  background: var(--warn-soft); color: var(--demo); text-align: center; font-size: .82rem; font-weight: 700;
  padding: .5rem 1rem;
}

.app-main { flex: 1; padding: 1.6rem; display: flex; flex-direction: column; gap: 1.2rem; }
.app-grid { display: grid; gap: 1.2rem; flex: 1; min-height: 0; }
@media (min-width: 960px) { .app-grid { grid-template-columns: 1.4fr .9fr; } }

.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 3rem 1.5rem; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: .8rem; background: var(--surface);
  transition: border-color .15s, background .15s;
}
.dropzone[data-state="drag"] { border-color: var(--accent); background: var(--accent-soft); }
.dropzone svg { color: var(--accent); }
.dropzone[hidden] { display: none; }

.viewer { display: none; flex-direction: column; gap: 1rem; min-height: 0; }
.viewer[data-active="true"] { display: flex; }
.viewer-toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: space-between; }
.viewer-pages { display: flex; flex-direction: column; gap: 1rem; overflow-y: auto; padding-right: .3rem; max-height: 62vh; }
.page-wrap { position: relative; flex-shrink: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.page-wrap canvas { display: block; width: 100%; height: auto; }
.page-overlay { position: absolute; inset: 0; cursor: default; }
/* touch-action: none evita que el dedo haga scroll mientras dibujas el recuadro. */
.page-overlay.manual-mode { cursor: crosshair; touch-action: none; }
.page-status { position: absolute; top: 8px; left: 8px; font-size: .72rem; font-weight: 700; background: rgba(0,0,0,.6); color: #fff; padding: .25rem .55rem; border-radius: 99px; }
.box-rect { position: absolute; background: #000; opacity: .92; }
.box-rect.off { background: transparent; border: 2px dashed var(--danger); opacity: 1; }
.box-rect.manual { outline: 2px solid var(--accent); }

.side-panel { display: flex; flex-direction: column; gap: 1rem; min-height: 0; }
.detections-card { display: flex; flex-direction: column; gap: .8rem; min-height: 0; }
.detections-list { display: flex; flex-direction: column; gap: .5rem; overflow-y: auto; max-height: 40vh; }
.detection-item {
  display: flex; align-items: center; gap: .6rem; padding: .6rem .7rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: .87rem;
}
.detection-item.off { opacity: .5; }
.detection-item.no-localizada { border-color: var(--danger); background: var(--danger-soft); }
.detection-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detection-toggle { width: 38px; height: 22px; border-radius: 99px; background: var(--line); position: relative; flex-shrink: 0; }
.detection-toggle.on { background: var(--accent); }
.detection-toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .15s var(--ease-out);
}
.detection-toggle.on::after { transform: translateX(16px); }
.detection-del { color: var(--muted); flex-shrink: 0; }
.detection-del:hover { color: var(--danger); }
.empty-hint { font-size: .85rem; color: var(--muted); text-align: center; padding: 1rem 0; }

.cost-line { display: flex; justify-content: space-between; align-items: center; font-size: .9rem; padding: .7rem .9rem; background: var(--bg); border-radius: var(--radius-sm); }
.progress-bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress-bar > span { display: block; height: 100%; background: var(--accent); transition: width .2s; }

.limits-hint { font-size: .8rem; color: var(--muted); }

/* =============================================================
   8. Cuenta / Account
   ============================================================= */
.account-grid { display: grid; gap: 1.2rem; max-width: 780px; margin: 0 auto; width: 100%; }
@media (min-width: 720px) { .account-grid { grid-template-columns: 1fr 1fr; } }
.plan-summary { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.plan-summary strong { font-size: 1.3rem; font-family: var(--serif); }
table.history { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.history th, table.history td { text-align: left; padding: .55rem .3rem; border-bottom: 1px solid var(--line); }
table.history th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }

/* =============================================================
   9. Legal pages
   ============================================================= */
.legal { padding: 3rem 0 5rem; max-width: 760px; margin: 0 auto; }
.legal h2 { margin-top: 2rem; }
.legal p, .legal li { color: var(--muted); margin-top: .6rem; }
.legal ul { list-style: disc; padding-left: 1.3rem; }
.legal ol { padding-left: 1.3rem; }
.legal h3 { margin-top: 1.6rem; font-size: 1.15rem; }
.legal a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.legal .lead { color: var(--ink); font-size: 1.08rem; }
.legal .notice { margin-top: 1.5rem; }
.guias-list { display: grid; gap: 1rem; margin-top: 1.5rem; }
.guias-list a { text-decoration: none; }
.guias-list h2 { margin-top: 0; font-size: 1.25rem; }

/* =============================================================
   10. Responsive niceties
   ============================================================= */
@media (max-width: 719px) {
  .viewer-pages, .detections-list { max-height: none; }
}

/* =============================================================
   10b. Móvil — menú, cabeceras y áreas de pulsación
   ============================================================= */

/* Menú desplegable con <details>: sin JavaScript, cierra con Escape solo. */
.nav-menu { position: relative; display: none; }
.nav-menu > summary {
  list-style: none; cursor: pointer; width: 44px; height: 44px;
  display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line);
  font-size: 1.1rem; line-height: 1;
}
.nav-menu > summary::-webkit-details-marker { display: none; }
.nav-menu[open] > summary { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.nav-menu-panel {
  position: absolute; right: 0; top: 52px; min-width: 210px; z-index: 600;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .5rem; display: flex; flex-direction: column;
}
.nav-menu-panel a {
  padding: .8rem .9rem; border-radius: 9px; font-weight: 500;
}
.nav-menu-panel a:hover { background: var(--bg); }
.nav-menu-panel .btn { margin-top: .3rem; }

@media (max-width: 719px) {
  .nav-menu { display: block; }
  /* En el móvil, «Iniciar sesión» vive dentro del menú. */
  .nav-actions > [data-open-auth="login"] { display: none; }

  /* Cabecera de la app: el logo enlaza a la herramienta, así que el botón
     «Ir a la herramienta» sobra y era lo que desbordaba la pantalla. */
  .topbar { gap: .6rem; padding: .7rem .9rem; }
  .topbar-left { gap: .7rem; min-width: 0; }
  .topbar-right > .btn-ghost { display: none; }
  .topbar .logo { font-size: .95rem; }

  /* Nada de texto de arrastrar donde no se puede arrastrar. */
  .dropzone { padding: 2.2rem 1.1rem; }

  /* El botón de descarga queda siempre a mano al revisar detecciones. */
  #download-btn {
    position: sticky; bottom: .8rem;
    box-shadow: 0 6px 22px rgba(20, 24, 33, .18);
  }

  .footer-row { gap: .4rem; }
  .footer-links { gap: .2rem; flex-direction: column; }
  .footer-links a { padding: .55rem 0; }
}

/* Áreas de pulsación cómodas en cualquier pantalla táctil. */
@media (hover: none) {
  .btn-sm { min-height: 44px; }
  .detection-toggle { width: 46px; height: 28px; }
  .detection-toggle::after { width: 24px; height: 24px; }
  .detection-toggle.on::after { transform: translateX(18px); }
  .detection-del { min-width: 40px; min-height: 40px; }
  .solo-raton { display: none; }
}
@media (hover: hover) {
  .solo-tactil { display: none; }
}

/* =============================================================
   11. Reduced motion
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .credits-pill.bump { transform: none; }
}
