/* Identidad visual de Candina Group (misma que el portal de publicaciones):
   marino #213559 (acento) · tinta #0E1317 · texto #6D7A8E · superficies #F3F3F5 */

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

:root {
  --marino: #213559;
  --marino-oscuro: #182843;
  --marino-suave: #2e4570;
  --tinta: #0e1317;
  --texto: #26303d;
  --gris: #6d7a8e;
  --superficie: #f3f3f5;
  --tarjeta: #ffffff;
  --borde: #e2e5ea;
  --verde: #2e7d4f;
  --rojo: #b3423a;
  --ambar: #8a6d1f;
  --sombra: 0 1px 2px rgba(33, 53, 89, 0.06), 0 8px 24px -12px rgba(33, 53, 89, 0.18);
  --radio: 12px;
}

body {
  font-family: "Open Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--superficie);
  color: var(--texto);
  min-height: 100dvh;
  line-height: 1.55;
}

h1, h2, h3 {
  font-family: "Poppins", "Open Sans", system-ui, sans-serif;
  color: var(--tinta);
  letter-spacing: -0.015em;
  line-height: 1.25;
  text-wrap: balance;
}

a { color: var(--marino); }
.muted { color: var(--gris); }

/* --- Cabecera --- */

header.barra {
  background: var(--marino);
  color: #fff;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  box-shadow: 0 2px 12px rgba(14, 19, 23, 0.25);
}

.marca-cabecera { display: flex; align-items: center; gap: 0.7rem; }
.marca-cabecera img { height: 42px; width: 42px; }
.marca-cabecera .titulo {
  font-family: "Poppins", sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.01em;
}
.marca-cabecera .subtitulo {
  display: block;
  font-family: "Open Sans", sans-serif;
  font-size: 0.72rem;
  font-weight: 400;
  color: #aebad0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

header.barra nav { display: flex; gap: 1.1rem; align-items: center; font-size: 0.9rem; }
header.barra a {
  color: #d5deee;
  text-decoration: none;
  padding: 0.3rem 0;
  border-bottom: 2px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
}
header.barra a:hover { color: #fff; }
header.barra a.activo { color: #fff; border-bottom-color: #fff; }

main { max-width: 1240px; margin: 2.5rem auto 3.5rem; padding: 0 1.25rem; }

.encabezado-pagina { margin-bottom: 1.5rem; }
.encabezado-pagina h2 { font-size: 1.45rem; }
.encabezado-pagina p { color: var(--gris); max-width: 72ch; margin-top: 0.35rem; }

/* --- Tarjetas --- */

.tarjeta {
  background: var(--tarjeta);
  border-radius: var(--radio);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--sombra);
}
.tarjeta h2, .tarjeta h3 { font-size: 1.2rem; margin-bottom: 0.5rem; }

/* --- Formularios --- */

input[type="text"], input[type="password"], select {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--borde);
  border-radius: 8px;
  font: inherit;
  color: var(--texto);
  background: #fff;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input:hover, select:hover { border-color: #c3cad6; }
input:focus, select:focus {
  outline: none;
  border-color: var(--marino);
  box-shadow: 0 0 0 3px rgba(33, 53, 89, 0.15);
}
input::placeholder { color: #a3adbd; }

.filtros { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.filtros input[type="text"] { flex: 2 1 240px; }
.filtros select { flex: 1 1 190px; max-width: 340px; }

/* --- Botones --- */

.boton {
  display: inline-block;
  border: 0;
  border-radius: 8px;
  padding: 0.6rem 1.4rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--marino);
  color: #fff;
  text-decoration: none;
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
  box-shadow: 0 1px 2px rgba(14, 19, 23, 0.15);
}
.boton:hover { background: var(--marino-suave); box-shadow: 0 3px 10px -2px rgba(33, 53, 89, 0.4); }
.boton:active { transform: scale(0.98); }
.boton:focus-visible { outline: 3px solid rgba(33, 53, 89, 0.35); outline-offset: 2px; }
.boton:disabled { opacity: 0.5; cursor: wait; }
.boton.gris { background: #5d6c81; }
.boton.gris:hover { background: #6b7b92; }
.boton.pequeno { padding: 0.45rem 1rem; font-size: 0.88rem; }

/* --- Avisos y etiquetas --- */

.aviso, .fallo {
  padding: 0.85rem 1.1rem;
  border-radius: 10px;
  margin-bottom: 1.25rem;
  font-size: 0.93rem;
}
.fallo { background: #f9eae9; color: #7e2d27; border: 1px solid #ecc8c5; }
.aviso { background: #e8f3ec; color: #1e5637; border: 1px solid #c5e0d0; }

/* --- Formularios de posts --- */
label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--tinta);
  margin: 1.1rem 0 0.35rem;
}
label .opcional { font-weight: 400; color: var(--gris); }
label .req { color: var(--rojo); }
textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--borde);
  border-radius: 8px;
  font: inherit;
  color: var(--texto);
  background: #fff;
  resize: vertical;
  min-height: 92px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
textarea:hover { border-color: #c3cad6; }
textarea:focus { outline: none; border-color: var(--marino); box-shadow: 0 0 0 3px rgba(33, 53, 89, 0.15); }
input[type="file"] { display: block; font-size: 0.9rem; color: var(--gris); margin-top: 0.2rem; }
input[type="text"] { width: 100%; }
.filtros input[type="text"] { width: auto; }

.boton.rojo { background: var(--rojo); }
.boton.rojo:hover { background: #c25049; }
.acciones { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1rem; }
.miniatura {
  max-width: 240px; max-height: 170px; border-radius: 8px;
  display: block; margin: 0.6rem 0; box-shadow: var(--sombra);
}

.etiqueta {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.18rem 0.65rem;
  border-radius: 5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.etiqueta.vigente { background: #e2f0e8; color: var(--verde); }
.etiqueta.caducado { background: #f9e7e5; color: var(--rojo); }
.etiqueta.caduca-pronto { background: #f5edd7; color: var(--ambar); }
.etiqueta.sin-caducidad, .etiqueta.sin-fecha { background: #e9ecf1; color: var(--gris); }

.meta { color: var(--gris); font-size: 0.85rem; margin-bottom: 0.6rem; }

/* --- Tablas --- */

.table-wrap {
  overflow-x: auto;
  background: var(--tarjeta);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
th, td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--borde);
  vertical-align: top;
  white-space: nowrap;
}
tr:last-child td { border-bottom: 0; }
thead th {
  color: var(--gris);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  position: sticky;
  top: 0;
  background: var(--tarjeta);
}
tbody tr { transition: background 0.15s ease; }
tbody tr:hover { background: #f7f8fa; }
tbody tr.enlace { cursor: pointer; }

.vacio { text-align: center; padding: 2.5rem 1rem; color: var(--gris); }

.pager { display: flex; gap: 1rem; align-items: center; margin: 1.25rem 0; color: var(--gris); }

/* --- Ficha de tripulante --- */

.cards { display: flex; flex-wrap: wrap; gap: 1.5rem; }
.cards .tarjeta { flex: 1 1 320px; margin-bottom: 0; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1.2rem; margin-top: 0.6rem; }
dt { color: var(--gris); font-size: 0.9rem; }
dd { font-size: 0.93rem; }
h2.seccion { margin: 1.75rem 0 0.9rem; font-size: 1.2rem; }

/* --- Chat --- */

#chat-box {
  background: var(--tarjeta);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  min-height: 340px;
  max-height: 62vh;
  overflow-y: auto;
  padding: 1.25rem;
  margin-bottom: 0.9rem;
}
.bubble { max-width: 95%; margin: 0.6rem 0; padding: 0.7rem 1rem; border-radius: 12px; font-size: 0.93rem; }
.bubble.user { background: var(--marino); color: #fff; margin-left: auto; width: fit-content; border-bottom-right-radius: 4px; }
.bubble.bot { background: var(--superficie); border: 1px solid var(--borde); border-bottom-left-radius: 4px; }
.bubble.bot.error, .error-text { background: #f9eae9; color: #7e2d27; border-color: #ecc8c5; }
.bubble.wait { color: var(--gris); font-style: italic; }
.bubble tbody tr:hover { cursor: default; }
.bubble details { margin: 0.5rem 0; }
.bubble details summary { cursor: pointer; color: var(--marino); font-size: 0.85rem; font-weight: 600; }
.bubble pre {
  background: var(--tinta);
  color: #d5deee;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.85rem;
  margin-top: 0.4rem;
}
.bubble .table-wrap { max-height: 340px; overflow-y: auto; box-shadow: none; border: 1px solid var(--borde); margin-top: 0.5rem; }
.csv-btn { margin-top: 0.6rem; }
#chat-form { display: flex; gap: 0.6rem; }
#chat-input { flex: 1; }

/* --- Página de acceso --- */

body.acceso {
  background:
    linear-gradient(160deg, rgba(14, 19, 23, 0.82) 0%, rgba(33, 53, 89, 0.78) 55%, rgba(3, 25, 85, 0.72) 100%),
    url("/marca/fondo-barco.jpg") center / cover no-repeat fixed;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.panel-acceso { width: 100%; max-width: 400px; }
.panel-acceso .logo-grande { display: block; height: 96px; width: 96px; margin: 0 auto 1.2rem; }
.panel-acceso .lema {
  text-align: center;
  color: #d5deee;
  font-size: 0.8rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  margin-bottom: 1.6rem;
}
.panel-acceso .tarjeta { padding: 2rem; }
.panel-acceso h2 { font-size: 1.15rem; }
.panel-acceso label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--tinta);
  margin: 1.1rem 0 0.35rem;
}
.panel-acceso input { width: 100%; }
.panel-acceso .boton { width: 100%; margin-top: 1.3rem; }
.panel-acceso .pie {
  text-align: center;
  color: #93a3c0;
  font-size: 0.78rem;
  margin-top: 1.4rem;
}

/* --- Dashboard --- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.kpi {
  background: var(--tarjeta);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 1rem 1.2rem;
}
.kpi-etiqueta {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--gris);
  font-size: 0.82rem;
  font-weight: 600;
}
.kpi-valor {
  display: block;
  font-family: "Poppins", "Open Sans", sans-serif;
  font-weight: 600;
  font-size: 1.9rem;
  color: var(--tinta);
  margin-top: 0.3rem;
}
.kpi-nota { display: block; color: var(--gris); font-size: 0.8rem; margin-top: 0.15rem; }
.punto { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.punto.rojo { background: var(--rojo); }
.punto.ambar { background: var(--ambar); }

.paneles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
  align-items: start;
}
.paneles .tarjeta { margin-bottom: 0; }

.grafico-barras { margin-top: 0.9rem; display: grid; gap: 0.55rem; }
.gb-fila {
  display: grid;
  grid-template-columns: minmax(110px, 34%) 1fr;
  align-items: center;
  gap: 0.7rem;
  font-size: 0.88rem;
}
.gb-nombre { color: var(--texto); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gb-pista { display: flex; align-items: center; gap: 0.5rem; }
.gb-relleno {
  /* barra: extremo de datos redondeado (derecha), base recta (izquierda) */
  height: 14px;
  background: #3c62a8;
  border-radius: 0 4px 4px 0;
  transition: background 0.15s ease;
}
.gb-fila:hover .gb-relleno { background: #34568f; }
.gb-valor { color: var(--gris); font-size: 0.82rem; }

.paneles .tarjeta.ancha { grid-column: 1 / -1; }

/* gráficos de columnas (SVG generado por graficos.js) */
.grafico-columnas { margin-top: 0.9rem; }
.svg-columnas { display: block; width: 100%; height: auto; }
.gc-grid { stroke: var(--borde); stroke-width: 1; }
.gc-tick { fill: var(--gris); font-size: 11px; }
.gc-max { fill: var(--tinta); font-size: 11px; font-weight: 600; }
.gc-hit:focus { outline: none; }
.gc-hit:focus-visible { outline: 2px solid var(--marino); outline-offset: -2px; }

.tooltip-grafico {
  display: none;
  position: absolute;
  z-index: 30;
  background: var(--tinta);
  color: #fff;
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
  font-size: 0.82rem;
  pointer-events: none;
  box-shadow: var(--sombra);
}
.tooltip-grafico strong { display: block; font-size: 0.95rem; }
.tooltip-grafico span { color: #c9d3e4; }

.ver-tabla { margin-top: 0.6rem; }
.ver-tabla summary { cursor: pointer; color: var(--marino); font-size: 0.85rem; font-weight: 600; }
.ver-tabla table { margin-top: 0.5rem; }
.ver-tabla tbody tr:hover { cursor: default; }

/* --- Pie de página --- */

footer.pie-portal {
  text-align: center;
  color: var(--gris);
  font-size: 0.8rem;
  padding: 0 1rem 2rem;
}

@media (max-width: 640px) {
  main { margin-top: 1.5rem; }
  .tarjeta { padding: 1.25rem; }
  header.barra { padding: 0.7rem 1rem; }
  .marca-cabecera .subtitulo { display: none; }
}

/* ---------------- Mensajes internos y ranking ---------------- */
.aviso-num {
  display: inline-block;
  min-width: 1.3em;
  padding: 0.05em 0.35em;
  border-radius: 999px;
  background: var(--rojo);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
}
.mensajes-panel { display: flex; padding: 0; overflow: hidden; min-height: 480px; }
.mensajes-contactos {
  flex: 0 0 250px;
  border-right: 1px solid var(--borde);
  overflow-y: auto;
  max-height: 640px;
  padding: 0.6rem 0;
}
.mensajes-contactos .contacto {
  display: block;
  padding: 0.55rem 1rem;
  text-decoration: none;
  color: var(--texto);
  border-left: 3px solid transparent;
}
.mensajes-contactos .contacto:hover { background: var(--superficie); }
.mensajes-contactos .contacto.activo { background: var(--superficie); border-left-color: var(--marino); }
.contacto-nombre { display: flex; align-items: center; gap: 0.4rem; font-weight: 600; }
.contacto-detalle { display: block; font-size: 0.8rem; color: var(--gris); }
.mensajes-conversacion { flex: 1; display: flex; flex-direction: column; padding: 1rem 1.25rem; min-width: 0; }
.mensajes-vacio { margin: auto; }
.conversacion-cabecera {
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--borde);
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
}
.hilo {
  flex: 1;
  overflow-y: auto;
  max-height: 440px;
  padding: 0.8rem 0.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.msg {
  max-width: 72%;
  align-self: flex-start;
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 12px 12px 12px 4px;
  padding: 0.5rem 0.8rem;
}
.msg.mio { align-self: flex-end; background: #e7edf8; border-radius: 12px 12px 4px 12px; }
.msg-texto { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-fecha { font-size: 0.72rem; color: var(--gris); margin-top: 0.15rem; text-align: right; }
.envio { display: flex; gap: 0.6rem; padding-top: 0.8rem; border-top: 1px solid var(--borde); }
.envio input { flex: 1; }
.ranking-tabla { width: 100%; border-collapse: collapse; }
.ranking-tabla th, .ranking-tabla td { padding: 0.55rem 0.7rem; text-align: left; border-bottom: 1px solid var(--borde); }
.ranking-tabla th { color: var(--gris); font-size: 0.85rem; font-weight: 600; }
.ranking-barra-celda { width: 40%; }
.ranking-barra { height: 0.8rem; min-width: 2px; border-radius: 4px; background: var(--marino); }
@media (max-width: 720px) {
  .mensajes-panel { flex-direction: column; }
  .mensajes-contactos { flex: none; max-height: 200px; border-right: none; border-bottom: 1px solid var(--borde); }
}
.contactos-seccion {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gris);
}
.msg-autor { font-size: 0.76rem; font-weight: 600; color: var(--marino); margin-bottom: 0.1rem; }
.en-linea { display: inline; }
.boton-enlace {
  background: none;
  border: none;
  padding: 0;
  color: var(--rojo);
  font: inherit;
  font-size: 0.82rem;
  text-decoration: underline;
  cursor: pointer;
}
.nota-form { display: flex; gap: 0.6rem; align-items: flex-start; margin-bottom: 1rem; }
.nota-form textarea { flex: 1; margin: 0; }
.notas-lista { list-style: none; display: flex; flex-direction: column; gap: 0.7rem; }
.notas-lista li { border-left: 3px solid var(--marino); background: var(--superficie); padding: 0.55rem 0.8rem; border-radius: 0 6px 6px 0; }
.nota-texto { white-space: pre-wrap; overflow-wrap: anywhere; }
.nota-meta { font-size: 0.78rem; color: var(--gris); margin-top: 0.25rem; }
