/* ====== ScanPro — estilos ============================================== */
:root {
  --bg: #0f172a;
  --bg-elev: #1e293b;
  --bg-card: #ffffff;
  --text: #f1f5f9;
  --text-dark: #0f172a;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary-h: #1d4ed8;
  --danger: #ef4444;
  --success: #10b981;
  --border: #334155;
  --radius: 12px;
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  --safe-top: env(safe-area-inset-top);
  --safe-bot: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ---- Pantallas ------------------------------------------------------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bot);
}
.screen.active { display: flex; }

/* ---- Barra superior -------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar-overlay {
  position: absolute; top: 0; left: 0; right: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.6), transparent);
  border-bottom: none;
  z-index: 5;
}
.pages-count { font-size: 14px; color: #fff; opacity: 0.85; }

/* ---- Botones --------------------------------------------------------- */
.btn-primary {
  display: block; width: 100%;
  padding: 14px 16px;
  background: var(--primary);
  color: #fff; border: none; border-radius: var(--radius);
  font-size: 16px; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-primary:hover { background: var(--primary-h); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-icon {
  background: transparent; color: inherit; border: none;
  font-size: 22px; cursor: pointer; padding: 6px 10px;
  border-radius: 8px;
}
.btn-icon:hover { background: rgba(255,255,255,0.08); }
.btn-icon-lg { font-size: 28px; background: rgba(255,255,255,0.1); border: none; color: #fff; width: 48px; height: 48px; border-radius: 50%; cursor: pointer; }

/* ---- Login ----------------------------------------------------------- */
#screen-login { background: linear-gradient(160deg, #0f172a, #1e293b); justify-content: center; align-items: center; padding: 32px; }
.login-box { width: 100%; max-width: 380px; }
.brand { text-align: center; margin-bottom: 32px; }
.brand-logo { font-size: 64px; line-height: 1; }
.brand h1 { font-size: 32px; margin: 8px 0 4px; }
.brand-tagline { color: var(--muted); margin: 0; }

form label { display: block; margin-bottom: 14px; }
form label > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
form input[type="text"], form input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}
form input:focus { border-color: var(--primary); }
.error-msg { color: var(--danger); font-size: 14px; margin-top: 10px; text-align: center; }
.info-msg { color: var(--muted); font-size: 14px; margin-top: 10px; text-align: center; }

/* ---- Lista ----------------------------------------------------------- */
#screen-list { background: var(--bg); }
.docs-list {
  list-style: none;
  padding: 12px 12px 120px;
  margin: 0;
  overflow-y: auto;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.doc-card {
  position: relative;
  background: var(--bg-elev);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.thumb {
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #0b1220;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.thumb-loading { color: var(--muted); font-size: 24px; opacity: 0.5; }
.thumb-pdf {
  color: var(--muted);
  font-size: 42px;
  text-align: center;
  line-height: 1.2;
}
.thumb-pdf small { font-size: 11px; letter-spacing: 1px; }
.doc-meta { padding: 8px 10px 4px; min-width: 0; }
.doc-name {
  font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.doc-actions {
  display: flex; gap: 4px; justify-content: flex-end;
  padding: 0 6px 8px;
}
.doc-actions .btn-icon { font-size: 18px; padding: 4px 8px; }
@media (min-width: 600px) {
  .docs-list { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 900px) {
  .docs-list { grid-template-columns: repeat(4, 1fr); }
}

.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); text-align: center; padding: 32px;
}
.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.5; }

.fab {
  position: fixed; right: 20px; bottom: calc(24px + var(--safe-bot));
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--primary); color: #fff;
  border: none; font-size: 32px; font-weight: 300;
  box-shadow: var(--shadow);
  cursor: pointer; z-index: 10;
}

/* ---- Cámara ---------------------------------------------------------- */
#screen-camera { background: #000; }
.camera-stage { position: relative; flex: 1; overflow: hidden; }
#camera-video { width: 100%; height: 100%; object-fit: cover; }
.overlay { position: absolute; inset: 0; pointer-events: none; }
.cam-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 32px calc(18px + var(--safe-bot));
  background: rgba(0,0,0,0.7);
}
.shoot-btn {
  width: 76px; height: 76px; border-radius: 50%;
  background: #fff; border: 6px solid rgba(255,255,255,0.4);
  cursor: pointer; padding: 0;
}
.shoot-btn:active { transform: scale(0.95); }

/* Indicador del estado del detector */
.detector-status {
  position: absolute; left: 50%; top: 70px; transform: translateX(-50%);
  padding: 8px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 500; color: #fff;
  background: rgba(0,0,0,0.65);
  z-index: 6; max-width: 90vw; text-align: center;
}
.detector-status.loading { background: rgba(37, 99, 235, 0.85); }
.detector-status.ok      { background: rgba(34, 197, 94, 0.85); }
.detector-status.warn    { background: rgba(234, 88, 12, 0.85); }

/* Flash blanco cuando se captura (efecto camara real) */
#shutter-flash {
  position: fixed; inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  transition: opacity 0.15s ease-out;
}

/* Panel de debug visible (solo cuando se activa con ?debug=1).
   Se posiciona ARRIBA para no tapar los botones de capturar. */
.debug-log {
  position: absolute; left: 8px; right: 8px; top: 110px;
  background: rgba(0,0,0,0.85); color: #0f0;
  font-family: monospace; font-size: 11px;
  padding: 8px; border-radius: 8px;
  max-height: 30vh; overflow-y: auto;
  z-index: 4;
  pointer-events: none;
}
.debug-log div { margin: 2px 0; }
.debug-log .err { color: #f66; }
.debug-log .warn { color: #fc6; }
.debug-log .ok { color: #6f6; }

/* ---- Editor ---------------------------------------------------------- */
#screen-editor { background: #1a1a1a; }
.editor-stage {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 12px; overflow: hidden;
}
#editor-canvas {
  max-width: 100%; max-height: 100%;
  background: #fff;
  touch-action: none;
}
.editor-tools { padding: 12px 16px calc(12px + var(--safe-bot)); background: var(--bg); border-top: 1px solid var(--border); }
.tool-row { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.tool {
  flex: 1; min-width: 70px;
  padding: 10px 8px;
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; font-weight: 500; cursor: pointer;
}
.tool.active { background: var(--primary); border-color: var(--primary); }

/* ---- Save form ------------------------------------------------------- */
#screen-save { background: var(--bg); }
.save-form { padding: 20px 16px; overflow-y: auto; flex: 1; }
.save-form fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; }
.save-form legend { padding: 0 8px; color: var(--muted); font-size: 13px; }
.save-form .radio, .save-form .checkbox { display: flex; align-items: center; gap: 8px; padding: 8px 0; cursor: pointer; }

/* ---- Toast ----------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-bot)); transform: translateX(-50%);
  background: var(--bg-elev); color: var(--text);
  padding: 12px 18px; border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 100;
  font-size: 14px;
  max-width: 90vw;
}
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
