*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-500: #6b7280;
  --gray-900: #111827;
  --red: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  color: var(--gray-900);
  background: var(--gray-50);
  min-height: 100dvh;
}

/* ── Landing ─────────────────────────────────────────── */
.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 2rem;
}

.landing-inner {
  text-align: center;
  max-width: 360px;
}

.landing-title {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -.02em;
  margin-bottom: 1rem;
}

.landing-desc {
  color: var(--gray-500);
  line-height: 1.6;
  margin-bottom: 2rem;
}

/* ── App header ───────────────────────────────────────── */
/* 4 zonas (ADR-0003 área App, corrige la Decisión 4 del ADR-0002): mobile
   apila en 3 filas (título+controles / nombre de planilla / email); desktop
   las junta en una sola fila. */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "left right" "center center" "email email";
  align-items: center;
  gap: .25rem 1rem;
  padding: .75rem 1rem;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
}
@media (min-width: 700px) {
  .app-header {
    grid-template-columns: 1fr auto auto 1fr;
    grid-template-areas: "left center email right";
  }
}

.header-left { grid-area: left; }
.header-right { grid-area: right; justify-self: end; }

/* Nombre de la planilla (o "Conectá tu planilla" sin conectar) — trunca
   con ellipsis, nunca rompe el layout del header. Límite más agresivo en
   mobile que en desktop. */
.header-center {
  grid-area: center;
  justify-self: center;
  display: block;
  min-width: 0;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--blue);
  font-weight: 500;
  font-size: .85rem;
  text-decoration: none;
}
.header-center:hover { text-decoration: underline; }
@media (min-width: 700px) {
  .header-center { max-width: 320px; }
}

/* Email de la cuenta logueada — texto discreto, sin acción de click. */
.header-email {
  grid-area: email;
  justify-self: center;
  display: block;
  min-width: 0;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--gray-500);
  font-size: .76rem;
}
@media (min-width: 700px) {
  .header-email { justify-self: start; max-width: 200px; }
}

/* Contador de facturas del mes (ADR-0008 repo general) — discreto, al
   lado de "Configuración". */
.header-contador {
  color: var(--gray-500);
  font-size: .78rem;
  white-space: nowrap;
}

.app-title {
  font-weight: 700;
  font-size: 1.1rem;
}

/* ── Screens ──────────────────────────────────────────── */
.screen { display: none; padding: 1rem; }
.screen.active { display: block; }

/* Ancho máximo del contenido en desktop (ADR-0002 área App) — en mobile no
   tiene efecto (el viewport ya es más angosto que el max-width). */
.contenido-centrado { max-width: 760px; margin: 0 auto; }

/* Jerarquía tipográfica de la home (ADR-0004 área App): título del header
   > .entrada > .feedback. */
.entrada {
  color: var(--gray-900);
  font-weight: 500;
  font-size: 1rem;
  line-height: 1.5;
  text-align: center;
  margin-bottom: .5rem;
}

.feedback {
  color: var(--gray-500);
  font-size: .88rem;
  line-height: 1.5;
  text-align: center;
  margin-bottom: 1rem;
}

/* Tip rotativo (ADR-0004 área App, rediseño visual — adenda 2026-07-15):
   tarjeta con ícono, debajo de la dropzone, arriba de "Últimas facturas".
   Fondo celeste (mismo tono que el foco de los inputs, #eef4ff) para no
   confundirse con el amarillo de .aviso-limite/.aviso-duplicado. El JS de
   rotación (static/js/app.js) no cambia: sigue togglando "hidden" y
   "tip-oculto" solo en #tip-rotativo — el show/hide y el fade de la
   tarjeta entera (ícono incluido) se resuelven acá con :has(), sin tocar
   la lógica de rotación. Las reglas en .tip-rotativo quedan como resguardo
   por si algún navegador no soporta :has(). */
.tip-card {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: .75rem 0;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  background: #eef4ff;
  opacity: 1;
  transition: opacity .3s ease;
}
.tip-card:has(> .tip-rotativo.hidden) { display: none; }
.tip-card:has(> .tip-rotativo.tip-oculto) { opacity: 0; }

.tip-icono {
  flex: none;
  width: 1.4rem;
  height: 1.4rem;
  color: var(--blue);
}

.tip-rotativo {
  flex: 1;
  min-width: 0;
  color: var(--gray-900);
  font-size: .92rem;
  line-height: 1.4;
  margin: 0;
  min-height: 1.2em;
  opacity: 1;
  transition: opacity .3s ease;
}
.tip-rotativo.hidden,
.tip-rotativo.tip-oculto { opacity: 0; }
.tip-rotativo.hidden { display: none; }

/* ── Overlay de espera (ADR-0005 general) ────────────────
   Cubre cold start de Render y el tiempo de extracción (reintentos
   automáticos ante 503 de Gemini incluidos, invisibles para el
   usuario) — tapa cualquier .screen, arriba del header sticky
   (z-index 10). Reutiliza .tip-card/.tip-icono/.tip-rotativo tal cual
   para el mensaje rotativo. */
.overlay-espera {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(249, 250, 251, .96);
}
.overlay-espera.hidden { display: none; }

.overlay-espera-contenido {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  width: 100%;
  max-width: 420px;
}
.overlay-espera-contenido .tip-card { width: 100%; margin: 0; }
.overlay-espera-contenido .tip-rotativo { text-align: center; }

.spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid var(--gray-200);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: girar .8s linear infinite;
}
@keyframes girar {
  to { transform: rotate(360deg); }
}

/* ── Capture screen ───────────────────────────────────── */
.capture-area {
  display: flex;
  justify-content: center;
  padding: 1.5rem 0;
}

.btn-capture {
  font-size: 1.1rem;
  padding: .9rem 2rem;
  border-radius: 999px;
  gap: .5rem;
}

.section-title {
  font-size: .85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-500);
  margin-bottom: .75rem;
}

.invoice-list { display: flex; flex-direction: column; gap: .5rem; }

.invoice-item {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: .1rem .5rem;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  box-shadow: var(--shadow);
}

.inv-razon { font-weight: 500; grid-column: 1; }
.inv-total { font-weight: 700; color: var(--blue); grid-column: 2; grid-row: 1; text-align: right; }
.inv-fecha { font-size: .8rem; color: var(--gray-500); grid-column: 1 / -1; }

.list-placeholder, .list-empty, .list-error {
  text-align: center;
  color: var(--gray-500);
  padding: 2rem 0;
  font-size: .9rem;
}
.list-error { color: var(--red); }

/* ── Review screen ────────────────────────────────────── */
.review-image-wrap {
  width: 100%;
  max-height: 200px;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--gray-100);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.review-image-wrap img {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
}

.review-form { display: flex; flex-direction: column; gap: .75rem; }

.field-label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .85rem;
  font-weight: 500;
  color: var(--gray-500);
}

.field-label input {
  font-size: 1rem;
  color: var(--gray-900);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: .6rem .75rem;
  background: #fff;
  outline: none;
  transition: border-color .15s;
}

.field-label input:focus { border-color: var(--blue); }

.review-actions {
  display: flex;
  gap: .75rem;
  margin-top: .5rem;
}

.review-actions .btn { flex: 1; }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .7rem 1.25rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background .15s, opacity .15s;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.hidden { display: none; }

.btn-primary {
  background: var(--blue);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }

.btn-ghost {
  background: transparent;
  color: var(--gray-500);
  border: 1px solid var(--gray-200);
}
.btn-ghost:hover:not(:disabled) { background: var(--gray-100); }

.btn-lg { padding: .9rem 2rem; font-size: 1.1rem; }

/* ── Status messages ──────────────────────────────────── */
.status-msg {
  padding: .6rem .9rem;
  border-radius: 8px;
  font-size: .9rem;
  background: var(--gray-100);
  margin-bottom: .75rem;
}
.status-msg.error { background: #fef2f2; color: var(--red); }
.status-msg.hidden { display: none; }

/* ── Dropzone (captura) ───────────────────────────────── */
.zona {
  display: block;
  border: 2px dashed var(--gray-500);
  border-radius: var(--radius);
  background: #fff;
  padding: 1.75rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.zona.arrastrando { border-color: var(--blue); background: #eef4ff; }
.zona p { margin: .15rem 0; color: var(--gray-500); font-size: .9rem; }
.zona-formatos { color: #bbb; font-size: .78rem; margin-top: .4rem; }
/* Mientras se procesa una tanda (ADR-0001 área App, punto c: sin botón
   manual) no se puede soltar/elegir otra tanda hasta que termine. */
.zona.procesando { opacity: .6; pointer-events: none; }

/* ── Cards de revisión ────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  margin-bottom: .9rem;
  overflow: hidden;
}
.card.pendiente { border-left: 4px solid var(--blue); }
.card.guardado { border-left: 4px solid #2e9e5b; opacity: .85; }
.card.con-error { border-left: 4px solid var(--red); }

.card-header {
  background: var(--gray-50);
  padding: .5rem .75rem .5rem 1rem;
  font-size: .87rem;
  font-weight: 600;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.btn-descartar {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  border: 1px solid var(--red);
  background: #fff;
  color: var(--red);
  cursor: pointer;
  font-size: .78rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  padding: .35rem .65rem;
  border-radius: 999px;
}
.btn-descartar:hover { background: #fdf0ee; }

.card-body { padding: .8rem 1rem; }
.card-footer { padding: .4rem 1rem .8rem; }

/* Grilla externa: 1 columna en celular, 2 en desktop (ADR-0001 área App,
   punto b). Cada .campo-item es un par label+control autocontenido. */
.campos-grid { display: grid; grid-template-columns: 1fr; gap: .5rem 1.5rem; }
@media (min-width: 700px) {
  .campos-grid { grid-template-columns: repeat(2, 1fr); }
}

.campo-item { display: grid; grid-template-columns: 80px 1fr; gap: .5rem .7rem; align-items: center; }
.campo-label { font-size: .81rem; color: var(--gray-500); text-align: right; }

/* Campos poco frecuentes ocultos por defecto si vinieron vacíos (ADR-0001
   área App, punto a) — el botón "Mostrar campos ocultos" los despliega. */
.campo-item.campo-oculto { display: none; }
.campos-grid.mostrar-ocultos .campo-item.campo-oculto { display: grid; }

.btn-mostrar-ocultos {
  display: block;
  width: 100%;
  margin-top: .6rem;
  padding: .4rem;
  border: none;
  background: none;
  color: var(--blue);
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
}
.btn-mostrar-ocultos:hover { text-decoration: underline; }

.campo-ctrl {
  width: 100%;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  padding: .32rem .5rem;
  font-size: .87rem;
  font-family: inherit;
  background: #fff;
}
.campo-ctrl:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px #eef4ff; }
.campo-ctrl.campo-vacio { border-color: #e67e22; background: #fffbf5; }
.campo-ctrl.campo-invalido { border-color: var(--red); background: #fdf0ee; }
/* Campo completado con baja certeza por la IA (ADR-0008) — aviso visual, no bloquea guardar */
.campo-ctrl.campo-en-duda { border-color: var(--red); background: #fdf0ee; }

.msg-validacion { font-size: .82rem; color: #e67e22; margin-bottom: .45rem; display: none; }

/* Aviso de posible factura duplicada (ADR-0009 planillas) — informativo, no bloquea el guardado */
.aviso-duplicado {
  margin: .6rem 1rem 0;
  padding: .5rem .75rem;
  border-radius: 8px;
  background: #fff8e6;
  color: #b5750a;
  font-size: .85rem;
}

/* Aviso de acercarse al tope mensual de facturas (ADR-0008 repo general) —
   mismo lenguaje visual que .aviso-duplicado, informativo, no bloquea. */
.aviso-limite {
  margin-bottom: 1rem;
  padding: .6rem .9rem;
  border-radius: 8px;
  background: #fff8e6;
  color: #b5750a;
  font-size: .85rem;
  text-align: center;
}
.aviso-limite.hidden { display: none; }
.ok-msg { font-size: .85rem; color: #2e9e5b; padding: .3rem 0; }
.error-msg { font-size: .83rem; color: var(--red); }

.btn-reintentar-ia {
  width: 100%;
  padding: .6rem;
  border-radius: 7px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--red);
  background: #fff;
  color: var(--red);
  margin-top: .6rem;
}
.btn-reintentar-ia:disabled { opacity: .5; cursor: not-allowed; }

/* ── Cuenta regresiva tras guardar la tanda (reemplaza al botón único de
   guardado en su mismo lugar, sin cambiar de pantalla — las tarjetas
   guardadas quedan visibles arriba) ──────────────────────────────────── */
.exito-texto {
  width: 100%;
  margin-top: 1rem;
  padding: .8rem 1rem;
  border-radius: var(--radius);
  background: #f0fdf4;
  color: #2e9e5b;
  font-size: 1rem;
  font-weight: 500;
  text-align: center;
}
.exito-texto.hidden { display: none; }

/* ── Configuración de planilla ────────────────────────── */
.subtitulo { color: var(--gray-500); margin-bottom: 1.5rem; font-size: .93rem; }
.paso {
  background: #fff;
  border: 1px solid var(--gray-500);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}
.paso h2 { font-size: .95rem; font-weight: 600; margin-bottom: .6rem; }
.paso p { font-size: .88rem; color: var(--gray-500); line-height: 1.55; }
.email-sa {
  display: inline-flex;
  align-items: center;
  gap: 2.4rem;
  margin-top: .75rem;
  background: var(--gray-50);
  border: 1px solid var(--gray-500);
  border-radius: 8px;
  padding: .55rem .9rem;
  max-width: 100%;
}
.email-sa code { font-size: .88rem; word-break: break-all; }

/* Botón de copiar (paso 1 config) y "Crear planilla nueva" (paso 2) —
   mismo formato: fondo azul, texto blanco. Al copiar, pasa a texto verde
   cursiva "Copiado" (sin fondo, deja de leerse como botón activo). */
.btn-copiar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .5rem 1.1rem;
  border: none;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-copiar:hover:not(:disabled) { background: var(--blue-dark); }
.btn-copiar.copiado {
  background: transparent;
  color: #2e9e5b;
  font-style: italic;
}
.input-planilla {
  display: block;
  width: 100%;
  margin-top: .75rem;
  padding: .55rem .75rem;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: .9rem;
  font-family: inherit;
}
.input-planilla:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px #eef4ff; }
