:root {
  --azul: #2e5f8a;
  --azul-osc: #234a6e;
  --gris-finde: #dfe3e7;
  --gris-borde: #c7ccd1;
  --amarillo-editado: #ffd400;
  --rojo-desconocido: #ffd2d2;
  --fondo: #f4f6f8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 13px;
  background: var(--fondo);
  color: #1b1f23;
  height: 100%;
}

button, select, input {
  font-family: inherit;
  font-size: 13px;
}

button {
  background: var(--azul);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 3px;
  cursor: pointer;
}
button:hover { background: var(--azul-osc); }
button:disabled { background: #9aa5ad; cursor: default; }
button.secundario { background: #6c757d; }
button.secundario:hover { background: #565e64; }
button.peligro { background: #c8102e; }
button.peligro:hover { background: #97001f; }

select, input[type="text"], input[type="search"], input[type="email"] {
  padding: 5px 8px;
  border: 1px solid var(--gris-borde);
  border-radius: 3px;
}

/* Topbar */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--azul);
  color: #fff;
  padding: 6px 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}
#topbar .marca { font-weight: bold; font-size: 16px; white-space: nowrap; }
#tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab-btn {
  background: rgba(255,255,255,0.15);
  color: #fff;
}
.tab-btn.active { background: #fff; color: var(--azul); font-weight: bold; }
.acciones { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#usuario-nombre { font-weight: bold; }

#app { padding: 10px; }
.panel { display: none; }
.panel.active { display: block; }

.panel-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

/* Grid genérico */
.grid-wrap {
  overflow: auto;
  max-height: calc(100vh - 150px);
  border: 1px solid var(--gris-borde);
  background: #fff;
}
table.cuadrante {
  border-collapse: collapse;
  table-layout: fixed;
}
table.cuadrante th, table.cuadrante td {
  border: 1px solid #d4d8dc;
  padding: 0;
  text-align: center;
}
table.cuadrante thead th {
  background: var(--azul);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 5;
  font-weight: normal;
  min-width: 46px;
  padding: 2px 1px;
}
table.cuadrante thead th.finde { background: #24507a; }
table.cuadrante th.col-nombre, table.cuadrante td.col-nombre {
  position: sticky;
  left: 0;
  z-index: 4;
  background: var(--azul);
  color: #fff;
  text-align: left;
  padding: 4px 8px;
  min-width: 220px;
  max-width: 260px;
  font-size: 12px;
}
table.cuadrante thead th.col-nombre { z-index: 6; }
.dh-letter { font-size: 11px; }
.dh-num { font-weight: bold; font-size: 13px; }
.dh-mes { font-size: 9px; opacity: 0.85; }

table.cuadrante td.dia { width: 46px; height: 34px; background: #fff; vertical-align: middle; }
table.cuadrante td.dia.finde { background: var(--gris-finde); }
table.cuadrante td.total, table.cuadrante td.inc {
  background: var(--azul);
  color: #fff;
  font-weight: bold;
  min-width: 52px;
}
table.cuadrante tfoot td, table.cuadrante tfoot td.dia, table.cuadrante tfoot td.dia.finde { background: var(--azul-osc); color: #fff; font-weight: bold; font-size: 11px; }
table.cuadrante tfoot td.col-nombre { background: var(--azul-osc); }

.celda {
  width: 100%;
  height: 100%;
  min-height: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 10px;
  line-height: 12px;
  cursor: pointer;
  position: relative;
  user-select: none;
}
.celda.vacia { cursor: pointer; background: transparent; }
.celda:hover { outline: 2px solid #333; outline-offset: -2px; }
.celda .l1, .celda .l2 { display: block; }
.celda.ausencia { color: #3a2c00; font-weight: bold; }
.celda.ausencia .lbl { font-size: 10px; }
.celda.variante { border: 1px dashed #fff; }
.celda.desconocido { background: var(--rojo-desconocido); color: #7a0000; font-weight: bold; border: 1px solid #c00; }
.celda.desconocido .cod { font-size: 9px; word-break: break-all; }
.celda.atenuado { opacity: 0.35; }
.edit-mark {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 6px;
  height: 6px;
  background: var(--amarillo-editado);
  border-radius: 1px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.oculto { display: none; }
.modal {
  background: #fff;
  border-radius: 4px;
  padding: 16px 20px;
  min-width: 340px;
  max-width: 92vw;
  max-height: 88vh;
  overflow: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}
.modal h2 { margin-top: 0; font-size: 16px; color: var(--azul); }
.modal .cerrar {
  float: right;
  background: transparent;
  color: #666;
  font-size: 18px;
  padding: 0 6px;
}
.modal .campo { margin-bottom: 10px; }
.modal .campo label { display: block; margin-bottom: 3px; font-weight: bold; font-size: 12px; }
.modal .fila-botones { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.modal table.lista { width: 100%; border-collapse: collapse; }
.modal table.lista th, .modal table.lista td { border-bottom: 1px solid #eee; padding: 4px 6px; text-align: left; font-size: 12px; }
.modal .pestanas { display: flex; gap: 4px; margin-bottom: 10px; border-bottom: 1px solid #ddd; }
.modal .pestanas button { background: transparent; color: #444; border-bottom: 3px solid transparent; border-radius: 0; }
.modal .pestanas button.active { color: var(--azul); border-bottom-color: var(--azul); font-weight: bold; }
.modal .resultados-catalogo { max-height: 220px; overflow: auto; border: 1px solid #ddd; margin-top: 6px; }
.modal .resultados-catalogo div { padding: 5px 8px; cursor: pointer; border-bottom: 1px solid #f0f0f0; font-size: 12px; }
.modal .resultados-catalogo div:hover, .modal .resultados-catalogo div.sel { background: #e8f0f8; }
.modal .aviso-texto { color: #97001f; font-size: 12px; margin-top: 6px; }

/* Toasts */
#toasts {
  position: fixed;
  bottom: 14px;
  right: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: #333;
  color: #fff;
  padding: 10px 14px;
  border-radius: 4px;
  min-width: 220px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.3);
  transition: opacity 0.3s;
}
.toast.ok { background: #1e7e34; }
.toast.error { background: #97001f; }
.toast.fuera { opacity: 0; }

/* Ficha empleado */
.ficha {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  background: #fff;
  border: 1px solid var(--gris-borde);
  padding: 10px 14px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.ficha .datos { flex: 1; min-width: 260px; }
.ficha .datos div { margin-bottom: 3px; }
.ficha .acciones-empleado { display: flex; gap: 8px; flex-direction: column; }
.ficha .estado-envio { font-size: 12px; color: #555; }
.ficha .estado-envio.modificado { color: #b06a00; font-weight: bold; }
.ficha .estado-envio.sin-correo { color: #97001f; font-weight: bold; }

.sugerencias {
  position: relative;
}
.sugerencias .lista-sug {
  position: absolute;
  top: 30px;
  left: 0;
  background: #fff;
  border: 1px solid var(--gris-borde);
  z-index: 30;
  min-width: 280px;
  max-height: 260px;
  overflow: auto;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
.sugerencias .lista-sug div { padding: 6px 10px; cursor: pointer; font-size: 12px; }
.sugerencias .lista-sug div:hover { background: #e8f0f8; }

.bloque { background: #fff; border: 1px solid var(--gris-borde); padding: 10px 14px; margin-bottom: 10px; }
.bloque h3 { margin: 0 0 8px; font-size: 13px; color: var(--azul); }

table.simple { width: 100%; border-collapse: collapse; }
table.simple th, table.simple td { border-bottom: 1px solid #eee; padding: 5px 7px; text-align: left; font-size: 12px; }
table.simple th { background: #eef2f5; }
table.simple tr:hover td { background: #f5f9fc; }
table.simple tr.sel td { background: #dce9f5; }

.badge { display: inline-block; padding: 1px 6px; border-radius: 10px; font-size: 11px; color: #fff; }
.badge.ok { background: #1e7e34; }
.badge.caducado { background: #97001f; }
.badge.proximo { background: #b06a00; }
.badge.pendiente { background: #6c757d; }
.badge.modificado { background: #b06a00; }
.badge.error { background: #97001f; }
.badge.sin-correo { background: #97001f; }
.badge.enviado { background: #1e7e34; }
.badge.en-cola { background: #1f3fd6; }

.banner { background: #dce9f5; border: 1px solid #2e5f8a; border-radius: 4px; padding: 8px 12px; margin-bottom: 10px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.banner a { color: #1f3fd6; }

#personal-layout { display: flex; gap: 10px; align-items: flex-start; }
#personal-tabla { flex: 1; min-width: 0; }
#personal-panel { width: 320px; background: #fff; border: 1px solid var(--gris-borde); padding: 10px 14px; }
#personal-panel:empty { display: none; }

.grupo-campos { margin-bottom: 8px; }
.grupo-campos .fila-campo { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 2px 0; border-bottom: 1px dotted #eee; }
.grupo-campos .fila-campo .h { color: #666; }

.progreso-envio { font-size: 12px; margin-left: 10px; }

/* login */
body.pagina-login {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #2e5f8a, #12704a);
}
.caja-login {
  background: #fff;
  padding: 30px 34px;
  border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  width: 320px;
}
.caja-login h1 { font-size: 18px; color: var(--azul); margin-top: 0; text-align: center; }
.caja-login .campo { margin-bottom: 14px; }
.caja-login .campo label { display: block; margin-bottom: 4px; font-weight: bold; font-size: 12px; }
.caja-login .campo input { width: 100%; }
.caja-login .recordarme { display: flex; align-items: center; gap: 6px; font-size: 12px; margin-bottom: 14px; }
.caja-login button { width: 100%; padding: 9px; font-size: 14px; }
.caja-login .error { color: #97001f; font-size: 12px; margin-bottom: 10px; min-height: 14px; }

.oculto { display: none !important; }
