:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --strip: #e4e6ea;
  --text: #1b1e24;
  --muted: #6b7280;
  --border: #e3e5e9;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --ok: #16a34a;
  --warn: #dc2626;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card: #1d2026;
    --strip: #2a2e36;
    --text: #eef0f3;
    --muted: #9aa1ac;
    --border: #2c3038;
    --accent: #60a5fa;
    --accent-soft: #1e3a5f;
    --ok: #4ade80;
    --warn: #f87171;
  }
}

* { box-sizing: border-box; }

/* El atributo [hidden] tiene que ganar siempre, aunque la propia clase del
   elemento (p. ej. .paso { display:flex }) le fije otro display — si no,
   el CSS del autor pisa el "display:none" por defecto del navegador y el
   elemento se queda visible pese a estar "hidden". */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 3rem;
  -webkit-tap-highlight-color: transparent;
}

/* --- Login --------------------------------------------------------------- */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: min(320px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  text-align: center;
}

.login-card input, .login-card button {
  padding: 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
}

.login-card button {
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

.error { color: var(--warn); font-size: 0.9rem; }
.ok { color: var(--ok); font-size: 0.9rem; }

/* --- Cabecera fija -------------------------------------------------------- */

.top-fijo {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--strip);
  border-bottom: 1px solid var(--border);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  padding-top: max(1rem, env(safe-area-inset-top));
}

.volver {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

/* --- Dashboard: solo dos botones, mismo tamaño ---------------------------- */

.dashboard {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  padding: 1.5rem;
  min-height: 100vh;
  min-height: 100dvh;
  justify-content: center;
}

.boton-grande {
  flex: 1;
  max-height: 320px;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  text-decoration: none;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  cursor: pointer;
}

.btn-salir {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  right: 1rem;
  z-index: 10;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.btn-salir svg { width: 1.3rem; height: 1.3rem; }
.btn-salir:active { color: var(--warn); }

.boton-grande:active { background: var(--accent-soft); }

.boton-icono {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.boton-icono svg { width: 2.4rem; height: 2.4rem; }

.boton-texto { font-size: 1.15rem; font-weight: 700; }

/* --- Flujo "nuevo gasto" --------------------------------------------------- */

.flujo-nuevo { padding: 1.5rem; max-width: 480px; margin: 0 auto; }

.paso { display: flex; flex-direction: column; align-items: center; gap: 1.2rem; }

.captura {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--card);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  cursor: pointer;
  text-align: center;
  padding: 1rem;
}

.captura svg { width: 4rem; height: 4rem; }
.captura span { color: var(--text); font-weight: 600; }

.miniatura-paso {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
}

.previews-dobles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  width: 100%;
}

.previews-dobles img {
  width: 100%;
  height: 160px;
  object-fit: contain;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}

#form-datos, #form-editar {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

#form-datos label, #form-editar label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

#form-datos input, #form-editar input,
#form-datos select, #form-editar select {
  padding: 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 1rem;
  background: var(--card);
  color: var(--text);
}

#form-datos button, #form-editar button, .btn-secundario {
  padding: 0.9rem;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}

.ok-grande { font-size: 1.3rem; font-weight: 700; text-align: center; }

.acciones-finales { display: flex; flex-direction: column; gap: 0.8rem; width: 100%; }

/* --- Historial -------------------------------------------------------------- */

.lista-historial {
  padding: 1rem;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.vacio { text-align: center; color: var(--muted); margin-top: 3rem; }

.tarjeta-gasto {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.tarjeta-fotos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  background: var(--border);
}

.tarjeta-foto {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
  background: var(--strip);
}

.tarjeta-cuerpo { padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }

.tarjeta-fila-principal {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.tarjeta-descripcion { font-size: 1.05rem; }
.tarjeta-importe { font-weight: 700; color: var(--accent); white-space: nowrap; }

.tarjeta-meta {
  display: flex;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.tarjeta-acciones {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.accion {
  flex: 1 1 auto;
  min-width: 44%;
  text-align: center;
  padding: 0.55rem 0.4rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
}

.accion-borrar { color: var(--warn); border-color: var(--warn); background: transparent; }

/* --- Editar ------------------------------------------------------------------ */

.pagina-editar {
  padding: 1.5rem;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.preview-editable {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

.preview-editable img {
  width: 100%;
  height: 160px;
  object-fit: contain;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.cambiar-foto {
  font-size: 0.8rem;
  color: var(--accent);
  text-align: center;
  cursor: pointer;
}
