:root {
  --verde: #2e7d32;
  --verde-claro: #e8f5e9;
  --rojo: #c62828;
  --texto: #1b1b1b;
  --fondo: #eef1ee;
  --tarjeta: #ffffff;
  --borde: #e1e6e1;
  --sombra: 0 1px 2px rgba(16,24,16,0.04), 0 4px 10px rgba(16,24,16,0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  padding-bottom: 2rem;
  -webkit-font-smoothing: antialiased;
}

header {
  background: linear-gradient(135deg, #1b5e20, #2e7d32);
  color: white;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.01em;
}

.boton-instalar {
  width: auto;
  padding: 0.5rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 700;
  background: rgba(255,255,255,0.18);
  color: white;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 8px;
  backdrop-filter: blur(2px);
}
.boton-instalar:hover { background: rgba(255,255,255,0.3); }
.boton-instalar.instalada { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.3); cursor: default; }

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2rem;
}

/* Pantallas angostas: menu, login, config, auth de agricultor */
#menu-principal, #config, #login, #agricultor-auth {
  max-width: 440px;
  margin: 1.5rem auto 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.tarjeta {
  background: var(--tarjeta);
  border: 1px solid var(--borde);
  border-radius: 14px;
  padding: 1.15rem 1.25rem;
  box-shadow: var(--sombra);
}

.tarjeta h2 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #667066;
  margin: 0 0 0.9rem;
}

.fila {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--borde);
}
.fila:last-of-type { border-bottom: none; }
.fila span { color: #666; }
.fila strong { font-weight: 600; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}
.pill.ok { background: var(--verde-claro); color: var(--verde); }
.pill.mal { background: #fdecea; color: var(--rojo); }
.pill.cargando { background: #fff8e1; color: #8d6e00; }
.pill.externo { background: #e3f2fd; color: #1565c0; }
.pill.estatico { background: #ede7f6; color: #5e35b1; }

.modulo-cabecera {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.2rem;
}
.modulo-cabecera h2 { margin: 0; }
.capa {
  font-size: 0.72rem;
  color: #93998f;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 0 0 1rem;
  font-weight: 600;
}

.boton-enlace {
  display: block;
  text-align: center;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: var(--verde);
  color: white;
  text-decoration: none;
  font-weight: 700;
  margin-bottom: 0.5rem;
  transition: transform 0.1s, box-shadow 0.1s;
}
.boton-enlace:hover { box-shadow: var(--sombra); transform: translateY(-1px); }
.boton-enlace.secundario-enlace {
  background: white;
  color: var(--verde);
  border: 1px solid var(--verde);
}

.hint { font-size: 0.82rem; color: #777; margin-top: 0.4rem; line-height: 1.4; }
.hint-config { text-align: center; }
.hint-config a { color: var(--verde); font-weight: 600; }

.tarjeta-menu {
  background: var(--tarjeta);
  border: 1px solid var(--borde);
  border-radius: 14px;
  padding: 1.4rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.1rem;
  cursor: pointer;
  box-shadow: var(--sombra);
  transition: transform 0.12s, box-shadow 0.12s;
}
.tarjeta-menu:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(16,24,16,0.1); }
#ir-admin { border-left: 5px solid #1565c0; }
#ir-agricultor { border-left: 5px solid var(--verde); }
.tarjeta-menu .menu-icono { font-size: 2.3rem; }
.tarjeta-menu h2 { margin: 0 0 0.2rem; font-size: 1.05rem; text-transform: none; letter-spacing: normal; color: var(--texto); font-weight: 700; }
.tarjeta-menu p { margin: 0; }

.enlace-volver {
  background: none;
  border: none;
  color: #666;
  font-size: 0.85rem;
  padding: 0.4rem 0;
  width: auto;
  text-align: left;
  cursor: pointer;
  margin-bottom: 0.25rem;
}

.tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1.1rem;
  background: #eef1ee;
  padding: 0.3rem;
  border-radius: 10px;
}
.tab {
  flex: 1;
  background: transparent;
  border: none;
  color: #555;
  width: auto;
  padding: 0.55rem;
  font-size: 0.88rem;
  border-radius: 8px;
}
.tab.activa {
  background: var(--verde);
  color: white;
  font-weight: 700;
  box-shadow: var(--sombra);
}

.boton-chico {
  width: auto;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  border-radius: 7px;
}

/* ===== Paneles con tema por rol: admin (azul) vs agricultor (verde) ===== */
.tema-agricultor { --acento: var(--verde); --acento-oscuro: #1b5e20; }
.tema-admin { --acento: #1565c0; --acento-oscuro: #0d47a1; }

.panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.1rem;
  align-items: start;
}

.panel-header {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, var(--acento-oscuro), var(--acento));
  color: white;
  border-radius: 14px;
  padding: 1.1rem 1.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--sombra);
}
.panel-header h2 { margin: 0.15rem 0 0; font-size: 1.25rem; font-weight: 700; }
.panel-rotulo {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  opacity: 0.85;
}
.panel-header-botones { display: flex; gap: 0.5rem; flex-shrink: 0; }
.boton-salir {
  width: auto;
  padding: 0.5rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  background: rgba(255,255,255,0.16);
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 8px;
  backdrop-filter: blur(2px);
}
.boton-salir.secundario { background: transparent; }
.boton-salir:hover { background: rgba(255,255,255,0.28); }

.tabs-modulos {
  grid-column: 1 / -1;
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding-bottom: 0.3rem;
  -webkit-overflow-scrolling: touch;
}
.tab-modulo {
  flex: 0 0 auto;
  width: auto;
  white-space: nowrap;
  background: var(--tarjeta);
  border: 1px solid var(--borde);
  color: #555;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 999px;
  box-shadow: var(--sombra);
}
.tab-modulo.activa {
  background: var(--acento);
  border-color: var(--acento);
  color: white;
}

.modulo { grid-column: 1 / -1; }

@media (min-width: 880px) {
  .panel { grid-template-columns: 230px 1fr; }
  .tabs-modulos {
    grid-column: 1;
    flex-direction: column;
    position: sticky;
    top: 1.25rem;
  }
  .tab-modulo { width: 100%; text-align: left; border-radius: 10px; }
  .modulo { grid-column: 2; }
}

input[type=text], input[type=password], input[type=tel], input[type=number], input[type=date], select {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--borde);
  border-radius: 9px;
  font-size: 1rem;
  margin-bottom: 0.65rem;
  background: #fbfcfb;
  font-family: inherit;
}
input:focus, select:focus { outline: 2px solid var(--acento, var(--verde)); outline-offset: 1px; background: white; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 0.6rem;
}
.grid-2 input { min-width: 0; }

.subtitulo {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #667066;
  margin: 1.3rem 0 0.6rem;
}
.subtitulo:first-of-type { margin-top: 0; }

.fila-botones {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.fila-botones button { width: auto; flex: 1 1 180px; }

#mapa-suelos {
  height: 220px;
  border-radius: 10px;
  margin-bottom: 0.9rem;
  border: 1px solid var(--borde);
  background: #eef1ee;
}

.contenedor-grafico {
  position: relative;
  height: 220px;
  margin-bottom: 0.4rem;
}

button {
  width: 100%;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 9px;
  background: var(--verde);
  color: white;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}
button:hover:not(:disabled) { box-shadow: var(--sombra); }
button:active:not(:disabled) { transform: scale(0.98); }
button.secundario {
  background: white;
  color: var(--verde);
  border: 1px solid var(--verde);
}
button:disabled { opacity: 0.55; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th {
  text-align: left;
  padding: 0.5rem 0.5rem;
  border-bottom: 2px solid var(--borde);
  color: #667066;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
td { text-align: left; padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--borde); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f7f9f7; }

.hint { font-size: 0.8rem; color: #666; margin-top: 0.4rem; }
.error { color: var(--rojo); font-size: 0.88rem; margin-top: 0.5rem; font-weight: 600; }
[hidden] { display: none !important; }

.aviso-offline {
  background: #fff8e1;
  border: 1px solid #f0d98c;
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: #7a5c00;
}
.aviso-offline ul { margin: 0.5rem 0; padding-left: 1.2rem; }
.aviso-offline button { margin-top: 0.5rem; }
