/* FUNDHEG Scanner — minimal, high-contrast, phone-first styles.
   No animations, no decorative elements: speed and clarity only. */

:root {
  --bg: #ffffff;
  --surface: #f2f3f5;
  --text: #111827;
  --muted: #4b5563;
  --primary: #1155cc;
  --primary-ink: #ffffff;
  --border: #c9ced6;
  --danger: #b42318;
  --radius: 12px;
  --radius-lg: 16px;
  --tap: 56px;
}

* { box-sizing: border-box; }

/* The hidden attribute must win over .btn's display and any other author rule. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app { min-height: 100vh; min-height: 100dvh; }

/* --- Screens ------------------------------------------------------------- */

.screen { display: none; }

.screen.is-active {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* --- Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 12px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.btn[disabled] { opacity: 0.45; cursor: default; }

.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}

.btn--xl {
  width: 100%;
  min-height: 72px;
  font-size: 21px;
  letter-spacing: 0.03em;
  border-radius: var(--radius-lg);
}

.btn--ghost { background: transparent; }

.btn--wide { width: 100%; }

.btn--capture {
  width: 88px;
  height: 88px;
  min-height: 88px;
  padding: 0;
  border-radius: 50%;
  border: 4px solid var(--primary-ink);
  background: var(--primary);
  color: var(--primary-ink);
  font-size: 13px;
  letter-spacing: 0.06em;
}

/* --- Home ---------------------------------------------------------------- */

.home {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 24px;
  text-align: center;
}

.home__title {
  margin: 0;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.home__tagline {
  margin: 0;
  font-size: 18px;
  color: var(--muted);
}

.home__note {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--muted);
}

/* Logo de FUNDHEG sobre el título: nunca más alto que 80 px y sin deformar.
   En pantallas bajas se achica para no empujar los botones fuera de vista. */
.home__logo {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 80px;
  margin: 0 auto;
  object-fit: contain;
}

/* Crédito del desarrollador: solo en la pantalla de inicio, texto plano. */
.home__credit {
  margin: 8px 0 0;
  font-size: 12px;
  color: #6B7280;
}

/* --- Camera -------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}

.topbar__title {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.topbar__spacer { width: 72px; }

.camera {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  padding: 0 12px 12px;
}

.camera__stage {
  position: relative;
  flex: 1;
  min-height: 240px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: #000;
}

.camera__stage video,
.camera__stage .camera__still {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.camera__guide {
  position: absolute;
  inset: 6%;
  border: 2px dashed rgba(255, 255, 255, 0.85);
  border-radius: 8px;
  pointer-events: none;
}

.camera__hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  margin: 0;
  color: #ffffff;
  font-size: 14px;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.camera__stage.is-still .camera__guide { display: none; }

.camera__controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.message {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 5px solid var(--danger);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 15px;
}

.message--info { border-left-color: var(--primary); }

/* --- Corner adjustment and corrected page (Phase 2) ---------------------- */

.crop {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  padding: 0 12px 12px;
}

.crop__hint {
  margin: 0;
  font-size: 15px;
  color: var(--muted);
}

.crop__stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 55dvh;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: #000;
}

.crop__canvas,
.crop__image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Dragging a handle must never scroll the page. */
.crop__canvas { touch-action: none; }

.crop__image { object-fit: contain; }

.crop__controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.crop__controls .btn--wide { grid-column: 1 / -1; }

/* Filtros de la página corregida (Fase H2): cuatro botones en una fila. */
.filters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.filter-btn {
  min-height: 48px;
  padding: 8px 4px;
  font-size: 13px;
  letter-spacing: 0.01em;
}

.filter-btn--active {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
}

/* --- Pages list and PDF (Phases 3-4) ------------------------------------- */

.pages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 0 12px 12px;
}

.pages__list {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.pages__item {
  display: grid;
  grid-template-columns: 64px 1fr;
  grid-template-areas: "thumb info" "thumb actions";
  gap: 4px 12px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.pages__thumb-wrap {
  grid-area: thumb;
  position: relative;
  width: 64px;
  height: 84px;
}

.pages__thumb {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  border-radius: 6px;
}

.pages__badge {
  position: absolute;
  top: 2px;
  left: 2px;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--primary);
  color: var(--primary-ink);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.pages__info {
  grid-area: info;
  font-size: 15px;
  font-weight: 600;
}

.pages__actions {
  grid-area: actions;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pages__actions .btn {
  min-height: 44px;
  padding: 6px 12px;
  font-size: 14px;
}

.pages__empty {
  padding: 16px;
  color: var(--muted);
  text-align: center;
}

.pages__controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pages__size {
  margin: 0;
  font-size: 15px;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field__label {
  font-size: 14px;
  color: var(--muted);
}

.field__input {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.field__input:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* --- Landscape / larger screens ------------------------------------------ */

@media (orientation: landscape) and (max-height: 520px) {
  .camera { flex-direction: row; }
  .camera__stage { flex: 1 1 auto; }
  .camera__controls { flex: 0 0 150px; justify-content: center; }
  .topbar { padding: 4px 12px; }
}

/* Teléfonos bajos en vertical: el logo se achica para que los botones entren. */
@media (max-height: 640px) {
  .home__logo { max-height: 56px; }
}

/* --- Aviso de versión nueva (PWA) ---------------------------------------- */

.updatebar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 10;
  min-height: var(--tap);
  padding: 12px 16px;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  touch-action: manipulation;
}
