/* static/css/layout.css */

:root {
    --sidebar-width: 260px;
    --header-height: 70px;
    --sb-bg: #1e293b; 
    --sb-hover: rgba(255, 255, 255, 0.08);
    --sb-active: rgba(13, 110, 253, 0.15);
    --sb-active-text: #60a5fa;
    --sb-border: 1px solid rgba(255, 255, 255, 0.05);
    --bg-body: #f1f5f9;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    /* Correção para altura dinâmica mobile (iPhone) */
    height: 100%;
    min-height: 100dvh; 
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
}

/* --- ESTRUTURA PRINCIPAL --- */
.app-container {
    display: flex;
    min-height: 100dvh;
}

.main-content {
    flex: 1;
    margin-left: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    background-color: var(--bg-body);
    transition: all 0.3s ease;
    position: relative;
}

/* --- SIDEBAR (CORRIGIDO PARA IPHONE) --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sb-bg);
    /* 100dvh resolve a barra de endereço do iOS */
    height: 100%;
    height: 100dvh; 
    position: fixed;
    top: 0;
    left: 0;
    color: white;
    display: flex;
    flex-direction: column;
    z-index: 2000; 
    box-shadow: 4px 0 15px rgba(0,0,0,0.2);
    transform: translateX(-100%); 
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: var(--sb-border);
    overflow: hidden; 
}

.sidebar.sidebar-open {
    transform: translateX(0);
}

.sidebar-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); 
    z-index: 1999; 
    display: none; 
    backdrop-filter: blur(3px); 
}
.sidebar-overlay.show { display: block; }

/* ANIMAÇÃO DE SYNC */
@keyframes spin-sync {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
.spin-animation {
    animation: spin-sync 1s linear infinite;
}

/* BOTÃO DE FECHAR (MOBILE) */
.mobile-close-btn {
    display: none;
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    z-index: 2001;
    transition: background 0.2s;
}
.mobile-close-btn:active { background: rgba(255,255,255,0.2); }

/* --- CONTEÚDO MENU --- */
.nav-menu {
    flex: 1; 
    overflow-y: auto; 
    overflow-x: hidden; 
    padding: 20px 15px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.nav-menu::-webkit-scrollbar { width: 4px; }
.nav-menu::-webkit-scrollbar-track { background: transparent; }
.nav-menu::-webkit-scrollbar-thumb { background-color: rgba(255,255,255,0.1); border-radius: 4px; }

.nav-item { display: flex; align-items: center; gap: 12px; padding: 12px 15px; color: #94a3b8; text-decoration: none; border-radius: 10px; margin-bottom: 5px; transition: all 0.2s ease; font-size: 14px; font-weight: 500; white-space: nowrap; }
.nav-item:hover { background-color: var(--sb-hover); color: white; transform: translateX(3px); }
.nav-item.active { background-color: var(--sb-active); color: var(--sb-active-text); font-weight: 600; }
.nav-item .material-icons { font-size: 20px; }

.app-header { height: var(--header-height); background: #1e293b; color: white; display: flex; align-items: center; justify-content: flex-start; padding: 0 20px; position: sticky; top: 0; z-index: 900; box-shadow: 0 4px 10px rgba(0,0,0,0.1); width: 100%; box-sizing: border-box; }
.header-title { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: 0.5px; }
.btn-toggle-menu { background: none; border: none; color: white; cursor: pointer; padding: 8px; border-radius: 8px; display: flex; align-items: center; justify-content: center; margin-right: 15px; transition: background 0.2s; }

/* Correção para não cortar no iPhone: safe-area-inset-bottom */
.user-profile { 
    padding: 20px; 
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 10px));
    border-top: 1px solid rgba(255,255,255,0.1); 
    background: rgba(0,0,0,0.1); 
    flex-shrink: 0; 
}
#sidebar-user-name { font-size: 14px; font-weight: 600; color: white; }
#sidebar-user-role { font-size: 11px; font-weight: 400; color: #94a3b8; }
.sidebar-status-box { margin: 0 15px 20px 15px; font-size: 12px; flex-shrink: 0; }

/* ==========================================================================
   NOVO LOADER GLOBAL ELEGANTE (Centralizado)
   ========================================================================== */
.elegant-loader-overlay {
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background: rgba(15, 23, 42, 0.85); 
    z-index: 99999; 
    display: none; /* Ativado via JS com flex */
    align-items: center; 
    justify-content: center; 
    flex-direction: column; 
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.elegant-spinner {
    width: 50px; 
    height: 50px; 
    border: 4px solid rgba(255, 255, 255, 0.2); 
    border-top-color: #3b82f6; 
    border-radius: 50%; 
    animation: spin 1s linear infinite;
}

.elegant-loader-title {
    color: white; 
    margin-top: 20px; 
    font-weight: 600; 
    font-size: 18px;
    margin-bottom: 0;
}

.elegant-loader-desc {
    color: #cbd5e1; 
    margin-top: 5px; 
    font-size: 14px; 
    text-align: center; 
    padding: 0 20px;
    line-height: 1.4;
}

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

/* Spinner moderno (Mantido para compatibilidade com Modal Sync) */
.modern-spinner { width: 40px; height: 40px; border: 4px solid #e2e8f0; border-top: 4px solid #0d6efd; border-radius: 50%; animation: spin 0.8s linear infinite; }

/* --- TOAST --- */
.modern-toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-20px); background: white; padding: 12px 25px; border-radius: 50px; box-shadow: 0 10px 30px rgba(0,0,0,0.15); display: flex; align-items: center; gap: 15px; z-index: 11000; opacity: 0; visibility: hidden; transition: all 0.4s; }
.modern-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); visibility: visible; }
.toast-icon { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; }
.toast-success .toast-icon { background: #10b981; }
.toast-error .toast-icon { background: #ef4444; }
.toast-content h4 { margin: 0; font-size: 14px; font-weight: 700; color: #1e293b; }
.toast-content p { margin: 0; font-size: 12px; color: #64748b; }

.logout-modal-content {
    background-color: #ffffff; 
    padding: 25px;
    border-radius: 16px;
    text-align: center;
    width: 90%;
    max-width: 320px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25); 
    position: relative;
    z-index: 10001; 
}

@media (max-width: 768px) {
    .main-content { margin-left: 0; width: 100%; }
    .sidebar { width: 100%; }
    .mobile-close-btn { display: flex; }
}

/* --- MODAL DE SINCRONIZAÇÃO MODERNO --- */
.sync-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.7); 
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.sync-overlay.visible { opacity: 1; visibility: visible; }

.sync-card {
    background: white;
    width: 90%;
    max-width: 320px;
    border-radius: 24px;
    padding: 30px 25px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: scale(0.9);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.sync-overlay.visible .sync-card { transform: scale(1); }

.sync-icon-wrapper {
    width: 72px; height: 72px; border-radius: 50%;
    margin: 0 auto 20px; display: flex; align-items: center; justify-content: center; font-size: 32px;
}

.sync-success-bg { background: #dcfce7; color: #16a34a; box-shadow: 0 0 0 8px #f0fdf4; }
.sync-error-bg { background: #fee2e2; color: #dc2626; box-shadow: 0 0 0 8px #fef2f2; }

.sync-title { font-size: 20px; font-weight: 800; color: #1e293b; margin: 0 0 5px 0; }
.sync-subtitle { font-size: 13px; color: #64748b; margin: 0 0 25px 0; }

.sync-stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 25px; }
.sync-stat-item { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 12px; display: flex; flex-direction: column; align-items: center; }
.stat-icon-sm { font-size: 18px; margin-bottom: 5px; }
.stat-val { font-size: 18px; font-weight: 800; color: #0f172a; }
.stat-desc { font-size: 11px; color: #64748b; font-weight: 600; text-transform: uppercase; }

.btn-sync-close { width: 100%; padding: 14px; border-radius: 12px; border: none; font-size: 15px; font-weight: 700; cursor: pointer; transition: transform 0.1s; }
.btn-sync-close.success { background: #16a34a; color: white; box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3); }
.btn-sync-close.error { background: #1e293b; color: white; }
.btn-sync-close:active { transform: scale(0.96); }

/* --- NOVO BOTÃO: LIMPAR DADOS --- */
.btn-sync-clear {
    width: 100%; padding: 12px; background: transparent; border: 1px solid #fecaca; color: #dc2626;
    border-radius: 12px; font-size: 12px; font-weight: 700; cursor: pointer; display: flex;
    align-items: center; justify-content: center; gap: 6px; transition: background 0.2s;
}
.btn-sync-clear:hover { background: #fef2f2; }
.btn-sync-clear:active { background: #fee2e2; transform: scale(0.98); }

/* --- NOVOS ESTILOS PARA CONFIRMAÇÃO --- */
.modal-actions-row { display: flex; gap: 10px; margin-top: 15px; }
.btn-modal-cancel { flex: 1; padding: 12px; background: transparent; border: 1px solid #cbd5e1; color: #64748b; border-radius: 12px; font-weight: 600; cursor: pointer; }
.btn-modal-confirm { flex: 1; padding: 12px; background: #dc2626; border: none; color: white; border-radius: 12px; font-weight: 700; cursor: pointer; box-shadow: 0 4px 10px rgba(220, 38, 38, 0.3); }
.btn-modal-cancel:active, .btn-modal-confirm:active { transform: scale(0.96); }