/* GLOBALSA app-operarios — estilos MVP (mobile-first, sin framework) */

:root {
  /* Paleta GLOBALSA (tomada del logo corporativo) */
  --corp-oscuro: #5a5e6b;       /* fondo del logo (dark slate) */
  --corp-oscuro-2: #484b57;     /* variante hover del oscuro */
  --corp-teal:    #17b2a8;      /* acento teal del logo */
  --corp-teal-2:  #128a82;      /* teal más profundo para hover */
  --corp-teal-bg: #e6f6f5;      /* teal muy claro para fondos suaves */

  /* Compat con código anterior */
  --azul:        var(--corp-teal);
  --azul-claro:  var(--corp-teal-2);

  --gris-bg:     #f4f5f7;
  --gris-borde:  #d0d4db;
  --gris-texto:  #4a4f5a;
  --verde:       #2e7d32;
  --rojo:        #c62828;
  --naranja:     #e67e22;
  --blanco:      #ffffff;
  --sombra:      0 1px 3px rgba(0, 0, 0, 0.08);
  --radio:       6px;
  --fuente:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--gris-bg);
  color: #222;
  font-family: var(--fuente);
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
}

body {
  display: flex;
  flex-direction: column;
}

header {
  background: var(--corp-oscuro);
  color: var(--blanco);
  padding: 0.6rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--sombra);
  border-bottom: 3px solid var(--corp-teal);
}

header .brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.logo-header {
  height: 36px;
  width: auto;
  display: block;
  /* Ocultar elegantemente si la imagen no carga */
  image-rendering: auto;
}
.logo-header-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--corp-teal);
  color: var(--blanco);
  font-weight: 700;
}

.logo-login {
  display: block;
  margin: 0 auto 1rem;
  width: 180px;
  height: auto;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
}

.user-bar button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: var(--blanco);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radio);
  font-size: 0.8rem;
  cursor: pointer;
}

.user-bar button:hover { background: rgba(255, 255, 255, 0.15); }

main {
  flex: 1;
  padding: 1rem;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

footer {
  padding: 0.6rem 1rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--gris-texto);
}

/* Tarjetas */
.card {
  background: var(--blanco);
  border-radius: var(--radio);
  padding: 1rem;
  box-shadow: var(--sombra);
  margin-bottom: 1rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  color: var(--corp-oscuro);
  border-bottom: 2px solid var(--corp-teal);
  padding-bottom: 0.35rem;
  display: inline-block;
}

/* Formularios */
label {
  display: block;
  font-weight: 600;
  margin: 0.75rem 0 0.3rem;
  font-size: 0.9rem;
}

input[type="text"], input[type="number"], input[type="date"],
input[type="password"], select, textarea {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio);
  font-size: 1rem;
  font-family: var(--fuente);
  background: var(--blanco);
}

input[type="number"] { text-align: right; }

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--azul-claro);
  outline-offset: -1px;
}

.btn {
  display: inline-block;
  padding: 0.65rem 1.1rem;
  background: var(--corp-teal);
  color: var(--blanco);
  border: 0;
  border-radius: var(--radio);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--fuente);
}

.btn:hover { background: var(--corp-teal-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.secundario { background: var(--gris-borde); color: #333; }
.btn.secundario:hover { background: #b9bec7; }
.btn.peligro { background: var(--rojo); }

/* Login */
.login-wrap {
  max-width: 320px;
  margin: 3rem auto;
}
.login-wrap .card { padding: 1.5rem; }

.pin-input { letter-spacing: 0.4rem; text-align: center; font-size: 1.4rem; }

/* Mensajes */
.error {
  background: #fdecea;
  border: 1px solid var(--rojo);
  color: var(--rojo);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radio);
  margin: 0.75rem 0;
  font-size: 0.9rem;
}
.ok {
  background: #e8f5e9;
  border: 1px solid var(--verde);
  color: var(--verde);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radio);
  margin: 0.75rem 0;
  font-size: 0.9rem;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--gris-borde);
}
.tabs button {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 0.65rem 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--gris-texto);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  font-family: var(--fuente);
}
.tabs button.activo {
  color: var(--corp-teal);
  border-bottom-color: var(--corp-teal);
}

/* Sub-pestañas (segundo nivel, dentro de un grupo) */
.tabs.tabs-sub {
  background: var(--gris-bg);
  border-radius: var(--radio);
  border-bottom: 0;
  padding: 0.2rem 0.3rem;
  margin-top: -0.5rem;
  margin-bottom: 1rem;
  gap: 0;
}
.tabs.tabs-sub button {
  font-size: 0.85rem;
  padding: 0.45rem 0.85rem;
  border-bottom: 0;
  border-radius: var(--radio);
  flex: 0 0 auto;
}
.tabs.tabs-sub button.activo {
  background: white;
  color: var(--corp-teal);
  border-bottom: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Fichaje: tabla de operarios/máquinas */
.tabla-presencia {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
}
.tabla-presencia th, .tabla-presencia td {
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--gris-borde);
  text-align: left;
  font-size: 0.9rem;
  vertical-align: middle;
}
.tabla-presencia th {
  background: var(--gris-bg);
  font-weight: 600;
  color: var(--gris-texto);
}
.tabla-presencia td.horas { width: 5rem; }
.tabla-presencia input[type="number"] {
  padding: 0.35rem 0.4rem;
  font-size: 0.9rem;
}
.tabla-presencia tr.activa { background: var(--corp-teal-bg); }
.tabla-presencia input[type="checkbox"] { width: 1.2rem; height: 1.2rem; }

/* Historial */
.historial {
  width: 100%;
  border-collapse: collapse;
}
.historial th, .historial td {
  padding: 0.5rem;
  text-align: left;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--gris-borde);
}
.historial th { background: var(--gris-bg); color: var(--gris-texto); font-weight: 600; }
.historial td.estado { font-weight: 600; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge.borrador  { background: #eceff1; color: #37474f; }
.badge.enviado   { background: #fff3e0; color: #e65100; }
.badge.aprobado  { background: #e8f5e9; color: #1b5e20; }
.badge.rechazado { background: #fdecea; color: #b71c1c; }

.muted { color: var(--gris-texto); font-size: 0.85rem; }

.spinner { padding: 2rem; text-align: center; color: var(--gris-texto); }

/* ===== Calendario ===== */
.calendario-cabecera {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.calendario-cabecera h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--corp-oscuro);
}
.calendario-cabecera button {
  background: var(--corp-teal-bg);
  color: var(--corp-teal-2);
  border: 0;
  border-radius: var(--radio);
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  font-weight: 600;
}

.calendario-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.calendario-grid .cal-dow {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gris-texto);
  padding-bottom: 0.25rem;
}
.cal-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radio);
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid transparent;
  cursor: default;
}
.cal-cell.verde    { background: #d4edda; color: #155724; }
.cal-cell.amarillo { background: #fff3cd; color: #856404; }
.cal-cell.naranja  { background: #ffe5b4; color: #8a4f00; }
.cal-cell.azul     { background: #cfe2ff; color: #084298; }
.cal-cell.rojo     { background: #f8d7da; color: #721c24; }
.cal-cell.futuro   { background: var(--gris-bg); color: var(--gris-texto); }
.cal-cell.neutro   { background: var(--gris-bg); color: var(--gris-texto); }
.cal-cell.vacio    { background: transparent; }
.cal-cell.hoy      { border-color: var(--corp-teal); border-width: 2px; }

.cal-leyenda {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--gris-texto);
}
.cal-leyenda span {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.cal-leyenda i {
  width: 14px; height: 14px;
  border-radius: 3px;
  display: inline-block;
}

/* ===== Calendario MENSUAL grande (cuadrícula tipo agenda) ===== */
.calendario-mes {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 0.5rem;
}
.calendario-mes .cal-mes-dow {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gris-texto);
  padding-bottom: 0.25rem;
  background: var(--gris-bg);
  padding: 0.4rem 0;
  border-radius: var(--radio);
}
.calendario-mes .cal-mes-cell {
  aspect-ratio: 1;
  border-radius: var(--radio);
  border: 1px solid transparent;
  padding: 0.3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  font-size: 0.85rem;
  position: relative;
  min-height: 70px;
}
.calendario-mes .cal-mes-cell.vacio {
  background: transparent;
}
.calendario-mes .cal-mes-cell.verde    { background: #d4edda; color: #155724; }
.calendario-mes .cal-mes-cell.amarillo { background: #fff3cd; color: #856404; }
.calendario-mes .cal-mes-cell.naranja  { background: #ffe5b4; color: #8a4f00; }
.calendario-mes .cal-mes-cell.azul     { background: #cfe2ff; color: #084298; }
.calendario-mes .cal-mes-cell.rojo     { background: #f8d7da; color: #721c24; }
.calendario-mes .cal-mes-cell.neutro,
.calendario-mes .cal-mes-cell.futuro   { background: var(--gris-bg); color: var(--gris-texto); }
.calendario-mes .cal-mes-cell.festivo {
  background: repeating-linear-gradient(-45deg, var(--gris-bg), var(--gris-bg) 4px, #e9ecef 4px, #e9ecef 8px);
}
.calendario-mes .cal-mes-cell.hoy { border-color: var(--corp-teal); border-width: 2px; }
.calendario-mes .cal-mes-cell .dia-num {
  align-self: flex-start;
  font-weight: 700;
  font-size: 0.95rem;
}
.calendario-mes .cal-mes-cell .label-tipo {
  margin-top: 0.4rem;
  font-weight: 600;
  text-align: center;
  font-size: 0.8rem;
}
.calendario-mes .cal-mes-cell .huella-mes {
  margin-top: auto;
  font-family: monospace;
  font-size: 0.65rem;
  color: var(--gris-texto);
  opacity: 0.85;
}
.calendario-mes .cal-mes-cell .festivo-name {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  font-size: 0.6rem;
  font-style: italic;
  color: var(--gris-texto);
  max-width: 60%;
  text-align: right;
  line-height: 1.1;
}
/* Botón para borrar el registro de un día (X arriba derecha)
 * Visible SIEMPRE (no solo en hover) para que funcione en móvil/tablet
 * donde no hay hover. */
.calendario-mes .cal-mes-cell .borrar-dia {
  position: absolute;
  top: 0.2rem;
  right: 0.2rem;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #b71c1c;
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid rgba(0, 0, 0, 0.15);
  user-select: none;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.calendario-mes .cal-mes-cell .borrar-dia:hover,
.calendario-mes .cal-mes-cell .borrar-dia:active {
  background: var(--rojo); color: white;
}

/* Sumatorio del mes */
.sumatorio-mes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.5rem;
  margin-top: 1rem;
}
.sumatorio-mes .item {
  padding: 0.6rem 0.75rem;
  border-radius: var(--radio);
  text-align: center;
}
.sumatorio-mes .item.verde    { background: #d4edda; color: #155724; }
.sumatorio-mes .item.amarillo { background: #fff3cd; color: #856404; }
.sumatorio-mes .item.naranja  { background: #ffe5b4; color: #8a4f00; }
.sumatorio-mes .item.azul     { background: #cfe2ff; color: #084298; }
.sumatorio-mes .item.rojo     { background: #f8d7da; color: #721c24; }
.sumatorio-mes .item.total    { background: var(--corp-teal-bg); color: var(--corp-teal-2); border: 1px solid var(--corp-teal); }
.sumatorio-mes .item .num     { display: block; font-size: 1.4rem; font-weight: 700; }
.sumatorio-mes .item .label   { font-size: 0.78rem; }

/* ===== Calendario global (Adrià) ===== */
.cal-global {
  display: block;
  overflow-x: auto;
  margin-top: 0.5rem;
}
.cal-global table {
  border-collapse: collapse;
  font-size: 0.78rem;
}
.cal-global th, .cal-global td {
  padding: 0.25rem 0.35rem;
  border: 1px solid var(--gris-borde);
  text-align: center;
}
.cal-global th.jefe-col {
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  background: var(--gris-bg);
  position: sticky;
  left: 0;
  z-index: 1;
}
.cal-global td.jefe-col {
  text-align: left;
  white-space: nowrap;
  background: var(--blanco);
  position: sticky;
  left: 0;
  z-index: 1;
  font-weight: 600;
}
.cal-global td.dom { background: var(--gris-bg); color: var(--gris-texto); }
.cal-global td.cell-verde    { background: #d4edda; color: #155724; }
.cal-global td.cell-amarillo { background: #fff3cd; color: #856404; }
.cal-global td.cell-naranja  { background: #ffe5b4; color: #8a4f00; }
.cal-global td.cell-azul     { background: #cfe2ff; color: #084298; }
.cal-global td.cell-rojo     { background: #f8d7da; color: #721c24; font-weight: 700; }
.cal-global td.cell-futuro   { background: transparent; color: var(--gris-texto); }
.cal-global td.cell-neutro   { background: var(--gris-bg); color: var(--gris-texto); }

/* ===== Banner de corrección ===== */
.banner-corregir {
  background: #fff8e1;
  border-left: 4px solid var(--naranja);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radio);
}
.banner-corregir strong { color: var(--rojo); }

/* ===== Validación horaria diaria ===== */
.horario-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  border-left: 4px solid var(--gris-borde);
}
.horario-card.verde   { background: linear-gradient(135deg, #e8f5e9, #ffffff); border-left-color: #2e7d32; }
.horario-card.rojo    { background: linear-gradient(135deg, #fff5f5, #ffffff); border-left-color: var(--rojo); }
.horario-card.aviso   { background: linear-gradient(135deg, #fff3e0, #ffffff); border-left-color: var(--naranja); }
.horario-card.neutro  { background: linear-gradient(135deg, #f4f5f7, #ffffff); }

.horario-info { flex: 1; min-width: 240px; }
.horario-titulo { font-size: 1.05rem; font-weight: 700; color: var(--corp-oscuro); }
.horario-titulo.verde  { color: #1b5e20; }
.horario-titulo.rojo   { color: #b71c1c; }
.horario-titulo.aviso  { color: #b35900; }
.horario-turnos { color: var(--gris-texto); font-size: 0.95rem; margin-top: 0.25rem; }
.horario-turnos strong { color: var(--corp-oscuro); }
.horario-validado { font-size: 0.82rem; color: var(--gris-texto); margin-top: 0.25rem; }

.horario-btn-validar {
  font-size: 1.05rem !important;
  padding: 0.85rem 1.5rem !important;
  background: var(--corp-teal) !important;
  min-width: 200px;
}
.horario-btn-validar.aviso { background: var(--naranja) !important; }

/* Botones secundarios para ausencias justificadas */
.horario-ausencia-row {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--gris-borde);
  font-size: 0.85rem;
}
.horario-ausencia-row .label {
  color: var(--gris-texto);
  margin-right: 0.3rem;
}
.btn.btn-ausencia {
  font-size: 0.85rem !important;
  padding: 0.4rem 0.7rem !important;
  background: white !important;
  color: var(--gris-texto) !important;
  border: 1px solid var(--gris-borde) !important;
}
.btn.btn-ausencia:hover {
  background: var(--gris-bg) !important;
  border-color: var(--corp-teal) !important;
  color: var(--corp-teal-2) !important;
}

/* Festivo en celda del calendario — diagonal sutil para distinguir de un sábado/domingo normal */
.cell-festivo, .cal-cell.festivo {
  background: repeating-linear-gradient(
    -45deg,
    var(--gris-bg),
    var(--gris-bg) 4px,
    #e9ecef 4px,
    #e9ecef 8px
  ) !important;
  color: var(--gris-texto) !important;
}

/* Modal de firma */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal {
  background: white;
  border-radius: var(--radio);
  padding: 1.25rem;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.modal h2 { margin-top: 0; }
.firma-canvas {
  display: block;
  width: 100%;
  height: 180px;
  border: 2px dashed var(--corp-teal);
  border-radius: var(--radio);
  background: #fafcff;
  touch-action: none;
  cursor: crosshair;
  margin-top: 0.5rem;
}
.firma-instr { font-size: 0.85rem; color: var(--gris-texto); margin-top: 0.4rem; }

/* ===== Fichaje (LEGACY — ya no se usa) ===== */
.fichaje-card {
  background: linear-gradient(135deg, var(--corp-teal-bg), #ffffff);
  border-left: 4px solid var(--corp-teal);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.fichaje-info { flex: 1; min-width: 220px; }
.fichaje-titulo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--corp-oscuro);
}
.fichaje-titulo.dentro { color: #1b5e20; }
.fichaje-titulo.fuera  { color: var(--gris-texto); }
.fichaje-sub { font-size: 0.85rem; color: var(--gris-texto); margin-top: 0.15rem; }
.fichaje-horas { font-size: 1.5rem; font-weight: 700; color: var(--corp-teal-2); }
.fichaje-btn-grande {
  font-size: 1.1rem !important;
  padding: 0.85rem 1.5rem !important;
  min-width: 180px;
}
.fichaje-btn-entrada { background: #2e7d32 !important; }
.fichaje-btn-entrada:hover { background: #1b5e20 !important; }
.fichaje-lista {
  width: 100%;
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
  font-size: 0.82rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--gris-borde);
}
.fichaje-evt {
  background: white;
  padding: 0.2rem 0.55rem;
  border-radius: 12px;
  border: 1px solid var(--gris-borde);
}
.fichaje-evt.entrada { border-color: #2e7d32; color: #1b5e20; }
.fichaje-evt.salida  { border-color: var(--rojo); color: #b71c1c; }

/* Responsive */
@media (min-width: 700px) {
  main { padding: 1.5rem; }
  .card { padding: 1.25rem 1.5rem; }
}

/* Grid helpers */
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 500px) {
  .row { grid-template-columns: 1fr; }
}

.acciones {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.tipo-toggle {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
}
.tipo-toggle label {
  flex: 1;
  margin: 0;
  padding: 0.6rem;
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio);
  text-align: center;
  cursor: pointer;
  font-weight: 600;
  color: var(--gris-texto);
  background: var(--blanco);
}
.tipo-toggle input { display: none; }
.tipo-toggle input:checked + span {
  /* applied via class on parent label by JS (see app.js) */
}
.tipo-toggle label.activo {
  background: var(--corp-teal);
  color: var(--blanco);
  border-color: var(--corp-teal);
}
