/* =====================================================
   AgroMaíz · Sistema de diseño v2 — Moderno & minimalista
   Software profesional de gestión agrícola
   ===================================================== */
:root {
  /* Superficies */
  --campo: #F7F8F5;        /* fondo general, casi blanco con tinte natural */
  --blanco: #FFFFFF;
  --panel: #FFFFFF;

  /* Marca / verdes */
  --hoja: #15402B;         /* verde profundo principal */
  --hoja-osc: #0E2C1D;
  --hoja-suave: #1F5639;
  --hoja-tenue: #ECF3EE;   /* verde muy claro para fondos suaves */

  /* Acento (grano de maíz, más refinado) */
  --grano: #D69A1F;
  --grano-claro: #EFC15A;
  --grano-tenue: #FBF3DF;

  /* Tinta / texto */
  --tinta: #16201A;        /* texto principal */
  --tinta-media: #45514A;  /* texto secundario */
  --tinta-suave: #6B776E;  /* texto terciario / etiquetas */
  --tierra: #7A6240;

  /* Líneas y estados */
  --linea: #E7EAE3;
  --linea-fuerte: #D6DBD1;
  --ok: #1E7A4C;
  --error: #C8472F;
  --info: #2C6CB0;

  /* Forma */
  --radio: 16px;
  --radio-sm: 10px;
  --radio-lg: 22px;
  --sombra: 0 1px 2px rgba(20,40,28,.04), 0 4px 16px -8px rgba(20,40,28,.10);
  --sombra-alta: 0 2px 6px rgba(20,40,28,.06), 0 16px 40px -16px rgba(20,40,28,.18);
  --trans: 200ms cubic-bezier(.2,.7,.3,1);
}

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

/* Color de selección de texto (combina con la marca, en vez del morado del navegador) */
::selection { background: rgba(214,154,31,.28); color: var(--tinta); }
::-moz-selection { background: rgba(214,154,31,.28); color: var(--tinta); }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Instrument Sans', system-ui, -apple-system, sans-serif;
  background: var(--campo);
  color: var(--tinta);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,h2,h3,h4 { font-family: 'Epilogue', sans-serif; letter-spacing: -.02em; line-height: 1.25; color: var(--tinta); }

/* ---------- Estructura ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 252px; flex-shrink: 0;
  background: var(--hoja);
  color: #DCE6DF;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: 20px 14px;
  border-right: 1px solid rgba(255,255,255,.04);
}

.contenido { flex: 1; padding: 32px 40px 64px; min-width: 0; max-width: 1280px; }

/* ---------- Marca ---------- */
.marca { display: flex; align-items: center; gap: 12px; padding: 6px 10px 24px; }
.marca-icono {
  width: 36px; height: 36px;
  display: grid; grid-template-columns: repeat(3,1fr); gap: 3px;
}
.marca-icono span {
  background: var(--grano);
  border-radius: 50% 50% 50% 4px;
  animation: brotar .6s cubic-bezier(.2,.7,.3,1.4) backwards;
}
.marca-icono span:nth-child(1){animation-delay:.05s}
.marca-icono span:nth-child(2){animation-delay:.10s}
.marca-icono span:nth-child(3){animation-delay:.15s}
.marca-icono span:nth-child(4){animation-delay:.20s}
.marca-icono span:nth-child(5){animation-delay:.25s; background: var(--grano-claro)}
.marca-icono span:nth-child(6){animation-delay:.30s}
.marca-icono span:nth-child(7){animation-delay:.35s}
.marca-icono span:nth-child(8){animation-delay:.40s}
.marca-icono span:nth-child(9){animation-delay:.45s}
@keyframes brotar { from { transform: scale(0); opacity: 0; } }
.marca-nombre { font-family:'Epilogue'; font-weight: 800; font-size: 18px; color:#fff; letter-spacing: -.02em; }
.marca-sub { font-size: 11.5px; color: #8AA593; letter-spacing: .01em; }

/* ---------- Navegación ---------- */
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-seccion {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .14em;
  color: #6E8674; padding: 18px 12px 7px; font-weight: 600;
}
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: var(--radio-sm);
  color: #BDCDC2; text-decoration: none; font-weight: 500; font-size: 14px;
  transition: background var(--trans), color var(--trans);
  position: relative;
}
.nav a svg { width: 18px; height: 18px; fill: currentColor; opacity: .8; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.activo { background: rgba(214,154,31,.16); color: var(--grano-claro); font-weight: 600; }
.nav a.activo svg { opacity: 1; }
.nav a.activo::before {
  content:''; position: absolute; left: -14px; top: 22%; bottom: 22%;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--grano);
}

/* ---------- Grupos colapsables del menú ---------- */
.nav-grupo { border: none; }
.nav-grupo summary {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: var(--radio-sm);
  color: #BDCDC2; font-weight: 500; font-size: 14px; cursor: pointer;
  list-style: none; user-select: none;
  transition: background var(--trans), color var(--trans);
}
.nav-grupo summary::-webkit-details-marker { display: none; }
.nav-grupo summary svg { width: 18px; height: 18px; fill: currentColor; opacity: .8; flex-shrink: 0; }
.nav-grupo summary span { flex: 1; }
.nav-grupo summary .flecha { width: 16px; height: 16px; opacity: .6; transition: transform var(--trans); }
.nav-grupo[open] summary .flecha { transform: rotate(90deg); }
.nav-grupo summary:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-grupo[open] summary { color: #fff; }
.nav-grupo > a {
  margin-left: 14px; padding-left: 14px;
  border-left: 1px solid rgba(255,255,255,.10);
  border-radius: 0 var(--radio-sm) var(--radio-sm) 0;
  font-size: 13.5px;
}
.nav-grupo[open] { margin-bottom: 4px; }

/* ---------- Pie de sidebar ---------- */
.sidebar-pie {
  display: flex; align-items: center; gap: 10px;
  border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; margin-top: 10px;
}
.usuario-chip { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: var(--radio-sm); flex-shrink: 0;
  background: var(--grano); color: var(--hoja-osc);
  display: grid; place-items: center; font-weight: 800; font-family:'Epilogue'; font-size: 15px;
}
.usuario-info { min-width: 0; }
.usuario-info strong { display: block; font-size: 13px; color:#fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.usuario-info span { font-size: 11.5px; color: #8AA593; }
.btn-salir {
  width: 34px; height: 34px; border-radius: var(--radio-sm); display: grid; place-items: center;
  color: #BDCDC2; transition: var(--trans);
}
.btn-salir svg { width: 17px; height: 17px; fill: currentColor; }
.btn-salir:hover { background: rgba(200,71,47,.22); color: #FFB4A4; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; gap: 16px; margin-bottom: 30px; }
.titulo-pagina { font-size: 25px; font-weight: 800; flex: 1; animation: aparecer .5s backwards; }
.fecha-hoy { color: var(--tinta-suave); font-size: 13px; font-weight: 500; }
.btn-menu { display: none; background: none; border: none; cursor: pointer; }
.btn-menu svg { width: 26px; height: 26px; fill: var(--tinta); }
.velo { display: none; }

/* ---------- Animación de entrada ---------- */
@keyframes aparecer { from { opacity: 0; transform: translateY(10px); } }
.anim > * { animation: aparecer .5s cubic-bezier(.2,.7,.3,1) backwards; }
.anim > *:nth-child(1){animation-delay:.03s} .anim > *:nth-child(2){animation-delay:.07s}
.anim > *:nth-child(3){animation-delay:.11s} .anim > *:nth-child(4){animation-delay:.15s}
.anim > *:nth-child(5){animation-delay:.19s} .anim > *:nth-child(6){animation-delay:.23s}
.anim > *:nth-child(7){animation-delay:.27s} .anim > *:nth-child(8){animation-delay:.31s}

/* ---------- Tarjetas y métricas ---------- */
.rejilla { display: grid; gap: 18px; }
.rejilla-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.rejilla-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.tarjeta {
  background: var(--panel); border: 1px solid var(--linea);
  border-radius: var(--radio); padding: 24px; box-shadow: var(--sombra);
  transition: transform var(--trans), box-shadow var(--trans), border-color var(--trans);
}
.tarjeta:hover { transform: translateY(-2px); box-shadow: var(--sombra-alta); border-color: var(--linea-fuerte); }

.metrica { position: relative; overflow: hidden; }
.metrica .etiqueta { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--tinta-suave); font-weight: 600; }
.metrica .valor { font-family:'Epilogue'; font-size: 32px; font-weight: 800; margin: 8px 0 2px; letter-spacing: -.02em; }
.metrica .detalle { font-size: 13px; color: var(--tinta-suave); }
.metrica.alerta .valor { color: var(--error); }

/* ---------- Tablas ---------- */
.tabla-envoltura { background: var(--panel); border: 1px solid var(--linea); border-radius: var(--radio); overflow: hidden; box-shadow: var(--sombra); }
.tabla-cabecera { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 20px 24px; border-bottom: 1px solid var(--linea); flex-wrap: wrap; }
.tabla-cabecera h2 { font-size: 16px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--tinta-suave); padding: 13px 24px; background: var(--campo); border-bottom: 1px solid var(--linea); font-weight: 600; }
td { padding: 14px 24px; border-bottom: 1px solid var(--linea); font-size: 14px; vertical-align: middle; color: var(--tinta-media); }
tbody tr { transition: background var(--trans); }
tbody tr:hover { background: var(--hoja-tenue); }
tbody tr:last-child td { border-bottom: none; }
.tabla-scroll { overflow-x: auto; }

/* ---------- Insignias ---------- */
.insignia {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 4px 11px; border-radius: 999px;
}
.insignia::before { content:''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.i-verde  { background: #E3F1E8; color: var(--ok); }
.i-dorado { background: var(--grano-tenue); color: #9A6E0E; }
.i-rojo   { background: #FAE6E1; color: var(--error); }
.i-azul   { background: #E5EEF8; color: var(--info); }
.i-gris   { background: #EDEFEA; color: var(--tinta-suave); }
.i-tierra { background: #F1EADE; color: var(--tierra); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: inherit; font-size: 14px; font-weight: 600;
  padding: 10px 18px; border-radius: var(--radio-sm); border: none; cursor: pointer;
  text-decoration: none; transition: var(--trans); line-height: 1;
}
.btn:active { transform: scale(.97); }
.btn-primario { background: var(--hoja); color: #fff; }
.btn-primario:hover { background: var(--hoja-suave); box-shadow: 0 6px 18px -8px rgba(21,64,43,.55); }
.btn-dorado { background: var(--grano); color: var(--hoja-osc); }
.btn-dorado:hover { background: var(--grano-claro); box-shadow: 0 6px 18px -8px rgba(214,154,31,.6); }
.btn-fantasma { background: transparent; color: var(--tinta-media); border: 1px solid var(--linea-fuerte); }
.btn-fantasma:hover { border-color: var(--tinta-suave); color: var(--tinta); background: var(--campo); }
.btn-peligro { background: #FAE6E1; color: var(--error); }
.btn-peligro:hover { background: var(--error); color: #fff; }
.btn-mini { padding: 7px 13px; font-size: 13px; border-radius: 8px; }

/* ---------- Formularios ---------- */
.campo-form { margin-bottom: 16px; }
.campo-form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; color: var(--tinta); }
.campo-form input, .campo-form select, .campo-form textarea {
  width: 100%; font-family: inherit; font-size: 14.5px;
  padding: 11px 14px; border: 1.5px solid var(--linea-fuerte); border-radius: var(--radio-sm);
  background: var(--blanco); color: var(--tinta); transition: var(--trans);
}
.campo-form input:focus, .campo-form select:focus, .campo-form textarea:focus {
  outline: none; border-color: var(--grano); box-shadow: 0 0 0 4px rgba(214,154,31,.15);
}
.form-fila { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- Modal ---------- */
.modal-fondo {
  position: fixed; inset: 0; background: rgba(14,30,20,.5);
  backdrop-filter: blur(4px);
  display: none; place-items: center; z-index: 100; padding: 20px;
  animation: fundido .25s;
}
.modal-fondo.abierto { display: grid; }
@keyframes fundido { from { opacity: 0; } }
.modal {
  background: var(--blanco); border-radius: var(--radio-lg); width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto; padding: 30px;
  animation: escalar .3s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes escalar { from { transform: scale(.94) translateY(10px); opacity: 0; } }
.modal h3 { font-size: 19px; margin-bottom: 18px; }
.modal-acciones { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* ---------- Toasts ---------- */
.toast {
  padding: 13px 18px; border-radius: var(--radio-sm); font-weight: 500; font-size: 14px;
  margin-bottom: 22px; animation: deslizar .4s cubic-bezier(.2,.8,.3,1.2);
  border: 1px solid;
}
@keyframes deslizar { from { transform: translateY(-12px); opacity: 0; } }
.toast-ok    { background: #E3F1E8; color: var(--ok); border-color: #BFDDCB; }
.toast-error { background: #FAE6E1; color: var(--error); border-color: #F2C7BD; }

/* ---------- Barra de progreso de granos ---------- */
.granos-barra { display: flex; gap: 5px; margin-top: 10px; }
.granos-barra i {
  flex: 1; height: 8px; border-radius: 4px; background: var(--linea);
  transition: background .5s;
}
.granos-barra i.lleno { background: var(--grano); animation: brillar 2.4s ease-in-out infinite; }
@keyframes brillar { 50% { filter: brightness(1.12); } }

/* ---------- Login ---------- */
.login-cuerpo {
  min-height: 100vh; display: grid; place-items: center;
  background:
    radial-gradient(1000px 480px at 82% -12%, rgba(214,154,31,.18), transparent 60%),
    radial-gradient(820px 560px at -12% 112%, rgba(31,86,57,.45), transparent 60%),
    linear-gradient(160deg, var(--hoja-osc), var(--hoja) 72%);
  padding: 24px;
}
.login-caja {
  width: 100%; max-width: 420px; background: var(--blanco);
  border-radius: var(--radio-lg); padding: 44px 40px; box-shadow: var(--sombra-alta);
  animation: escalar .5s cubic-bezier(.2,.9,.3,1.15);
}
.login-caja .marca { padding-bottom: 8px; }
.login-caja .marca-nombre { color: var(--tinta); }
.login-caja .marca-sub { color: var(--tinta-suave); }
.login-caja h2 { font-size: 22px; margin: 16px 0 4px; }
.login-caja p.sub { color: var(--tinta-suave); font-size: 14px; margin-bottom: 26px; }
.login-caja .btn { width: 100%; justify-content: center; padding: 13px; font-size: 15px; }

/* ---------- Estado vacío ---------- */
.vacio { text-align: center; padding: 56px 20px; color: var(--tinta-suave); }
.vacio .icono { font-size: 42px; margin-bottom: 12px; opacity: .7; }

/* ---------- Responsivo ---------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 200;
    transform: translateX(-100%); transition: transform .3s cubic-bezier(.2,.8,.3,1);
    box-shadow: var(--sombra-alta);
  }
  .sidebar.abierto { transform: translateX(0); }
  .velo.visible { display: block; position: fixed; inset: 0; background: rgba(14,30,20,.4); z-index: 150; animation: fundido .25s; }
  .btn-menu { display: block; }
  .contenido { padding: 22px 18px 54px; }
  .form-fila { grid-template-columns: 1fr; }
  .titulo-pagina { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
