/* Bloques compartidos por las aplicaciones (cabecera, botones, modal, toast). */

.hd-app .cabecera {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 20px;
    min-height: 51px;
    padding: 8px 24px;
}

.hd-app .cabecera-izquierda, .hd-app .cabecera-derecha {
    display: flex;
    align-items: center;
}

.hd-app .cabecera-izquierda { gap: 14px; min-width: 0; }

.hd-app .cabecera h1 {
    flex: 0 1 auto;
    margin: 0;
    font-size: 20px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hd-app .cabecera-derecha {
    justify-content: flex-end;
    gap: 8px 10px;
}

.hd-app .boton {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 7px 13px;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 700;
    line-height: 1.2;
}

.hd-app .boton.primario {
    border: 1px solid var(--hd-verde-borde);
    color: #ffffff;
    background: var(--hd-verde);
}

.hd-app .boton.primario:hover {
    background: var(--hd-verde-profundo);
}

.hd-app .boton.secundario {
    border: 1px solid var(--hd-verde-borde);
    color: var(--hd-verde-profundo);
    background: var(--hd-papel);
}

.hd-app .boton.secundario:hover {
    background: var(--hd-verde-suave);
}

.hd-app .boton.calor {
    border-color: var(--hd-aviso-oscuro);
    color: #3A2600;
    background: var(--hd-aviso);
}

.hd-app .boton.calor:hover {
    background: var(--hd-aviso-oscuro);
    color: #3A2600;
}

.hd-app .boton:active,
.hd-app .boton-quiet:active,
.hd-app .boton-modal:active,
.hd-app .modal-cerrar:active {
    filter: brightness(0.97);
    transform: translateY(1px);
}

/* ---------- Base y piezas comunes de las aplicaciones ----------
   Los tokens (paleta, semánticos, sombras) viven en :root de shell.css. */
.hd-app, .hd-app *, .hd-app *::before, .hd-app *::after { box-sizing: border-box; }

.hd-app {
    margin: 0;
    min-width: 320px;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: var(--hd-tinta);
    background: var(--hd-canvas);
    font: 14px/1.45 var(--hd-fuente);
    -webkit-tap-highlight-color: transparent;
}

/* La cabecera queda fuera del scroll: la barra de desplazamiento
   de la vista empieza debajo de ella. */
.hd-app > .cabecera {
    flex: 0 0 auto;
}

.hd-app > main {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    /* Hueco de la scrollbar siempre reservado: el ancho útil no oscila
       cuando el contenido pasa de desbordar a caber (paginador de colas). */
    scrollbar-gutter: stable;
}

@media print {
    .hd-app {
        display: block;
        height: auto;
        overflow: visible;
    }

    .hd-app > main {
        overflow: visible;
    }
}

.hd-app button, .hd-app input, .hd-app select, .hd-app textarea { font: inherit; }
.hd-app button { cursor: pointer; }
.hd-app .oculto { display: none !important; }

.hd-app .pagina-envoltura {
    width: 100%;
    margin: 0;
    /* Derecho 14px, no 24px: junto a los 10px del gutter reservado por
       scrollbar-gutter (apps.css:122) suman los mismos 24px que el izquierdo,
       y la barra de desplazamiento queda dentro del margen: el contenido se
       ve en el mismo sitio haya barra o no (en movil la barra es flotante y
       las reglas <=900px vuelven a 14px simetricos). */
    padding: calc(18px + env(safe-area-inset-top, 0px)) calc(14px + env(safe-area-inset-right, 0px)) max(30px, env(safe-area-inset-bottom, 0px)) calc(24px + env(safe-area-inset-left, 0px));
}

.hd-app .panel {
    margin-bottom: 18px;
    padding: 12px 14px;
    border: 1px solid var(--hd-linea);
    border-radius: 6px;
    background: var(--hd-papel-alto);
    box-shadow: var(--hd-sombra-2);
}

.hd-app .panel-titulo {
    margin: 8px 0 6px;
    color: var(--hd-verde-oscuro);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
}

.hd-app .panel-titulo-fila {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 10px;
    margin: 8px 0 6px;
    min-height: 32px;
}

.hd-app .panel-titulo-fila .panel-titulo { margin: 0; }

.hd-app .campo {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 5px;
    color: #44525c;
    font-size: 13px;
    font-weight: 700;
}

.hd-app .campo small { color: var(--hd-tinta-suave); font-size: 11px; font-weight: 400; }

.hd-app .campo select, .hd-app .campo input {
    width: 100%;
    min-height: 32px;
    padding: 6px 8px;
    border: 1px solid #bcc7d0;
    border-radius: 4px;
    color: var(--hd-tinta);
    background: #fff;
    outline: none;
}

.hd-app .campo select:focus, .hd-app .campo input:focus {
    border-color: var(--hd-verde);
    box-shadow: 0 0 0 3px rgba(0,106,62,.16);
}

.hd-app a:focus-visible,
.hd-app button:focus-visible,
.hd-app input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--hd-verde);
    outline-offset: 2px;
}

/* Sobre la cabecera verde del modal el anillo verde es invisible
   (verde sobre verde, 1,25:1): blanco alli. */
.hd-app .modal-cabecera button:focus-visible {
    outline-color: #ffffff;
}

.hd-app .campo input:disabled { background: #eef1f4; color: var(--hd-tinta-suave); cursor: not-allowed; }

.hd-app .texto-ayuda { margin: 10px 0 0; color: var(--hd-tinta-suave); font-size: 12px; }

/* Botón discreto secundario (Buscar, Añadir barra, Modo medir...) */
.hd-app .boton-quiet {
    min-height: 28px;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--hd-linea-fuerte);
    color: var(--hd-tinta-suave);
    background: var(--hd-papel);
    font-size: var(--hd-texto-s);
    font-weight: 700;
    line-height: 1;
}

.hd-app .boton-quiet:hover { background: #eef2f5; }

.hd-app .boton-quiet.active {
    border-color: var(--hd-verde);
    color: var(--hd-verde-profundo);
    background: var(--hd-verde-suave);
}

.hd-app .boton-quiet.active:hover { border-color: var(--hd-verde); background: #d3e7dc; }

.hd-app .badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border: 1px solid;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.hd-app .badge-neutro { border-color: #bcc7d0; color: #4e5963; background: #edf0f2; }
.hd-app .badge-positivo { border-color: #86a78d; color: #22643a; background: #d4edda; }
.hd-app .badge-aviso { border-color: #e3b23c; color: #7a5600; background: #fff0be; }

.hd-app .modal-contenido {
    position: relative;
    z-index: 1;
    width: min(460px, 100%);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--hd-sombra-3);
}

.hd-app .modal-confirmacion { width: min(420px, 100%); }
.hd-app .confirmacion-cuerpo { padding: 20px 18px 6px; }
.hd-app .confirmacion-cuerpo p { margin: 0; color: #44525c; line-height: 1.45; }
.hd-app .confirmacion-acciones { padding: 10px 18px 18px; }

.hd-app .modal-acciones { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.hd-app .boton-modal {
    min-height: 32px;
    padding: 6px 13px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 700;
    line-height: 1.2;
}
.hd-app .boton-modal.primario { border: 1px solid var(--hd-verde-borde); color: #fff; background: var(--hd-verde); }
.hd-app .boton-modal.primario:hover { border-color: var(--hd-verde-profundo); background: var(--hd-verde-profundo); }
.hd-app .boton-modal.secundario { border: 1px solid #9aa9b5; color: #3a4e5c; background: #fff; }
.hd-app .boton-modal.secundario:hover { border-color: #7d8d99; background: #eef2f5; }
.hd-app .boton-modal.peligro { border: 1px solid var(--hd-peligro-texto); color: #fff; background: var(--hd-rojo); }
.hd-app .boton-modal.peligro:hover { background: #962020; }

@media (max-width: 900px) {
    .hd-app .boton-quiet, .hd-app .boton-modal { min-height: 44px; }
    .hd-app .boton-quiet .boton-texto { display: none; }
    .hd-app .boton-quiet { gap: 0; }
    .hd-app .boton-quiet .boton-icono svg { width: 18px; height: 18px; }
    .hd-app input, .hd-app select, .hd-app textarea { font-size: 16px; }
}

@media (hover: none) {
    .hd-app .boton:hover { background: var(--hd-papel); }
    .hd-app .boton.primario:hover { background: var(--hd-verde); }
    .hd-app .boton.secundario:hover { background: var(--hd-papel); }
    .hd-app .boton.calor:hover { background: var(--hd-aviso); }
    .hd-app .boton-quiet:hover { background: var(--hd-papel); }
    .hd-app .boton-quiet.active:hover { background: var(--hd-verde-suave); }
    .hd-app .boton-modal.primario:hover { background: var(--hd-verde); }
    .hd-app .boton-modal.secundario:hover { background: var(--hd-papel); }
    .hd-app .boton-modal.peligro:hover { background: var(--hd-rojo); }
}

.hd-app .modal {
    position: fixed;
    z-index: 5000;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.hd-app .modal.oculto {
    display: none;
}

.hd-app .modal-fondo {
    position: absolute;
    inset: 0;
    background: rgba(20, 35, 46, 0.56);
}

.hd-app .modal-cabecera {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 17px;
    color: #ffffff;
    background: var(--hd-verde-oscuro);
}

.hd-app .modal-cabecera h2 {
    margin: 0;
    font-size: 17px;
}

.hd-app .modal-cerrar {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: #ffffff;
    background: transparent;
    line-height: 1;
}

.hd-app .modal-cerrar:hover {
    background: rgba(255, 255, 255, .14);
}

.hd-app .modal-cerrar svg {
    display: block;
}

@media (max-width: 900px) {
    .hd-app .modal-cerrar {
        width: 44px;
        height: 44px;
    }
}

.hd-app input[aria-invalid="true"],
.hd-app textarea[aria-invalid="true"],
.hd-app select[aria-invalid="true"] { border-color: var(--hd-peligro-texto); }

/* Aviso de conexion perdida (planificacion y proceso): pildora fija sobre la
   vista, fuera del flujo, asi no roba espacio. En uso normal el div queda
   vacio y :empty lo retira; solo se pinta cuando el ultimo cargarTodo
   correcto tiene mas de un ciclo y cuarto (sondeos fallando, wifi
   intermitente) y se limpia sola en cuanto un sondeo vuelve a ir bien. */
.hd-app .aviso-conexion {
    position: fixed;
    top: calc(56px + env(safe-area-inset-top, 0px) + 10px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    margin: 0;
    padding: 8px 16px;
    border-radius: 999px;
    color: #fff;
    background: var(--hd-rojo);
    box-shadow: var(--hd-sombra-3);
    font-size: var(--hd-texto-s);
    font-weight: 700;
    white-space: nowrap;
    backdrop-filter: blur(4px);
}

.hd-app .aviso-conexion:empty { display: none; }

/* Fallo de la carga inicial sin render previo: bloque persistente con
   boton Reintentar en el contenedor de colas (planificacion y proceso). */
.hd-app .error-carga {
    display: grid;
    gap: 6px;
    justify-items: start;
    max-width: 420px;
    margin: 24px auto;
    padding: 18px 20px;
    border: 1px solid var(--hd-peligro-borde);
    border-radius: var(--hd-radio-m);
    background: var(--hd-peligro-fondo);
}

.hd-app .error-carga p { margin: 0; font-weight: 700; }
.hd-app .error-carga small { color: var(--hd-tinta-suave); }
.hd-app .error-carga .boton { margin-top: 6px; }

.hd-app .toast {
    position: fixed;
    z-index: 9999;
    right: 24px;
    bottom: 24px;
    max-width: 380px;
    padding: 12px 16px;
    border-radius: 6px;
    color: #ffffff;
    background: var(--hd-verde);
    box-shadow: 0 5px 18px rgba(20, 40, 58, 0.28);
    font-size: 13px;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity var(--hd-dur-evento) var(--hd-ease), transform var(--hd-dur-evento) var(--hd-ease);
}

.hd-app .toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.hd-app .toast.error {
    background: var(--hd-rojo);
    white-space: pre-line;
    line-height: 1.4;
}

.hd-app .toast.exito {
    background: var(--hd-verde-profundo);
}

/* ---------- Transiciones de entrada y micro-interacciones ---------- */
@keyframes hd-modal-fondo-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes hd-modal-contenido-in {
    from { opacity: 0; transform: scale(.96); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes hd-panel-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes hd-grupo-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes hd-flash {
    from { background-color: var(--hd-verde-suave); }
    to { background-color: transparent; }
}

.hd-app .modal:not(.oculto) .modal-fondo {
    animation: hd-modal-fondo-in var(--hd-dur-evento) var(--hd-ease);
}

.hd-app .modal:not(.oculto) .modal-contenido {
    animation: hd-modal-contenido-in var(--hd-dur-evento) var(--hd-ease);
}

.hd-app .menu-procesos:not(.oculto),
.hd-app .patron-barras-opciones:not([hidden]),
.hd-app .comentario-flotante,
.hd-app .capas-panel:not(.oculto) {
    animation: hd-panel-in var(--hd-dur-rapido) var(--hd-ease);
}

.hd-app .patron-grupo-bloque {
    animation: hd-grupo-in var(--hd-dur-evento) var(--hd-ease);
}

.hd-app .tarjeta-resumen.destello {
    animation: hd-flash .6s ease;
}

.hd-app .boton,
.hd-app .boton-quiet,
.hd-app .boton-modal,
.hd-app .modal-cerrar {
    transition: background-color var(--hd-dur-rapido) var(--hd-ease), border-color var(--hd-dur-rapido) var(--hd-ease), color var(--hd-dur-rapido) var(--hd-ease);
}

@media (prefers-reduced-motion: reduce) {
    .hd-app .modal:not(.oculto) .modal-fondo,
    .hd-app .modal:not(.oculto) .modal-contenido,
    .hd-app .menu-procesos:not(.oculto),
    .hd-app .patron-barras-opciones:not([hidden]),
    .hd-app .comentario-flotante,
    .hd-app .capas-panel:not(.oculto),
    .hd-app .patron-grupo-bloque,
    .hd-app .tarjeta-resumen.destello {
        animation: none;
    }

    .hd-app .boton,
    .hd-app .boton-quiet,
    .hd-app .boton-modal,
    .hd-app .modal-cerrar,
    .hd-app .toast {
        transition: none;
    }
}

/* ================================================================
   Tarjeta de operación compartida (planificación + proceso).
   Las colas de ambas apps salen de /cola-vertical: un solo
   componente. Las peculiaridades de cada app (arrastre y filtro en
   planificación, iniciar/pausar y trabajadores en proceso) siguen
   en su CSS, que se carga después y prevalece.
   ================================================================ */

.hd-app .contenedor-colas {
    display: grid;
    /* minmax(0, 1fr): con 1fr desnudo un hijo no encogible empujaria la
       pista mas alla del contenedor (scroll horizontal en movil) */
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
    align-items: start;
    padding-bottom: 8px;
}

.hd-app .lista-operaciones {
    min-width: 0;
    min-height: 150px;
    padding: 0;
}

.hd-app .separador-fecha {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 14px 0 8px;
    color: var(--hd-tinta-suave);
    font-size: 11px;
    line-height: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
    text-align: center;
}

.hd-app .separador-fecha::before,
.hd-app .separador-fecha::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    background: var(--hd-linea-fuerte);
}

.hd-app .separador-fecha.hoy {
    color: var(--hd-verde);
}

.hd-app .separador-fecha.hoy::before,
.hd-app .separador-fecha.hoy::after {
    background: var(--hd-verde);
}

.hd-app .cargando,
.hd-app .sin-operaciones {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 18px;
    color: var(--hd-tinta-suave);
    text-align: center;
    font-size: var(--hd-texto-s);
}

/* Anillo de carga para los estados "Cargando…" que antes eran solo texto */
.hd-app .cargando::before {
    content: "";
    width: 16px;
    height: 16px;
    border: 2px solid var(--hd-verde-suave);
    border-top-color: var(--hd-verde);
    border-radius: 50%;
    animation: hd-giro-carga 0.9s linear infinite;
}

@keyframes hd-giro-carga {
    to { transform: rotate(360deg); }
}

.hd-app .tarjeta-operacion {
    position: relative;
    margin-bottom: 8px;
    padding: 10px 12px;
    border: 1px solid var(--hd-linea);
    border-left: 4px solid var(--hd-verde);
    border-radius: var(--hd-radio-m);
    cursor: default;
    background: var(--hd-papel);
    box-shadow: var(--hd-sombra-1);
}

.hd-app .tarjeta-operacion:hover {
    border-color: var(--hd-verde-borde);
    box-shadow: var(--hd-sombra-2);
}

.hd-app .tarjeta-operacion:active {
    filter: brightness(0.98);
}

/* Estados (en curso prevalece sobre riesgo/retraso: se declara al final) */
.hd-app .tarjeta-operacion.terminada {
    border-color: #cfe0d4;
    border-left-color: #8fb79c;
    background: #f3f7f4;
    opacity: 0.92;
}

.hd-app .tarjeta-operacion.bloqueada {
    border-color: #c9d1d8;
    border-left-color: #8a95a0;
    background: #f1f3f5;
    opacity: 0.92;
}

.hd-app .tarjeta-operacion.terminada:hover,
.hd-app .tarjeta-operacion.bloqueada:hover {
    box-shadow: var(--hd-sombra-1);
}

.hd-app .tarjeta-operacion.retraso {
    border-color: var(--hd-peligro-borde);
    border-left-color: var(--hd-rojo);
    background: #fff1f1;
}

.hd-app .tarjeta-operacion.en-riesgo {
    border-color: var(--hd-aviso-borde);
    border-left-color: #d49a11;
    background: var(--hd-aviso-fondo-suave);
}

.hd-app .tarjeta-operacion.en-curso {
    border-color: #2e8b57;
    border-left-color: #1e7a45;
    background: #f2fbf4;
    box-shadow: 0 1px 5px rgba(30, 122, 69, 0.28);
}

.hd-app .tarjeta-operacion.en-curso:hover {
    border-color: #1e7a45;
    box-shadow: 0 3px 8px rgba(30, 122, 69, 0.28);
}

.hd-app .tarjeta-cabecera {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 22px;
}

.hd-app .operacion-numero {
    flex: none;
    color: var(--hd-verde-oscuro);
    font-size: var(--hd-texto-s);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: .01em;
}

.hd-app .terminada .operacion-numero {
    color: var(--hd-exito-texto);
}

.hd-app .operacion-fecha-objetivo {
    padding: 2px 8px;
    border: 1px solid var(--hd-linea-fuerte);
    border-radius: 999px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 11px;
    line-height: 14px;
    font-weight: 700;
    color: var(--hd-verde-oscuro);
    background: var(--hd-verde-suave);
    white-space: nowrap;
    transition: background var(--hd-dur-evento) var(--hd-ease), color var(--hd-dur-evento) var(--hd-ease), border-color var(--hd-dur-evento) var(--hd-ease);
}

.hd-app .terminada .operacion-fecha-objetivo {
    color: var(--hd-exito-texto);
    background: #d4edda;
    border-color: #86a78d;
}

.hd-app .bloqueada .operacion-fecha-objetivo {
    color: #55646F;
    background: #eef0f2;
    border-color: #aab2b9;
}

.hd-app .operacion-fecha-objetivo.riesgo {
    color: var(--hd-aviso-texto);
    background: var(--hd-aviso-fondo);
    border-color: var(--hd-aviso-borde);
}

.hd-app .operacion-fecha-objetivo.retraso {
    color: var(--hd-peligro-texto);
    background: var(--hd-peligro-fondo);
    border-color: var(--hd-peligro-borde);
}

.hd-app .operacion-cliente {
    overflow: hidden;
    margin-top: 5px;
    color: var(--hd-tinta-suave);
    font-size: var(--hd-texto-xs);
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hd-app .tarjeta-datos {
    margin-top: 7px;
    min-height: 16px;
    overflow: hidden;
    color: var(--hd-tinta);
    font-size: var(--hd-texto-xs);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.hd-app .tarjeta-estados {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    min-width: 0;
}

.hd-app .operacion-avance {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--hd-exito-texto);
    background: var(--hd-exito-fondo);
    font-size: 11px;
    line-height: 14px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.hd-app .operacion-avance.en-curso {
    border: 1px solid #2e8b57;
}

.hd-app .operacion-avance.en-curso::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 4px;
    border-radius: 50%;
    background: currentColor;
    vertical-align: middle;
    animation: hd-parpadeo-en-curso 1.2s ease-in-out infinite;
}

@keyframes hd-parpadeo-en-curso {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

/* En curso fuera del horario productivo del proceso (tambien no laborables,
   paradas y procesos sin horario): el reloj no cuenta y el punto "live" se
   apaga; la pildora conserva su borde para verse sobre la tarjeta verde.
   Gana por especificidad a la regla base y a prefers-reduced-motion. */
.hd-app .operacion-avance.en-curso.fuera-horario::before {
    display: none;
}

.hd-app .operacion-avance.retraso {
    color: var(--hd-peligro-texto);
    background: var(--hd-peligro-fondo);
    border: 1px solid var(--hd-peligro-borde);
}

.hd-app .operacion-avance.en-curso.retraso {
    border-color: var(--hd-peligro-borde);
}

.hd-app .operacion-tiempo-real {
    margin-left: 6px;
    color: var(--hd-aviso-texto);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.hd-app .operacion-tiempo-real svg {
    margin-right: 3px;
    vertical-align: -1px;
}

.hd-app .terminada .operacion-avance {
    color: var(--hd-exito-texto);
    background: #d7ebda;
}

.hd-app .terminada .operacion-avance.retraso {
    color: var(--hd-peligro-texto);
    background: var(--hd-peligro-fondo);
}

.hd-app .tarjeta-acciones {
    position: relative;
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 8px;
    min-height: 30px;
}

.hd-app .tarjeta-trabajadores {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 4px;
    margin-right: auto;
    min-height: 21px;
    overflow: hidden;
}

.hd-app .trabajador-mini {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    padding: 3px 6px;
    border: 1px solid var(--hd-linea-fuerte);
    border-radius: 999px;
    color: #44525c;
    background: #eef2f5;
    font-size: 11px;
    font-weight: 700;
    cursor: default;
}

/* Aviso personal de la tarjeta: badge-pildora abajo a la izquierda con el
   estado propio del usuario (sin avisos / cambios / terminado). */
.hd-app .boton-aviso {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    min-height: 30px;
    margin-right: auto;
    padding: 3px 6px 3px 9px;
    border: 1px solid var(--hd-linea-fuerte);
    border-radius: 999px;
    color: #8a95a0;
    background: #eef2f5;
    cursor: pointer;
    transition: background-color var(--hd-dur-rapido) var(--hd-ease), border-color var(--hd-dur-rapido) var(--hd-ease), color var(--hd-dur-rapido) var(--hd-ease);
}

.hd-app .boton-aviso .boton-icono {
    display: inline-flex;
}

.hd-app .boton-aviso-flecha {
    color: #aab5bd;
    transition: transform var(--hd-dur-rapido) var(--hd-ease);
}

.hd-app .boton-aviso[aria-expanded="true"] .boton-aviso-flecha {
    transform: rotate(180deg);
}

.hd-app .boton-aviso:hover {
    border-color: #7d8d99;
    color: #5b6b76;
    background: #e1e8ee;
}

.hd-app .boton-aviso.aviso-cambios {
    border-color: #e0be5a;
    color: #a67408;
    background: #fdf3d9;
}

.hd-app .boton-aviso.aviso-terminado {
    border-color: var(--hd-exito-borde);
    color: var(--hd-exito-texto);
    background: var(--hd-exito-fondo);
}

/* El desplegable vive en body (position:fixed) y se abre sobre el boton:
   dentro de la tarjeta el resumen fijo, otras tarjetas o el recorte del
   scroll se comian las opciones de arriba segun la posicion en pantalla. */
.menu-avisos {
    position: fixed;
    z-index: 1400;
    display: grid;
    gap: 2px;
    min-width: 200px;
    padding: 4px;
    border: 1px solid var(--hd-linea-fuerte);
    border-radius: var(--hd-radio-m);
    background: var(--hd-papel);
    box-shadow: 0 12px 30px rgba(20, 40, 58, 0.24);
}

.menu-avisos button {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 32px;
    padding: 5px 9px;
    border: 0;
    border-radius: var(--hd-radio-s);
    color: var(--hd-tinta);
    background: transparent;
    cursor: pointer;
    font-family: var(--hd-fuente);
    font-size: var(--hd-texto-s);
    text-align: left;
}

.menu-avisos button:hover {
    background: #eef2f5;
}

.menu-avisos button.activa {
    background: #e3e9ee;
    font-weight: 700;
}

.menu-aviso-icono {
    display: inline-flex;
    color: #5b6b76;
}

.menu-avisos button.activa .menu-aviso-icono {
    color: #1e7a45;
}

/* Localizar una tarjeta desde una notificacion: doble pulso verde. */
.hd-app .tarjeta-operacion.aviso-flash {
    animation: hd-aviso-flash 2.4s ease;
}

@keyframes hd-aviso-flash {
    0%, 100% { box-shadow: var(--hd-sombra-1); }
    20%, 60% { box-shadow: 0 0 0 4px rgba(30, 122, 69, 0.4); }
    40%, 80% { box-shadow: 0 0 0 4px rgba(30, 122, 69, 0.12); }
}

/* Botones de acción de tarjeta (compartidos por las dos colas) */
.hd-app .boton-comentario,
.hd-app .boton-editar,
.hd-app .boton-terminar,
.hd-app .boton-reabrir,
.hd-app .boton-desbloquear,
.hd-app .boton-iniciar,
.hd-app .boton-pausar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 30px;
    padding: 3px 9px;
    border-radius: var(--hd-radio-s);
    cursor: pointer;
    font-family: var(--hd-fuente);
    font-size: var(--hd-texto-xs);
    font-weight: 700;
    line-height: 1;
    transition: background-color var(--hd-dur-rapido) var(--hd-ease), border-color var(--hd-dur-rapido) var(--hd-ease), color var(--hd-dur-rapido) var(--hd-ease);
}

.hd-app .boton-comentario,
.hd-app .boton-editar,
.hd-app .boton-desbloquear {
    border: 1px solid var(--hd-linea-fuerte);
    color: #44525c;
    background: #eef2f5;
}

.hd-app .boton-comentario:hover,
.hd-app .boton-editar:hover,
.hd-app .boton-desbloquear:hover {
    background: #e1e8ee;
}

.hd-app .boton-comentario.activo {
    border-color: #7d8d99;
    color: #3a4e5c;
    background: #e1e8ee;
}

.hd-app .boton-terminar,
.hd-app .boton-iniciar {
    border: 1px solid var(--hd-exito-borde);
    color: var(--hd-exito-texto);
    background: var(--hd-exito-fondo);
}

.hd-app .boton-terminar:hover,
.hd-app .boton-iniciar:hover {
    background: var(--hd-exito-fondo-suave);
}

.hd-app .boton-reabrir,
.hd-app .boton-pausar {
    border: 1px solid var(--hd-aviso-borde);
    color: var(--hd-aviso-texto);
    background: var(--hd-aviso-fondo-suave);
}

.hd-app .boton-reabrir:hover,
.hd-app .boton-pausar:hover {
    background: #fbe9bd;
}

.hd-app .comentario-flotante {
    position: absolute;
    z-index: 100;
    right: 0;
    bottom: calc(100% + 6px);
    width: min(280px, 70vw);
    padding: 9px 10px;
    border: 1px solid var(--hd-linea-fuerte);
    border-radius: var(--hd-radio-s);
    color: #44525c;
    background: #f4f6f8;
    box-shadow: var(--hd-sombra-2);
    font-size: 11px;
    font-weight: 400;
    line-height: 1.35;
    text-align: left;
    white-space: pre-wrap;
}

/* Tooltip flotante compartido (comun/tooltip.js): un solo div en el body con
   el HTML que cada app monta (rejilla tt-grid de dos columnas con tt-fuerte /
   tt-divisoria / tt-nombre / tt-valor; la variante tt-grid-3 añade una tercera
   para las rejillas nombre|valor|valor del tooltip de Proceso). Sin el prefijo
   .hd-app porque el div cuelga del body, fuera del contenedor de la vista.
   z-index 1500: sobre las cabeceras fijas (3) y comentario-flotante (100),
   bajo modal (5000) y toast (9999). */
.tooltip-hd {
    position: fixed;
    z-index: 1500;
    min-width: 110px;
    max-width: 320px;
    padding: 7px 9px;
    border: 1px solid var(--hd-linea-fuerte);
    border-radius: var(--hd-radio-s);
    color: #44525c;
    background: #f4f6f8;
    box-shadow: var(--hd-sombra-2);
    font-size: 11px;
    line-height: 1.4;
    text-align: left;
    white-space: nowrap;
    pointer-events: none;
}

.tooltip-hd.oculto { display: none; }
.tooltip-hd .tt-fuerte { font-weight: 700; }
/* Rejilla de dos columnas: nombre a la izquierda y valor con los dígitos
   alineados a la derecha (columnas al contenido máximo). */
.tooltip-hd .tt-grid {
    display: grid;
    grid-template-columns: auto auto;
    column-gap: 12px;
    align-items: baseline;
}
/* Variante de tres columnas (nombre | valor | valor): el tooltip de Proceso
   alinea tiempo y coste a la derecha en columnas propias. */
.tooltip-hd .tt-grid-3 { grid-template-columns: auto auto auto; }
.tooltip-hd .tt-valor { text-align: right; font-variant-numeric: tabular-nums; }
.tooltip-hd .tt-divisoria { grid-column: 1 / -1; border-top: 1px solid var(--hd-linea); margin: 4px 0; }

/* Menú contextual compartido (comun/menu-contextual.js): un solo div en el
   body que cada app abre junto al cursor con sus items (botones .menu-hd-item
   y .menu-hd-separador para { divisor: true }). Sin prefijo .hd-app porque
   cuelga del body, fuera del contenedor de la vista (igual que tooltip-hd).
   La política de dónde se sustituye el menú nativo la decide cada app; aquí
   solo se dibuja y se cierra. Lenguaje visual del menú de procesos de
   planificación. z-index 1600: sobre tooltip-hd (1500), bajo modal (5000) y
   toast (9999). */
.menu-hd {
    position: fixed;
    z-index: 1600;
    min-width: 140px;
    max-width: 280px;
    padding: 5px 0;
    border: 1px solid var(--hd-linea-fuerte);
    border-radius: var(--hd-radio-m);
    color: var(--hd-tinta);
    background: var(--hd-papel);
    box-shadow: 0 8px 22px rgba(20, 40, 58, 0.22);
    font-size: 12px;
    line-height: 1.35;
    text-align: left;
}

.menu-hd.oculto { display: none; }

.menu-hd .menu-hd-item {
    display: block;
    width: 100%;
    padding: 7px 12px;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.menu-hd .menu-hd-item:hover,
.menu-hd .menu-hd-item:focus-visible {
    background: #eef3f7;
}

.menu-hd .menu-hd-separador {
    height: 0;
    margin: 3px 8px;
    border-top: 1px solid var(--hd-linea);
}

/* El menú cuelga del body (fuera de .hd-app): la animación no puede ir en la
   lista con prefijo del principio del fichero. */
.menu-hd:not(.oculto) {
    animation: hd-panel-in var(--hd-dur-rapido) var(--hd-ease);
}

@media (prefers-reduced-motion: reduce) {
    .menu-hd:not(.oculto) {
        animation: none;
    }
}

/* Zona de terminadas recientes (compartida) */
.hd-app .zona-terminadas {
    margin-top: 16px;
}

.hd-app .bloque-terminadas {
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.hd-app .bloque-terminadas h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 8px;
    margin-left: calc(-24px - env(safe-area-inset-left, 0px));
    margin-right: calc(-24px - env(safe-area-inset-right, 0px));
    color: var(--hd-tinta-suave);
    font-size: 11px;
    line-height: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
    text-align: center;
}

.hd-app .bloque-terminadas h2::before,
.hd-app .bloque-terminadas h2::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    background: var(--hd-linea-fuerte);
}

.hd-app .columnas-terminadas {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
}

.hd-app .columnas-terminadas > * {
    min-width: 0;
}

.hd-app .grupo-bloqueados {
    margin-top: 14px;
    padding-top: 0;
    border-top: none;
}

.hd-app .grupo-bloqueados-titulo {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 8px;
    color: var(--hd-tinta-suave);
    background: none;
    font-size: 11px;
    line-height: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
    text-align: center;
}

.hd-app .grupo-bloqueados-titulo::before,
.hd-app .grupo-bloqueados-titulo::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    background: var(--hd-linea-fuerte);
}

@media (max-width: 900px) {
    .hd-app .bloque-terminadas h2 {
        margin-left: calc(-14px - env(safe-area-inset-left, 0px));
        margin-right: calc(-14px - env(safe-area-inset-right, 0px));
    }
}

@media (prefers-reduced-motion: reduce) {
    .hd-app .operacion-avance.en-curso::before {
        animation: none;
    }

    .hd-app .operacion-fecha-objetivo {
        transition: none;
    }

    .hd-app .cargando::before {
        animation-duration: 1.6s;
    }
}

@media (hover: none) {
    .hd-app .tarjeta-operacion:hover {
        border-color: var(--hd-linea);
        box-shadow: var(--hd-sombra-1);
    }

    .hd-app .tarjeta-operacion.en-riesgo:hover {
        border-color: var(--hd-aviso-borde);
        box-shadow: var(--hd-sombra-1);
    }

    .hd-app .tarjeta-operacion.retraso:hover {
        border-color: var(--hd-peligro-borde);
        box-shadow: var(--hd-sombra-1);
    }

    .hd-app .tarjeta-operacion.en-curso:hover {
        border-color: #2e8b57;
        box-shadow: var(--hd-sombra-1);
    }

    .hd-app .tarjeta-operacion.terminada:hover,
    .hd-app .tarjeta-operacion.bloqueada:hover {
        box-shadow: var(--hd-sombra-1);
    }
}


/* ------------------------------------------------------------------
   Táctil por capacidad de puntero, no por anchura: un iPad vertical
   (768-1024px) recibe estilos de escritorio y iOS hace zoom automático
   al enfocar cualquier input por debajo de 16px (salto de layout con la
   cabecera sticky descolocada). Con pointer: coarse mandan los dedos.
   ------------------------------------------------------------------ */
@media (pointer: coarse) {
    .hd-app input,
    .hd-app select,
    .hd-app textarea { font-size: 16px; }
}

/* Toast común en móvil: centrado y sobre el área segura (antes solo
   proceso lo corregía; en iPhone con barra de gestos quedaba pegado al
   borde o medio tapado). */
@media (max-width: 900px) {
    .hd-app .toast.visible {
        left: 14px;
        right: 14px;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        max-width: none;
        text-align: center;
        font-size: 14px;
    }
}

/* ------------------------------------------------------------------
   Impresion global. El @page { margin: 0 } de comun/reporte.css vale
   para TODA la SPA (los reportes compensan con padding propio en mm),
   asi que un Ctrl+P suelto en una vista saldria pegado al borde fisico:
   las apps sin gestion propia de impresion (planificacion, proceso)
   llevan un padding que hace de margen; optimizador y visor montan su
   .print-documento y no deben tocarse. Nada de toast ni modales en
   papel en ninguna app.
   ------------------------------------------------------------------ */
@media print {
    .hd-app .toast,
    .hd-app .modal,
    .hd-app .aviso-conexion { display: none !important; }

    .app-planificacion main,
    .app-proceso main { padding: 12mm !important; }
}
