/* --- 1. VARIÁVEIS E BASE (Design Premium) --- */
:root { 
    /* Paleta de Cores Sofisticada */
    --primary: #0f766e; /* Esmeralda profundo */
    --primary-hover: #115e59;
    --accent: #0ea5e9; /* Azul Céu para destaque */
    --bg-app: #f8f9fa; /* Cinza gelo muito suave */
    --surface: #ffffff; 
    --border: #e2e8f0; /* Cinza borda sutil */
    --text-main: #1e293b; /* Ardósia escuro */
    --text-muted: #64748b; 
    --danger: #ef4444; 
    --success: #10b981;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; outline: none; }

body { 
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; 
    background: var(--bg-app); 
    color: var(--text-main); 
    margin: 0; 
    height: 100vh; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
}

/* --- 2. HEADER LUXUOSO --- */
header { 
    background: var(--surface); 
    height: 70px; 
    border-bottom: 1px solid var(--border); 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    padding: 0 20px; 
    flex-shrink: 0; 
    z-index: 40; 
    box-shadow: var(--shadow-sm);
}

.header-left { display: flex; align-items: center; gap: 10px; }
.logo-img { height: 36px; width: auto; object-fit: contain; }
.app-title { font-size: 1.1rem; color: var(--primary); font-weight: 800; letter-spacing: -0.02em; }

.header-right { display: flex; align-items: center; gap: 12px; }

.user-info-box { text-align: right; display: flex; flex-direction: column; justify-content: center; }
.user-name { font-weight: 600; font-size: 0.85rem; color: var(--text-main); }
.user-role { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; margin-top: 2px; }

.user-avatar-container { position: relative; cursor: pointer; }
.user-avatar { 
    width: 40px; height: 40px; border-radius: 50%; 
    object-fit: cover; border: 2px solid var(--surface); 
    box-shadow: 0 0 0 1px var(--border);
}

.btn-logout { 
    background: transparent; border: none; padding: 8px; 
    border-radius: 8px; color: var(--text-muted); cursor: pointer;
}

/* --- 3. BARRA DE CONTROLES --- */
.controls { 
    padding: 10px 20px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    flex-shrink: 0; 
    background: var(--bg-app);
    z-index: 30;
}

.date-nav { display: flex; align-items: center; gap: 15px; width: 100%; justify-content: space-between; max-width: 600px; }
.date-display { font-size: 1.2rem; font-weight: 700; color: var(--text-main); text-align: center; flex: 1; }

.nav-group { display: flex; align-items: center; gap: 8px; background: var(--surface); padding: 4px; border-radius: 10px; border: 1px solid var(--border); }
.nav-btn { 
    background: transparent; border: none; cursor: pointer; font-size: 1.2rem; 
    width: 36px; height: 36px; border-radius: 8px; color: var(--text-muted); 
    display: flex; align-items: center; justify-content: center;
}
.btn-today { 
    background: var(--primary); border: none; padding: 8px 16px; 
    border-radius: 8px; font-weight: 600; cursor: pointer; color: white;
    font-size: 0.9rem;
}

/* --- 4. CALENDÁRIO GRID (CONFIGURAÇÃO DE ROLAGEM) --- */
.calendar-container { 
    flex: 1; 
    overflow: auto; /* Habilita rolagem em ambas direções */
    position: relative; 
    margin: 0; 
    background: var(--bg-app);
    -webkit-overflow-scrolling: touch; /* Rolagem suave no iOS */
}

.calendar-grid { 
    display: grid; 
    /* Desktop: 7 colunas iguais */
    grid-template-columns: repeat(7, 1fr); 
    background: var(--surface);
    border-top: 1px solid var(--border);
}

/* Cabeçalhos Fixos (Dias da Semana) */
.cell-header { 
    text-align: center; padding: 12px 0; 
    font-size: 0.75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; 
    border-bottom: 1px solid var(--border); 
    border-right: 1px solid var(--border); 
    background: #f1f5f9; 
    position: sticky; top: 0; z-index: 20; /* Fixa o topo ao rolar */
}

/* --- LAYOUT DA CÉLULA (DIA) --- */
.cell-slot { 
    border-bottom: 1px solid var(--border); 
    border-right: 1px solid var(--border); 
    /* Altura mínima para caber 5 itens + cabeçalho */
    min-height: 190px; 
    position: relative; 
    display: flex;
    flex-direction: column;
    padding-top: 36px; /* Espaço para o cabeçalho interno */
    padding-bottom: 4px;
    background: white;
    transition: background 0.1s;
}
.cell-slot:hover { background-color: #f8fafc; }
.cell-slot.drag-over { background-color: #f0fdf4; box-shadow: inset 0 0 0 2px var(--primary); }

/* Cabeçalho Flutuante dentro da célula */
.day-cell-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: space-between; /* Separa Data e Botões */
    padding: 0 6px;
    background: rgba(255,255,255,0.9); /* Fundo quase sólido para leitura */
    border-bottom: 1px solid transparent;
    z-index: 10;
}

.day-number {
    font-weight: 700; font-size: 0.9rem; color: var(--text-main);
    width: 26px; height: 26px; line-height: 26px; text-align: center;
}
.day-number.today { background: var(--primary); color: white; border-radius: 50%; }

/* Área dos Botões (Olho e Mais) */
.day-actions { 
    display: flex; 
    align-items: center;
    gap: 16px; /* AFASTAMENTO SOLICITADO */
    padding-right: 4px;
}

.action-btn {
    background: transparent; border: none; cursor: pointer;
    font-size: 1.1rem; /* Ícones maiores */
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}
.action-btn:active { background: #e2e8f0; }

.btn-eye { color: var(--text-muted); }
.btn-add { color: var(--primary); font-weight: 800; font-size: 1.3rem; }

/* Cards de Evento */
.month-event-card { 
    margin: 2px 4px; padding: 4px 6px; 
    border-radius: 4px; 
    font-size: 0.7rem; font-weight: 600; 
    color: white; 
    cursor: grab; 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    z-index: 5;
    line-height: 1.2;
}

/* --- 5. MODAL --- */
.modal-overlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background: rgba(0,0,0,0.5); backdrop-filter: blur(3px);
    z-index: 1000; display: none; align-items: center; justify-content: center;
}

.modal-box { 
    background: var(--surface); width: 90%; max-width: 450px; 
    border-radius: 16px; padding: 24px; 
    box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
    max-height: 90vh; overflow-y: auto;
}

.form-title { font-size: 1.3rem; font-weight: 700; color: var(--text-main); margin-bottom: 20px; }
.form-input { 
    width: 100%; padding: 12px; margin: 8px 0 16px 0;
    border: 1px solid var(--border); border-radius: 8px; font-size: 1rem;
}
.time-row { display: flex; gap: 15px; }
.time-group { flex: 1; }
.label-small { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; display: block; }

.color-options { display: flex; gap: 12px; margin: 20px 0; justify-content: center; flex-wrap: wrap; }
.color-circle { 
    width: 30px; height: 30px; border-radius: 50%; cursor: pointer; 
    border: 2px solid white; box-shadow: 0 0 0 2px var(--border);
}
.color-circle.selected { box-shadow: 0 0 0 2px var(--text-main); transform: scale(1.1); }

.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }
.btn { padding: 12px 20px; border-radius: 8px; border: none; font-weight: 600; cursor: pointer; }
.btn-save { background: var(--primary); color: white; }
.btn-cancel { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-delete { background: #fee2e2; color: var(--danger); margin-right: auto; }

/* Lista Modal */
.day-list-item { display: flex; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.day-list-time { font-weight: 700; color: var(--primary); font-size: 0.85rem; width: 45px; }
.day-list-info { flex: 1; }
.day-list-title { font-weight: 600; font-size: 0.9rem; }
.day-list-resp { font-size: 0.75rem; color: var(--text-muted); }

/* --- 6. MOBILE RESPONSIVO (A CORREÇÃO PRINCIPAL) --- */
@media (max-width: 768px) {
    body { height: 100%; overflow: auto; } /* Garante scroll na página se necessário */
    
    header { padding: 0 16px; }
    .app-title { font-size: 1rem; }
    
    .controls { padding: 10px; }
    .date-display { font-size: 1rem; }

    .calendar-container {
        margin: 0;
        border: none;
        border-radius: 0;
        /* Força altura total restante */
        height: calc(100vh - 130px); 
    }

    .calendar-grid {
        /* A MÁGICA: Define largura mínima por coluna */
        /* 7 colunas x 145px = 1015px de largura total */
        /* Isso força o scroll horizontal e garante células sólidas */
        grid-template-columns: repeat(7, minmax(145px, 1fr));
        
        width: max-content; /* Garante que a grade cresça horizontalmente */
        min-width: 100%;
    }

    /* Ajuste fino para os botões no mobile */
    .day-actions { gap: 20px; } /* Ainda mais afastado no toque */
    .action-btn { width: 32px; height: 32px; font-size: 1.2rem; }
}