﻿/* =========================================================
   gestor.css — Diseño moderno Hospital SJL
   Base: propiedades.css (rediseño_firmador)
   Extensiones: login, alert, debug, diagnóstico, firma
   ========================================================= */

:root {
    --font-sans: 'Geist', system-ui, -apple-system, sans-serif;
    --font-mono: 'Cascadia Code', Consolas, 'Segoe UI Mono', monospace;

    /* Escala tipográfica (16px root): 12 / 13 / 14 / 16 / 20 / 24 */
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-md: 0.875rem;
    --text-lg: 1rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;

    --background: #fafafa;
    --foreground: #09090b;
    --card: #ffffff;
    --muted: #f4f4f5;
    --muted-foreground: #52525b; /* ~7.5:1 sobre blanco (AAA). #71717a solo llega a 4.8:1 */
    --border: #e4e4e7;
    --primary-foreground: #ffffff;

    --brand-blue: #0061bd;
    --brand-blue-hover: #004da1;
    --brand-blue-ink: #004a94; /* texto sobre --brand-blue-soft, ~7.2:1 AAA */
    --brand-blue-rgb: 0, 97, 189;
    --brand-blue-soft: #e5eff8; /* sólido ≈ rgba(0, 97, 189, 0.1) sobre blanco */
    --brand-blue-ring: #ccdff2; /* sólido ≈ rgba(0, 97, 189, 0.2) sobre blanco */
    --brand-red: #d90429;
    --danger-soft: #fff1f2;
    --danger-border: #fecdd3;
    --status-ok: #16a34a;

    /* Teal oscuro: blanco cumple WCAG AAA (~7.5:1). #25d366 y #008069 no. */
    --whatsapp: #075e54;
    --whatsapp-hover: #054c44;
    --whatsapp-focus: #0d9488;

    --login-bg: #f4f7fb;

    --radius-md: 0.375rem;
    --radius-sm: 0.25rem;
    --radius-lg: 0.5rem;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    scroll-behavior: smooth;
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--foreground);
}

body {
    font-family: inherit;
    background-color: var(--background);
    color: inherit;
    font-size: var(--text-sm);
    letter-spacing: -0.01em;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

body:has(.dashboard-layout) {
    height: 100%;
    overflow: hidden;
}

input, select, button, textarea, a, option, optgroup {
    font-family: inherit;
    font-size: inherit;
}

button, input, select, textarea {
    color: inherit;
}

h1, h2, h3, h4, h5, h6 {
    font-size: inherit;
    font-weight: inherit;
}

/* ── Layout principal ── */
.dashboard-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    overflow: hidden;
}

/* ── Navbar ── */
.navbar {
    background-color: var(--card);
    border-bottom: 1px solid var(--border);
    min-height: 3.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 20;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

/* Logo institucional completo: 75 % de 72px (4.5rem) → 54px — ver docs/gestor-interfaz.md */
.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 3.375rem;
    height: 3.375rem;
}

.logo-img-placeholder {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.logo-icon { width: 1.1rem; height: 1.1rem; color: var(--brand-blue); }

.brand-info { display: flex; flex-direction: column; }
.hospital-name { font-weight: 600; font-size: var(--text-md); color: var(--foreground); }
.app-slug { font-size: var(--text-xs); color: var(--muted-foreground); }

.session-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-left: 1px solid var(--border);
    padding-left: 0.75rem;
}

.user-details { display: flex; flex-direction: column; }
.user-name { font-weight: 600; font-size: var(--text-sm); }
.user-role { font-size: var(--text-xs); color: var(--muted-foreground); }

.user-avatar {
    width: 1.85rem;
    height: 1.85rem;
    background-color: var(--brand-blue-soft);
    color: var(--brand-blue-ink);
    font-weight: 700;
    font-size: var(--text-xs);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--brand-blue-ring);
    flex-shrink: 0;
}

.btn-logout {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: transparent;
    border: 1px solid var(--border);
    padding: 0 0.5rem;
    height: 1.85rem;
    border-radius: var(--radius-sm);
    color: var(--muted-foreground);
    cursor: pointer;
    font-size: var(--text-xs);
    font-weight: 500;
    text-decoration: none;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-logout:hover {
    background-color: var(--danger-soft);
    border-color: var(--danger-border);
    color: var(--brand-red);
}

.logout-icon { width: 0.9rem; height: 0.9rem; }

/* ── Contenido principal ── */
.dashboard-main {
    flex: 1;
    min-height: 0;
    padding: 1.25rem 1.5rem;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.workspace {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    box-shadow: 0 1px 2px rgba(9, 9, 11, 0.04), 0 10px 28px -18px rgba(9, 9, 11, 0.28);
    overflow: hidden;
}

.view-header {
    position: relative;
    z-index: 6;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.view-header-title {
    width: 100%;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
}

.view-header-meta {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    padding: 0.7rem 1rem 0.15rem;
}

.pendientes-totales-chip {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.12rem;
    min-width: 7.25rem;
    padding: 0.45rem 0.8rem 0.4rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.7rem;
}

.pendientes-totales-chip--activo {
    background: var(--danger-soft);
    border-color: var(--danger-border);
}

.pendientes-totales-label {
    display: inline-flex;
    align-items: center;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--foreground);
    white-space: nowrap;
}

.pendientes-totales-info {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--muted-foreground);
    cursor: pointer;
}

.pendientes-totales-info .tag-icon {
    width: 1rem;
    height: 1rem;
    display: block;
    color: var(--foreground);
}

.pendientes-totales-icono {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--foreground);
    cursor: pointer;
    line-height: 1;
}

.pendientes-totales-word {
    border-radius: 0.3rem;
    padding: 0.05rem 0.28rem;
    color: var(--foreground);
    transition: background-color 0.12s ease;
}

.pendientes-totales-info:hover .pendientes-totales-word,
.pendientes-totales-info.is-pinned .pendientes-totales-word {
    background-color: var(--border);
}

.pendientes-meses-popover {
    display: none;
    position: absolute;
    left: 0;
    top: calc(100% + 0.45rem);
    z-index: 40;
    width: max-content;
    max-height: 18rem;
    overflow-x: clip;
    overflow-y: auto;
    scrollbar-gutter: stable;
    padding: 0.85rem 0.85rem 0.75rem;
    background: var(--card);
    color: var(--foreground);
    border: 1px solid var(--border);
    border-radius: 0.85rem;
    box-shadow: 0 10px 28px rgba(9, 9, 11, 0.12), 0 1px 2px rgba(9, 9, 11, 0.04);
    text-align: left;
}

.pendientes-totales-info:hover .pendientes-meses-popover,
.pendientes-totales-info:focus-within .pendientes-meses-popover,
.pendientes-totales-info.is-pinned .pendientes-meses-popover {
    display: block;
}

.pendientes-totales-info.is-dismissed .pendientes-meses-popover {
    display: none;
}

.pendientes-meses-popover-head {
    margin-bottom: 0.75rem;
}

.pendientes-meses-popover-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.pendientes-meses-popover-title {
    display: block;
    font-size: var(--text-md);
    font-weight: 600;
    line-height: 1.2;
    color: var(--foreground);
}

.pendientes-meses-popover-hint {
    display: block;
    margin-top: 0.2rem;
    font-size: var(--text-xs);
    font-weight: 400;
    line-height: 1.35;
    color: var(--muted-foreground);
}

.pendientes-meses-popover-hint span {
    display: block;
}

.pendientes-meses-cerrar {
    flex-shrink: 0;
    width: 1.35rem;
    height: 1.35rem;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0.3rem;
    background: transparent;
    color: var(--muted-foreground);
    font-size: var(--text-lg);
    line-height: 1;
    cursor: pointer;
}

.pendientes-meses-cerrar:hover {
    background: var(--muted);
    color: var(--foreground);
}

.pendientes-meses-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.pendientes-meses-list li {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    background: var(--card);
}

.pendientes-meses-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--brand-red);
    flex-shrink: 0;
}

.pendientes-meses-nombre {
    flex: 1;
    min-width: 0;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--foreground);
}

.pendientes-meses-conteo {
    font-size: var(--text-sm);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--foreground);
}

.pendientes-meses-popover-empty {
    display: block;
    font-size: var(--text-sm);
    color: var(--muted-foreground);
}

.pendientes-totales-value {
    font-size: var(--text-2xl);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    letter-spacing: -0.03em;
    color: var(--foreground);
}

.pendientes-totales-chip--activo .pendientes-totales-value {
    color: var(--brand-red);
}

.gestor-form {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.view-header h1 {
    font-size: var(--text-xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--foreground);
}

/* ── Panel de filtros (fila única) ──
   Hijos, en este orden:
   1. .search-group          crece y se queda con el ancho libre
   2. #idEstado              ancho fijo (PENDIENTE / FIRMADO)
   3. #tipoDocumento         ancho fijo, cabe el nombre del grupo
   4. .date-range            ancho fijo (etiqueta + dos fechas)
   5. .actions-group         ancho fijo; al crecer el buscador, Firmar queda al borde derecho
*/
.control-panel {
    flex-shrink: 0;
    background-color: transparent;
    border: none;
    border-radius: 0;
    padding: 0.65rem 1rem;
    display: flex;
    gap: 0.4rem;
    align-items: center;
    box-shadow: none;
    /* wrap en vez de scroll horizontal: overflow visible deja ver el tooltip de fechas */
    flex-wrap: wrap;
    position: relative;
    z-index: 5;
}

/* Mensajes de selección / firma, debajo del panel de filtros */
.panel-feedback {
    flex-shrink: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem 0.75rem;
    padding: 0 1rem;
}

.panel-feedback:has(.search-hint:not(:empty)),
.panel-feedback:has(.acciones-firma-info:not(:empty)),
.panel-feedback:has(.firma-status:not(:empty)) {
    min-height: 1.6rem;
    padding-bottom: 0.35rem;
}

/* Buscador compuesto. flex-grow: 1 absorbe el hueco de la fila. */
.search-group {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
}

.select-search-criteria {
    height: 2rem;
    flex: 0 0 7rem;
    width: 7rem;
    min-width: 7rem;
    border: 1px solid var(--border);
    border-right: none;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    padding: 0 1.15rem 0 0.35rem;
    font-family: inherit;
    font-size: var(--text-sm);
    background-color: var(--muted);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2371717a' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.25rem center;
    background-size: 0.75rem;
    color: var(--foreground);
    white-space: nowrap;
    flex-shrink: 0;
}

/* El texto del placeholder ocupa lo que sobre dentro del grupo. */
.search-input-container {
    position: relative;
    flex: 1 1 auto;
    min-width: 12rem;
    width: auto;
}

.search-input-container .search-icon {
    position: absolute;
    left: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 0.8rem;
    height: 0.8rem;
    color: var(--muted-foreground);
    pointer-events: none;
}

.input-modern-search {
    width: 100%;
    height: 2rem;
    background-color: transparent;
    border: 1px solid var(--border);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 0 0.5rem 0 1.5rem;
    font-family: inherit;
    font-size: var(--text-sm);
    color: var(--foreground);
}

.input-modern-search:focus {
    outline: none;
    border-color: var(--brand-blue);
    box-shadow: 0 0 0 1px var(--brand-blue);
}

.input-modern-search:disabled {
    background-color: var(--muted);
    color: var(--muted-foreground);
    cursor: not-allowed;
}

/* Criterio elegido sin texto: el cuadro sigue brillando hasta que se escribe. */
.search-group.is-attention .input-modern-search {
    border-color: var(--brand-blue);
    background-color: rgba(var(--brand-blue-rgb), 0.07);
    animation: search-attention 1.6s ease-in-out infinite;
}

.search-group.is-attention .search-icon {
    color: var(--brand-blue);
}

@keyframes search-attention {
    0%, 100% {
        box-shadow:
            0 0 0 3px rgba(var(--brand-blue-rgb), 0.16),
            0 0 12px rgba(var(--brand-blue-rgb), 0.28);
    }
    50% {
        box-shadow:
            0 0 0 5px rgba(var(--brand-blue-rgb), 0.3),
            0 0 22px rgba(var(--brand-blue-rgb), 0.55);
    }
}

@media (prefers-reduced-motion: reduce) {
    .search-group.is-attention .input-modern-search {
        animation: none;
    }
}

/* Aviso de búsqueda: debajo del panel de filtros (no dentro del input, para no ensanchar la fila) */
.panel-feedback .search-hint {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--brand-blue);
    flex: 1 1 100%;
    width: 100%;
}

.search-hint:empty {
    display: none;
}


/* Selectores estándar */
.select-modern {
    height: 2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 1.4rem 0 0.4rem;
    font-family: inherit;
    font-size: var(--text-sm);
    background-color: transparent;
    color: var(--foreground);
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2371717a' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.3rem center;
    background-size: 0.8rem;
    appearance: none;
}

.select-modern:focus {
    outline: none;
    border-color: var(--brand-blue);
}

/* Grupo: visualmente igual al resto aunque esté disabled */
.select-modern:disabled {
    opacity: 1;
    cursor: default;
    color: var(--muted-foreground);
}

.min-w-filter {
    flex: 0 0 auto;
    width: 8.6rem;
    min-width: 8.6rem;
    max-width: 9.5rem;
}

.select-tipo-doc {
    flex: 0 0 auto;
    width: 18.75rem;
    min-width: 18.75rem;
    max-width: 20rem;
}

/* Rango de fechas */
.date-range { display: flex; align-items: center; gap: 0.35rem; flex-shrink: 0; }

.date-range-label {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--muted-foreground);
    white-space: nowrap;
    cursor: default;
}

.info-icon {
    width: 0.85rem;
    height: 0.85rem;
    color: var(--brand-blue);
    cursor: default;
}

/* Tooltip CSS: texto en data-tooltip, visible al pasar el mouse o con foco de teclado */
.has-tooltip { position: relative; }

.has-tooltip::after,
.has-tooltip::before {
    position: absolute;
    left: 50%;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 30;
}

.has-tooltip::after {
    content: attr(data-tooltip);
    top: calc(100% + 0.5rem);
    transform: translate(-50%, -0.2rem);
    padding: 0.4rem 0.6rem;
    background-color: var(--foreground);
    color: var(--primary-foreground);
    font-size: var(--text-xs);
    font-weight: 500;
    white-space: nowrap;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.has-tooltip::before {
    content: '';
    top: calc(100% + 0.2rem);
    transform: translate(-50%, -0.2rem);
    border: 0.3rem solid transparent;
    border-bottom-color: var(--foreground);
    border-top-width: 0;
}

.has-tooltip:hover::after,
.has-tooltip:hover::before,
.has-tooltip:focus-visible::after,
.has-tooltip:focus-visible::before {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
}

/* Al usar el calendario nativo, el foco va al input: el tooltip no debe quedarse visible */
.date-range:has(.input-date:focus) .date-range-label.has-tooltip::after,
.date-range:has(.input-date:focus) .date-range-label.has-tooltip::before {
    opacity: 0;
    visibility: hidden;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.input-modern.input-date {
    height: 2rem;
    width: 105px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 0.3rem;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--foreground);
    background-color: transparent;
    cursor: pointer;
}

.input-modern.input-date:focus {
    outline: none;
    border-color: var(--brand-blue);
}

.range-separator { color: var(--muted-foreground); font-size: var(--text-xs); flex-shrink: 0; }

/* Botones + info firma inline */
.actions-group {
    flex: 0 0 auto;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: nowrap;
}

.btn-modern {
    height: 2rem;
    padding: 0 0.75rem;
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    border: 1px solid transparent;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    white-space: nowrap;
}

.btn-primary {
    background-color: var(--brand-blue);
    color: var(--primary-foreground);
    border-color: var(--brand-blue);
}

.btn-primary:hover { background-color: var(--brand-blue-hover); border-color: var(--brand-blue-hover); }

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-outline {
    background-color: transparent;
    color: var(--foreground);
    border-color: var(--border);
}

.btn-outline:hover {
    background-color: var(--muted);
}

.btn-outline:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    background-color: transparent;
}

.btn-icon { width: 0.85rem; height: 0.85rem; flex-shrink: 0; }

/* Checkbox */
.checkbox-modern {
    width: 0.9rem;
    height: 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: pointer;
    accent-color: var(--brand-blue);
    flex-shrink: 0;
}

/* ── Sección de resultados ── */
.table-view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background-color: transparent;
    border: none;
    border-top: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
}

.acciones-firma-info {
    font-size: var(--text-xs);
    color: var(--muted-foreground);
    font-family: var(--font-mono);
    white-space: nowrap;
}

.firma-status { font-size: var(--text-xs); font-weight: 600; white-space: nowrap; }
.firma-status-ok { color: var(--brand-blue); }
.firma-status-err { color: var(--brand-red); }

/* Tabla */
.table-wrapper {
    flex: 1;
    min-height: 0;
    overflow-x: clip;
    overflow-y: auto;
    /* Evita que aparezca/desaparezca la barra vertical y mueva el ancho de columnas al paginar */
    scrollbar-gutter: stable;
}

.modern-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: var(--text-sm);
    text-align: left;
}

/* Anchos solo en % (suman 100): con table-layout:fixed no “bailan” al cambiar de página */
.col-w-check { width: 2.75%; }
.col-w-icon { width: 3.5%; }
.col-w-doc { width: 5%; }
.col-w-paciente { width: 17%; }
.col-w-edad { width: 5%; }
.col-w-hc { width: 6%; }
.col-w-cuenta { width: 7%; }
.col-w-estado { width: 6%; }
.col-w-tipo { width: 15%; }
.col-w-fecha { width: 7%; }
.col-w-fecha-firma { width: 7%; }
.col-w-servicio { width: 22.25%; }

.modern-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 0.5rem 0.6rem;
    background-color: var(--muted);
    color: var(--muted-foreground);
    font-weight: 600;
    font-size: var(--text-xs);
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modern-table td {
    padding: 0.35rem 0.6rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modern-table tbody tr:hover { background-color: rgba(var(--brand-blue-rgb), 0.03); }

.modern-table th.col-actions,
.modern-table td.col-actions,
.modern-table th.col-shrink,
.modern-table td.col-shrink {
    overflow: hidden;
    text-overflow: clip;
    padding-left: 0.3rem;
    padding-right: 0.3rem;
}

.modern-table td.col-actions {
    vertical-align: middle;
}

.doc-actions {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    max-width: 100%;
}

/* Columnas especiales */
.text-center { text-align: center; }
.font-medium { font-weight: 600; color: var(--foreground); }
.text-mono { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--muted-foreground); }
.text-muted { color: var(--muted-foreground); }
.text-sm { font-size: var(--text-xs); }

/* Badge de tipo de documento */
.badge-doc {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
    color: var(--foreground);
}

/* Badges de estado */
.status-badge { font-weight: 600; font-size: var(--text-xs); }
.status-pending { color: var(--brand-red); }
.status-signed { color: var(--status-ok); }
.status-anulado { color: var(--muted-foreground); }

/* Botones de acción en fila (iconos) */
.row-icon-btn {
    display: inline-block;
    width: 1.4rem;
    height: 1.4rem;
    border: 1px solid var(--border);
    background-color: transparent;
    cursor: pointer;
    border-radius: var(--radius-sm);
    background-position: center;
    background-repeat: no-repeat;
    background-size: 0.8rem;
    text-decoration: none;
    transition: background-color 0.12s ease, border-color 0.12s ease;
    vertical-align: middle;
}

.row-icon-btn:hover {
    background-color: var(--muted);
    border-color: var(--muted-foreground);
}

/* Icono "previsualizar" (lupa) */
.action-view {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%230061bd'%3e%3cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.604 10.604z'/%3e%3c/svg%3e");
}

/* Icono "PDF firmado" (documento) */
.action-pdf {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23d90429'%3e%3cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z'/%3e%3c/svg%3e");
}

/* PDF firmado legacy (binario SQL / FirmaDigital2) — documento + indicador BD */
.action-pdf-legacy {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23b45309' stroke-width='2'%3e%3cpath stroke-linecap='round' stroke-linejoin='round' d='M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z'/%3e%3ccircle cx='17.5' cy='17.5' r='3.25' fill='%23fff7ed'/%3e%3cpath stroke-linecap='round' stroke-linejoin='round' d='M16 17.5h3M17.5 16v3'/%3e%3c/svg%3e");
}

/* Icono "sin PDF firmado" (desactivado) */
.action-pdf-empty {
    border-color: transparent;
    cursor: default;
    opacity: 0;
}

/* Footer de estadísticas de la tabla */
.table-footer-stats {
    flex-shrink: 0;
    min-height: 2.75rem;
    background-color: var(--background);
    border-top: 1px solid var(--border);
    padding: 0.625rem 1rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 1.75rem 2.25rem;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--muted-foreground);
    letter-spacing: 0.01em;
}

.table-footer-stats strong {
    font-size: var(--text-md);
    font-weight: 700;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--foreground);
    line-height: 1;
}

.table-footer-stats .text-success {
    color: var(--status-ok);
}

.table-footer-stats .text-error {
    color: var(--brand-red);
}

.table-pager {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.125rem;
    font-size: var(--text-sm);
    color: var(--muted-foreground);
}

.table-pager-range {
    margin-right: 0.75rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.table-pager .btn-pager {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    min-width: 2rem;
    height: 2rem;
    margin: 0;
    padding: 0 0.5rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    vertical-align: middle;
}

.table-pager .btn-pager {
    background: transparent;
    color: var(--foreground);
    cursor: pointer;
    transition: background-color 0.12s ease;
}

.table-pager .btn-pager:hover:not(:disabled) {
    background-color: var(--muted);
}

.table-pager .btn-pager-arrow {
    padding: 0;
    width: 2rem;
}

.table-pager .btn-pager-arrow svg {
    width: 1rem;
    height: 1rem;
    display: block;
}

.table-pager .btn-pager:disabled {
    color: var(--muted-foreground);
    opacity: 0.4;
    cursor: not-allowed;
}

/* Estado vacío */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2.5rem 1.5rem 3rem;
    color: var(--muted-foreground);
}

.empty-state p {
    max-width: 28rem;
}

.empty-state-art {
    display: block;
    width: 150px;
    height: 150px;
    margin: 0 auto 0.85rem;
    object-fit: contain;
    user-select: none;
    pointer-events: none;
}

.empty-state-icon { font-size: 2rem; margin-bottom: 0.5rem; }

.empty-state-title {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--foreground);
    margin-bottom: 0.25rem;
}

/* Foco visible para navegación con teclado */
.btn-modern:focus-visible,
.btn-logout:focus-visible,
.row-icon-btn:focus-visible,
.select-modern:focus-visible,
.select-search-criteria:focus-visible,
.input-date:focus-visible {
    outline: 2px solid var(--brand-blue);
    outline-offset: 1px;
}

.empty-state a {
    color: var(--brand-blue);
    font-weight: 600;
    text-decoration: none;
}

/* ── Footer ── */
.dashboard-footer {
    flex-shrink: 0;
    min-height: 2.75rem;
    background-color: var(--card);
    border-top: 1px solid var(--border);
    padding: 0.5rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.footer-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.footer-right { flex-shrink: 0; }

/* Soporte por WhatsApp (footer del gestor y pie del login) */
.btn-whatsapp {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: 2rem;
    padding: 0 0.75rem;
    border-radius: 999px;
    background-color: var(--whatsapp);
    color: var(--primary-foreground);
    font-size: var(--text-sm);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.btn-whatsapp:hover { background-color: var(--whatsapp-hover); transform: translateY(-1px); }
.btn-whatsapp:focus-visible { outline: 2px solid var(--whatsapp-focus); outline-offset: 2px; }
.btn-whatsapp-icon { width: 1rem; height: 1rem; flex-shrink: 0; }
.btn-whatsapp-text strong { font-weight: 700; font-variant-numeric: tabular-nums; }

.footer-connected-text {
    font-size: var(--text-sm);
    color: var(--foreground);
    letter-spacing: 0.01em;
}

.footer-connected-text strong {
    font-weight: 700;
    color: var(--foreground);
}

.status-indicator-ok {
    width: 8px;
    height: 8px;
    background-color: var(--brand-blue);
    border-radius: 50%;
    flex-shrink: 0;
    animation: footer-pulse 1.4s ease-in-out infinite;
}

@keyframes footer-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(0.85); }
}

/* ── Alertas ── */
.alert {
    flex-shrink: 0;
    margin-bottom: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 0.625rem 0.75rem;
    font-size: var(--text-sm);
}

.alert-error {
    background: #fff5f5;
    border-color: #fecaca;
    color: #991b1b;
}

.alert-info {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e3a8a;
}

.alert-success {
    background: #f0fdf4;
    border-color: #bbf7d0;
    color: #166534;
}

.debug-trace {
    margin-top: 0.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid #fecaca;
    background: var(--card);
    color: #334155;
    padding: 0.5rem;
    overflow: auto;
    max-height: 220px;
    font-size: var(--text-xs);
    font-family: var(--font-mono);
}

/* ── Login ── */
.login-page {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.75rem 1.5rem;
    background-color: var(--login-bg);
    background-image:
        radial-gradient(ellipse 55% 45% at 50% 42%, var(--card) 0%, rgba(255, 255, 255, 0) 70%);
}

.login-art {
    position: absolute;
    z-index: 0;
    height: auto;
    pointer-events: none;
    user-select: none;
}

.login-art-left {
    left: 0;
    bottom: 0;
    width: min(320px, 21vw, 46vh);
}

.login-art-right {
    right: 0;
    bottom: 0;
    /* Más grande que la izquierda. Se corre a la derecha y hacia abajo
       para alinear a las personas; el óvalo de la base puede quedar cortado. */
    width: min(560px, calc(50vw - 270px), 74vh);
    transform: translate(18%, 18%);
}

.login-shell {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.login-shell .login-card { width: 100%; }

/* Clave en type="text" enmascarada: el navegador no la trata como contraseña guardable */
.input-secret {
    -webkit-text-security: disc;
    font-family: var(--font-mono);
    letter-spacing: 0.1em;
}

.login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.875rem;
    padding: 1.75rem 1.625rem;
    box-shadow:
        0 1px 2px rgba(15, 23, 42, 0.04),
        0 16px 40px rgba(15, 23, 42, 0.06);
}

/* Ilustraciones de login (hoy comentadas en login.php). Al reactivarlas:
   @media (min-width: 1081px) {
     .login-page { background-image: radial-gradient(ellipse 55% 45% at 48.75% 42%, var(--card) 0%, rgba(255, 255, 255, 0) 70%); }
     .login-shell { transform: translateX(-1.125rem); }
   }
   Ver docs/frontend/01-login.md */
@media (max-width: 1080px) {
    .login-art { display: none; }
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.875rem;
    margin-bottom: 1.5rem;
}

.login-logo {
    width: auto;
    max-width: 200px;
    max-height: 120px;
    height: auto;
    object-fit: contain;
    display: block;
}

.login-title {
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    font-size: var(--text-lg);
    line-height: 1.3;
}

.login-title-main {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--foreground);
    letter-spacing: -0.02em;
}

/* Marca de producto (eGALENS): capitalización fija en HTML, sin forzar mayúsculas */
.login-title-mark {
    font-size: var(--text-md);
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--brand-blue);
}

.login-form { display: flex; flex-direction: column; gap: 0.875rem; }

.login-field { display: flex; flex-direction: column; gap: 0.375rem; }

.login-field span {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--foreground);
}

.login-input {
    width: 100%;
    height: 2.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 0.625rem;
    font-size: var(--text-sm);
    color: var(--foreground);
    background: var(--card);
}

.login-input:focus {
    outline: none;
    border-color: var(--brand-blue);
    box-shadow: 0 0 0 2px rgba(var(--brand-blue-rgb), 0.12);
}

.password-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-wrap .login-input {
    padding-right: 2.5rem;
}

/* Edge / IE: ocultar el ojo nativo del navegador (evita duplicado con .password-toggle) */
.password-input-wrap .login-input::-ms-reveal,
.password-input-wrap .login-input::-ms-clear {
    display: none;
    width: 0;
    height: 0;
}

.password-toggle {
    position: absolute;
    right: 0.3rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted-foreground);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.password-toggle:hover {
    color: var(--brand-blue);
    background-color: var(--muted);
}

.password-toggle-icon {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.password-toggle-hide {
    display: none;
}

.password-toggle.is-visible .password-toggle-show {
    display: none;
}

.password-toggle.is-visible .password-toggle-hide {
    display: block;
}

.login-submit {
    width: 100%;
    height: 2.25rem;
    margin-top: 0.25rem;
    background-color: var(--brand-blue);
    color: var(--primary-foreground);
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    line-height: 1;
    transition: background-color 0.15s ease;
}

.login-submit-icon {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.login-submit:hover { background-color: var(--brand-blue-hover); }

/* ── Diagnóstico / páginas secundarias ── */
.page-narrow { max-width: 860px; margin: 0 auto; padding: 1.5rem 1rem; }

.diag-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.125rem;
    margin-bottom: 1rem;
}

.diag-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.diag-table th, .diag-table td {
    border-bottom: 1px solid var(--border);
    padding: 0.5rem;
    text-align: left;
}
.diag-table th {
    color: var(--muted-foreground);
    font-weight: 600;
    background-color: var(--muted);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.diag-ok { color: #166534; font-weight: 600; }
.diag-fail { color: #b91c1c; font-weight: 600; }

.footer-note {
    margin-top: 0.75rem;
    text-align: center;
    color: var(--muted-foreground);
    font-size: var(--text-sm);
}

.footer-note a { color: var(--brand-blue); text-decoration: none; font-weight: 600; }

/* Header genérico (diagnóstico, páginas secundarias) */
.menu-top {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0.625rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.menu-top-title { font-size: var(--text-lg); font-weight: 600; color: var(--foreground); }
.menu-top-sub { margin-left: auto; color: var(--muted-foreground); font-size: var(--text-xs); }

/* ── Bloqueo de pantalla durante la firma ── */
/* z-index por debajo de blockUI (1000) para no tapar la interfaz del Cliente Firma Perú. */
.firma-procesando-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background-color: rgba(9, 9, 11, 0.5);
    backdrop-filter: blur(2px);
    cursor: progress;
}

.firma-procesando-overlay.is-open {
    display: flex;
}

.firma-procesando-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.65rem;
    min-width: 260px;
    max-width: 380px;
    padding: 1.5rem 1.75rem;
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    text-align: center;
}

.firma-procesando-spinner {
    width: 2.25rem;
    height: 2.25rem;
    border: 3px solid var(--border);
    border-top-color: var(--brand-blue);
    border-radius: 50%;
    animation: firma-procesando-giro 0.8s linear infinite;
}

.firma-procesando-titulo {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--foreground);
}

.firma-procesando-detalle {
    font-size: var(--text-sm);
    color: var(--muted-foreground);
}

.firma-procesando-detalle:empty {
    display: none;
}

@keyframes firma-procesando-giro {
    to { transform: rotate(360deg); }
}

/* ── Modal (confirmación DNI / firma) ── */
.gestor-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background-color: rgba(9, 9, 11, 0.45);
    backdrop-filter: blur(2px);
}

.gestor-modal-overlay.is-open {
    display: flex;
}

.gestor-modal-card {
    width: 100%;
    max-width: 420px;
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
    padding: 1.25rem 1.25rem 1.125rem;
}

.gestor-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.gestor-modal-title {
    font-size: var(--text-lg);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--foreground);
    line-height: 1.3;
}

.gestor-modal-close {
    flex-shrink: 0;
    width: 1.75rem;
    height: 1.75rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted-foreground);
    font-size: var(--text-xl);
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.gestor-modal-close:hover {
    background-color: var(--muted);
    color: var(--foreground);
}

.gestor-modal-lead {
    font-size: var(--text-sm);
    color: var(--muted-foreground);
    line-height: 1.45;
    margin-bottom: 0.75rem;
}

.gestor-modal-user {
    font-size: var(--text-sm);
    padding: 0.5rem 0.625rem;
    background-color: var(--muted);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 0.875rem;
    color: var(--foreground);
}

.gestor-modal-user-label {
    display: block;
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted-foreground);
    margin-bottom: 0.2rem;
}

.gestor-modal-form {
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
}

.gestor-modal-error {
    margin-bottom: 0;
    font-size: var(--text-sm);
}

.gestor-modal-error[hidden] {
    display: none !important;
}

.gestor-modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.gestor-modal-actions .btn-modern {
    min-width: 7rem;
    justify-content: center;
    height: 2.125rem;
}

/* ── Responsive ── */
@media (max-width: 900px) {
    .navbar { min-height: 3.25rem; padding: 0.35rem 1rem; }
    .logo-container { width: 2.625rem; height: 2.625rem; }
    .control-panel { flex-wrap: wrap; }
    .search-group { flex: 1 1 100%; min-width: unset; }
    .search-input-container { flex: 1 1 auto; width: auto; min-width: 8rem; }
    .select-search-criteria { width: 7.2rem; min-width: 7.2rem; }
    .min-w-filter { min-width: 100px; max-width: none; width: auto; flex: 1 1 auto; }
    .select-tipo-doc { min-width: 16rem; width: 100%; max-width: none; flex: 1 1 100%; }
    .date-range { flex-wrap: wrap; }
    .actions-group { margin-left: 0; width: 100%; }
    .btn-modern { width: 100%; justify-content: center; }
    .dashboard-main { padding: 0.85rem 1rem; }
    .btn-whatsapp-text { display: none; }
    .btn-whatsapp { width: 2rem; padding: 0; justify-content: center; }
}
