/**
 * Modal bloqueante de coleta de CPF (Fase 1 - controle de jornada / LGPD).
 * Self-contained (não depende de Bootstrap) para funcionar em qualquer página
 * autenticada. Usa as variáveis de tema da empresa quando disponíveis.
 */

.cpf-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.62);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: cpfFadeIn 0.18s ease-out;
}

@keyframes cpfFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes cpfSlideUp {
    from { transform: translateY(12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.cpf-modal-card {
    width: 100%;
    max-width: 560px;
    background: #ffffff;
    color: #1f2937;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
    overflow: hidden;
    animation: cpfSlideUp 0.22s ease-out;
    max-height: calc(100vh - 24px);
    display: flex;
    flex-direction: column;
}

.cpf-modal-header {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 13px 20px;
    background: linear-gradient(135deg, var(--brand-primary, #4f46e5), var(--brand-secondary, #7c3aed));
    color: #fff;
}

.cpf-modal-icon {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
}

.cpf-modal-header h2 {
    margin: 0;
    font-size: 1.02rem;
    font-weight: 700;
    line-height: 1.2;
}

.cpf-modal-sub {
    margin: 2px 0 0;
    font-size: 0.78rem;
    opacity: 0.92;
}

.cpf-modal-body {
    padding: 14px 20px 4px;
    overflow-y: auto;
}

.cpf-step label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: #374151;
}

.cpf-step input[type="text"],
.cpf-step input#cpfInput {
    width: 100%;
    padding: 12px 14px;
    font-size: 1.15rem;
    letter-spacing: 0.04em;
    border: 1.5px solid #d1d5db;
    border-radius: 10px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}

.cpf-step input#cpfInput:focus {
    border-color: var(--brand-primary, #4f46e5);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary, #4f46e5) 22%, transparent);
}

.cpf-lgpd-note {
    margin-top: 12px;
    font-size: 0.76rem;
    line-height: 1.5;
    color: #6b7280;
    background: #f8fafc;
    border: 1px solid #eef2f7;
    border-radius: 10px;
    padding: 10px 12px;
}

.cpf-alert {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 0.82rem;
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* Preview da escala (etapa 2) */
.cpf-preview {
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    margin-bottom: 10px;
}

.cpf-preview-head {
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.84rem;
}

.cpf-preview-head.ok {
    background: color-mix(in srgb, #16a34a 12%, #fff);
    color: #15803d;
    border-bottom: 1px solid color-mix(in srgb, #16a34a 24%, #fff);
}

.cpf-preview-head.warn {
    background: #fffbeb;
    color: #b45309;
    border-bottom: 1px solid #fde68a;
}

.cpf-preview-body {
    padding: 12px 14px;
    font-size: 0.86rem;
    color: #374151;
}

.cpf-preview-body .row-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0;
}

.cpf-preview-body .row-item .lbl { color: #6b7280; }
.cpf-preview-body .row-item .val { font-weight: 600; text-align: right; }

.cpf-horarios {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 10px;
}

.cpf-horario {
    text-align: center;
    background: #f8fafc;
    border: 1px solid #eef2f7;
    border-radius: 8px;
    padding: 8px 4px;
}

.cpf-horario .h-lbl { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.04em; color: #9ca3af; }
.cpf-horario .h-val { font-size: 0.98rem; font-weight: 700; color: #111827; }

/* Escala do mês (tabela compacta - últimos 10 dias) */
.cpf-esc-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: #374151;
    margin: 4px 0 8px;
}
.cpf-esc-ref { color: #9ca3af; font-weight: 500; }

.cpf-esc-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid #e5e7eb; }
.cpf-esc-wrap::-webkit-scrollbar { height: 6px; }
.cpf-esc-wrap::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.cpf-esc-tbl {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 0.66rem;
    text-align: center;
}
.cpf-esc-tbl th,
.cpf-esc-tbl td {
    width: 10%;
    min-width: 34px;
    padding: 3px 2px;
    border: 1px solid rgba(255, 255, 255, 0.12);
}
/* Cabeçalho com a cor do sidebar + texto branco */
.cpf-esc-tbl thead th {
    background: var(--sidebar-bg-light, var(--brand-primary, #4f46e5));
    color: #fff;
    font-weight: 700;
    line-height: 1.15;
}
.cpf-esc-tbl thead tr.r-dow th {
    font-weight: 600;
    font-size: 0.6rem;
    opacity: 0.92;
    text-transform: uppercase;
}
.cpf-esc-tbl thead th.is-today {
    background: #16a34a;
}
/* Célula de status (corpo) */
.cpf-esc-tbl tbody td {
    color: #fff;
    font-weight: 700;
    border-color: #fff;
}
.cpf-esc-tbl tbody td.is-today {
    outline: 2px solid #16a34a;
    outline-offset: -2px;
}

/* Cores por status */
.st-trab  { background: #f4b400; }           /* trabalha (diurno/noturno) */
.st-folga { background: #94a3b8; }           /* folga (dia útil) */
.st-sab   { background: #7c3aed; }           /* folga sábado */
.st-dom   { background: #dc2626; }           /* folga domingo */
.st-fer   { background: #0ea5e9; }           /* férias */
.st-outro { background: #6b7280; }

.cpf-esc-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 0.72rem;
    color: #6b7280;
    margin: 8px 0 14px;
}
.cpf-esc-legend .lg {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 3px;
    vertical-align: -1px;
    margin-right: 4px;
}

body.dark-mode .cpf-esc-title { color: #cbd5e1; }
body.dark-mode .cpf-esc-wrap { border-color: #374151; }
body.dark-mode .cpf-esc-legend { color: #9ca3af; }

.cpf-consent {
    display: flex !important;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.85rem !important;
    font-weight: 500 !important;
    color: #374151;
    cursor: pointer;
    margin-bottom: 6px;
}

.cpf-consent input[type="checkbox"] {
    margin-top: 2px;
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    cursor: pointer;
}

.cpf-consent a {
    color: var(--brand-primary, #4f46e5);
    font-weight: 600;
    text-decoration: underline;
}

.cpf-modal-footer {
    padding: 16px 22px 20px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    border-top: 1px solid #f1f5f9;
}

.cpf-btn {
    border: none;
    border-radius: 10px;
    padding: 11px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.08s, filter 0.15s, background 0.15s;
}

.cpf-btn:active { transform: translateY(1px); }
.cpf-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.cpf-btn-primary {
    background: linear-gradient(135deg, var(--brand-primary, #4f46e5), var(--brand-secondary, #7c3aed));
    color: #fff;
}

.cpf-btn-primary:not(:disabled):hover { filter: brightness(1.06); }

.cpf-btn-ghost {
    background: #f1f5f9;
    color: #475569;
}

.cpf-btn-ghost:hover { background: #e2e8f0; }

.cpf-btn .cpf-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #fff;
    border-radius: 50%;
    animation: cpfSpin 0.7s linear infinite;
    vertical-align: -2px;
    margin-right: 6px;
}

@keyframes cpfSpin { to { transform: rotate(360deg); } }

body.cpf-modal-open { overflow: hidden !important; }

/* ---------- Dark mode ---------- */
body.dark-mode .cpf-modal-card {
    background: #1f2937;
    color: #e5e7eb;
}
body.dark-mode .cpf-step label { color: #cbd5e1; }
body.dark-mode .cpf-step input#cpfInput {
    background: #111827;
    border-color: #374151;
    color: #f3f4f6;
}
body.dark-mode .cpf-lgpd-note {
    background: #111827;
    border-color: #374151;
    color: #9ca3af;
}
body.dark-mode .cpf-preview { border-color: #374151; }
body.dark-mode .cpf-preview-body { color: #cbd5e1; }
body.dark-mode .cpf-preview-body .row-item .val { color: #f3f4f6; }
body.dark-mode .cpf-horario { background: #111827; border-color: #374151; }
body.dark-mode .cpf-horario .h-val { color: #f3f4f6; }
body.dark-mode .cpf-consent { color: #cbd5e1; }
body.dark-mode .cpf-modal-footer { border-top-color: #374151; }
body.dark-mode .cpf-btn-ghost { background: #374151; color: #e5e7eb; }
body.dark-mode .cpf-btn-ghost:hover { background: #4b5563; }
body.dark-mode .cpf-alert { background: #3f1d1d; color: #fca5a5; border-color: #7f1d1d; }

@media (max-width: 520px) {
    .cpf-horarios { grid-template-columns: repeat(2, 1fr); }
    .cpf-modal-header h2 { font-size: 1rem; }
}
