/* ===========================================================
   Telli — sistema de diseño
   Paleta pensada en el mundo del cultivo: verde musgo como color
   estructural, papel cálido de fondo, ámbar como acento de acción.
   Los colores de etapa (vegetativo/floración/secado/etc.) son
   funcionales — codifican información, no decoran.
   =========================================================== */

:root {
  --bg: #EEF0E6;
  --superficie: #F7F8F1;
  --panel: #E3E4D6;
  --linea: #D3D2C2;
  --tinta: #1B2420;
  --tinta-suave: #55604F;

  --musgo: #3B5D3B;
  --musgo-oscuro: #2C462C;
  --ambar: #B8863B;
  --ambar-oscuro: #96702F;
  --rojo: #A6432F;

  --etapa-vacia: #A8A399;
  --etapa-madre: #4E8C86;
  --etapa-clon: #4E8C86;
  --etapa-vegetativo: #5C8A4C;
  --etapa-floracion: #8C5FA8;
  --etapa-secado: #9C7A4E;
  --etapa-manicura: #B8863B;
  --etapa-produccion: #3B5D3B;
  --etapa-preparacion: #C4A15A;

  --fuente-display: 'Fraunces', Georgia, serif;
  --fuente-ui: 'Inter', -apple-system, sans-serif;

  --radio: 10px;
  --sombra: 0 2px 10px rgba(27, 36, 32, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--tinta);
  font-family: var(--fuente-ui);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

button { font-family: inherit; }

.oculto { display: none !important; }

/* ---------- Vistas de pantalla completa (config / login) ---------- */

.vista-full {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(92, 138, 76, 0.10), transparent 45%),
    radial-gradient(circle at 80% 75%, rgba(140, 95, 168, 0.08), transparent 45%),
    var(--bg);
}

.panel-centro {
  width: 360px;
  padding: 40px 36px;
  background: var(--superficie);
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
}

.marca {
  font-family: var(--fuente-display);
  font-weight: 500;
  font-size: 34px;
  margin: 0 0 4px;
  color: var(--musgo-oscuro);
}

.subtitulo {
  margin: 0 0 28px;
  color: var(--tinta-suave);
  font-size: 14px;
}

.ayuda {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--tinta-suave);
  line-height: 1.5;
}

/* ---------- Formularios ---------- */

form { display: flex; flex-direction: column; gap: 16px; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--tinta-suave);
  font-weight: 500;
}

input, select, textarea {
  font-family: var(--fuente-ui);
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--linea);
  border-radius: 8px;
  background: #fff;
  color: var(--tinta);
}

input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--musgo);
  outline-offset: 1px;
}

textarea { resize: vertical; min-height: 60px; }

.fila-form { display: flex; flex-direction: row; gap: 12px; }
.fila-form > label { flex: 1; }

/* ---------- Botones ---------- */

.btn {
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease, transform 60ms ease;
}
.btn:active { transform: translateY(1px); }

.btn-primario { background: var(--musgo); color: #fff; }
.btn-primario:hover { background: var(--musgo-oscuro); }

.btn-secundario { background: transparent; border-color: var(--linea); color: var(--tinta); }
.btn-secundario:hover { background: var(--panel); }

.btn-ambar { background: var(--ambar); color: #fff; }
.btn-ambar:hover { background: var(--ambar-oscuro); }

.btn-peligro { background: transparent; border-color: var(--rojo); color: var(--rojo); }
.btn-peligro:hover { background: rgba(166, 67, 47, 0.08); }

.btn-texto {
  background: none; border: none; color: var(--tinta-suave);
  font-size: 13px; cursor: pointer; text-decoration: underline;
  padding: 4px;
}
.btn-texto:hover { color: var(--tinta); }

.mensaje-error {
  background: rgba(166, 67, 47, 0.08);
  color: var(--rojo);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  margin: 0;
}

/* ---------- Layout general de la app ---------- */

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--musgo-oscuro);
  color: #EDEFE4;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.sidebar-marca {
  font-family: var(--fuente-display);
  font-size: 22px;
  padding: 0 22px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: 12px;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 0 12px; }

.grupo-nav { margin-bottom: 20px; }

.grupo-etiqueta {
  display: block;
  font-size: 11px;
  color: rgba(237,239,228,0.55);
  padding: 6px 10px 4px;
  letter-spacing: 0.02em;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #EDEFE4;
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 14px;
  cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,0.08); }
.nav-item.activo { background: var(--ambar); color: #fff; font-weight: 600; }
.nav-item.deshabilitado { color: rgba(237,239,228,0.35); cursor: default; }
.nav-item.deshabilitado:hover { background: none; }

.sidebar-usuario {
  border-top: 1px solid rgba(255,255,255,0.12);
  padding: 16px 22px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.usuario-nombre { font-size: 13px; font-weight: 600; }
.usuario-rol { font-size: 12px; color: rgba(237,239,228,0.6); text-transform: capitalize; }
.sidebar-usuario .btn-texto { color: rgba(237,239,228,0.7); }
.sidebar-usuario .btn-texto:hover { color: #fff; }

.contenido {
  overflow-y: auto;
  padding: 36px 44px;
}

.seccion-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
}

.seccion-titulo {
  font-family: var(--fuente-display);
  font-size: 28px;
  font-weight: 500;
  margin: 0;
  color: var(--musgo-oscuro);
}

.seccion-descripcion {
  color: var(--tinta-suave);
  margin: 4px 0 0;
  font-size: 14px;
}

/* ---------- Tarjetas de sala ---------- */

.grid-salas {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.tarjeta-sala {
  background: var(--superficie);
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  padding: 18px;
  cursor: pointer;
  transition: box-shadow 120ms ease, border-color 120ms ease;
  border-left: 5px solid var(--etapa-vacia);
}
.tarjeta-sala:hover { box-shadow: var(--sombra); border-color: var(--tinta-suave); }

.tarjeta-sala-nombre { font-weight: 600; font-size: 16px; margin: 0 0 6px; }

.etiqueta-etapa {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  color: #fff;
  margin-bottom: 10px;
}

.tarjeta-sala-datos { font-size: 13px; color: var(--tinta-suave); line-height: 1.7; }

/* ---------- Tablas ---------- */

table { width: 100%; border-collapse: collapse; background: var(--superficie); border-radius: var(--radio); overflow: hidden; }
th, td { text-align: left; padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--linea); }
th { color: var(--tinta-suave); font-weight: 600; background: var(--panel); }
.th-ordenable { cursor: pointer; user-select: none; }
.th-ordenable:hover { color: var(--tinta); }
tr:last-child td { border-bottom: none; }

.tabla-envoltorio { border: 1px solid var(--linea); border-radius: var(--radio); overflow-x: auto; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(27, 36, 32, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}

.modal {
  background: var(--superficie);
  border-radius: var(--radio);
  padding: 28px;
  width: min(760px, 95vw);
  max-height: 84vh;
  overflow-y: auto;
  box-shadow: 0 8px 28px rgba(27,36,32,0.25);
}

.modal h2 {
  font-family: var(--fuente-display);
  font-weight: 500;
  font-size: 20px;
  margin: 0 0 18px;
  color: var(--musgo-oscuro);
}

.modal-acciones { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--tinta);
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 60;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.toast.error { background: var(--rojo); }

/* ---------- Utilidades ---------- */

.acciones-barra { display: flex; gap: 10px; margin-bottom: 20px; }
.vacio-estado { color: var(--tinta-suave); font-size: 14px; padding: 30px 0; text-align: center; }
.chip-rol { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--panel); color: var(--tinta-suave); }
.catalogo-fecha { color: var(--tinta-suave); font-size: 13px; margin: -12px 0 20px; }

@media print {
  .sidebar, .seccion-header button, .toast, .modal-overlay, #form-filtros-estadisticas { display: none !important; }
  .app-shell { display: block; }
  .contenido { padding: 0; }
  body { background: #fff; }
}

/* ---------- Barra móvil (oculta en escritorio) ---------- */

.barra-movil {
  display: none;
  align-items: center;
  gap: 12px;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  padding: 0 14px;
  background: var(--musgo-oscuro);
  color: #EDEFE4;
  z-index: 60;
}

.btn-hamburguesa {
  background: none;
  border: none;
  color: #EDEFE4;
  font-size: 22px;
  line-height: 1;
  padding: 6px 8px;
  cursor: pointer;
}

.marca-movil {
  font-family: var(--fuente-display);
  font-size: 18px;
}

.overlay-sidebar {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(27, 36, 32, 0.45);
  z-index: 90;
}
.overlay-sidebar.visible { display: block; }

/* ---------- Punto de corte único: celular y tablet ---------- */

@media (max-width: 900px) {
  .barra-movil { display: flex; }

  .app-shell { display: block; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: 260px;
    max-width: 82vw;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 95;
    overflow-y: auto;
  }
  .sidebar.abierta { transform: translateX(0); }

  .contenido {
    padding: 72px 16px 24px;
  }

  .fila-form { flex-direction: column !important; align-items: stretch !important; }
  .fila-form input, .fila-form select { width: 100% !important; }

  .panel-centro { width: 90vw; max-width: 340px; padding: 32px 24px; }

  .modal { width: 94vw; padding: 20px; }

  .grid-salas { grid-template-columns: 1fr 1fr; }

  #lienzo-mapa, #visor-mapa { touch-action: pan-x pan-y; }
}

@media (max-width: 480px) {
  .grid-salas { grid-template-columns: 1fr; }
  table { font-size: 12px; }
  th, td { padding: 8px 10px; }
}
