/* --- CSS VARIABLES & DESIGN SYSTEM --- */
:root {
    --primary-color: #F58220; /* Laranja CF */
    --primary-light: #FF9A42; /* Hover/destaque */
    --primary-dark: #D96D10; /* Pressed/ativo */
    --secondary-color: #3C3C3C; /* Charcoal */
    --accent-color: #FFB347; /* Dourado */
    --text-main: #2D2D2D; /* Texto principal */
    --text-muted: #6B6B6B; /* Texto secundário */
    --text-light: #F9FAF9;
    --bg-color: #F8F9F8;
    --surface-color: rgba(255, 255, 255, 0.85);
    --surface-hover: rgba(255, 255, 255, 1);
    --success: #6CB08E;
    --warning: #EDB36F;
    --danger: #E47C7C;
    --info: #79A3D0;
    --font-family: 'Outfit', sans-serif;
    --shadow-sm: 0 4px 15px rgba(0,0,0,0.03);
    --shadow-md: 0 8px 25px rgba(60, 60, 60, 0.08);
    --shadow-glass: inset 0 0 0 1px rgba(255,255,255,0.4), 0 8px 30px rgba(0,0,0,0.05);
    --radius-sm: 12px;
    --radius-md: 20px;
    --radius-lg: 30px;
    --radius-full: 9999px;
    --transition: cubic-bezier(0.2, 0.8, 0.2, 1);
    --primary-gradient: linear-gradient(135deg, #FF9A42 0%, #D96D10 100%);
    --shadow-hover: 0 12px 35px rgba(245, 130, 32, 0.20);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
*:focus-visible { outline: 2px solid var(--primary-dark); outline-offset: 2px; transition: outline-color 0.2s; }
body { font-family: var(--font-family); color: var(--text-main); background-color: var(--bg-color); line-height: 1.5; overscroll-behavior-y: none; overflow: hidden; height: 100vh; height: 100dvh; width: 100vw; }
.app-bg { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; background-image: url('../assets/images/cintura_fina_bg_curves.png'); background-size: cover; background-position: center; background-repeat: no-repeat; opacity: 1; }
.app-container { width: 100%; height: 100%; max-width: 500px; margin: 0 auto; background: transparent; position: relative; display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-md); }
@media (min-width: 501px) and (max-width: 767px) { 
    body { display: flex; align-items: center; justify-content: center; background-color: #EDEDED; } 
    .app-bg { filter: blur(20px); opacity: 0.5; } 
    .app-container { height: 90vh; max-height: 900px; border-radius: var(--radius-lg); background: var(--bg-color); } 
}



.view-container { flex: 1; overflow-y: auto; padding: 24px 20px 100px 20px; animation: fadeInView 0.5s var(--transition) forwards; -ms-overflow-style: none; scrollbar-width: none; }
/* Custom scrollbar for better desktop experience */
@media (max-width: 767px) {
    .view-container::-webkit-scrollbar { display: none; }
}
@media (min-width: 768px) {
    .view-container::-webkit-scrollbar { width: 8px; }
    .view-container::-webkit-scrollbar-track { background: rgba(0,0,0,0.02); border-radius: 10px; }
    .view-container::-webkit-scrollbar-thumb { background: rgba(245, 130, 32, 0.25); border-radius: 10px; transition: background 0.2s; }
    .view-container::-webkit-scrollbar-thumb:hover { background: rgba(245, 130, 32, 0.5); }
}
@keyframes fadeInView { 0% { opacity: 0; } 100% { opacity: 1; } }

h1 { font-size: 28px; font-weight: 600; margin-bottom: 8px; color: var(--text-main); }
h2 { font-size: 20px; font-weight: 600; margin-bottom: 12px; }
h3 { font-size: 16px; font-weight: 500; }
p { font-size: 14px; color: var(--text-muted); }

.card { background: var(--surface-color); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-radius: var(--radius-md); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow-glass); transition: transform 0.3s var(--transition), background 0.3s; }

.card:hover { background: var(--surface-hover); transform: translateY(-4px); box-shadow: var(--shadow-hover); }

.input-group { margin-bottom: 16px; display: flex; flex-direction: column; }
.input-group label { font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text-muted); }
input:not([type="checkbox"]):not([type="radio"]), select { width: 100%; padding: 14px 16px; border-radius: var(--radius-md); border: 1px solid rgba(245, 130, 32, 0.2); background: rgba(255, 255, 255, 0.7); font-family: inherit; font-size: 15px; color: var(--text-main); transition: all 0.3s ease; outline: none; }
input:not([type="checkbox"]):not([type="radio"]):focus, select:focus { border-color: var(--primary-color); background: #fff; box-shadow: 0 0 0 3px rgba(245, 130, 32, 0.15); }

/* Custom Checkboxes */
input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    padding: 0;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 16px; border-radius: var(--radius-md); font-weight: 600; font-size: 15px; font-family: inherit; border: none; cursor: pointer; transition: all 0.3s var(--transition); }

.btn-primary { background: var(--primary-gradient); color: white; box-shadow: 0 6px 15px rgba(245, 130, 32, 0.35); text-shadow: 0 1px 2px rgba(0,0,0,0.1); border: 1px solid rgba(255,255,255,0.1); }
.btn-primary:active, .btn-secondary:active, .btn-outline:active { transform: scale(0.96); box-shadow: 0 2px 8px rgba(245, 130, 32, 0.2); }
.btn-danger { background: rgba(228, 124, 124, 0.15); color: var(--danger); border: 1px solid rgba(228, 124, 124, 0.3); box-shadow: none; }
.btn-danger:hover { background: rgba(228, 124, 124, 0.25); }
.btn-secondary { background: linear-gradient(135deg, var(--accent-color) 0%, var(--secondary-color) 100%); color: white; border: 1px solid rgba(255,255,255,0.1); box-shadow: 0 6px 15px rgba(60, 60, 60, 0.2); }


.btn-outline { background: transparent; border: 1px solid var(--primary-color); color: var(--primary-color); }
.btn-text { background: transparent; color: var(--primary-color); padding: 12px; }

.badge { padding: 4px 10px; border-radius: var(--radius-full); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap; display: inline-block; }
.badge.success { background: rgba(108, 176, 142, 0.15); color: var(--success); }
.badge.warning { background: rgba(237, 179, 111, 0.15); color: var(--warning); }
.badge.danger { background: rgba(228, 124, 124, 0.15); color: var(--danger); }
.badge.info { background: rgba(121, 163, 208, 0.15); color: var(--info); }

.bottom-nav { position: fixed; bottom: 0; left: 0; width: 100%; height: 70px; background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); display: flex; justify-content: space-around; align-items: center; border-top: 1px solid rgba(0,0,0,0.05); padding-bottom: env(safe-area-inset-bottom); z-index: 100; transform: translateY(100%); transition: transform 0.4s var(--transition); }
.bottom-nav.visible { transform: translateY(0); }
.nav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); text-decoration: none; font-size: 11px; font-weight: 500; flex: 1; height: 100%; transition: color 0.3s; cursor: pointer; text-align: center; }
.nav-item span { font-size: 9.5px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; width: 100%; padding: 0 4px; box-sizing: border-box; display: block; }
.nav-item.hidden-role { display: none !important; }
.nav-item ion-icon { font-size: 24px; margin-bottom: 4px; transition: transform 0.3s var(--transition); }
.nav-item.active { color: var(--primary-dark); font-weight: 700; }
.nav-item.active ion-icon { transform: translateY(-3px) scale(1.1); color: var(--primary-dark); }

.view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.user-avatar { width: 44px; height: 44px; border-radius: var(--radius-full); background: var(--secondary-color); display: flex; align-items: center; justify-content: center; color: white; font-weight: 600; font-size: 18px; }

.toast-container { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); width: 90%; max-width: 400px; z-index: 999999; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { background: white; color: var(--text-main); padding: 16px 20px; border-radius: var(--radius-md); box-shadow: 0 10px 30px rgba(0,0,0,0.1); display: flex; align-items: center; gap: 12px; font-size: 14px; font-weight: 500; animation: toastEnter 0.4s var(--transition) forwards; }
.toast ion-icon { font-size: 22px; }
.toast.success ion-icon { color: var(--success); }
.toast.error ion-icon { color: var(--danger); }
.toast.info ion-icon { color: var(--info); }
.toast.fade-out { animation: toastExit 0.4s var(--transition) forwards; }
@keyframes toastEnter { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastExit { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-20px); } }

.text-center { text-align: center; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; } .mb-0 { margin-bottom: 0px !important; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.flex { display: flex; } .flex-column { display: flex; flex-direction: column; } .align-center { align-items: center; } .justify-between { justify-content: space-between; } .hidden { display: none !important; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }


/* ============================================================
   HEADER FIXO (Desktop)
   ============================================================ */
.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 60px;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(245, 130, 32, 0.15);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 200;
    box-shadow: 0 2px 12px rgba(0,0,0,0.05);
}
.app-header-left  { display: flex; align-items: center; gap: 12px; }
.app-header-center { flex: 1; text-align: center; }
.app-header-right { display: flex; align-items: center; gap: 12px; }

.header-logo {
    height: 36px;
    object-fit: contain;
}
.header-page-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: -0.3px;
}
.sidebar-toggle-btn,
.header-refresh-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    width: 40px; height: 40px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: var(--secondary-color);
    font-size: 22px;
    transition: background 0.2s, color 0.2s;
}
.sidebar-toggle-btn:hover,
.header-refresh-btn:hover { background: rgba(245, 130, 32, 0.08); color: var(--primary-color); }
.sidebar-toggle-btn:focus-visible,
.header-refresh-btn:focus-visible { outline: 2px solid var(--primary-dark); }

.header-user-info { display: flex; align-items: center; gap: 8px; cursor: default; }
.header-avatar {
    width: 36px; height: 36px;
    border-radius: var(--radius-full);
    background: var(--primary-gradient);
    display: flex; align-items: center; justify-content: center;
    color: white; font-weight: 700; font-size: 13px;
    box-shadow: 0 2px 8px rgba(245,130,32,0.3);
}
.header-user-name {
    font-size: 13px; font-weight: 500;
    color: var(--text-muted);
    max-width: 120px; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}

/* ============================================================
   BOTÃO MOBILE (apenas mobile — substitui o refresh antigo)
   ============================================================ */
.mobile-refresh-btn {
    position: fixed; top: 12px; right: 12px;
    z-index: 9999;
    background: rgba(255,255,255,0.9);
    border: 1px solid #e5e7eb;
    border-radius: 50%;
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    cursor: pointer;
    backdrop-filter: blur(4px);
}

/* ============================================================
   OVERLAY DA SIDEBAR
   ============================================================ */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 150;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

/* ============================================================
   DESKTOP WRAPPER + SIDEBAR
   ============================================================ */
.desktop-wrapper {
    width: 100%;
    height: 100%;
}

@media (min-width: 768px) {
    /* Ocultar elementos mobile no desktop */
    .hidden-mobile { display: flex !important; }
    .mobile-refresh-btn { display: none !important; }

    body {
        display: flex;
        flex-direction: column;
        background-color: #EDEDED;
        height: 100vh; height: 100dvh;
        overflow: hidden;
        padding: 0;
    }
    .app-bg { filter: blur(20px); opacity: 0.5; }

    /* Wrapper principal: ocupa o espaço abaixo do header */
    .desktop-wrapper {
        display: flex;
        flex-direction: row;
        margin-top: 60px; /* altura do header */
        height: calc(100vh - 60px);
        height: calc(100dvh - 60px);
        overflow: hidden;
    }

    /* ---- SIDEBAR (nav reutilizado) ---- */
    .bottom-nav {
        position: relative !important;
        order: -1;
        width: 240px;
        min-width: 240px;
        height: 100%;
        max-height: none;
        transform: none !important;
        flex-direction: column;
        justify-content: flex-start;
        align-items: flex-start;
        padding: 24px 12px 24px 12px;
        border-radius: 0;
        border-top: none;
        border-right: 1px solid rgba(245, 130, 32, 0.12);
        background: var(--secondary-color);
        box-shadow: 2px 0 20px rgba(0,0,0,0.10);
        overflow-y: auto;
        overflow-x: hidden;
        transition: width 0.3s var(--transition), min-width 0.3s var(--transition), padding 0.3s var(--transition);
        scrollbar-width: none;
    }
    .bottom-nav::-webkit-scrollbar { display: none; }
    .bottom-nav.visible { transform: none !important; }

    /* Sidebar COLAPSADA */
    .bottom-nav.sidebar-collapsed {
        width: 64px;
        min-width: 64px;
        padding: 24px 8px;
    }
    .bottom-nav.sidebar-collapsed .nav-item span,
    .bottom-nav.sidebar-collapsed .subnav-item span,
    .bottom-nav.sidebar-collapsed #reports-subnav { display: none !important; }
    .bottom-nav.sidebar-collapsed .nav-item {
        justify-content: center;
        padding: 14px 8px;
    }
    .bottom-nav.sidebar-collapsed #logout-btn {
        justify-content: center;
        padding: 14px 8px;
    }

    /* Itens do nav no desktop (sidebar) */
    .nav-item {
        flex-direction: row;
        justify-content: flex-start;
        font-size: 14px;
        width: 100%;
        padding: 13px 16px;
        border-radius: 12px;
        margin-bottom: 4px;
        flex: none;
        height: auto;
        color: rgba(255,255,255,0.65);
        transition: background 0.2s, color 0.2s, border-color 0.2s;
        border-left: 3px solid transparent;
        white-space: nowrap;
        overflow: hidden;
    }
    .nav-item span {
        font-size: 14px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: none;
        width: auto;
        padding: 0;
        display: inline;
        text-align: left;
        opacity: 1;
        transition: opacity 0.2s;
    }
    .nav-item:hover {
        background: rgba(255,255,255,0.08);
        color: rgba(255,255,255,0.9);
    }
    .nav-item.active {
        background: rgba(245, 130, 32, 0.18);
        color: var(--primary-light);
        border-left: 3px solid var(--primary-color);
        font-weight: 600;
    }
    .nav-item.active ion-icon { color: var(--primary-color); }
    .nav-item ion-icon {
        font-size: 22px;
        margin-bottom: 0;
        margin-right: 14px;
        min-width: 22px;
        transition: margin 0.3s var(--transition);
    }
    .bottom-nav.sidebar-collapsed .nav-item ion-icon { margin-right: 0; }

    #logout-btn {
        margin-top: auto;
        border-top: 1px solid rgba(255,255,255,0.1);
        border-radius: 0;
        border-left: 3px solid transparent;
        padding-top: 16px;
        color: rgba(255,255,255,0.5);
    }
    #logout-btn:hover { color: var(--danger); background: rgba(228,124,124,0.1); }

    /* Reports Subnav */
    .reports-subnav {
        display: flex; flex-direction: column;
        width: 100%; padding-left: 12px;
        margin-bottom: 4px;
        overflow: hidden;
    }
    .reports-subnav.hidden { display: none !important; }
    .subnav-item {
        display: flex; align-items: center; gap: 10px;
        padding: 9px 16px;
        border-radius: 10px;
        font-size: 13px; font-weight: 500;
        color: rgba(255,255,255,0.5);
        text-decoration: none; cursor: pointer;
        transition: background 0.2s, color 0.2s;
        white-space: nowrap; overflow: hidden;
    }
    .subnav-item ion-icon { font-size: 17px; min-width: 17px; }
    .subnav-item:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.8); }
    .subnav-item.active { background: rgba(245,130,32,0.15); color: var(--primary-light); font-weight: 600; }

    /* ---- APP CONTAINER (área de conteúdo) ---- */
    .app-container {
        flex: 1;
        height: 100%;
        max-width: none;
        margin: 0;
        border-radius: 0;
        background: var(--bg-color);
        box-shadow: none;
        overflow: hidden;
    }
    .view-container { padding: 32px 40px; }
    .grid-2 { gap: 24px; }
}

/* Configurações de layout no mobile */
@media (max-width: 767px) {
    .sidebar-overlay { display: none !important; }
    .reports-subnav { display: none !important; }
    .sidebar-toggle-btn { display: none !important; }
    .header-user-name { display: none !important; }
    .app-header { padding: 0 16px; }
    .header-logo { height: 28px; }
}

/* Espaçamento para o cabeçalho fixo apenas no mobile real */
@media (max-width: 500px) {
    .desktop-wrapper { margin-top: 60px; height: calc(100vh - 60px); height: calc(100dvh - 60px); }
}



/* Modal Bounce Animations */
@keyframes bounceInModal {
    0% { opacity: 0; transform: translateY(-30px) scale(0.95); }
    70% { opacity: 1; transform: translateY(5px) scale(1.02); }
    100% { opacity: 1; transform: none; }
}

@keyframes bounceOutModal {
    0% { opacity: 1; transform: none; }
    100% { opacity: 0; transform: translateY(-30px) scale(0.95); }
}

.animate-modal-pop {
    animation: bounceInModal 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.25) forwards;
}

.animate-modal-pop-out {
    animation: bounceOutModal 0.25s ease-in forwards;
}

/* UI Turmas Pills */
.turma-pill {
    padding: 8px 14px; margin: 4px; border: 1px solid rgba(245, 130, 32, 0.3);
    border-radius: 20px; font-size: 13px; font-weight: 500; color: var(--text-main);
    cursor: pointer; background: white; transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1); user-select: none;
    display: inline-block;
}
.turma-pill:hover { background: rgba(245, 130, 32, 0.06); transform: translateY(-2px); }
.turma-pill.active {
    background: var(--primary-gradient); color: white;
    border-color: transparent; box-shadow: 0 4px 10px rgba(245, 130, 32, 0.3);
}

/* Special layout for schedule view to allow sticky headers inside table */
.view-container.schedule-view-mode {
    display: flex;
    flex-direction: column;
    overflow-y: hidden !important;
    padding-bottom: 0 !important;
}
@media (max-width: 767px) {
    .view-container.schedule-view-mode {
        padding-bottom: 70px !important; /* reserve space for bottom nav */
    }
}


/* Modal Context Protection */
.app-container:has(.modal-overlay:not(.hidden)) {
    z-index: 10000;
}

/* Hide reports subnav on mobile */
@media (max-width: 767px) {
    .reports-subnav {
        display: none !important;
    }
}

/* ============================================================
   LOADING OVERLAY GLOBAL — Salvando...
   ============================================================ */
#cf-save-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    animation: cfLoadFadeIn 0.2s ease-out;
}

#cf-save-loading-overlay.hidden {
    display: none;
}

.cf-save-loading-box {
    background: rgba(30, 30, 30, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 28px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.cf-save-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.15);
    border-top: 4px solid #7c3aed;
    border-radius: 50%;
    animation: cfSpinRotate 0.8s linear infinite;
}

.cf-save-loading-text {
    color: #e5e5e5;
    font-size: 15px;
    font-weight: 500;
    letter-spacing: 0.3px;
}

@keyframes cfSpinRotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes cfLoadFadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}
