/* Jornada — scoped styles (no :root / no html/body globals) */

/* Page variables (reuse global vars from common.css where possible) */
.jornada-page{
  --panel: rgba(255,255,255,0.03);
  --card-bg: var(--card);
  --border: rgba(255,255,255,0.04);
  --primary: var(--accent);
  --danger: var(--danger);
  --sidebar-w: 380px;
  --header-h: 64px; /* ajustable si tu header tiene otra altura */
}

/* Basic box-sizing */
*{ box-sizing: border-box; }

/* Scoped body defaults (do not override global display/flex) */
body.jornada-page{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

/* Layout for sidebar + map (friendly, responsive) */
.jornada-layout {
  display: flex;
  gap: 16px;
  align-items: stretch;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-w, 380px);
  max-width: 42%;
  min-width: 260px;
  box-sizing: border-box;
  padding: 14px;
  overflow-y: auto;
  background: var(--card-bg, var(--card));
  border-right: 1px solid var(--panel);
  border-radius: 8px;
}

/* Stage (map) */
#stage {
  flex: 1 1 auto;
  /* altura real basada en viewport menos header: garantiza que el mapa tenga espacio real */
  height: calc(100vh - var(--header-h,64px));
  display: flex;
  align-items: stretch;
  justify-content: center;
}

/* ensure map fills stage */
#stage > #map {
  width: 100%;
  height: 100%;
  min-height: 420px;
  border-radius: 8px;
  overflow: hidden;
}

/* make panels inside sidebar visually distinct */
#sidebar .panel { margin-bottom: 12px; padding: 12px; border-radius: 8px; background: var(--card-bg, var(--card)); border:1px solid var(--panel); }

/* Text / headings */
h1{ margin:0 0 10px; font-size:18px; color:var(--text) }
.label{ font-size:12px; color:var(--muted); margin-bottom:6px; text-transform:uppercase; letter-spacing:.3px }
.hint{ font-size:12px; color:var(--muted) }

/* Inputs: dark theme, use panel/card variables */
input, textarea, select{
  border:1px solid var(--panel);
  border-radius:8px;
  padding:8px;
  color:var(--text);
  background: rgba(255,255,255,0.02);
  min-width:0;
}
input[type="date"]{ padding:6px 8px }
textarea{ width:100% }
.num{ width:90px; height:34px }

/* Buttons: use theme variables */
.btn{
  height:34px; padding:0 12px; border-radius:8px; cursor:pointer;
  border:1px solid var(--panel);
  background: transparent;
  color:var(--text);
}
.btn:hover{ filter:brightness(.98) }
.btn.primary{ background:var(--primary); border-color:var(--primary); color:#fff }
.btn.ghost{ background:transparent; border-style:dashed }

/* Cards / panels: dark surfaces */
.card, .panel{
  border:1px solid var(--panel);
  border-radius:8px;
  padding:10px;
  margin-bottom:8px;
  background: var(--card-bg);
}

/* Icon buttons */
.icon-btn{
  border: 1px solid var(--panel);
  background: transparent;
  color: var(--danger);
  width: 28px; height: 28px;
  border-radius: 6px;
  display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn:hover{ background: rgba(255,50,50,0.06); border-color: rgba(255,50,50,0.12); }

/* Capture card layout: dark card */
.cap-card{
  display:grid; gap:12px;
  grid-template-columns: 120px 1fr auto;
  align-items:start;
  border:1px solid var(--panel);
  border-radius:12px;
  padding:12px; margin-bottom:12px;
  background: var(--card-bg);
}

/* Left thumbnail */
.cap-left{ display:flex; flex-direction:column; gap:8px; align-items:center }
.cap-thumb-wrap{ width:120px; height:120px; position:relative; }
.cap-thumb{
  width:100%; height:100%; border:1px solid var(--panel); border-radius:10px; object-fit:cover;
  background: rgba(255,255,255,0.02);
}
.cap-thumb-ph{
  position:absolute; inset:0; display:grid; place-items:center;
  border:1px dashed var(--panel); border-radius:10px;
  color:var(--muted); font-size:28px; background:transparent;
  pointer-events:none; z-index:0;
}
.cap-photo-btn{ height:auto; padding:6px 10px; font-size:12px; z-index:1 }

/* Mid fields */
.cap-mid{ display:grid; gap:8px; }
.cap-mid .full{ grid-column: 1 / -1; }
.cap-mid input{ height:38px; padding:0 10px; width:100%; min-width:0; border:1px solid var(--panel); border-radius:10px; background: rgba(255,255,255,0.02); color:var(--text); }
.time-field{ min-width: 140px; }

/* Actions column */
.cap-actions{ display:flex; flex-direction:column; gap:8px }

/* Delete wrap */
.cap-del-wrap { grid-column: 1 / -1; display:flex; justify-content:flex-end; }

/* Layout: mapa (stage) a la izquierda, sidebar a la derecha */
.layout {
  display: flex;
  gap: 16px;
  align-items: stretch;
}

/* area del mapa (izquierda) */
.layout #stage {
  order: 0;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* barra lateral (derecha) */
.layout #sidebar {
  order: 1;
  width: 340px;
  flex: 0 0 340px;
  box-sizing: border-box;
  max-height: calc(93vh - var(--header-height, 0px));
  overflow: auto;
}

/* asegurar que el mapa llene el contenedor */
#map {
  flex: 1 1 auto;
  min-height: 400px;
}

/* Responsive adjustments */
@media (max-width: 720px){
  #sidebar{ position: static; width:100%; max-height:none; border-radius:8px; }
  .jornada-page .layout{ flex-direction: column; }
  .cap-card{ grid-template-columns: 1fr; }
  .cap-left{ flex-direction:row; align-items:flex-start; gap:12px }
  .cap-thumb-wrap{ max-width:96px }
  .cap-mid{ grid-template-columns: 1fr; }
  .time-field{ min-width: 0; }
}
@media (max-width: 920px){
  .layout, .jornada-layout { flex-direction: column; }
  .layout { display: block;}

  /* mover el área del mapa al principio en móviles */
  #stage { order: -1; width: 100%; min-height: 0; height: auto;}

  /* el mapa debe ocupar ancho completo y altura razonable */
  #stage > #map,
  #map {
    width: 100% !important;
    height: 44vh !important;
    min-height: 280px !important;
    max-height: 60vh;
    border-radius: 8px;
    box-sizing: border-box;
    overflow: hidden;
  }

  /* sidebar debajo del mapa */
  #sidebar {
    order: 0;
    width: 100% !important; 
    max-width: 100%;
    max-height: none;
    position: static;
  }
}

/* Ajustes para pantallas muy pequeñas */
@media (max-width: 520px){
  #stage > #map,
  #map {
    height: 36vh !important;
    min-height: 200px !important;
  }

  /* evitar que hijos del layout recorten el mapa */
  .layout { overflow: visible; }
}
/* small z-index tweak so leaflet controls stay on top inside the map container */
#map .leaflet-control-container { z-index: 1000; }

/* Small select tweaks */
.cap-mid select {
  padding: 8px;
  border: 1px solid var(--panel);
  border-radius: 8px;
  font-size: 14px;
  background: rgba(255,255,255,0.02);
  color: var(--text);
}

/* Asegurar que el <select> del editor muestre correctamente la opción seleccionada */
.cap-mid select[data-k="species"],
.cap-mid select[data-k="species"]:focus {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.06);
  background: transparent;          /* hereda fondo del card */
  color: inherit;                   /* muestra texto con el color del tema */
  -webkit-appearance: menulist;     /* evitar estilos custom que oculten texto */
  appearance: auto;
  font-size: 15px;
  line-height: 1.2;
}

/* Forzar color legible dentro del menú desplegable (navegadores que respetan) */
.cap-mid select[data-k="species"] option {
  color: #111;                      /* texto de las opciones */
  background: #fff;                 /* fondo del desplegable */
}

/* Si el select queda muy alto en móviles, ajustar altura */
.cap-mid .time-field,
.cap-mid select[data-k="species"] {
  min-height: 40px;
}

/* Opcional: destacar opción seleccionada en el input visible */
.cap-mid select[data-k="species"] option:checked {
  font-weight: 600;
}

/* Estilos para la fila de cada caña: espacio superior para el botón */
#rods .rod {
  position: relative;
  padding-top: 44px; /* deja sitio para el botón arriba */
}

/* Asegurar fila en la parte superior */
#rods .rod {
  /* reducir padding-top si hay demasiado espacio visual */
  padding: 10px 12px;
}

#rods .rod .rod-row {
  display: flex;
  gap: 12px;
  align-items: flex-start; /* alinear ambos elementos al tope */
}

/* acciones: forzar alineación superior y pequeño offset para quedar justo al nivel del primer input */
#rods .rod .rod-actions {
  flex: 0 0 48px;
  display: flex;
  align-items: flex-start; /* sitúa el botón en la parte superior */
  justify-content: center;
  padding-top: 6px; /* ajustable si quieres subir/bajar la X */
}

/* botón eliminar: sin márgenes verticales que lo desplacen */
#rods .rod .rod-delete {
  height: 36px;
  width: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  cursor: pointer;
  background: rgba(255,48,48,0.08);
  border: 1px solid rgba(255,48,48,0.18);
  color: #ff5a5a;
  box-shadow: 0 1px 0 rgba(0,0,0,0.06);
  margin: 0;
  transform: none;
}

#rods .rod .rod-delete:hover {
  background: rgba(255,48,48,0.14);
  filter: none;
}

/* Compatibilidad: si el botón lleva .btn.ghost o data-del asegurarse mismo estilo */
#rods .rod button.btn.ghost.rod-delete,
#rods .rod button[data-del].rod-delete {
  background: rgba(255,48,48,0.08);
  border: 1px solid rgba(255,48,48,0.18);
  color: #ff5a5a;
}

/* Checklist: fila con contenido a la izquierda y botón eliminar a la derecha */
#checklist .row,
#checklist .check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  min-width: 0;
}

/* checkbox fijo al inicio */
#checklist .row input[type="checkbox"] {
  flex: 0 0 auto;
  margin: 0;
}

/* texto / input del item ocupa el espacio disponible */
#checklist .row input[type="text"],
#checklist .row .item-label,
#checklist .row .check-text {
  flex: 1 1 auto;
  min-width: 0;
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  box-sizing: border-box;
}

/* botón eliminar (papelera / X) alineado a la derecha */
#checklist .row button[data-del],
#checklist .row button.btn.ghost[data-del],
#checklist .row .trash,
#checklist .row .icon-btn.trash {
  margin-left: auto;
  flex: 0 0 36px;
  height: 36px;
  width: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid rgba(255,48,48,0.18);
  background: rgba(255,48,48,0.08);
  color: #ff5a5a;
  cursor: pointer;
}

/* hover */
#checklist .row button[data-del]:hover,
#checklist .row button.btn.ghost[data-del]:hover {
  background: rgba(255,48,48,0.14);
}

/* Ajustes móviles: si el espacio es pequeño, mantener fila pero reducir gaps */
@media (max-width: 520px) {
  #checklist .row { gap: 6px; padding: 6px; }
  #checklist .row button[data-del] { flex: 0 0 34px; height: 34px; width: 34px; }
}
