/* ============================================================
   firmar.css — Portal de firma para empleados
   Diseño mobile-first, funciona desde 300px
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:           #f5f6fa;
    --card-bg:      #ffffff;
    --text:         #1f2937;
    --text-muted:   #6b7280;
    --border:       #e5e7eb;
    --accent:       #f75900;
    --accent-hover: #d94d00;
    --accent-light: #fff5f0;
    --success:      #16a34a;
    --success-bg:   #dcfce7;
    --warning:      #d97706;
    --warning-bg:   #fef3c7;
    --danger:       #dc2626;
    --danger-bg:    #fee2e2;
    --shadow:       0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --radius:       10px;
}

[data-theme="dark"] {
    --bg:           #0f172a;
    --card-bg:      #1e293b;
    --text:         #e2e8f0;
    --text-muted:   #94a3b8;
    --border:       #334155;
    --accent:       #ff7a33;
    --accent-hover: #ff6622;
    --accent-light: #2d1500;
    --success:      #34d399;
    --success-bg:   #064e3b;
    --warning:      #fbbf24;
    --warning-bg:   #451a03;
    --danger:       #f87171;
    --danger-bg:    #450a0a;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    -webkit-text-size-adjust: 100%;
}

/* ── Header ─────────────────────────────────────────────────── */

.fp-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.fp-header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
}

.fp-header-logo img {
    height: 32px;
    width: auto;
}

.fp-header-logo {
    min-width: 0;
}

.fp-header-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--text-muted);
    min-width: 0;
    flex-shrink: 0;
}

.fp-header-user strong {
    color: var(--text);
    font-weight: 600;
    max-width: 110px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fp-reportes-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--warning, #d97706);
    text-decoration: none;
    padding: 4px 9px;
    border: 1px solid currentColor;
    border-radius: 20px;
    white-space: nowrap;
    position: relative;
    transition: background .13s;
}
.fp-reportes-btn:hover { background: rgba(217,119,6,.1); }
.fp-reportes-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--warning, #d97706);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
}

.fp-salir-link {
    font-size: 0.78rem;
    color: var(--accent);
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 5px;
    border: 1px solid var(--border);
    white-space: nowrap;
}
.fp-salir-link:hover { background: var(--bg); }

/* ── Layout principal ─────────────────────────────────────── */

.fp-main {
    max-width: 720px;
    margin: 0 auto;
    padding: 20px 14px 48px;
}

/* ── Login ──────────────────────────────────────────────────── */

.fp-login-wrap {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: var(--bg);
}

.fp-login-box {
    width: 100%;
    max-width: 380px;
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.1);
    padding: 32px 28px;
}

.fp-login-logo {
    text-align: center;
    margin-bottom: 24px;
}
.fp-login-logo img {
    height: 48px;
    width: auto;
    margin-bottom: 8px;
}
.fp-login-logo h1 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 4px;
}
.fp-login-logo p {
    font-size: 0.83rem;
    color: var(--text-muted);
}

.fp-form-group {
    margin-bottom: 16px;
}
.fp-form-group label {
    display: block;
    font-size: 0.83rem;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--text);
}
.fp-form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
}
.fp-form-group input:focus { border-color: var(--accent); }

.fp-btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 4px;
}
.fp-btn-primary:hover { background: var(--accent-hover); }

.fp-error-msg {
    background: var(--danger-bg);
    color: var(--danger);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.85rem;
    margin-bottom: 16px;
    border: 1px solid #fca5a5;
}

.fp-login-note {
    margin-top: 20px;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.5;
}

.fp-login-legal {
    margin-top: 20px;
    padding: 12px 14px;
    background: var(--bg, #f5f6fa);
    border-radius: 8px;
    border: 1px solid var(--border, #e5e7eb);
    font-size: 0.74rem;
    color: var(--text-muted, #6b7280);
    line-height: 1.55;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.fp-login-legal p { margin: 0; }
.fp-login-legal strong { color: var(--text, #1f2937); }

/* Declaración de consentimiento antes de firmar */
.fp-declaracion {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: var(--bg, #f5f6fa);
    border-radius: 8px;
    border: 1px solid var(--border, #e5e7eb);
    margin-bottom: 14px;
    cursor: pointer;
}
.fp-declaracion input[type="checkbox"] {
    flex-shrink: 0;
    margin-top: 2px;
    width: 17px;
    height: 17px;
    accent-color: var(--accent, #f75900);
    cursor: pointer;
}
.fp-declaracion label {
    font-size: 0.8rem;
    color: var(--text, #1f2937);
    line-height: 1.5;
    cursor: pointer;
}
.fp-declaracion label strong { color: var(--text, #1f2937); }

/* ── Sección de títulos ──────────────────────────────────── */

.fp-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin: 24px 0 10px;
}
.fp-section-title:first-child { margin-top: 0; }

.fp-section-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    margin: 24px 0 10px;
}
.fp-section-header-row:first-child { margin-top: 0; }
.fp-section-header-row .fp-section-title { margin: 0; }

/* ── Cards de documentos ─────────────────────────────────── */

.fp-doc-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 14px 16px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 10px;
    text-decoration: none;
    color: var(--text);
    transition: box-shadow 0.15s, border-color 0.15s;
}
.fp-doc-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); border-color: #d1d5db; }

.fp-doc-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}
.fp-doc-icon.pendiente {
    background: var(--warning-bg);
}
.fp-doc-icon.firmado {
    background: var(--success-bg);
}

.fp-doc-info {
    flex: 1;
    min-width: 0;
}
.fp-doc-nombre {
    font-weight: 600;
    font-size: 0.93rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fp-doc-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 3px;
    line-height: 1.4;
}

.fp-doc-badge {
    flex-shrink: 0;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 20px;
}
.fp-doc-badge.pendiente {
    background: var(--warning-bg);
    color: var(--warning);
}
.fp-doc-badge.firmado {
    background: var(--success-bg);
    color: var(--success);
}

.fp-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 28px 20px;
    font-size: 0.88rem;
}

/* ── Vista documento ────────────────────────────────────── */

.fp-doc-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.fp-back-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    white-space: nowrap;
    flex-shrink: 0;
    order: 1;
}
.fp-back-link:hover { background: var(--bg); }

/* En móvil: Reportar se queda en la misma fila que Volver (empujado a la derecha) */
.fp-btn-reportar {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 11px;
    background: transparent;
    color: var(--warning, #d97706);
    border: 1.5px solid var(--warning, #d97706);
    border-radius: 7px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
    order: 2;
    margin-left: auto;
}
.fp-btn-reportar:hover { background: var(--warning-bg, #fef3c7); }

/* En móvil: el título ocupa toda la segunda fila */
.fp-doc-title {
    order: 3;
    width: 100%;
    font-size: 1rem;
    font-weight: 700;
    min-width: 0;
    white-space: nowrap;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* En pantallas anchas: título entre Volver y Reportar en la misma fila */
@media (min-width: 500px) {
    .fp-doc-title {
        order: 2;
        flex: 1;
        width: auto;
    }
    .fp-btn-reportar {
        order: 3;
        margin-left: 0;
    }
}

.fp-pdf-frame-wrap {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 16px;
}

.fp-zoom-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 5px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-2, #f3f4f6);
}

.fp-zoom-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    padding: 0;
    transition: background 0.15s;
}

.fp-zoom-btn:hover {
    background: var(--bg-3, #e5e7eb);
}

.fp-zoom-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 38px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Área donde se muestra el PDF (canvas + iframe) */
.fp-pdf-visor {
    width: 100%;
    height: 68dvh;
    min-height: 320px;
    background: #525659;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    /* Ocultar scrollbars: el desplazamiento se hace arrastrando */
    scrollbar-width: none;
}
.fp-pdf-visor::-webkit-scrollbar {
    display: none;
}

@media (max-width: 640px) {
    /* Altura mientras carga; PDF.js la sobreescribe a 'auto' al renderizar */
    .fp-pdf-visor {
        height: min(82dvh, calc(100vw * 1.5));
        min-height: 280px;
    }
}

.fp-pdf-loading {
    color: #fff;
    font-size: 0.88rem;
    text-align: center;
    padding: 20px;
}

#fp-pdf-canvas {
    display: block;
    width: 100%;
    height: auto;
    max-height: 65dvh;
    object-fit: contain;
}

.fp-doc-acciones {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.fp-btn-firmar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
}
.fp-btn-firmar:hover { background: var(--accent-hover); }
.fp-btn-firmar:disabled { opacity: 0.5; cursor: not-allowed; }

.fp-btn-confirmar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    background: var(--success);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
}
.fp-btn-confirmar:hover { background: #15803d; }
.fp-btn-confirmar:disabled { opacity: 0.5; cursor: not-allowed; }

.fp-btn-limpiar-firma {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 10px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background 0.15s;
}
.fp-btn-limpiar-firma:hover { background: var(--bg); }

/* Estado firmado */
.fp-firmado-banner {
    background: var(--success-bg);
    border: 1px solid #86efac;
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--success);
    font-weight: 600;
    margin-bottom: 14px;
}

/* Pasos del flujo de firma */
.fp-firma-step {
    display: none;
}
.fp-firma-step.activo {
    display: block;
}

/* Mensaje de alerta inline */
.fp-alerta {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 12px;
}
.fp-alerta.error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #fca5a5;
}
.fp-alerta.info {
    background: var(--accent-light, #fff5f0);
    color: var(--text, #1f2937);
    border: 1px solid var(--border, #e5e7eb);
    border-left: 3px solid var(--accent, #f75900);
}

/* Preview firma (miniatura en el flujo) */
.fp-firma-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 12px;
}
.fp-firma-preview img {
    max-height: 80px;
    max-width: 100%;
    object-fit: contain;
    border-bottom: 2px solid var(--text);
}
.fp-firma-preview span {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Spinner */
.fp-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.5);
    border-top-color: #fff;
    border-radius: 50%;
    animation: fp-spin 0.7s linear infinite;
    vertical-align: middle;
}
@keyframes fp-spin { to { transform: rotate(360deg); } }

/* ── Footer portal ──────────────────────────────────────── */

.fp-portal-footer {
    text-align: center;
    padding: 24px 0 10px;
    font-size: 0.74rem;
    color: var(--text-muted);
}
.fp-portal-footer button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: inherit;
    text-decoration: underline;
    padding: 0;
}
.fp-portal-footer button:hover { color: var(--text); }

/* ── Popup aviso legal ───────────────────────────────────── */

.fp-legal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.fp-legal-overlay.activo { display: flex; }

.fp-legal-box {
    background: var(--card-bg, #fff);
    border-radius: 12px;
    padding: 28px 24px;
    max-width: 520px;
    width: 100%;
    max-height: 82dvh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
.fp-legal-box h2 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--text);
}
.fp-legal-box p {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.65;
    margin-bottom: 12px;
}
.fp-legal-box p:last-of-type { margin-bottom: 0; }
.fp-legal-box strong { color: var(--text); font-weight: 600; }
.fp-legal-close {
    display: block;
    margin-top: 18px;
    width: 100%;
    padding: 10px;
    background: var(--bg, #f5f6fa);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.87rem;
    color: var(--text);
}
.fp-legal-close:hover { background: var(--border); }

/* ── Responsive mín. 300px ───────────────────────────────── */

@media (max-width: 380px) {
    .fp-login-box { padding: 24px 18px; }
    .fp-header { padding: 10px 12px; }
    .fp-main  { padding: 16px 10px 40px; }
    .fp-doc-card { padding: 12px 12px; gap: 10px; }
    .fp-header-user strong { max-width: 130px; }
}
