/* ===== Colores (claro y oscuro según el celular) ===== */
:root {
  --fondo: #f4f3f0;
  --superficie: #ffffff;
  --texto: #1f1f1f;
  --suave: #6b6b6b;
  --borde: #e1dfda;
  --acento: #1a73e8;
  --acento-texto: #ffffff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #121212;
    --superficie: #1e1e1e;
    --texto: #ececec;
    --suave: #a3a3a3;
    --borde: #2f2f2f;
    --acento: #5b9cf5;
    --acento-texto: #0b1a33;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--fondo);
  color: var(--texto);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
[hidden] { display: none !important; }

.vista {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100%;
  padding: env(safe-area-inset-top) 16px calc(96px + env(safe-area-inset-bottom));
}
.vista.oscura {
  position: fixed; inset: 0;
  max-width: none;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  background: #111; color: #f2f2f2;
}

/* ===== Barras ===== */
.barra { display: flex; align-items: center; gap: 4px; min-height: 56px; }
.barra h1 { margin: 0; font-size: 1.4rem; }
.oscura .barra { padding: 0 4px; }
.icono {
  width: 48px; height: 48px; flex: none;
  border: 0; border-radius: 50%;
  background: transparent;
  display: grid; place-items: center;
}
.icono svg { width: 24px; height: 24px; fill: currentColor; }
.icono:active { background: rgba(128, 128, 128, 0.25); }
.nombre-doc {
  flex: 1; min-width: 0;
  height: 44px;
  border: 1px solid transparent; border-radius: 10px;
  background: transparent;
  padding: 0 10px;
  font-weight: 600; font-size: 1.05rem;
  text-overflow: ellipsis;
}
.nombre-doc:focus { border-color: var(--borde); background: var(--superficie); outline: none; }
.titulo-pagina { flex: 1; text-align: center; font-weight: 600; }

/* ===== Botones ===== */
.boton {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px;
  padding: 0 20px;
  border: 0; border-radius: 16px;
  font-weight: 600;
}
.boton svg { width: 22px; height: 22px; fill: currentColor; }
.boton.principal { background: var(--acento); color: var(--acento-texto); }
.boton.secundario { background: var(--superficie); border: 1px solid var(--borde); }
.boton.texto { background: transparent; color: inherit; padding: 0 12px; }

.acciones-fijas {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; justify-content: flex-end;
  background: linear-gradient(transparent, var(--fondo) 30%);
  max-width: 720px; margin: 0 auto;
}
.acciones-fijas .principal { flex: 1.4; }
.acciones-fijas .secundario { flex: 1; }

/* ===== Inicio ===== */
.lista-docs { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; }
.doc {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--borde); border-radius: 14px;
  background: var(--superficie);
  text-align: left;
}
.doc img { width: 56px; height: 72px; object-fit: cover; border-radius: 6px; background: var(--borde); flex: none; }
.texto-doc { min-width: 0; }
.doc .nombre { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc .detalle { display: block; font-size: 0.85rem; color: var(--suave); }
.vacio { text-align: center; color: var(--suave); margin: 56px 16px; }

/* ===== Documento ===== */
.cuadricula { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 12px; margin-top: 8px; }
.miniatura {
  position: relative;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 1px solid var(--borde); border-radius: 8px;
  background: var(--superficie);
  overflow: hidden;
}
.miniatura img { width: 100%; height: 100%; object-fit: contain; display: block; }
.miniatura .numero {
  position: absolute; left: 6px; bottom: 6px;
  min-width: 24px; height: 24px; padding: 0 6px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.7); color: #fff;
  font-size: 0.8rem; font-weight: 700;
  display: grid; place-items: center;
}
.agregar-fila { display: flex; gap: 10px; margin-top: 16px; }
.agregar-fila .boton { flex: 1; }
.tamano { display: flex; align-items: center; gap: 8px; margin-top: 16px; color: var(--suave); }
.tamano button, .filtros button {
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--borde); border-radius: 20px;
  background: transparent;
}
.tamano button[aria-pressed="true"] { background: var(--acento); color: var(--acento-texto); border-color: var(--acento); }

/* ===== Recorte ===== */
.ayuda { text-align: center; margin: 10px 16px 0; font-size: 0.9rem; color: #cfcfcf; min-height: 22px; }
.area-recorte { flex: 1; min-height: 0; display: grid; place-items: center; }
.marco-foto { position: relative; }
.marco-foto canvas { display: block; width: 100%; height: 100%; }
.marco { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; touch-action: none; }
.marco .contorno { fill: rgba(26, 115, 232, 0.18); stroke: #4d94ff; stroke-width: 2.5; }
.marco .contorno.invalido { fill: rgba(220, 40, 40, 0.18); stroke: #ff5252; }
.marco .esquina { fill: rgba(255, 255, 255, 0.25); stroke: #fff; stroke-width: 3; }
.marco .esquina.activa { fill: rgba(77, 148, 255, 0.6); }
.lupa {
  position: fixed;
  width: 132px; height: 132px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 50;
}
.barra-inferior { display: flex; align-items: center; gap: 4px; padding: 8px 12px 12px; }
.barra-inferior .principal { margin-left: auto; min-width: 120px; }

/* ===== Página ===== */
.area-pagina { flex: 1; min-height: 0; display: grid; place-items: center; padding: 8px 16px; }
.area-pagina img { max-width: 100%; max-height: 100%; object-fit: contain; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.6); background: #fff; }
.filtros { display: flex; gap: 8px; justify-content: center; padding: 8px 12px 0; flex-wrap: wrap; }
.filtros button { border-color: #444; color: #eee; }
.filtros button[aria-pressed="true"] { background: #4d94ff; border-color: #4d94ff; color: #0b1a33; font-weight: 600; }

/* ===== Procesando y avisos ===== */
.procesando {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.45);
  z-index: 40;
}
.procesando span { padding: 14px 22px; border-radius: 14px; background: #222; color: #fff; }
.aviso {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(92px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  min-height: 48px;
  padding: 10px 10px 10px 16px;
  border-radius: 12px;
  background: #2b2b2b; color: #f2f2f2;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  z-index: 60;
}
.aviso button { margin-left: auto; border: 0; background: transparent; color: #8ab4ff; font-weight: 700; padding: 8px 10px; }
