/* --- style.css | ESCALA MASTER PRO V7.4 (MOBILE FIXED ULTIMATE) --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --brand-dark: #0f172a; --brand-blue: #3b82f6; --brand-orange: #f97316; --brand-orange-hover: #ea580c;
    --bg-body: #f8fafc; --bg-surface: #ffffff;
    --text-primary: #1e293b; --text-secondary: #64748b; --border: #e2e8f0;
    --sidebar-width: 260px; --sidebar-collapsed-width: 72px; 
    --shadow-card: 0 4px 15px -3px rgba(0,0,0,0.05);
}

body.dark-mode {
    --brand-dark: #020617; --brand-blue: #60a5fa; --brand-orange: #fb923c;
    --bg-body: #0f172a; --bg-surface: #1e293b;
    --text-primary: #f8fafc; --text-secondary: #94a3b8; --border: #334155;
    --shadow-card: 0 4px 15px -3px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; outline: none; -webkit-tap-highlight-color: transparent; }
body { font-family: 'Inter', sans-serif; background-color: var(--bg-body); color: var(--text-primary); margin: 0; padding: 0; height: 100vh; display: flex; overflow: hidden; }

/* SPLASH SCREEN */
#splash-screen { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: var(--brand-dark); z-index: 99999; display: flex; flex-direction: column; justify-content: center; align-items: center; transition: opacity 0.8s ease-out, visibility 0.8s; }
.splash-logo { width: 80px; height: 80px; fill: var(--brand-orange); margin-bottom: 20px; animation: pulse 2s infinite; }
.splash-title { font-size: 2rem; font-weight: 700; color: white; margin-bottom: 5px; }
.splash-subtitle { font-size: 1rem; color: #94a3b8; letter-spacing: 1px; }
.splash-loader { width: 40px; height: 4px; background: rgba(255,255,255,0.2); margin-top: 30px; border-radius: 2px; overflow: hidden; }
.splash-bar { width: 0%; height: 100%; background: var(--brand-orange); animation: load 2s ease-in-out forwards; }
.splash-dev { position: absolute; bottom: 30px; font-size: 0.75rem; color: #64748b; }
@keyframes load { 0% { width: 0%; } 100% { width: 100%; } } @keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.05); } 100% { transform: scale(1); } }

/* SIDEBAR */
.sidebar { width: var(--sidebar-width); background-color: var(--brand-dark); color: white; display: flex; flex-direction: column; padding: 20px 15px; flex-shrink: 0; transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1); z-index: 100; position: relative; box-shadow: 4px 0 24px rgba(0,0,0,0.05); }
.sidebar.collapsed { width: var(--sidebar-collapsed-width); padding: 20px 10px; }
.sidebar.collapsed .logo-text, .sidebar.collapsed .nav-item span, .sidebar.collapsed .sidebar-rights { display: none !important; opacity: 0; }
.sidebar.collapsed .logo-svg { margin: 0 auto; width: 32px; height: 32px; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 14px 0; }
.sidebar.collapsed .sidebar-footer { text-align: center; }
.toggle-desk { position: absolute; top: 25px; right: -14px; width: 28px; height: 28px; background: var(--brand-orange); color: white; border-radius: 0 8px 8px 0; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 14px; z-index: 150; box-shadow: 2px 2px 5px rgba(0,0,0,0.1); transition: background 0.2s; }
.toggle-desk:hover { background: var(--brand-orange-hover); }
.toggle-icon { width: 16px; height: 16px; fill: white; transition: transform 0.3s; }
.sidebar.collapsed .toggle-icon { transform: rotate(180deg); }
.logo-area { display: flex; align-items: center; gap: 12px; margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1px solid rgba(255,255,255,0.1); overflow: hidden; white-space: nowrap; height: 60px; }
.logo-svg { width: 34px; height: 34px; fill: var(--brand-orange); flex-shrink: 0; }
.logo-text h1 { font-size: 1.15rem; margin: 0; font-weight: 700; color: white; letter-spacing: -0.5px; }
.logo-text small { color: #94a3b8; font-size: 0.75rem; }
.nav-menu { display: flex; flex-direction: column; gap: 6px; flex: 1; overflow-y: auto; overflow-x: hidden; }
.nav-item { background: transparent; border: none; color: #94a3b8; text-align: left; padding: 12px 16px; border-radius: 8px; cursor: pointer; font-size: 0.9rem; display: flex; align-items: center; gap: 14px; transition: 0.2s; white-space: nowrap; height: 48px; }
.nav-item svg { width: 22px; height: 22px; stroke: #94a3b8; fill: none; stroke-width: 2; flex-shrink: 0; transition: 0.2s; }
.nav-item:hover { background: rgba(255,255,255,0.05); color: white; }
.nav-item:hover svg { stroke: var(--brand-orange); }
.nav-item.active { background: rgba(249, 115, 22, 0.15); color: white; font-weight: 600; }
.nav-item.active svg { stroke: var(--brand-orange); }
.sidebar-rights { font-size: 0.65rem; color: #64748b; text-align: center; margin-top: 15px; border-top: 1px solid rgba(255,255,255,0.05); padding-top: 10px; }

/* MAIN CONTENT */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; width: 100%; }
.top-header { background: var(--bg-surface); height: 64px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; flex-shrink: 0; }
.menu-toggle-mobile { display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-primary); margin-right: 15px; }
.page-title h2 { font-size: 1.2rem; margin: 0; color: var(--text-primary); font-weight: 700; }
.date-controller { display: flex; gap: 10px; align-items: center; background: var(--bg-body); padding: 5px 10px; border-radius: 8px; border: 1px solid var(--border); }
.date-controller select { background: transparent; border: none; font-weight: 600; color: var(--text-primary); font-size: 0.9rem; cursor: pointer; }
.action-bar { padding: 12px 24px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; background: var(--bg-surface); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.action-group { display: flex; gap: 10px; flex-wrap: wrap; }
.btn { padding: 8px 16px; border-radius: 6px; font-weight: 600; font-size: 0.85rem; cursor: pointer; border: 1px solid transparent; display: flex; align-items: center; gap: 8px; white-space: nowrap; transition: 0.2s; height: 40px; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--brand-orange); color: white; border: 1px solid var(--brand-orange); }
.btn-secondary { background: var(--bg-surface); border: 1px solid var(--border); color: var(--text-primary); }
.btn-secondary:hover { border-color: var(--brand-blue); color: var(--brand-blue); }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1px dashed var(--border); }
.btn-lock { background: #fee2e2 !important; color: #b91c1c !important; border-color: #fecaca !important; } .btn-unlock { background: #dcfce7 !important; color: #15803d !important; border-color: #86efac !important; }

/* --- TABELA (ESTRUTURA FUNDAMENTAL) --- */
.table-container { 
    flex: 1; 
    overflow: hidden; 
    display: flex; flex-direction: column; 
    padding: 20px; 
    background: var(--bg-body); 
}

/* O CARD PRECISA PERMITIR O STICKY */
.card-table { 
    background: var(--bg-surface); 
    border-radius: 12px; 
    box-shadow: var(--shadow-card); 
    border: 1px solid var(--border); 
    /* overflow: hidden;  <-- REMOVIDO PARA EVITAR BUGS DE STICKY NO MOBILE */
    display: flex; flex-direction: column; 
    flex: 1;
    position: relative;
    max-width: 100%;
}

.table-scroll { 
    overflow: auto; 
    flex: 1; 
    /* Truque para iOS scroll suave */
    -webkit-overflow-scrolling: touch; 
    position: relative;
    width: 100%;
}

table { 
    width: max-content; 
    border-collapse: separate; 
    border-spacing: 0; 
    min-width: 100%; 
}

/* CÉLULAS PADRÃO (DIAS) */
th, td { 
    width: 50px !important; min-width: 50px !important; max-width: 50px !important; 
    height: 50px !important; max-height: 50px !important; 
    padding: 0; text-align: center; 
    border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); 
    font-size: 0.9rem; color: var(--text-primary); 
    background: var(--bg-surface); 
}

/* HEADER (DATAS) */
th { 
    background: var(--bg-body); color: var(--text-secondary); 
    font-size: 0.75rem; font-weight: 700; 
    position: -webkit-sticky; position: sticky; 
    top: 0; 
    z-index: 20; 
    border-bottom: 2px solid var(--border); 
}

td { cursor: pointer; user-select: none; } 
td:hover { background-color: rgba(59, 130, 246, 0.05); }

/* --- COLUNA FIXA (PC E MOBILE) --- */
.col-fixed { 
    position: -webkit-sticky !important; /* Safari iOS */
    position: sticky !important;
    left: 0 !important;
    
    width: 260px !important; min-width: 260px !important; max-width: 260px !important;
    text-align: left !important; padding: 0 10px !important; border-right: 2px solid var(--border) !important;
    background: var(--bg-surface) !important; 
    z-index: 15 !important;
    display: flex !important; align-items: center !important; justify-content: space-between !important;
}

thead th:first-child {
    z-index: 30 !important;
    background: var(--bg-body) !important;
    left: 0 !important;
}

.row-actions { display: flex; gap: 4px; opacity: 1 !important; margin-left: auto; }
.btn-row { border: none; background: #f1f5f9; cursor: pointer; padding: 0; width: 28px; height: 28px; border-radius: 4px; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.btn-row svg { width: 16px; height: 16px; stroke-width: 2; fill: none; stroke: currentColor; }
.btn-row.edit { color: var(--text-secondary); } .btn-row.edit:hover { background: #eff6ff; color: var(--brand-blue); }
.btn-row.delete { color: #ef4444; } .btn-row.delete:hover { background: #fef2f2; color: #b91c1c; transform: scale(1.1); }

.badge { font-weight: 800; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.st-F { color: #be185d; background: transparent; } .st-D { color: #b91c1c; background: transparent; } .st-FER { color: #15803d; background: transparent; } .st-LM { color: #7e22ce; background: transparent; } .st-ATEST { color: #c2410c; background: transparent; } 
.is-sun { background: rgba(254, 226, 226, 0.3); } .is-sat { background: rgba(241, 245, 249, 0.5); } body.dark-mode .is-sun { background: rgba(127, 29, 29, 0.2); }
.footer-legend { padding: 12px; background: var(--bg-surface); border-top: 1px solid var(--border); display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; font-size: 0.75rem; color: var(--text-secondary); flex-shrink: 0; }
.legend-dot { font-weight: bold; margin-right: 3px; font-size: 0.8rem; }

/* IMPRESSÃO (QUADRADO 28px) */
.print-header-container, .print-footer-container, .print-credits { display: none; }
@media print {
    @page { size: landscape; margin: 0.5cm; }
    body { background: white; color: black; -webkit-print-color-adjust: exact; print-color-adjust: exact; height: auto; overflow: visible; font-family: sans-serif; }
    .sidebar, .top-header, .action-bar, #smartAlert, .toggle-desk, .menu-toggle-mobile, .row-actions, .btn { display: none !important; }
    .main-content { overflow: visible; height: auto; display: block; }
    .table-container { padding: 0; overflow: visible; height: auto; display: block; border: none; background: white; }
    .card-table { border: none; box-shadow: none; border-radius: 0; overflow: visible; display: block; }
    .table-scroll { overflow: visible; max-height: none; display: block; }
    table { width: 100% !important; border: 1px solid #000; font-size: 9px; border-collapse: collapse; table-layout: fixed; }
    
    /* Reseta sticky para impressão */
    th, td, th:first-child, td:first-child, .col-fixed { position: static !important; overflow: visible !important; }
    
    th, td { border: 1px solid #000; color: black; width: 28px !important; min-width: 28px !important; max-width: 28px !important; height: 28px !important; max-height: 28px !important; padding: 0; font-size: 8px; }
    
    th:first-child, td:first-child, .col-fixed { 
        border-right: 2px solid #000; width: 150px !important; min-width: 150px !important; max-width: 150px !important; 
        background: white !important; color: black !important;
        display: flex !important; align-items: center !important; 
    }
    
    .print-header-container { display: block; text-align: center; margin-bottom: 10px; border-bottom: 2px solid #000; padding-bottom: 5px; }
    .print-title { font-size: 20px; font-weight: bold; text-transform: uppercase; margin: 0; color: #000; }
    .print-subtitle { font-size: 12px; margin-top: 5px; }
    .print-footer-container { display: flex; justify-content: space-between; margin-top: 30px; padding-top: 10px; width: 100%; }
    .print-sig-box { border-top: 1px solid #000; width: 40%; text-align: center; padding-top: 5px; font-size: 11px; }
    .print-credits { display: flex !important; align-items: center; justify-content: center; gap: 10px; text-align: center; width: 100%; font-size: 9px; color: #444; margin-top: 15px; border-top: 1px dotted #ccc; padding-top: 5px; }
    .print-logo-small { width: 14px; height: 14px; fill: #f97316; margin-right: 5px; }
    .st-F, .st-D, .st-FER, .st-LM { color: #000 !important; font-weight: bold; }
    .is-sun, .is-sat { background: #d1d5db !important; }
}

/* MODAIS */
.modal-overlay { background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 2000; align-items: center; justify-content: center; display: none; }
.modal-box { background: var(--bg-surface); border-radius: 16px; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); width: 500px; max-width: 90%; max-height: 85vh; overflow-y: auto; padding: 0; animation: modalIn 0.2s ease-out; color: var(--text-primary); border: 1px solid var(--border); }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 20px; border-bottom: 1px solid var(--border); background: var(--bg-body); }
.modal-header h3 { margin: 0; font-size: 1.1rem; color: var(--text-primary); font-weight: 700; }
.btn-close-modal { background: transparent; border: none; font-size: 1.5rem; line-height: 1; color: var(--text-secondary); cursor: pointer; }
.modal-body { padding: 20px; }
.help-container { display: flex; flex-direction: column; gap: 10px; }
.help-item { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--bg-surface); }
.help-summary { padding: 15px; cursor: pointer; font-weight: 600; display: flex; justify-content: space-between; align-items: center; color: var(--text-primary); }
.help-summary:hover { background: var(--bg-body); }
.help-content { padding: 15px; background: var(--bg-body); border-top: 1px solid var(--border); font-size: 0.9rem; line-height: 1.6; color: var(--text-secondary); }
.help-content strong { color: var(--brand-orange); }
.social-link { color: var(--brand-blue); text-decoration: none; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }

#smartAlert { position: fixed !important; bottom: 25px; right: 25px; background: #ef4444; color: white; padding: 12px 24px; border-radius: 50px; font-weight: 600; font-size: 0.9rem; box-shadow: 0 10px 25px rgba(239, 68, 68, 0.4); cursor: pointer; z-index: 10000; display: none; transition: transform 0.2s; }
#smartAlert:hover { transform: scale(1.05); }
#overlay-mobile { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 90; }
#overlay-mobile.show { display: block; }

/* --- AQUI ESTÁ A CORREÇÃO DE OURO PARA O MOBILE --- */
@media (max-width: 768px) {
    .sidebar { position: fixed; transform: translateX(-100%); width: 280px; height: 100%; box-shadow: 10px 0 30px rgba(0,0,0,0.3); } 
    .sidebar.open { transform: translateX(0); } 
    .toggle-desk { display: none; } 
    .menu-toggle-mobile { display: block; } 
    .action-bar { padding: 10px 15px; gap: 8px; } 
    .btn { padding: 6px 12px; font-size: 0.75rem; } 
    #smartAlert { bottom: 15px; right: 15px; padding: 10px 20px; font-size: 0.8rem; }
    .table-container { padding: 10px 5px; } /* Menos padding no mobile */

    /* FORÇA BRUTA PARA O IPHONE STICKY */
    th:first-child, td:first-child, .col-fixed { 
        position: -webkit-sticky !important; /* Safari exige isso */
        position: sticky !important; 
        left: 0 !important; 
        z-index: 50 !important; /* Prioridade máxima sobre as outras células */
        background: var(--bg-surface) !important;
        border-right: 2px solid var(--border) !important;
        width: 140px !important; min-width: 140px !important; max-width: 140px !important;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1); /* Sombra para destacar */
    }
    
    thead th:first-child {
        z-index: 60 !important; /* Header acima da coluna */
        top: 0 !important;
    }
}

@media screen and (max-height: 500px) and (orientation: landscape) { .sidebar { display: none; } .menu-toggle-mobile { display: block; } .sidebar.open { display: flex; width: 250px; } .top-header { height: 40px; padding: 0 10px; } .action-bar { display: none; } .table-container { padding: 5px; } }