:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --texto: #1c2230;
  --suave: #667085;
  --borde: #e2e5ea;
  --input: #ffffff;
  --hover: #f0f2f5;
  --acento: #b3232a;
  --acento-2: #8f1b21;
  --acento-tenue: #fbeaea;
  --lateral: #1d2127;
  --lateral-2: #262b33;
  --lateral-texto: #d9dde3;
  --lateral-suave: #8e96a3;
  --ok: #18794e;
  --ok-tenue: #e6f4ec;
  --aviso: #9a5b00;
  --aviso-tenue: #fdf3e1;
  --peligro: #c22a2a;
  --peligro-tenue: #fdeaea;
  --info: #2457a6;
  --info-tenue: #e8f0fc;
  --gris-tenue: #eef0f3;
  --sombra: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .06);
  --radio: 10px;
  --scroll: #b9bfc8;
  --scroll-hover: #8e96a3;
  color-scheme: light;
}

[data-theme="oscuro"] {
  --bg: #111418;
  --panel: #1a1e24;
  --panel-2: #20252c;
  --texto: #e5e8ec;
  --suave: #9aa3af;
  --borde: #2d333c;
  --input: #14171c;
  --hover: #242a32;
  --acento: #d8434a;
  --acento-2: #b3232a;
  --acento-tenue: #3a1d20;
  --lateral: #0c0e11;
  --lateral-2: #171a1f;
  --ok: #4cc38a;
  --ok-tenue: #15301f;
  --aviso: #f0b34a;
  --aviso-tenue: #33280f;
  --peligro: #f06a6a;
  --peligro-tenue: #3a1a1a;
  --info: #79a8f2;
  --info-tenue: #172338;
  --gris-tenue: #262b33;
  --sombra: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  --scroll: #3d444e;
  --scroll-hover: #59616d;
  color-scheme: dark;
}

* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--scroll) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-hover); border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--texto);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
.ico { flex: none; vertical-align: middle; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--borde); background: var(--panel); color: var(--texto);
  cursor: pointer; white-space: nowrap; font-weight: 500;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primario { background: var(--acento); border-color: var(--acento); color: #fff; }
.btn.primario:hover { background: var(--acento-2); border-color: var(--acento-2); }
.btn.peligro { background: var(--peligro); border-color: var(--peligro); color: #fff; }
.btn.peligro:hover { filter: brightness(.92); }
.btn.sec { background: var(--panel); }
.btn.mini { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icono {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--suave); cursor: pointer;
}
.btn-icono:hover { background: var(--hover); color: var(--texto); }
.btn-icono.rojo:hover { color: var(--peligro); background: var(--peligro-tenue); }
:focus-visible { outline: 2px solid var(--acento); outline-offset: 2px; }

.esquina { position: fixed; top: 12px; right: 16px; z-index: 60; display: flex; gap: 8px; }
.idioma-btn {
  height: 38px; padding: 0 12px; border-radius: 19px; display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--borde); background: var(--panel); color: var(--texto); cursor: pointer; box-shadow: var(--sombra); font-weight: 600;
}
.idioma-btn:hover { color: var(--acento); }
.tema-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--borde); background: var(--panel); color: var(--texto);
  cursor: pointer; box-shadow: var(--sombra);
}
.tema-btn:hover { color: var(--acento); }

/* ---------- Inicio de sesión ---------- */
.login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(179, 35, 42, .12), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(179, 35, 42, .10), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--borde);
  border-radius: 16px; box-shadow: var(--sombra); padding: 28px 28px 24px;
}
.login-logo { display: flex; justify-content: center; margin-bottom: 12px; }
.login-logo img { width: 130px; height: auto; background: #fff; border-radius: 14px; padding: 8px; }
.login-card h1 { font-size: 19px; text-align: center; }
.login-sub { text-align: center; color: var(--suave); margin: 6px 0 20px; }
.login-botones { display: flex; gap: 10px; margin-top: 18px; }
.login-botones .btn { flex: 1; height: 40px; }

/* ---------- Formularios ---------- */
.campo { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 13px; color: var(--suave); margin-bottom: 12px; }
.campo > input, .campo > select, .campo > textarea { color: var(--texto); }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], input:not([type]), select, textarea {
  height: 38px; padding: 0 11px; border-radius: 8px; border: 1px solid var(--borde);
  background: var(--input); color: var(--texto); min-width: 0; width: 100%;
}
input.clave { -webkit-text-security: disc; text-security: disc; font-family: Verdana, sans-serif; letter-spacing: .08em; }
input.clave:placeholder-shown { font-family: inherit; letter-spacing: normal; }
textarea { height: auto; padding: 9px 11px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--acento); box-shadow: 0 0 0 3px var(--acento-tenue); }
input:disabled, select:disabled { opacity: .6; }
.req { color: var(--acento); }
.form-error {
  background: var(--peligro-tenue); color: var(--peligro); border: 1px solid color-mix(in srgb, var(--peligro) 35%, transparent);
  border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-bottom: 12px;
}
.nota { color: var(--suave); font-size: 12.5px; margin: 4px 0 0; line-height: 1.45; }
.grid { display: grid; gap: 0 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid .c2 { grid-column: span 2; }
.grid .c3 { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--borde); border-radius: 10px; padding: 10px 14px 4px; margin: 4px 0 14px; }
legend { padding: 0 6px; font-weight: 600; font-size: 13px; }
.dias { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.dias .campo { text-align: center; }
.dias input { text-align: center; padding: 0 4px; }
.total-jornada { margin: 0 0 10px; color: var(--suave); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; margin: 4px 0 12px; }
.check input { width: 17px; height: 17px; accent-color: var(--acento); }
.checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 14px; }
.info-horas { border-radius: 8px; padding: 9px 12px; font-size: 13px; margin: -2px 0 12px; background: var(--info-tenue); color: var(--info); }
.info-horas.mal { background: var(--peligro-tenue); color: var(--peligro); }

/* ---------- Estructura principal ---------- */
.app { display: flex; min-height: 100vh; }
.lateral {
  width: 252px; flex: none; background: var(--lateral); color: var(--lateral-texto);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 40;
}
.marca { padding: 18px 18px 12px; }
.logo-caja { background: #fff; border-radius: 12px; padding: 8px; display: flex; justify-content: center; }
.logo-caja img { height: 74px; width: auto; }
.menu { flex: 1; overflow-y: auto; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.menu a {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 8px;
  color: var(--lateral-texto); text-decoration: none; font-weight: 500; cursor: pointer;
}
.menu a:hover { background: var(--lateral-2); }
.menu a.activo { background: var(--acento); color: #fff; }
.menu a .ico { opacity: .9; }
.lateral-pie { border-top: 1px solid rgba(255, 255, 255, .08); padding: 14px 14px 16px; }
.sesion-info { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; min-width: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  background: var(--acento); color: #fff; font-weight: 700; font-size: 14px;
}
.sesion-datos { display: flex; flex-direction: column; min-width: 0; }
.sesion-datos strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sesion-datos span { color: var(--lateral-suave); font-size: 12.5px; }
.lateral-botones { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn.lat { background: var(--lateral-2); border-color: transparent; color: var(--lateral-texto); padding: 0 8px; font-size: 13px; }
.btn.lat:hover { background: #333944; }
.btn.lat#btnSalir:hover { background: var(--acento); color: #fff; }

.principal { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.superior {
  display: flex; align-items: center; gap: 12px; height: 62px; padding: 0 156px 0 24px;
  background: var(--panel); border-bottom: 1px solid var(--borde); position: sticky; top: 0; z-index: 30;
}
.superior h2 { font-size: 18px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sup-acciones { display: flex; gap: 8px; }
.contenido { padding: 22px 24px 40px; max-width: 1500px; width: 100%; }
.solo-movil { display: none; }
.velo { display: none; }

/* ---------- Componentes ---------- */
.barra { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.barra-izq, .barra-der { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.barra input, .barra select { width: auto; }
.barra .buscar { width: 230px; }
.filtro { display: inline-flex; align-items: center; gap: 6px; color: var(--suave); font-size: 13px; }
.tarjeta { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); box-shadow: var(--sombra); }
.tarjeta + .tarjeta { margin-top: 16px; }
.tarjeta-cab { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--borde); flex-wrap: wrap; }
.tarjeta-cab h3 { font-size: 15px; }
.tarjeta-cuerpo { padding: 16px; }
.meta { color: var(--suave); font-size: 13px; margin-top: 3px; }
.tabla-wrap { overflow: auto; max-height: calc(100vh - 200px); min-height: 160px; border-radius: var(--radio); }
.tabla-wrap.con-pestanas { max-height: calc(100vh - 260px); }
.tabla-wrap.con-resumen { max-height: calc(100vh - 330px); min-height: 260px; }
.tabla-wrap.interna { max-height: 320px; min-height: 0; border-radius: 0 0 var(--radio) var(--radio); }
.lista-scroll { max-height: calc(100vh - 170px); overflow-y: auto; padding-right: 6px; margin-right: -6px; }
.tabla thead th { position: sticky; top: 0; z-index: 2; box-shadow: inset 0 -1px 0 var(--borde); }
.historial-wrap { max-height: 170px; overflow-y: auto; border: 1px solid var(--borde); border-radius: 8px; margin: 6px 0 10px; }
.historial-wrap .historial { margin: 0; }
.bit-cambios { font-size: 12.5px; line-height: 1.45; min-width: 260px; max-width: 460px; }
.bit-cambios div { overflow-wrap: anywhere; }
.historial-wrap thead th { position: sticky; top: 0; background: var(--panel-2); }
.tabla { width: 100%; border-collapse: collapse; }
.tabla th, .tabla td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--borde); vertical-align: middle; }
.tabla th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--suave); font-weight: 600; background: var(--panel-2); white-space: nowrap; }
.tabla tbody tr:hover td { background: var(--hover); }
.tabla tbody tr:last-child td { border-bottom: none; }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tabla .acc { text-align: right; white-space: nowrap; width: 1%; }
.tabla tr.subtotal td { background: var(--panel-2); font-weight: 600; }
.tabla tr.total td { background: var(--acento-tenue); font-weight: 700; }
.tabla tr.con-extra td { background: color-mix(in srgb, var(--aviso-tenue) 70%, transparent); }
.tabla select.estado-sel { height: 30px; width: auto; padding: 0 8px; font-size: 13px; }
.vacio { text-align: center; color: var(--suave); padding: 34px 16px !important; }
.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-activo, .b-si { background: var(--ok-tenue); color: var(--ok); }
.b-inactivo { background: var(--gris-tenue); color: var(--suave); }
.b-pausado { background: var(--aviso-tenue); color: var(--aviso); }
.b-baja, .b-terminado { background: var(--peligro-tenue); color: var(--peligro); }
.b-extra { background: var(--aviso-tenue); color: var(--aviso); }
.b-info { background: var(--info-tenue); color: var(--info); }
.tag { display: inline-block; padding: 1px 8px; margin: 2px 4px 2px 0; border-radius: 6px; background: var(--gris-tenue); font-size: 12px; }
.resumen { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px 16px; box-shadow: var(--sombra); }
.kpi span { color: var(--suave); font-size: 12.5px; }
.kpi strong { display: block; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.semana { display: inline-flex; align-items: center; gap: 6px; }
.semana-txt { font-weight: 600; padding: 0 4px; white-space: nowrap; }
.pestanas { display: flex; gap: 4px; border-bottom: 1px solid var(--borde); margin-bottom: 16px; }
.pestanas button { border: none; background: none; padding: 10px 14px; cursor: pointer; color: var(--suave); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.pestanas button.activa { color: var(--acento); border-bottom-color: var(--acento); }
.cliente-proy .tabla th { background: transparent; }
.historial { width: 100%; border-collapse: collapse; font-size: 13px; margin: 6px 0 10px; }
.historial td, .historial th { padding: 5px 8px; border-bottom: 1px solid var(--borde); text-align: left; }
.historial .num { text-align: right; }
.cuadricula { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.cuadricula .tarjeta + .tarjeta { margin-top: 0; }
.acciones-fila { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.zona-peligro { border-color: color-mix(in srgb, var(--peligro) 45%, var(--borde)); }
.zona-peligro h3 { color: var(--peligro); }
.lista-aviso { margin: 8px 0 12px 18px; padding: 0; line-height: 1.6; }
.errores { max-height: 240px; overflow: auto; margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--peligro); }

/* ---------- Ventanas modales ---------- */
.modal-fondo {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 12, 16, .55);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow: hidden;
  animation: aparecer .15s ease-out;
}
.modal {
  width: 100%; max-width: 560px; background: var(--panel); border-radius: 14px; border: 1px solid var(--borde);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35); display: flex; flex-direction: column; max-height: calc(100vh - 6vh - 16px);
}
.modal.ancho { max-width: 760px; }
.modal-cab {
  display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--borde);
  cursor: move; user-select: none; touch-action: none; flex: none; border-radius: 14px 14px 0 0;
}
.modal-cab:hover { background: var(--panel-2); }
.modal.arrastrando { box-shadow: 0 28px 80px rgba(0, 0, 0, .45); }
.modal.arrastrando .modal-cab { cursor: grabbing; }
.modal-cab h3 { font-size: 16px; }
.modal-cuerpo { padding: 18px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-pie { flex: none; }
.modal-cuerpo p { margin: 0 0 10px; line-height: 1.5; }
.modal-pie { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--borde); }
@keyframes aparecer { from { opacity: 0; } to { opacity: 1; } }

#toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  min-width: 220px; max-width: 360px; padding: 11px 14px; border-radius: 9px; color: #fff; background: #1f2937;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); font-weight: 500; transition: opacity .3s, transform .3s;
  border-left: 4px solid var(--ok);
}
.toast.error { border-left-color: #f06a6a; }
.toast.fuera { opacity: 0; transform: translateY(8px); }

#printArea { display: none; }

/* ---------- Pantallas pequeñas ---------- */
@media (max-width: 900px) {
  .lateral { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; }
  .app.menu-abierto .lateral { transform: none; }
  .app.menu-abierto .velo { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 35; }
  .solo-movil { display: inline-flex; }
  .superior { padding: 0 150px 0 12px; }
  .contenido { padding: 16px; }
  .barra .buscar { width: 100%; }
  .barra-izq, .barra-der { width: 100%; }
  .grid, .grid.g3 { grid-template-columns: minmax(0, 1fr); }
  .grid .c2 { grid-column: auto; }
  .dias { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .btn-texto { display: none; }
  .tabla-wrap, .tabla-wrap.con-pestanas, .tabla-wrap.con-resumen { max-height: 70vh; min-height: 0; }
  .lista-scroll { max-height: none; overflow: visible; padding-right: 0; margin-right: 0; }
  .modal-fondo { padding-top: 12px; }
  .modal { max-height: calc(100vh - 24px); }
}
@media (max-width: 520px) {
  .sup-acciones .btn-texto { display: none; }
  .checks { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Impresión / PDF ---------- */
@media print {
  @page { size: landscape; margin: 12mm; }
  body { background: #fff !important; color: #000 !important; font-size: 10.5pt; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  .imp-cab { display: flex; align-items: center; gap: 16px; border-bottom: 2px solid #b3232a; padding-bottom: 10px; margin-bottom: 14px; }
  .imp-cab img { width: 80px; height: auto; }
  .imp-emp { font-size: 15pt; font-weight: 700; color: #b3232a; }
  .imp-tit { font-size: 13pt; font-weight: 600; margin-top: 2px; }
  .imp-sub { font-size: 9pt; color: #555; margin-top: 2px; }
  #printArea h3 { font-size: 11.5pt; margin: 16px 0 6px; }
  #printArea table { width: 100%; border-collapse: collapse; page-break-inside: auto; }
  #printArea tr { page-break-inside: avoid; }
  #printArea thead { display: table-header-group; }
  #printArea th { background: #b3232a !important; color: #fff !important; text-align: left; padding: 5px 6px; font-size: 9pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #printArea td { border-bottom: 1px solid #ccc; padding: 4px 6px; font-size: 9pt; vertical-align: top; }
  #printArea td.num { text-align: right; white-space: nowrap; }
  #printArea tr.tot td { background: #f1f1f1 !important; font-weight: 700; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .imp-pie { margin-top: 14px; font-size: 8.5pt; color: #666; }
}
