/* Mi Vaqueria - estilos moviles primero */
:root {
  --verde: #2e7d32;
  --verde-osc: #1b5e20;
  --verde-claro: #e8f5e9;
  --crema: #fbf7ec;
  --tierra: #8d6e63;
  --amarillo: #f9a825;
  --rojo: #c62828;
  --azul: #1565c0;
  --texto: #23291f;
  --gris: #6b7280;
  --linea: #e2e0d5;
  --tarjeta: #ffffff;
  --sombra: 0 2px 10px rgba(0, 0, 0, 0.08);
  --radio: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--texto);
  background: var(--crema);
  line-height: 1.5;
  padding-bottom: 78px; /* espacio para la barra inferior */
  min-height: 100vh;
}

/* ---------- Encabezado ---------- */
.encabezado {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--verde);
  color: #fff;
  padding: env(safe-area-inset-top, 0) 1rem 0;
  box-shadow: var(--sombra);
}
.encabezado-fila {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
}
.encabezado h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.encabezado .marca-emoji { font-size: 1.4rem; }
.encabezado .fecha { font-size: 0.8rem; opacity: 0.9; }
.encabezado-derecha { display: flex; align-items: center; gap: 0.7rem; }
.btn-salir {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  min-height: 34px;
  cursor: pointer;
}
.btn-salir:active { background: rgba(255, 255, 255, 0.32); }

/* ---------- Pantalla de acceso (PIN) ---------- */
.pantalla-acceso {
  padding-bottom: 0;
  background: linear-gradient(160deg, var(--verde), var(--verde-osc));
  min-height: 100vh;
}
.acceso {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
}
.acceso-tarjeta {
  background: var(--tarjeta);
  border-radius: 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  padding: 1.8rem 1.4rem 2rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.acceso-titulo {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--verde-osc);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.acceso-titulo .marca-emoji { font-size: 1.8rem; }
.acceso-sub { color: var(--gris); margin-top: 0.3rem; margin-bottom: 1.4rem; }
.pin-puntos {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.2rem;
}
.pin-punto {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--verde);
  background: transparent;
  transition: background 0.12s, transform 0.12s;
}
.pin-punto.lleno { background: var(--verde); transform: scale(1.1); }
.acceso-error {
  color: var(--rojo);
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 1.2em;
  margin-bottom: 0.9rem;
}
.teclado {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
}
.tecla {
  font-family: inherit;
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--texto);
  background: var(--verde-claro);
  border: none;
  border-radius: 16px;
  aspect-ratio: 1 / 1;
  min-height: 64px;
  cursor: pointer;
  display: grid;
  place-items: center;
  user-select: none;
}
.tecla:active { background: #d4ead6; transform: scale(0.96); }
.tecla-borrar { background: transparent; color: var(--verde-osc); font-size: 1.5rem; }
.tecla-borrar:active { background: var(--verde-claro); }
.tecla-vacia { aspect-ratio: 1 / 1; }

/* ---------- Contenido ---------- */
.contenido { max-width: 640px; margin: 0 auto; padding: 1rem; }
.seccion-titulo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0.4rem 0 0.8rem;
}
.seccion-titulo h2 { font-size: 1.1rem; color: var(--verde-osc); }
.subtexto { color: var(--gris); font-size: 0.9rem; }

/* ---------- Tarjetas de resumen ---------- */
.rejilla { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
.metrica {
  background: var(--tarjeta);
  border-radius: var(--radio);
  padding: 1rem;
  box-shadow: var(--sombra);
  border: 1px solid var(--linea);
}
.metrica .valor { font-size: 1.9rem; font-weight: 800; color: var(--verde-osc); line-height: 1.1; }
.metrica .etiqueta { font-size: 0.82rem; color: var(--gris); margin-top: 0.2rem; }
.metrica .emoji { font-size: 1.3rem; }

/* ---------- Tarjetas de lista ---------- */
.lista { display: flex; flex-direction: column; gap: 0.7rem; }
.tarjeta {
  background: var(--tarjeta);
  border-radius: var(--radio);
  padding: 0.9rem 1rem;
  box-shadow: var(--sombra);
  border: 1px solid var(--linea);
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.tarjeta .icono {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  border-radius: 12px;
  background: var(--verde-claro);
  display: grid; place-items: center;
  font-size: 1.5rem;
}
.tarjeta .cuerpo { flex: 1 1 auto; min-width: 0; }
.tarjeta .titulo { font-weight: 700; font-size: 1.02rem; }
.tarjeta .detalle { font-size: 0.85rem; color: var(--gris); }
.tarjeta .accion { flex: 0 0 auto; color: var(--gris); font-size: 1.4rem; background: none; border: none; padding: 0.3rem; cursor: pointer; }

/* ---------- Etiquetas de estado ---------- */
.chip {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.chip-verde { background: var(--verde-claro); color: var(--verde-osc); }
.chip-amarillo { background: #fff3d6; color: #b26a00; }
.chip-rojo { background: #fdecea; color: var(--rojo); }
.chip-azul { background: #e3f0fd; color: var(--azul); }
.chip-gris { background: #eceae1; color: var(--gris); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font-family: inherit; font-size: 1rem; font-weight: 700;
  padding: 0.85rem 1.2rem;
  border-radius: 12px;
  border: none; cursor: pointer;
  min-height: 48px;
}
.btn-primario { background: var(--verde); color: #fff; }
.btn-primario:active { background: var(--verde-osc); }
.btn-secundario { background: #fff; color: var(--verde-osc); border: 2px solid var(--verde); }
.btn-peligro { background: #fff; color: var(--rojo); border: 2px solid var(--rojo); }
.btn-bloque { width: 100%; }
.btn-flotante {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: calc(78px + 1rem);
  z-index: 60;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--amarillo); color: #3a2c00;
  font-size: 2rem; font-weight: 700;
  box-shadow: 0 6px 16px rgba(0,0,0,0.25);
  display: grid; place-items: center;
  border: none; cursor: pointer;
}

/* ---------- Barra inferior ---------- */
.barra {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 55;
  background: #fff;
  border-top: 1px solid var(--linea);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
}
.barra a {
  flex: 1;
  min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  padding: 0.5rem 0.2rem;
  text-decoration: none;
  color: var(--gris);
  font-size: 0.68rem;
  font-weight: 600;
}
.barra a span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barra a .b-emoji { font-size: 1.4rem; line-height: 1; filter: grayscale(0.4); opacity: 0.75; }
.barra a.activo { color: var(--verde); }
.barra a.activo .b-emoji { filter: none; opacity: 1; }

/* ---------- Formularios / modal ---------- */
.modal-fondo {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-fondo[hidden] { display: none; }
.modal {
  background: var(--crema);
  width: 100%; max-width: 640px;
  border-radius: 20px 20px 0 0;
  padding: 1.2rem 1.2rem calc(1.2rem + env(safe-area-inset-bottom, 0));
  max-height: 92vh; overflow-y: auto;
  animation: subir 0.22s ease;
}
@keyframes subir { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal h3 { color: var(--verde-osc); margin-bottom: 0.9rem; font-size: 1.15rem; }
.campo { margin-bottom: 0.9rem; }
.campo label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.3rem; color: var(--texto); }
.campo input, .campo select, .campo textarea {
  width: 100%;
  font-family: inherit; font-size: 1rem;
  padding: 0.75rem 0.8rem;
  border: 1px solid var(--linea); border-radius: 12px;
  background: #fff; color: var(--texto);
}
.campo input:focus, .campo select:focus, .campo textarea:focus {
  outline: none; border-color: var(--verde);
}
.campo textarea { min-height: 70px; resize: vertical; }
.fila-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.emoji-fila { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.emoji-op {
  font-size: 1.5rem;
  width: 48px; height: 48px;
  border: 2px solid var(--linea); border-radius: 12px;
  background: #fff; cursor: pointer;
  display: grid; place-items: center;
}
.emoji-op.sel { border-color: var(--verde); background: var(--verde-claro); }
.check-fila { display: flex; align-items: center; gap: 0.6rem; }
.check-fila input { width: 22px; height: 22px; }
.acciones-modal { display: flex; gap: 0.7rem; margin-top: 0.4rem; }
.acciones-modal .btn { flex: 1; }

/* ---------- Estados vacios / cargando ---------- */
.vacio {
  text-align: center; color: var(--gris);
  padding: 2.5rem 1rem;
}
.vacio .emoji { font-size: 2.6rem; display: block; margin-bottom: 0.5rem; }
.cargando { text-align: center; color: var(--gris); padding: 2rem; }

.aviso {
  background: #fff3d6; color: #7a4b00;
  border: 1px solid #f0d48a; border-radius: 12px;
  padding: 0.7rem 0.9rem; font-size: 0.9rem;
  margin-bottom: 0.8rem;
}
.aviso.rojo { background: #fdecea; color: var(--rojo); border-color: #f5b5b0; }

/* Aviso emergente */
.toast {
  position: fixed; bottom: calc(78px + 1rem); left: 50%; transform: translateX(-50%);
  background: var(--verde-osc); color: #fff;
  padding: 0.7rem 1.2rem; border-radius: 999px;
  font-size: 0.9rem; font-weight: 600;
  z-index: 200; box-shadow: var(--sombra);
  opacity: 0; transition: opacity 0.2s;
}
.toast.mostrar { opacity: 1; }

/* ---------- Finanzas ---------- */
.neto-card {
  border-radius: var(--radio);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--sombra);
  margin-bottom: 0.9rem;
  color: #fff;
}
.neto-card.positivo { background: linear-gradient(135deg, var(--verde), var(--verde-osc)); }
.neto-card.negativo { background: linear-gradient(135deg, #e53935, #b71c1c); }
.neto-card .etiqueta { font-size: 0.85rem; opacity: 0.92; }
.neto-card .valor { font-size: 2.3rem; font-weight: 800; line-height: 1.1; }
.neto-card .sub { font-size: 0.82rem; opacity: 0.92; margin-top: 0.25rem; }

.fin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-bottom: 0.9rem; }
.fin-card {
  background: var(--tarjeta);
  border-radius: var(--radio);
  padding: 0.9rem 1rem;
  box-shadow: var(--sombra);
  border: 1px solid var(--linea);
}
.fin-card .etiqueta { font-size: 0.8rem; color: var(--gris); }
.fin-card .valor { font-size: 1.5rem; font-weight: 800; }
.fin-card.ingreso .valor { color: var(--verde-osc); }
.fin-card.gasto .valor { color: var(--rojo); }

.grafica-caja {
  background: var(--tarjeta);
  border-radius: var(--radio);
  padding: 1.1rem;
  box-shadow: var(--sombra);
  border: 1px solid var(--linea);
  margin-bottom: 0.9rem;
}
.grafica-fila { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; justify-content: center; }
.grafica-caja canvas { width: 190px; height: 190px; flex: 0 0 auto; }
.leyenda { list-style: none; flex: 1 1 220px; min-width: 200px; }
.leyenda li {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.35rem 0; font-size: 0.9rem;
  border-bottom: 1px dashed var(--linea);
}
.leyenda li:last-child { border-bottom: none; }
.leyenda .punto { width: 14px; height: 14px; border-radius: 4px; flex: 0 0 auto; }
.leyenda .nombre { flex: 1 1 auto; }
.leyenda .monto { font-weight: 700; }
.leyenda .pct { color: var(--gris); font-size: 0.8rem; min-width: 42px; text-align: right; }
