/* ═══════════════════════════════════════════════════════
   style.css · Sistema de Fichajes
   Color principal: #F06134 (naranja corporativo)
═══════════════════════════════════════════════════════ */

:root {
  --color-brand: #F06134;
  --color-brand-dark: #c94d1c;
  --color-brand-light: #fff3ee;
  --sidebar-w: 80px;
  --sidebar-bg: #1a2642;
  --sidebar-hover: #243356;
  --sidebar-active: #F06134;
  --topbar-h: 54px;
  --bottomnav-h: 62px;
}

/* ── Reset layout ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }
body.app-layout { display: flex; background: #f4f6fa; }

/* ══════════════════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════════════════ */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  z-index: 1000;
  box-shadow: 2px 0 8px rgba(0,0,0,.18);
}

/* Logo */
.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 18px 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo img {
  width: 44px;
  height: auto;
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: .92;
}

/* Nav list */
.sidebar-nav {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  width: 100%;
  flex: 1;
}
.sidebar-item { width: 100%; }

/* Links */
.sidebar-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px 6px;
  color: rgba(255,255,255,.72);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .3px;
  transition: background .18s, color .18s;
  border-left: 3px solid transparent;
}
.sidebar-link i {
  font-size: 20px;
  line-height: 1;
}
.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
}
.sidebar-link.active {
  background: rgba(240,97,52,.18);
  color: #fff;
  border-left-color: var(--sidebar-active);
  font-weight: 700;
}
.sidebar-link.active i { color: var(--sidebar-active); }

/* Zona inferior */
.sidebar-bottom {
  width: 100%;
  border-top: 1px solid rgba(255,255,255,.08);
  padding-bottom: 6px;
}
.sidebar-logout:hover { color: #ff6b6b !important; }

/* ══════════════════════════════════════════════════════
   ÁREA PRINCIPAL
══════════════════════════════════════════════════════ */
.main-area {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

.login-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Cabecera superior ──────────────────────────────── */
.top-header {
  position: sticky;
  top: 0;
  z-index: 900;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid #e8eaf0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.top-header-title {
  font-size: 15px;
  font-weight: 700;
  color: #2c3e6b;
  letter-spacing: .2px;
}
.top-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #555;
}
.top-user-name { font-weight: 600; color: #333; }

/* ── Flash messages ─────────────────────────────────── */
.flash-zone { padding: 10px 24px 0; }

/* ── Contenido principal ────────────────────────────── */
.main-content {
  flex: 1;
  padding: 22px 24px;
}

/* ── Footer ─────────────────────────────────────────── */
.main-footer {
  text-align: center;
  color: #aaa;
  font-size: 11px;
  padding: 14px;
  border-top: 1px solid #eee;
}
.main-footer img {
  height: 18px;
  opacity: .45;
  vertical-align: middle;
  margin-right: 6px;
}

/* ── Colores globales ─────────────────────────────────── */
.bg-brand       { background-color: var(--color-brand) !important; }
.text-brand     { color: var(--color-brand) !important; }
.border-brand   { border-color: var(--color-brand) !important; }
.btn-brand {
  background-color: var(--color-brand);
  border-color: var(--color-brand);
  color: #fff;
}
.btn-brand:hover, .btn-brand:focus {
  background-color: var(--color-brand-dark);
  border-color: var(--color-brand-dark);
  color: #fff;
}
.btn-brand:active { transform: scale(.98); }

/* ── Accordion ────────────────────────────────────────── */
.accordion-button:not(.collapsed) {
  color: var(--color-brand);
  background-color: var(--color-brand-light);
  box-shadow: inset 0 -1px 0 rgba(240,97,52,.2);
}
.accordion-button:focus { box-shadow: 0 0 0 .2rem rgba(240,97,52,.25); }

/* ── Cards ────────────────────────────────────────────── */
.card { border-radius: 10px; }

/* ── Tabla matriz ─────────────────────────────────────── */
#tabla-matriz {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
#tabla-matriz th {
  background: var(--color-brand);
  color: #fff;
  font-weight: 700;
  text-align: center;
  padding: 6px 8px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}
#tabla-matriz td {
  vertical-align: middle;
  padding: 4px 6px;
  border-bottom: 1px solid #eee;
}
#tabla-matriz tr:hover td { background: #fff8f5; }
#tabla-matriz .col-nombre {
  min-width: 150px;
  max-width: 200px;
  font-weight: 600;
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
  border-right: 2px solid #ffe0d0;
}
#tabla-matriz th:first-child {
  left: 0;
  z-index: 3;
}

/* ── Tabla de horario dinámica (ínjectada vía AJAX) ─── */
.mu-matriz-horaria {
  border-collapse: separate;
  border-spacing: 4px;
  width: 100%;
  font-size: 13px;
}
.mu-matriz-horaria thead tr th {
  background: var(--sidebar-bg);
  color: #fff;
  font-weight: 700;
  text-align: center;
  padding: 8px 10px;
  white-space: nowrap;
  border-radius: 8px;
  font-size: 12px;
  letter-spacing: .3px;
}
.mu-matriz-horaria thead tr th:first-child {
  background: var(--color-brand-dark);
  min-width: 130px;
  text-align: left;
  border-radius: 8px;
  /* Sticky primera columna cabecera */
  position: sticky;
  left: 0;
  z-index: 3;
}
/* Sticky primera columna cuerpo */
.mu-matriz-horaria tbody tr td:first-child {
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
  border-right: 2px solid #ffe0d0;
  box-shadow: 2px 0 5px rgba(0,0,0,.07);
}
.mu-matriz-horaria thead tr th.header-finde {
  background: #6b7280 !important;
}
.mu-matriz-horaria thead tr th.header-fecha {
  cursor: pointer;
  transition: opacity .15s;
}
.mu-matriz-horaria thead tr th.header-fecha:hover {
  opacity: .82;
}
/* Celdas vacías de la matriz */
.mu-matriz-horaria tbody tr td.celda-turno:empty::before {
  content: '—';
  color: #ccc;
  font-weight: 400;
}
.mu-matriz-horaria tbody tr {
  vertical-align: middle;
}

/* Celdas de turno */
.celda-turno {
  min-width: 100px;
  cursor: pointer;
  border-radius: 8px;
  padding: 6px 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  white-space: pre-line;
  vertical-align: middle;
  transition: filter .15s, box-shadow .15s, transform .1s;
  user-select: none;
  border: 1px solid rgba(0,0,0,.08);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.celda-turno:not(.bloqueada):hover {
  filter: brightness(.92);
  box-shadow: 0 3px 8px rgba(0,0,0,.18);
  transform: translateY(-1px);
}
.celda-turno.vacia  { background: #f8f9fa !important; color: #bbb; font-size: 14px; font-weight: 300; border: 1px dashed #ddd; box-shadow: none; cursor: pointer; }
.celda-turno.bloqueada { cursor: default; }
.celda-turno.ausencia  { color: #333 !important; font-style: italic; font-size: 11px; border-style: dashed; }

/* Header fin de semana */
.header-finde { background: #c94d1c !important; }

/* ── Botones micro ────────────────────────────────────── */
.btn-xs {
  padding: 2px 7px;
  font-size: 11px;
  border-radius: 4px;
}

/* ── Badges fichaje ───────────────────────────────────── */
.badge-puntual  { background: #2e7d32 !important; }
.badge-tarde    { background: #e65100 !important; }
.badge-falta    { background: #d32f2f !important; }
.badge-sin-fich { background: #9e9e9e !important; }

/* ── Scrollbar personalizada ──────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: var(--color-brand); border-radius: 3px; }

/* ── Footer ───────────────────────────────────────────── */
footer { border-top: 1px solid #eee; margin-top: 2rem; }

/* ══════════════════════════════════════════════════════
   RESPONSIVE MÓVIL  (≤ 768 px)
══════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Sidebar lateral → barra inferior ── */
  .sidebar {
    top: auto;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--bottomnav-h);
    flex-direction: row;
    align-items: stretch;
    padding: 0;
    box-shadow: 0 -2px 10px rgba(0,0,0,.18);
    z-index: 1100;
  }

  /* Ocultar logo en barra inferior */
  .sidebar-logo { display: none; }

  /* Nav ocupa todo el ancho */
  .sidebar-nav {
    display: flex;
    flex-direction: row;
    flex: 1;
    margin: 0;
    height: 100%;
    align-items: stretch;
  }
  .sidebar-item {
    flex: 1;
    display: flex;
  }

  /* Links horizontales */
  .sidebar-link {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 6px 2px;
    font-size: 10px;
    border-left: none;
    border-top: 3px solid transparent;
    gap: 3px;
  }
  .sidebar-link i { font-size: 18px; }
  .sidebar-link.active {
    border-left-color: transparent;
    border-top-color: var(--sidebar-active);
    background: rgba(240,97,52,.15);
  }

  /* Zona inferior (perfil/salir) en fila al final */
  .sidebar-bottom {
    display: flex;
    flex-direction: row;
    border-top: none;
    border-left: 1px solid rgba(255,255,255,.08);
    padding: 0;
    width: auto;
  }
  .sidebar-bottom .sidebar-link {
    padding: 6px 10px;
    font-size: 10px;
  }

  /* ── Main area: sin margen izquierdo, con padding inferior ── */
  .main-area {
    margin-left: 0 !important;
    padding-bottom: var(--bottomnav-h);
  }

  /* ── Top header compacto ── */
  .top-header {
    padding: 0 12px;
    height: 48px;
  }
  .top-header-title { font-size: 13px; }
  .top-user-name { display: none; }   /* nombre usuario oculto, solo icono */
  .top-header-right .badge { font-size: 10px; }

  /* ── Contenido con menos padding ── */
  .main-content { padding: 14px 12px; }
  .flash-zone   { padding: 8px 12px 0; }

  /* ── Dashboard: controles apilados ── */
  #sel-centro, #sel-vista, #fecha-ref,
  #libre-inicio, #libre-fin {
    max-width: 100% !important;
    width: 100%;
  }
  .d-flex.flex-wrap.align-items-center.gap-2.mb-3 {
    flex-direction: column;
    align-items: stretch !important;
  }
  .d-flex.flex-wrap .ms-auto {
    margin-left: 0 !important;
    display: flex;
    justify-content: flex-end;
  }
  #btn-cargar { width: 100%; }

  /* ── Fichaje: botones grandes para dedo ── */
  .btn-fichaje {
    font-size: 1.1rem !important;
    padding: 1rem 1.5rem !important;
  }
  .hora-actual { font-size: 2.6rem; }

  /* ── Tabla matriz: scroll horizontal ── */
  .celda-turno  { min-width: 62px !important; font-size: 10px !important; padding: 3px 2px !important; line-height: 1.3; }
  #wrap-matriz  { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* Nombre empleado más estrecho en móvil */
  .mu-matriz-horaria thead tr th:first-child { min-width: 82px !important; font-size: 10px; padding: 6px 4px; }
  .mu-matriz-horaria tbody tr td:first-child  { min-width: 82px !important; font-size: 10px; padding: 4px 4px; }
  /* Cabecera de fecha compacta: solo el número de día */
  .mu-matriz-horaria thead tr th.header-fecha { min-width: 62px; padding: 5px 2px; }
  .mu-matriz-horaria thead tr th.header-fecha > div:last-child { display: none; }
  /* Ocultar botón fullscreen en móvil */
  #btn-fullscreen { display: none; }
  /* Barra de navegación de semana */
  #mobile-week-nav {
    background: #fff;
    border-radius: 10px;
    padding: 6px 8px;
    border: 1px solid #e8eaf0;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
  }

  /* ── Modales a pantalla completa ── */
  .modal-dialog {
    margin: 0;
    max-width: 100%;
    height: 100%;
  }
  .modal-dialog .modal-content {
    min-height: 100dvh;
    border-radius: 0;
  }
  .modal-dialog-scrollable .modal-body { max-height: calc(100dvh - 130px); }

  /* ── Cards sin bordes redondeados extremos ── */
  .card { border-radius: 8px; }

  /* ── Footer oculto en móvil (ya hay barra inferior) ── */
  .main-footer { display: none; }
}

/* Ajuste extra pantallas muy pequeñas */
@media (max-width: 375px) {
  .sidebar-link span { display: none; }  /* solo icono en iPhone SE */
  .sidebar-link i    { font-size: 20px; }
  .hora-actual       { font-size: 2.2rem; }
}

/* ── Modo compacto vista MES ──────────────────────────────── */
.mu-vista-mes {
  font-size: 10px;
  border-spacing: 2px;
}
.mu-vista-mes thead tr th:first-child {
  min-width: 110px;
}
.mu-vista-mes thead tr th.header-fecha {
  min-width: 34px !important;
  padding: 4px 1px !important;
}
.mu-vista-mes tbody tr td:first-child {
  min-width: 110px !important;
  max-width: 140px;
}
.mu-vista-mes .celda-turno {
  min-width: 34px !important;
  font-size: 9px !important;
  padding: 3px 2px !important;
  line-height: 1.3;
  border-radius: 5px;
  white-space: pre-line;
}

/* ── Leaflet en modales Bootstrap ────────────────────── */
/* Los controles de Leaflet deben estar por encima del modal (z-index 1055) */
.modal .leaflet-top,
.modal .leaflet-bottom {
  z-index: 1060 !important;
}
.modal .leaflet-draw-toolbar a,
.modal .leaflet-bar a {
  z-index: 1060 !important;
}
/* Evitar que el mapa quede oculto por overflow del modal */
.modal .leaflet-container {
  z-index: 1 !important;
}
/* El pane de tiles debe estar visible */
.modal .leaflet-pane {
  z-index: 400 !important;
}

/* ── Modo pintura ─────────────────────────────────────── */
body.modo-pintura .celda-turno:hover {
  outline: 2px solid var(--color-brand);
  outline-offset: -2px;
}

/* ── Modal barras de turno ────────────────────────────── */
#m-turno-bar,
#m-turno-bar2 {
  border: 1px solid #ccc;
  background: linear-gradient(to bottom, #f0f0f0 0%, #e0e0e0 100%);
  user-select: none;
}

/* Indicador de las horas al pasar el cursor */
#m-turno-bar *,
#m-turno-bar2 * {
  user-select: none;
}

/* Barra de descanso dentro del turno */
.mu-bar-descanso {
  cursor: grab;
}
.mu-bar-descanso:active {
  cursor: grabbing;
}

/* Botones favoritos de turno */
.btn-favorito {
  font-size: 12px;
  transition: opacity .15s, transform .1s;
}
.btn-favorito:hover {
  opacity: .85;
  transform: translateY(-1px);
}

/* Opciones de duración descanso */
.mu-opc-descanso {
  font-size: 12px;
  padding: 2px 10px;
}
.mu-opc-descanso.active {
  background: var(--color-brand);
  color: #fff;
  border-color: var(--color-brand);
}
