/**
 * Ademar09-2026 - Mobile First & Desktop Compact Design
 * Otimizado para smartphones em campo e sem barra de rolagem horizontal no desktop
 */

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --primary-border: #bfdbfe;
    
    --secondary: #475569;
    --secondary-light: #f1f5f9;
    
    --success: #10b981;
    --success-hover: #059669;
    --success-light: #ecfdf5;
    
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    
    --danger: #ef4444;
    --danger-light: #fef2f2;
    
    --purple: #8b5cf6;
    --purple-light: #f5f3ff;
    
    --info: #0284c7;
    --info-light: #f0f9ff;
    
    --dark: #0f172a;
    --sidebar-bg: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-active: #ffffff;
    
    --bg-main: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-muted: #64748b;
    
    --sidebar-width: 250px;
    --sidebar-width-collapsed: 68px;
    --header-height: 56px;
    --bottom-nav-height: 60px;
    
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    
    --shadow-subtle: 0 1px 3px 0 rgb(0 0 0 / 0.06), 0 1px 2px -1px rgb(0 0 0 / 0.04);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.06);
    --shadow-lg: 0 10px 25px -5px rgb(0 0 0 / 0.15);
    
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   RESET & PREVENÇÃO DE OVERFLOW HORIZONTAL GLOBAL
   ========================================================================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important; /* Nunca abre barra horizontal no rodapé do navegador */
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

/* Prevenção de overflow em elementos flex/grid */
img, svg, video, canvas, audio, iframe {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ==========================================================================
   LAYOUT PRINCIPAL (MOBILE FIRST)
   ========================================================================== */
.app-wrapper {
    display: flex;
    width: 100%;
    max-width: 100vw;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Main Wrapper Mobile First */
.main-wrapper {
    flex: 1;
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-bottom: calc(var(--bottom-nav-height) + 16px); /* Espaço para a barra inferior no celular */
    transition: margin-left 0.25s ease;
    overflow-x: hidden;
}

/* Topbar Compacta */
.topbar {
    height: var(--header-height);
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    position: sticky;
    top: 0;
    z-index: 800;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.btn-toggle-sidebar {
    background: transparent;
    border: none;
    color: var(--secondary);
    font-size: 1.25rem;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: var(--transition);
}

.btn-toggle-sidebar:active {
    background-color: var(--secondary-light);
}

.page-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Área de Conteúdo */
.content-area {
    padding: 12px;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    flex: 1;
}

/* ==========================================================================
   SIDEBAR & DRAWER MOBILE
   ========================================================================== */
.sidebar {
    width: 280px;
    max-width: 82vw;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.25);
    overflow-y: auto;
}

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

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(3px);
    z-index: 1040;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
}

body.mobile-sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    gap: 12px;
    text-decoration: none;
    color: #fff;
}

.brand-icon {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 17px;
    flex-shrink: 0;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.brand-text span {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: -0.3px;
    color: #fff;
}

.brand-text small {
    font-size: 0.68rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-menu {
    list-style: none;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
}

.menu-category {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #64748b;
    padding: 10px 12px 4px;
    font-weight: 700;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
    transition: var(--transition);
}

.sidebar-menu a i {
    width: 22px;
    font-size: 1.1rem;
    text-align: center;
}

.sidebar-menu a:hover, .sidebar-menu a:active {
    background-color: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar-menu a.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

/* Destaque Amarelo do Menu Parceiros */
.menu-category-parceiros {
    color: #facc15 !important;
    font-weight: 800 !important;
    letter-spacing: 1px !important;
}

.sidebar-menu a.menu-parceiro {
    color: #fef08a !important;
    font-weight: 600 !important;
}

.sidebar-menu a.menu-parceiro i {
    color: #facc15 !important;
}

.sidebar-menu a.menu-parceiro span {
    color: #fef08a !important;
}

.sidebar-menu a.menu-parceiro:hover {
    background-color: rgba(250, 204, 21, 0.15) !important;
    color: #ffffff !important;
}

.sidebar-menu a.menu-parceiro:hover span,
.sidebar-menu a.menu-parceiro:hover i {
    color: #ffffff !important;
}

.sidebar-menu a.menu-parceiro.active {
    background: #eab308 !important;
    color: #0f172a !important;
    box-shadow: 0 4px 12px rgba(234, 179, 8, 0.45) !important;
}

.sidebar-menu a.menu-parceiro.active span,
.sidebar-menu a.menu-parceiro.active i {
    color: #0f172a !important;
    font-weight: 800 !important;
}

.sidebar-footer {
    padding: 12px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.15);
}

.user-avatar {
    width: 34px;
    height: 34px;
    background-color: #334155;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.user-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.7rem;
    color: #94a3b8;
}

/* ==========================================================================
   BARRA DE NAVEGAÇÃO INFERIOR PARA CELULARES (BOTTOM NAV BAR)
   ========================================================================== */
.bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background-color: #ffffff;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    z-index: 950;
    justify-content: space-around;
    align-items: center;
    padding: 0 4px;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 600;
    gap: 3px;
    transition: var(--transition);
    user-select: none;
}

.bottom-nav-item i {
    font-size: 1.15rem;
}

.bottom-nav-item.active {
    color: var(--primary);
}

.bottom-nav-item.highlight {
    color: #ffffff;
}

.bottom-nav-item.highlight .nav-circle-btn {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--primary), #1d4ed8);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.25rem;
    margin-top: -16px;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.45);
    border: 3px solid #ffffff;
}

/* ==========================================================================
   CARDS DE KPI COMPACTOS (MOBILE FIRST)
   ========================================================================== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 colunas no celular para caber na tela */
    gap: 8px;
    margin-bottom: 14px;
    width: 100%;
}

.kpi-card {
    background: var(--card-bg);
    padding: 12px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-subtle);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 84px;
    position: relative;
    overflow: hidden;
}

.kpi-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    margin-bottom: 6px;
}

.kpi-icon.blue { background-color: var(--primary-light); color: var(--primary); }
.kpi-icon.green { background-color: var(--success-light); color: var(--success); }
.kpi-icon.yellow { background-color: var(--warning-light); color: #d97706; }
.kpi-icon.red { background-color: var(--danger-light); color: var(--danger); }
.kpi-icon.purple { background-color: var(--purple-light); color: var(--purple); }
.kpi-icon.cyan { background-color: var(--info-light); color: var(--info); }

.kpi-title {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    line-height: 1.2;
}

.kpi-value {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--dark);
    line-height: 1.2;
    margin-top: 2px;
}

.kpi-subtext {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==========================================================================
   CARDS DE MÉTRICAS (MÓDULO PARCEIROS & RELATÓRIOS)
   ========================================================================== */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
    width: 100%;
}

.metric-card {
    background: var(--card-bg, #ffffff);
    padding: 16px 18px;
    border-radius: var(--radius-sm, 8px);
    box-shadow: var(--shadow-subtle, 0 1px 3px rgba(0, 0, 0, 0.08));
    border: 1px solid var(--border-color, #e2e8f0);
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.metric-icon {
    width: 46px;
    height: 46px;
    border-radius: var(--radius-sm, 8px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.metric-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.metric-value {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--dark, #0f172a);
    line-height: 1.2;
}

.metric-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted, #64748b);
    margin-top: 3px;
    line-height: 1.3;
}

/* ==========================================================================
   CARDS & TABELAS COMPACTAS
   ========================================================================== */
.card {
    background-color: var(--card-bg);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-subtle);
    border: 1px solid var(--border-color);
    margin-bottom: 14px;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.card-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    background-color: #ffffff;
}

.card-title {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--dark);
    display: flex;
    align-items: center;
    gap: 6px;
}

.card-body {
    padding: 14px;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* CONTAINER RESPONSIVO DE TABELA (SCROLL LIMITADO À TABELA, NUNCA NO BODY) */
.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0;
    padding: 0;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    text-align: left;
    white-space: nowrap;
}

.table th {
    background-color: #f8fafc;
    color: var(--secondary);
    font-weight: 600;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

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

.table tbody tr:hover {
    background-color: #f8fafc;
}

/* ==========================================================================
   BADGES & BOTÕES MOBILE FRIENDLY
   ========================================================================== */
.badge {
    display: inline-block;
    padding: 3px 8px;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 999px;
    text-align: center;
    white-space: nowrap;
    line-height: 1.2;
}

.badge-primary { background-color: var(--primary-light); color: var(--primary); }
.badge-success { background-color: var(--success-light); color: #047857; }
.badge-warning { background-color: var(--warning-light); color: #b45309; }
.badge-danger { background-color: var(--danger-light); color: #b91c1c; }
.badge-info { background-color: var(--info-light); color: #0369a1; }
.badge-purple { background-color: var(--purple-light); color: #6d28d9; }
.badge-cyan { background-color: #e0f2fe; color: #0369a1; }
.badge-secondary { background-color: #f1f5f9; color: #475569; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 8px 14px;
    min-height: 38px; /* Touch target amigável */
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-success { background-color: var(--success); color: #fff; }
.btn-success:hover { background-color: var(--success-hover); }

.btn-warning { background-color: var(--warning); color: #fff; }
.btn-danger { background-color: var(--danger); color: #fff; }

.btn-secondary { background-color: #f1f5f9; color: var(--text-primary); border-color: var(--border-color); }
.btn-secondary:hover { background-color: #e2e8f0; }

.btn-outline-primary {
    background-color: transparent;
    border-color: var(--primary);
    color: var(--primary);
}

.btn-sm {
    padding: 5px 9px;
    min-height: 30px;
    font-size: 0.75rem;
}

/* ==========================================================================
   FORMULÁRIOS OTIMIZADOS PARA CELULAR
   ========================================================================== */
.form-group {
    margin-bottom: 12px;
    width: 100%;
}

.form-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.form-control, .form-select {
    width: 100%;
    padding: 8px 12px;
    font-size: 15px; /* Evita auto zoom chato no iOS */
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: #fff;
    color: var(--text-primary);
    outline: none;
    min-height: 40px;
    transition: var(--transition);
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.form-col {
    width: 100%;
    min-width: 0;
}

/* MODAIS FORMATO BOTTOM SHEET NO MOBILE */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    z-index: 1200;
    display: flex;
    align-items: flex-end; /* Abre embaixo no mobile */
    justify-content: center;
    padding: 0;
}

.modal-sheet {
    background: #ffffff;
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
    padding: 20px 16px 24px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ==========================================================================
   DESKTOP: AJUSTE PARA TELA COMPLETA SEM BARRA DE ROLAGEM NO RODAPÉ
   ========================================================================== */
@media (min-width: 992px) {
    /* Esconde barra de navegação móvel no desktop */
    .bottom-nav {
        display: none !important;
    }

    /* Retira o padding do fundo no desktop */
    .main-wrapper {
        margin-left: var(--sidebar-width);
        padding-bottom: 20px;
    }

    body.sidebar-collapsed .main-wrapper {
        margin-left: var(--sidebar-width-collapsed);
    }

    /* Sidebar fixa no desktop */
    .sidebar {
        width: var(--sidebar-width);
        max-width: var(--sidebar-width);
        transform: translateX(0) !important;
        box-shadow: 1px 0 6px rgba(0, 0, 0, 0.08);
    }

    /* Estado Recolhido Desktop */
    body.sidebar-collapsed .sidebar {
        width: var(--sidebar-width-collapsed);
        max-width: var(--sidebar-width-collapsed);
    }

    body.sidebar-collapsed .brand-logo-full {
        display: none !important;
    }

    body.sidebar-collapsed .brand-logo-collapsed {
        display: block !important;
    }

    body.sidebar-collapsed .brand-text,
    body.sidebar-collapsed .menu-category,
    body.sidebar-collapsed .sidebar-menu span,
    body.sidebar-collapsed .user-info {
        display: none !important;
    }

    body.sidebar-collapsed .sidebar-brand {
        justify-content: center;
        padding: 0;
    }

    body.sidebar-collapsed .sidebar-menu a {
        justify-content: center;
        padding: 10px 0;
    }

    body.sidebar-collapsed .sidebar-footer {
        justify-content: center;
        padding: 10px 0;
    }

    /* Topbar no Desktop */
    .topbar {
        padding: 0 20px;
    }

    .content-area {
        padding: 18px 20px;
    }

    /* KPIs no Desktop: 4 colunas distribuídas perfeitamente */
    .kpi-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 14px;
        margin-bottom: 18px;
    }

    .kpi-card {
        flex-direction: row;
        align-items: center;
        gap: 14px;
        padding: 14px 16px;
    }

    .kpi-icon {
        width: 44px;
        height: 44px;
        font-size: 1.35rem;
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .kpi-value {
        font-size: 1.35rem;
    }

    /* Formulários Desktop em Linha */
    .form-row {
        flex-direction: row;
        align-items: flex-end;
    }

    .form-col {
        flex: 1;
    }

    /* Modais Centralizados no Desktop */
    .modal-overlay {
        align-items: center;
        padding: 20px;
    }

    .modal-sheet {
        border-radius: var(--radius-md);
        max-width: 540px;
        padding: 24px;
        animation: none;
    }
}

/* ==========================================================================
   TELAS GRANDES (FULL HD 1080p / WIDESCREEN)
   ========================================================================== */
@media (min-width: 1400px) {
    .content-area {
        padding: 20px 24px;
    }
}

/* ==========================================================================
   TELA DE LOGIN
   ========================================================================== */
.login-page {
    min-height: 100vh;
    width: 100vw;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    padding: 20px;
    box-sizing: border-box;
}

.login-card {
    background: #ffffff;
    width: 100%;
    max-width: 440px;
    border-radius: var(--radius-md);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
    padding: 32px 28px;
    box-sizing: border-box;
}

@media print {
    .sidebar, .topbar, .bottom-nav, .btn, .no-print {
        display: none !important;
    }
    .main-wrapper {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    .content-area {
        padding: 0 !important;
    }
    .card {
        border: none !important;
        box-shadow: none !important;
    }
}

