/* ============================================================
   Tema corporativo D1 — Manual de imagen
   Carga cromática: 70-80% blanco, 10-15% rojo, 10-15% grises
   ============================================================ */
:root {
  --rojo: #E40520;          /* Pantone 185C */
  --rojo-oscuro: #B60D17;   /* rojo secundario del manual */
  --azul: #006AB4;          /* Pantone 3005C */
  --azul-oscuro: #24406B;   /* "extraordinarios" */
  --amarillo: #FFED00;      /* solo decorativo, nunca texto */
  --fondo: #F7F7F7;
  --carta: #FFFFFF;
  --texto: #3C3C3B;         /* gris D1 90% */
  --muted: #706F6F;         /* gris D1 70% */
  --borde: #E5E5E5;
  --gris-claro: #EDEDED;    /* gris D1 10% */
  --ok: #1e8e4e; --alerta: #c77800; --critico: #E40520;
  --sombra: 0 2px 10px rgba(60,60,59,.08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: Calibri, Carlito, 'Segoe UI', system-ui, sans-serif; background: var(--fondo); color: var(--texto); font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--critico); min-height: 1.2em; font-size: .9em; }
button, input, select, textarea { font-family: inherit; }
:focus-visible { outline: 2px solid var(--azul); outline-offset: 2px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; background: var(--fondo); padding: 16px; }
.login-card { background: #fff; border-radius: 18px; padding: 36px 32px; width: 100%; max-width: 380px; text-align: center; box-shadow: var(--sombra); border-top: 6px solid var(--rojo); }
.login-logo img { width: 92px; height: auto; }
.login-card h1 { margin: 10px 0 0; color: var(--texto); font-size: 26px; }
.login-card input { width: 100%; margin-top: 14px; padding: 13px 14px; border: 1px solid var(--borde); border-radius: 12px; font-size: 16px; }
.login-card button { margin-top: 18px; min-height: 48px; font-size: 16px; }

/* ---------- Layout ---------- */
.app { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px; background: #fff; color: var(--texto); padding: 8px 14px; border-bottom: 1px solid var(--borde); box-shadow: var(--sombra); }
.topbar .logo { width: 34px; height: 34px; display: block; }
.brand { font-weight: 700; font-size: 17px; color: var(--texto); }
.chip { margin-left: auto; background: var(--gris-claro); color: var(--texto); border-radius: 20px; padding: 5px 12px; font-size: 13px; }
.icon-btn { background: none; border: none; color: var(--texto); font-size: 22px; cursor: pointer; padding: 6px; }
.sidebar { position: fixed; top: 52px; left: 0; bottom: 0; width: 232px; background: #fff; border-right: 1px solid var(--borde); padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; transition: transform .2s; z-index: 25; overflow-y: auto; }
.sidebar.cerrado { transform: translateX(-100%); }
.nav-item { text-align: left; background: none; border: none; padding: 12px 14px; border-radius: 10px; font-size: 15px; cursor: pointer; color: var(--texto); min-height: 44px; }
.nav-item:hover { background: var(--fondo); }
.nav-item.activo { background: var(--rojo); color: #fff; font-weight: 700; }
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--borde); padding-top: 8px; }
.navbadge { background: var(--rojo); color: #fff; border-radius: 12px; padding: 1px 7px; font-size: 11px; font-weight: 800; vertical-align: middle; }
.nav-item.activo .navbadge { background: #fff; color: var(--rojo); }
.main { padding: 20px; margin-left: 232px; transition: margin .2s; }
.main.full { margin-left: 0; }

/* Barra de navegación inferior (solo móvil) */
.bottomnav { display: none; }
@media (max-width: 860px) {
  /* deja libre la barra inferior para que "Salir" siempre sea visible y accesible */
  .sidebar { transform: translateX(-100%); box-shadow: 4px 0 20px rgba(0,0,0,.15); top: 50px;
    padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .sidebar.abierto { transform: translateX(0); }
  .main { margin-left: 0; padding: 14px 12px calc(104px + env(safe-area-inset-bottom)); }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 35;
    background: #fff; border-top: 1px solid var(--borde); box-shadow: 0 -2px 12px rgba(60,60,59,.10);
    padding: 4px 2px calc(4px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .bottomnav button { flex: 1; max-width: 96px; background: none; border: none; display: flex; flex-direction: column;
    align-items: center; gap: 2px; padding: 6px 2px; font-size: 11px; color: var(--muted); cursor: pointer;
    border-radius: 10px; min-height: 52px; }
  .bottomnav button .bn-ico { font-size: 21px; line-height: 1; }
  .bottomnav button.activo { color: var(--rojo); font-weight: 700; }
}

/* ---------- Componentes ---------- */
h2.titulo { color: var(--texto); margin: 4px 0 16px; font-size: 22px; }
.card { background: var(--carta); border: 1px solid var(--borde); border-radius: 14px; padding: 18px; margin-bottom: 16px; box-shadow: var(--sombra); }
.card h3 { margin: 0 0 12px; color: var(--texto); font-size: 16px; }
.fila { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn { border: 1px solid var(--borde); background: #fff; padding: 10px 16px; border-radius: 10px; cursor: pointer; font-size: 14px; min-height: 42px; color: var(--texto); }
.btn.primary { background: var(--rojo); border-color: var(--rojo); color: #fff; font-weight: 700; }
.btn.primary:hover { background: var(--rojo-oscuro); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { background: #fff; border-color: var(--critico); color: var(--critico); }
.btn.sm { padding: 6px 10px; font-size: 13px; min-height: 34px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { padding: 9px 10px; border: 1px solid var(--borde); border-radius: 8px; font-size: 16px; background: #fff; color: var(--texto); }
label.lbl { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }

table.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th { background: var(--gris-claro); color: var(--texto); padding: 9px 10px; text-align: left; font-weight: 700; }
.tabla td { padding: 9px 10px; border-bottom: 1px solid var(--borde); }
.tabla tr:nth-child(even) td { background: #FAFAFA; }
.tabla-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge.ok { background: #e6f5ec; color: var(--ok); }
.badge.alerta { background: #fbf1df; color: var(--alerta); }
.badge.critico { background: #fde7e9; color: var(--rojo); }
.badge.info { background: #e6f0f8; color: var(--azul); }
.badge.gris { background: var(--gris-claro); color: var(--muted); }

/* ---------- Malla / calendario ---------- */
.malla-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.malla { border-collapse: collapse; font-size: 12px; }
.malla th, .malla td { border: 1px solid var(--borde); padding: 0; text-align: center; min-width: 36px; }
.malla th { background: var(--texto); color: #fff; padding: 5px 4px; position: sticky; top: 0; z-index: 1; }
.malla th.finde { background: var(--rojo); }
.malla td.nombre, .malla th.nombre { position: sticky; left: 0; background: #fff; text-align: left; padding: 5px 8px; min-width: 120px; max-width: 150px; font-weight: 700; z-index: 2; box-shadow: 2px 0 4px rgba(60,60,59,.08); }
.malla th.nombre { background: var(--texto); z-index: 3; }
.malla td .celda { display: block; width: 100%; height: 100%; padding: 8px 2px; border: none; cursor: pointer; font-size: 11px; font-weight: 700; background: transparent; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.25); min-height: 34px; }
.malla td.vacia .celda { color: transparent; text-shadow: none; }
.malla td.festivo { outline: 2px dashed var(--alerta); outline-offset: -2px; }
.malla td.solo-lectura .celda { cursor: default; }

.paleta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.paleta .ficha { border: 2px solid transparent; border-radius: 10px; padding: 8px 12px; color: #fff; font-weight: 700; cursor: pointer; font-size: 13px; min-height: 38px; }
.paleta .ficha.sel { border-color: var(--texto); box-shadow: 0 0 0 2px #fff inset; }
.paleta .ficha.borrar { background: #fff; color: var(--critico); border: 2px dashed var(--critico); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--carta); border: 1px solid var(--borde); border-radius: 14px; padding: 14px; box-shadow: var(--sombra); }
.kpi .valor { font-size: 26px; font-weight: 800; color: var(--rojo); }
.kpi .etiqueta { font-size: 12px; color: var(--muted); }
@media (max-width: 600px) { .kpis { grid-template-columns: 1fr 1fr; } }

/* ---------- Mi turno (vista del asistente) ---------- */
.hoy-card { border-radius: 18px; padding: 22px; color: #fff; margin-bottom: 16px; box-shadow: var(--sombra); }
.hoy-card .hc-fecha { font-size: 13px; opacity: .9; text-transform: capitalize; }
.hoy-card .hc-turno { font-size: 30px; font-weight: 800; margin: 4px 0 2px; }
.hoy-card .hc-horario { font-size: 20px; font-weight: 700; }
.hoy-card .hc-detalle { font-size: 13px; opacity: .9; margin-top: 6px; }
.hoy-card.descanso { background: var(--gris-claro); color: var(--texto); }
.hoy-card.sinturno { background: #fff; color: var(--muted); border: 2px dashed var(--borde); box-shadow: none; }

.sem-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.sem-nav .titulo-sem { font-weight: 700; font-size: 15px; text-transform: capitalize; }
.sem-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.sem-dia { border: 1px solid var(--borde); border-radius: 12px; padding: 8px 4px; text-align: center; background: #fff; min-height: 86px; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.sem-dia .sd-nombre { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.sem-dia .sd-num { font-size: 16px; font-weight: 800; }
.sem-dia .sd-turno { font-size: 11px; font-weight: 700; color: #fff; border-radius: 8px; padding: 3px 6px; width: 100%; }
.sem-dia .sd-horas { font-size: 10px; color: var(--muted); }
.sem-dia.hoy { border: 2px solid var(--rojo); background: #FEF3F4; }
.sem-dia.festivo-dia .sd-num { color: var(--rojo); }
@media (max-width: 600px) {
  .sem-strip { grid-template-columns: repeat(7, minmax(64px, 1fr)); overflow-x: auto; display: flex; padding-bottom: 4px; }
  .sem-dia { min-width: 76px; flex-shrink: 0; }
}
.resumen-sem { display: flex; gap: 14px; flex-wrap: wrap; }
.resumen-sem .rs-item { flex: 1; min-width: 120px; }
.rs-barra { height: 10px; background: var(--gris-claro); border-radius: 6px; overflow: hidden; margin-top: 6px; }
.rs-barra > div { height: 100%; background: var(--ok); border-radius: 6px; }
.rs-barra > div.excedido { background: var(--rojo); }

/* Lista "mi mes" del asistente */
.mi-mes { display: grid; gap: 8px; }
.mi-dia { display: flex; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--borde); border-radius: 12px; padding: 10px 14px; }
.mi-dia .md-fecha { min-width: 76px; text-align: center; }
.mi-dia .md-fecha .n { font-size: 20px; font-weight: 800; display: block; }
.mi-dia .md-fecha .d { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.mi-dia .md-turno { font-weight: 700; color: #fff; border-radius: 8px; padding: 4px 10px; font-size: 13px; }
.mi-dia .md-horario { color: var(--muted); font-size: 14px; }
.mi-dia.es-hoy { border: 2px solid var(--rojo); }

/* ---------- Detalle expandible de semanas (barras hacia las 42h) ---------- */
.btn-link { background: none; border: none; padding: 0; font: inherit; font-weight: 700; color: var(--texto); cursor: pointer; text-align: left; }
.btn-link:hover { color: var(--rojo); }
.btn-link small { color: var(--muted); }
.fila-detalle td { background: #FDF7F7 !important; padding: 12px 14px; }
.det-wrap { display: grid; gap: 8px; max-width: 620px; }
.det-fila { display: grid; grid-template-columns: 92px 1fr minmax(130px, auto); gap: 10px; align-items: center; }
.det-lbl { font-size: 12px; color: var(--muted); white-space: nowrap; }
.det-barra { height: 10px; background: var(--gris-claro); border-radius: 6px; overflow: hidden; display: flex; }
.det-base { height: 100%; background: var(--alerta); border-radius: 6px 0 0 6px; }
.det-base.llena { background: var(--ok); }
.det-extra { height: 100%; background: var(--rojo); }
.det-txt { font-size: 12px; font-weight: 700; white-space: nowrap; }
.det-txt.ok { color: var(--ok); } .det-txt.alerta { color: var(--alerta); } .det-txt.critico { color: var(--rojo); }
.det-txt small { font-weight: 400; }
@media (max-width: 600px) {
  .det-fila { grid-template-columns: 76px 1fr; }
  .det-txt { grid-column: 2; }
}

/* ---------- Malla de disponibilidad ---------- */
.malla-dia { border: 1px solid var(--borde); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.malla-dia.festivo-dia { border-color: var(--alerta); background: #FFFDF5; }
.malla-dia .md-titulo { font-weight: 700; margin-bottom: 8px; text-transform: capitalize; }
.malla-fila { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 6px 0; border-top: 1px dashed var(--borde); }
.malla-fila select { min-width: 150px; }
.chips-sig { display: flex; gap: 4px; flex-wrap: wrap; }
.chip-sig { border: 1px solid var(--borde); background: #fff; color: var(--muted); border-radius: 14px; padding: 3px 10px; font-size: 12px; font-weight: 700; cursor: pointer; }
.chip-sig.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.malla-cal th { background: var(--gris-claro); }
.malla-cal td { text-align: center; padding: 6px 4px; font-size: 13px; }

/* ---------- Modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(60,60,59,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 14px; }
.modal { background: #fff; border-radius: 16px; padding: 22px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin-top: 0; color: var(--texto); }
.modal .campos { display: grid; gap: 10px; }
@media (max-width: 600px) {
  .modal-bg { align-items: flex-end; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 88vh; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); }
}
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--texto); color: #fff; padding: 11px 20px; border-radius: 24px; font-size: 14px; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 60; max-width: 92vw; text-align: center; }
@media (max-width: 860px) { #toast { bottom: calc(92px + env(safe-area-inset-bottom)); } }
#toast.ver { opacity: 1; }
