/* ======================================
   CONTROLE DE VISITAS
   Componente: js/components/controle-visitas.js
   Usa variaveis de css/design-system.css
   ====================================== */

/* --- Container --- */
.cv-container {
    padding: var(--space-3) 0;
    position: relative;
}

/* --- Navegacao de Mes --- */
.cv-month-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    padding: var(--space-3) 0;
    margin-bottom: var(--space-4);
}

.cv-month-title {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-width: 220px;
    text-align: center;
    user-select: none;
}

.cv-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-primary);
    color: var(--color-primary);
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 14px;
}

.cv-nav-btn:hover:not(:disabled) {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.cv-nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Botao "Hoje" */
.cv-today-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 var(--space-4);
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-primary);
    cursor: pointer;
    font-size: var(--font-size-sm);
    font-weight: 600;
    letter-spacing: 0.3px;
    transition: all 0.15s ease;
}

.cv-today-btn:hover:not(:disabled) {
    background: var(--color-primary);
    color: #fff;
}

.cv-today-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* --- Secao da Semana --- */
.cv-week-section {
    margin-bottom: var(--space-5);
}

.cv-week-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    background: var(--color-primary);
    color: #fff;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease;
}

.cv-week-header:hover {
    background: var(--color-primary-light);
}

/* Semana atual com destaque sutil */
.cv-week-header--current {
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.cv-week-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.cv-week-chevron {
    font-size: 10px;
    transition: transform 0.2s ease;
}

.cv-week-chevron--collapsed {
    transform: rotate(-90deg);
}

.cv-week-dates {
    font-weight: 400;
    opacity: 0.85;
    font-size: var(--font-size-xs);
}

/* Resumo da semana no header */
.cv-week-summary {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-xs);
    opacity: 0.9;
}

.cv-week-stat {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
}

.cv-week-stat i {
    font-size: 10px;
    opacity: 0.8;
}

.cv-week-stat-sep {
    opacity: 0.4;
    font-weight: 300;
}

/* --- Tabela --- */
.cv-table-wrapper {
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    overflow: hidden;
}

.cv-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.cv-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
    table-layout: auto;
}

.cv-table thead {
    background: var(--color-bg-secondary);
    position: sticky;
    top: 0;
    z-index: 2;
}

.cv-table th {
    padding: var(--space-2) var(--space-2);
    text-align: center;
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    color: var(--color-text-secondary);
    border-bottom: 2px solid var(--color-border);
    white-space: nowrap;
    letter-spacing: 0.3px;
}

.cv-table td {
    padding: var(--space-2);
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.cv-table tbody tr {
    transition: background-color 0.12s ease;
}

.cv-table tbody tr:hover {
    background-color: rgba(30, 58, 95, 0.04);
}

/* Colunas fixas */
.cv-th-fixed {
    text-align: left !important;
    min-width: 120px;
    max-width: 160px;
}

.cv-th-meta {
    min-width: 50px;
}

.cv-th-day {
    min-width: 55px;
    position: relative;
}

/* Coluna do dia de hoje com destaque */
.cv-th-day--today {
    background: rgba(30, 58, 95, 0.06);
}

.cv-th-stat {
    min-width: 65px;
}

.cv-td-setor,
.cv-td-rep {
    text-align: left;
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cv-td-setor {
    color: var(--color-text-secondary);
}

.cv-td-rep {
    font-weight: 500;
    color: var(--color-text);
}

.cv-td-meta {
    text-align: center;
    font-weight: 600;
    color: var(--color-primary);
    font-size: var(--font-size-sm);
}

/* --- Celulas de Dia --- */
.cv-day-label {
    display: block;
    font-weight: 700;
    font-size: var(--font-size-xs);
    color: var(--color-text);
}

.cv-day-date {
    display: block;
    font-size: 10px;
    color: var(--color-text-secondary);
    font-weight: 400;
}

/* Data de hoje no header */
.cv-day-date--today {
    color: var(--color-primary);
    font-weight: 700;
    background: var(--color-primary);
    color: #fff;
    border-radius: var(--radius-sm);
    padding: 1px 4px;
    display: inline-block;
}

.cv-day-cell {
    text-align: center;
    position: relative;
    transition: all 0.12s ease;
    min-height: 36px;
}

/* Celulas clicaveis (tem visitas ou ausencia) */
.cv-day-cell--clickable {
    cursor: pointer;
}

.cv-day-cell--clickable:hover {
    background-color: rgba(30, 58, 95, 0.08);
}

/* Celulas inativas (feriado sem visitas, dia vazio) */
.cv-day-cell--inactive {
    cursor: default;
}

.cv-day-cell--absence {
    background-color: rgba(107, 114, 128, 0.08);
}

.cv-day-cell--holiday {
    background-color: rgba(245, 158, 11, 0.06);
}

/* Contagem de visitas */
.cv-day-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--font-size-sm);
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    line-height: 1;
}

.cv-day-count--text-success,
.cv-day-count--success {
    color: var(--color-success);
    background: rgba(16, 185, 129, 0.1);
}

.cv-day-count--text-danger,
.cv-day-count--danger,
.cv-day-count--error {
    color: var(--color-error);
    background: rgba(239, 68, 68, 0.1);
}

.cv-day-count--text-warning,
.cv-day-count--warning {
    color: var(--color-warning);
    background: rgba(245, 158, 11, 0.1);
}

.cv-day-zero {
    color: var(--color-text-secondary);
    font-size: var(--font-size-xs);
    opacity: 0.5;
}

/* Ausencia badge */
.cv-absence-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: var(--radius-full);
    font-size: 11px;
}

.cv-absence--ausencia_dia_todo {
    background: rgba(107, 114, 128, 0.2);
    color: #6B7280;
}

.cv-absence--ausencia_manha,
.cv-absence--ausencia_tarde {
    background: rgba(107, 114, 128, 0.12);
    color: #9CA3AF;
}

.cv-absence-count {
    display: block;
    font-size: 10px;
    color: var(--color-text-secondary);
    margin-top: 1px;
}

/* Feriado */
.cv-holiday-icon {
    color: var(--color-warning);
    font-size: 8px;
    position: absolute;
    top: 2px;
    right: 2px;
}

.cv-holiday-badge {
    color: var(--color-warning);
    font-size: 12px;
    opacity: 0.6;
}

/* --- Cobertura --- */
.cv-td-coverage {
    min-width: 80px;
}

.cv-coverage-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.cv-coverage-bar {
    width: 100%;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    overflow: hidden;
}

.cv-coverage-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease;
}

.cv-coverage--success { background: var(--color-success); }
.cv-coverage--warning { background: var(--color-warning); }
.cv-coverage--error { background: var(--color-error); }

.cv-coverage-text {
    font-size: 11px;
    font-weight: 600;
}

.cv-text--success { color: var(--color-success); }
.cv-text--warning { color: var(--color-warning); }
.cv-text--error { color: var(--color-error); }

/* --- Total e Gap --- */
.cv-td-total {
    text-align: center;
    font-weight: 700;
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.cv-td-gap {
    text-align: center;
    font-weight: 700;
    font-size: var(--font-size-sm);
}

.cv-gap--positive { color: var(--color-success); }
.cv-gap--negative { color: var(--color-error); }

/* --- Row vazio --- */
.cv-empty-row {
    text-align: center;
    color: var(--color-text-secondary);
    font-style: italic;
    padding: var(--space-4) !important;
}

/* --- Empty State --- */
.cv-empty-state {
    text-align: center;
    padding: var(--space-8) var(--space-4);
    color: var(--color-text-secondary);
}

.cv-empty-state i {
    font-size: 48px;
    opacity: 0.3;
    margin-bottom: var(--space-3);
    display: block;
}

.cv-empty-state p {
    font-size: var(--font-size-md);
    margin: 0;
}

/* --- Loading Skeleton --- */
.cv-loading {
    padding: var(--space-4) 0;
}

.cv-skeleton-week {
    margin-bottom: var(--space-5);
}

.cv-skeleton-bar {
    height: 36px;
    background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
    background-size: 200% 100%;
    animation: cv-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.cv-skeleton-table {
    height: 80px;
    background: linear-gradient(90deg, #f3f4f6 25%, #f9fafb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: cv-shimmer 1.5s ease-in-out infinite;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    border: 1px solid var(--color-border);
    border-top: none;
}

@keyframes cv-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* --- Overlay de Detalhes --- */
.cv-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    justify-content: flex-end;
    animation: cv-fade-in 0.15s ease;
}

@keyframes cv-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.cv-overlay-panel {
    width: 380px;
    max-width: 90vw;
    height: 100%;
    background: var(--color-bg-primary);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    animation: cv-slide-in 0.2s ease;
}

@keyframes cv-slide-in {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.cv-overlay-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: var(--space-4);
    background: var(--color-primary);
    color: #fff;
    flex-shrink: 0;
}

.cv-overlay-title {
    margin: 0;
    font-size: var(--font-size-lg);
    font-weight: 700;
}

.cv-overlay-subtitle {
    margin: var(--space-1) 0 0;
    font-size: var(--font-size-sm);
    font-weight: 500;
    opacity: 0.95;
}

.cv-overlay-bloco {
    margin: 2px 0 0;
    font-size: var(--font-size-xs);
    opacity: 0.7;
    font-weight: 400;
}

.cv-overlay-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--touch-target-min, 44px);
    height: var(--touch-target-min, 44px);
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 16px;
    transition: background 0.12s ease;
    flex-shrink: 0;
}

.cv-overlay-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.cv-overlay-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
}

/* Info boxes no overlay */
.cv-overlay-absence,
.cv-overlay-holiday {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-3);
    font-size: var(--font-size-sm);
}

.cv-overlay-absence {
    background: rgba(107, 114, 128, 0.1);
    color: #6B7280;
}

.cv-overlay-holiday {
    background: rgba(245, 158, 11, 0.1);
    color: #D97706;
}

.cv-overlay-count {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-3);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.cv-overlay-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--color-primary);
    color: #fff;
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: 700;
}

/* Cards de visita */
.cv-visit-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.cv-visit-card {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3);
}

.cv-visit-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.cv-visit-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: var(--color-primary);
    color: #fff;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 700;
    flex-shrink: 0;
}

.cv-visit-name {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text);
    text-transform: uppercase;
}

.cv-visit-field {
    margin-top: var(--space-2);
}

.cv-visit-label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-secondary);
    font-weight: 600;
    margin-bottom: 2px;
}

.cv-visit-text {
    font-size: var(--font-size-xs);
    color: var(--color-text);
    margin: 0;
    line-height: 1.4;
    word-break: break-word;
}

/* Sem visitas */
.cv-no-visits {
    text-align: center;
    padding: var(--space-6) 0;
    color: var(--color-text-secondary);
}

.cv-no-visits i {
    font-size: 36px;
    opacity: 0.3;
    margin-bottom: var(--space-2);
    display: block;
}

.cv-no-visits p {
    margin: 0;
    font-size: var(--font-size-sm);
}

/* --- Responsivo --- */
@media (max-width: 1024px) {
    .cv-month-title {
        font-size: var(--font-size-lg);
        min-width: 180px;
    }

    .cv-th-fixed {
        min-width: 100px;
    }

    .cv-overlay-panel {
        width: 340px;
    }

    .cv-week-summary {
        display: none;
    }
}

@media (max-width: 768px) {
    .cv-month-nav {
        gap: var(--space-2);
    }

    .cv-month-title {
        font-size: var(--font-size-md);
        min-width: 160px;
    }

    .cv-overlay-panel {
        width: 100vw;
        max-width: 100vw;
    }
}
