/* =====================================================================
   Ganadera — estilos
   Fondo gris cálido, barra verde campo, letras casi negras y títulos en
   verde: sobrio pero con contraste, y pensado para leerse al sol en el
   celular. Un solo archivo, sin dependencias.
   ===================================================================== */

:root {
  --fondo: #E8EAE4;
  --tarjeta: #FFFFFF;
  --barra: #2F5233;
  --barra-2: #24402A;
  --acento: #4A7C59;
  --acento-claro: #E4EDE6;
  --texto: #1A1D1A;
  --texto-suave: #5A615A;
  --borde: #C9CFC4;
  --borde-suave: #E0E4DC;
  --peligro: #A6342B;
  --alerta: #8A6212;
  --alerta-fondo: #FBF2DC;
  --ok: #2E6B3E;
  --radio: 10px;
  --sombra: 0 1px 2px rgba(26, 29, 26, .08), 0 2px 8px rgba(26, 29, 26, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--acento); }
h1, h2, h3 { color: var(--barra); margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

.cargando-pagina, .cargando { padding: 3rem 1rem; text-align: center; color: var(--texto-suave); }

/* ---------- barra superior ---------- */
.barra {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  background: var(--barra); color: #fff;
  padding: .5rem 1rem; position: sticky; top: 0; z-index: 20;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .2);
}
.marca { display: flex; align-items: center; gap: .5rem; color: #fff; text-decoration: none; font-weight: 600; }
.marca-logo { width: 28px; height: 28px; }
.boton-menu { display: none; }

#menu { display: flex; gap: .15rem; flex: 1; flex-wrap: wrap; }
#menu a {
  color: #E7EFE8; text-decoration: none; padding: .4rem .7rem;
  border-radius: 7px; white-space: nowrap; font-size: .94rem;
}
#menu a:hover { background: var(--barra-2); }
#menu a.activo { background: #fff; color: var(--barra); font-weight: 600; }

.usuario { display: flex; align-items: center; gap: .6rem; font-size: .88rem; color: #D7E3D9; }
.usuario-nombre, .est-nombre { white-space: nowrap; }
.est-nombre { font-weight: 600; color: #fff; }
.sel-est {
  background: var(--barra-2); color: #fff; border: 1px solid #4C6B52;
  border-radius: 7px; padding: .3rem .5rem; font-size: .88rem; max-width: 12rem;
}
.btn-link { background: none; border: 0; color: #D7E3D9; cursor: pointer; text-decoration: underline; font: inherit; padding: 0; }
.btn-link:hover { color: #fff; }

main { padding: 1.25rem 1rem 3rem; max-width: 1200px; margin: 0 auto; }

/* ---------- encabezado de pantalla ---------- */
.pantalla-cab {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.pantalla-cab p { margin: .15rem 0 0; color: var(--texto-suave); font-size: .92rem; }
.acciones { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------- tarjetas de indicador ---------- */
.tarjetas {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .75rem; margin-bottom: 1.25rem;
}
.tarjeta {
  background: var(--tarjeta); border: 1px solid var(--borde-suave);
  border-radius: var(--radio); padding: .8rem .9rem; box-shadow: var(--sombra);
}
.tarjeta-titulo { font-size: .8rem; color: var(--texto-suave); text-transform: uppercase; letter-spacing: .03em; }
.tarjeta-valor { font-size: 1.6rem; font-weight: 600; color: var(--barra); margin-top: .15rem; line-height: 1.1; }
.tarjeta-pie { font-size: .82rem; color: var(--texto-suave); margin-top: .2rem; }
.tarjeta.alerta { border-color: #E2CE92; background: var(--alerta-fondo); }
.tarjeta.alerta .tarjeta-valor { color: var(--alerta); }
.tarjeta.mal { border-color: #E0B3AE; background: #FBEDEB; }
.tarjeta.mal .tarjeta-valor { color: var(--peligro); }

/* ---------- bloques ---------- */
.bloque {
  background: var(--tarjeta); border: 1px solid var(--borde-suave);
  border-radius: var(--radio); padding: 1rem; margin-bottom: 1.25rem; box-shadow: var(--sombra);
}
.bloque > h2:first-child, .bloque > h3:first-child { margin-top: 0; }
.bloque-cab { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }

/* ---------- tablas ---------- */
.tabla-marco { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--borde-suave); }
th {
  background: var(--acento-claro); color: var(--barra); font-weight: 600;
  white-space: nowrap; position: sticky; top: 0;
}
tbody tr:hover { background: #F4F7F3; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.chico, th.chico { width: 1%; white-space: nowrap; }
tfoot td { font-weight: 600; background: #F4F7F3; border-top: 2px solid var(--borde); }
.fila-clic { cursor: pointer; }

/* ---------- chips y puntos ---------- */
.chip {
  display: inline-block; padding: .12rem .5rem; border-radius: 999px;
  font-size: .8rem; font-weight: 600; white-space: nowrap;
  background: #EDEFEA; color: var(--texto-suave);
}
.chip.res-prenada { background: #DCEBE0; color: #1F5C30; }
.chip.res-con_cria { background: #D6E7F2; color: #184C6B; }
.chip.res-vacia { background: #F0EADA; color: #6B5718; }
.chip.res-soltera { background: #F6E0DC; color: #8C3127; }
.chip.res-a_iatf { background: #E6DEF2; color: #4A3277; }
.chip.res-aborto, .chip.res-mortandad { background: #F3DAD7; color: #8C2A20; }
.chip.res-vendida { background: #E4E4E4; color: #444; }
.chip.res-sin_dato { background: #F0F0ED; color: #86897F; }

.punto {
  display: inline-block; width: .7rem; height: .7rem; border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, .25); vertical-align: -1px; margin-right: .3rem;
}
.punto-amarilla { background: #F2C230; }
.punto-azul { background: #3B6FB5; }
.punto-naranja { background: #E07A28; }
.punto-verde { background: #4A7C59; }
.punto-roja { background: #B5392B; }
.punto-blanca { background: #fff; }
.punto-otro { background: #9AA096; }
.punto-sc { background: repeating-linear-gradient(45deg, #CFD4C9 0 3px, #fff 3px 6px); }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .35rem; justify-content: center;
  padding: .45rem .9rem; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  min-height: 38px;
}
.btn-pri { background: var(--acento); color: #fff; }
.btn-pri:hover { background: var(--barra); }
.btn-sec { background: #fff; color: var(--barra); border-color: var(--borde); }
.btn-sec:hover { background: var(--acento-claro); }
.btn-peligro { background: var(--peligro); color: #fff; }
.btn-peligro:hover { background: #87291F; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-chico { padding: .25rem .55rem; min-height: 30px; font-size: .86rem; }
.btn-icono {
  background: none; border: 0; cursor: pointer; font-size: 1.1rem;
  color: var(--texto-suave); padding: .2rem .35rem; border-radius: 6px;
}
.btn-icono:hover { background: var(--borde-suave); }

/* ---------- formularios ---------- */
label { display: block; margin-bottom: .7rem; font-size: .88rem; color: var(--texto-suave); font-weight: 600; }
input, select, textarea {
  display: block; width: 100%; margin-top: .2rem;
  padding: .45rem .55rem; border: 1px solid var(--borde); border-radius: 8px;
  font: inherit; color: var(--texto); background: #fff; min-height: 38px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--acento); outline-offset: -1px; border-color: var(--acento); }
textarea { min-height: 70px; resize: vertical; }
.campos { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 .75rem; }
.filtros {
  display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem;
}
.filtros label { margin-bottom: 0; }
.filtros input, .filtros select { min-width: 9rem; }
.filtros .crece { flex: 1; min-width: 12rem; }
.ayuda { font-size: .84rem; color: var(--texto-suave); font-weight: 400; margin: .2rem 0 0; }

/* ---------- avisos ---------- */
.aviso {
  border-left: 4px solid var(--alerta); background: var(--alerta-fondo);
  padding: .7rem .9rem; border-radius: 8px; margin-bottom: .75rem; font-size: .92rem;
}
.aviso.mal { border-color: var(--peligro); background: #FBEDEB; }
.aviso.bien { border-color: var(--ok); background: #E8F2EA; }
.aviso h3 { margin: 0 0 .2rem; font-size: .95rem; }
.aviso p { margin: 0; }
.aviso ul { margin: .35rem 0 0; padding-left: 1.2rem; }

.vacio { text-align: center; padding: 2rem 1rem; color: var(--texto-suave); }
.vacio p { margin: 0 0 .25rem; font-size: 1rem; }
.vacio small { font-size: .86rem; }

.error-caja {
  background: #FBEDEB; border: 1px solid #E0B3AE; border-radius: var(--radio);
  padding: 1.25rem; text-align: center;
}
.error-caja h2 { color: var(--peligro); }

/* ---------- login ---------- */
.login { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-caja {
  background: var(--tarjeta); border: 1px solid var(--borde-suave); border-radius: 14px;
  padding: 1.5rem; width: min(400px, 100%); box-shadow: 0 4px 24px rgba(26, 29, 26, .1);
}
.login-marca { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.25rem; }
.login-logo { width: 48px; height: 48px; }
.login-marca strong { display: block; color: var(--barra); font-size: 1.15rem; }
.login-marca small { color: var(--texto-suave); }
.login-error { color: var(--peligro); font-size: .9rem; min-height: 1.2em; margin: .5rem 0 0; }
.login-caja .btn { width: 100%; margin-top: .35rem; }
.login-caja .btn-link { color: var(--acento); display: block; margin: .75rem auto 0; }
.sql-ayuda {
  background: #F4F6F2; border: 1px solid var(--borde-suave); border-radius: 8px;
  padding: .7rem; font-size: .8rem; overflow-x: auto; white-space: pre; color: var(--texto);
}

/* ---------- diálogos ---------- */
.dialogo {
  border: 0; border-radius: 14px; padding: 0; max-height: calc(100vh - 2rem);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25); color: var(--texto); background: var(--tarjeta);
}
.dialogo::backdrop { background: rgba(26, 29, 26, .45); }
.dialogo-form { display: flex; flex-direction: column; max-height: calc(100vh - 2rem); }
.dialogo header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem 1rem; border-bottom: 1px solid var(--borde-suave);
}
.dialogo header h2 { margin: 0; font-size: 1.05rem; }
.dialogo-cuerpo { padding: 1rem; overflow-y: auto; }
.dialogo footer {
  display: flex; gap: .5rem; justify-content: flex-end;
  padding: .75rem 1rem; border-top: 1px solid var(--borde-suave); background: #F7F9F6;
}
.lista-problemas { margin: .5rem 0 0; padding-left: 1.2rem; color: var(--peligro); font-size: .9rem; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: .5rem; width: min(440px, calc(100vw - 2rem)); }
.toast {
  padding: .7rem .9rem; border-radius: 9px; color: #fff; background: var(--barra);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25); font-size: .92rem; transition: opacity .4s, transform .4s;
}
.toast-error { background: var(--peligro); }
.toast.fuera { opacity: 0; transform: translateY(8px); }

/* ---------- celular ---------- */
@media (max-width: 860px) {
  .barra { gap: .5rem; }
  .boton-menu {
    display: inline-block; background: var(--barra-2); color: #fff;
    border: 1px solid #4C6B52; border-radius: 8px; padding: .4rem .7rem;
    font: inherit; font-weight: 600; cursor: pointer; min-height: 38px;
  }
  #menu { display: none; order: 10; width: 100%; flex-direction: column; gap: .1rem; }
  #menu.abierto { display: flex; }
  #menu a { padding: .6rem .7rem; }
  .usuario { margin-left: auto; }
  .usuario-nombre { display: none; }
  main { padding: 1rem .75rem 2.5rem; }
  .tarjeta-valor { font-size: 1.4rem; }
  th { position: static; }
}

@media (max-width: 480px) {
  .est-nombre { max-width: 7rem; overflow: hidden; text-overflow: ellipsis; }
  .tarjetas { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
}

/* ---------- impresión ---------- */
@media print {
  .barra, .acciones, .filtros, #toasts { display: none !important; }
  main { max-width: none; padding: 0; }
  .bloque, .tarjeta { box-shadow: none; border-color: #999; break-inside: avoid; }
  body { background: #fff; }
}
