/**
 * erp_style.css - Design System Gestão Integrada Júnior
 * Inspirado no Unleashed ERP / Layout Compras Oliveira
 * Suporte a Tema Claro (Padrão) e Tema Escuro Dinâmico
 */

:root {
    /* TEMA CLARO */
    --erp-bg-base: #f4f6f8;
    --erp-bg-surface: #ffffff;
    --erp-bg-card: #ffffff;
    --erp-bg-sidebar: #ffffff;
    --erp-border: #e5e7eb;
    --erp-border-light: #f1f5f9;
    
    --erp-text-main: #0f172a;
    --erp-text-muted: #475569;
    --erp-text-dim: #94a3b8;
    
    /* Cores Corporativas & Negócios */
    --erp-primary: #007d8a;
    --erp-primary-hover: #00636d;
    --erp-primary-light: #e0f7f6;
    --erp-teal: #48b0a8;
    
    /* Identidade Café & Salão */
    --cafe-primary: #b45309;
    --cafe-light: #fef3c7;
    --cafe-badge: #d97706;
    --salao-primary: #8b5cf6;
    --salao-light: #f3e8ff;
    --salao-badge: #7c3aed;
    
    /* Paleta de Status */
    --erp-emerald: #10b981;
    --erp-emerald-light: #d1fae5;
    --erp-amber: #f59e0b;
    --erp-amber-light: #fef3c7;
    --erp-rose: #ef4444;
    --erp-rose-light: #fee2e2;
    --erp-blue: #2563eb;
    --erp-blue-light: #dbeafe;
    --erp-cyan: #0284c7;
    
    /* Sidebar */
    --sidebar-active-bg: #e0f7f6;
    --sidebar-active-border: #48b0a8;
    --sidebar-active-text: #007d8a;
    --sidebar-hover-bg: #f8fafc;
    --sidebar-hover-text: #0f172a;
    
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.02);
    --card-hover-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

body.dark-theme {
    /* TEMA ESCURO */
    --erp-bg-base: #080d1a;
    --erp-bg-surface: #0e1526;
    --erp-bg-card: #121c32;
    --erp-bg-sidebar: #0e1526;
    --erp-border: #1e293b;
    --erp-border-light: #162035;
    
    --erp-text-main: #f8fafc;
    --erp-text-muted: #94a3b8;
    --erp-text-dim: #64748b;
    
    --erp-primary: #38bdf8;
    --erp-primary-hover: #0284c7;
    --erp-primary-light: rgba(56, 189, 248, 0.15);
    --erp-teal: #2dd4bf;
    
    --cafe-primary: #fbbf24;
    --cafe-light: rgba(251, 191, 36, 0.15);
    --salao-primary: #c084fc;
    --salao-light: rgba(192, 132, 252, 0.15);
    
    --erp-emerald: #34d399;
    --erp-emerald-light: rgba(52, 211, 153, 0.15);
    --erp-amber: #fbbf24;
    --erp-amber-light: rgba(251, 191, 36, 0.15);
    --erp-rose: #f87171;
    --erp-rose-light: rgba(248, 113, 113, 0.15);
    --erp-blue: #60a5fa;
    --erp-blue-light: rgba(96, 165, 250, 0.15);
    
    --sidebar-active-bg: rgba(56, 189, 248, 0.15);
    --sidebar-active-border: #38bdf8;
    --sidebar-active-text: #38bdf8;
    --sidebar-hover-bg: #162035;
    --sidebar-hover-text: #f8fafc;
    
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    --card-hover-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

/* RESET E BASE */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--erp-bg-base);
    color: var(--erp-text-main);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    transition: background-color 0.25s ease, color 0.25s ease;
}

/* ESTRUTURA PRINCIPAL */
.erp-layout, .erp-container {
    display: flex;
    width: 100%;
    min-height: 100vh;
    position: relative;
}

.desktop-only { display: flex !important; }
.mobile-only { display: none !important; }
.mobile-menu-btn { display: none !important; }

/* BACKDROP OVERLAY PARA MOBILE */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 198;
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}

.sidebar-backdrop.show {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

/* SIDEBAR */
.erp-sidebar {
    width: 250px;
    background: var(--erp-bg-sidebar);
    border-right: 1px solid var(--erp-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 90;
    transition: width 0.25s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.25s;
}

.erp-sidebar.collapsed {
    width: 72px;
}

.sidebar-top {
    height: 64px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--erp-border);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #007d8a, #48b0a8);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(0, 125, 138, 0.3);
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    transition: opacity 0.2s;
}

.sidebar-brand-text strong {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 15px;
    font-weight: 700;
    color: var(--erp-text-main);
    letter-spacing: -0.3px;
}

.sidebar-brand-text span {
    font-size: 11px;
    color: var(--erp-text-muted);
    font-weight: 500;
}

.erp-sidebar.collapsed .sidebar-brand-text {
    display: none;
}

.sidebar-collapse-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--erp-border);
    background: var(--erp-bg-surface);
    color: var(--erp-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.sidebar-collapse-btn:hover {
    background: var(--erp-primary-light);
    color: var(--erp-primary);
}

.erp-sidebar.collapsed .sidebar-collapse-btn i {
    transform: rotate(180deg);
}

/* SIDEBAR NAV */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* SEÇÕES RETRÁTEIS DO MENU LATERAL */
.nav-section {
    display: flex;
    flex-direction: column;
    margin-bottom: 6px;
}

.nav-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: transparent;
    border: none;
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 8px;
    user-select: none;
    transition: background 0.18s ease, color 0.18s ease;
}

.nav-section-header:hover {
    background: rgba(0, 0, 0, 0.04);
}

body.dark-theme .nav-section-header:hover {
    background: rgba(255, 255, 255, 0.04);
}

.nav-section-title {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--erp-text-dim);
    white-space: nowrap;
    overflow: hidden;
    transition: color 0.18s ease;
}

.nav-section-header:hover .nav-section-title {
    color: var(--erp-text-main);
}

.nav-section-arrow {
    font-size: 10px;
    color: var(--erp-text-dim);
    transform: rotate(0deg);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), color 0.18s ease;
}

.nav-section-header:hover .nav-section-arrow {
    color: var(--erp-text-main);
}

/* Itens de submenu com transição suave */
.nav-section-items {
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow: hidden;
    max-height: 400px;
    opacity: 1;
    transform: translateY(0);
    transition: max-height 0.28s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.22s ease, 
                transform 0.22s ease,
                margin 0.22s ease;
    margin-top: 2px;
}

/* Estado Recolhido (Retrátil) */
.nav-section.collapsed .nav-section-items {
    max-height: 0;
    opacity: 0;
    transform: translateY(-4px);
    margin-top: 0;
    pointer-events: none;
}

.nav-section.collapsed .nav-section-arrow {
    transform: rotate(-90deg);
}

/* Quando a sidebar inteira estiver minimizada (modo ícones apenas) */
.erp-sidebar.collapsed .nav-section-header {
    display: none;
}

.erp-sidebar.collapsed .nav-section-items {
    max-height: none !important;
    opacity: 1 !important;
    transform: none !important;
    pointer-events: auto !important;
    margin-top: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 9px;
    text-decoration: none;
    color: var(--erp-text-muted);
    font-size: 13.5px;
    font-weight: 500;
    transition: all 0.18s;
    white-space: nowrap;
    position: relative;
}

.nav-item i.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.nav-item:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-hover-text);
}

.nav-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
    border-left: 3px solid var(--sidebar-active-border);
}

.nav-item .nav-badge {
    margin-left: auto;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--erp-border);
    color: var(--erp-text-muted);
}

.erp-sidebar.collapsed .nav-item span,
.erp-sidebar.collapsed .nav-item .nav-badge {
    display: none;
}

.sidebar-user {
    padding: 14px;
    border-top: 1px solid var(--erp-border);
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--erp-bg-surface);
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0284c7, #38bdf8);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.sidebar-user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-user-info strong {
    font-size: 13px;
    color: var(--erp-text-main);
}

.sidebar-user-info span {
    font-size: 11px;
    color: var(--erp-text-muted);
}

.erp-sidebar.collapsed .sidebar-user-info {
    display: none;
}

/* ÁREA DE CONTEÚDO */
.erp-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    overflow-y: auto;
}

/* TOPBAR */
.erp-topbar {
    height: 64px;
    background: var(--erp-bg-surface);
    border-bottom: 1px solid var(--erp-border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 80;
    backdrop-filter: blur(8px);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--erp-text-main);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* SELETOR DE UNIDADE / NEGÓCIO */
.unit-switcher {
    display: inline-flex;
    background: var(--erp-bg-base);
    border: 1px solid var(--erp-border);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}

.unit-btn {
    border: none;
    background: transparent;
    padding: 6px 14px;
    border-radius: 7px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--erp-text-muted);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.unit-btn:hover {
    color: var(--erp-text-main);
}

.unit-btn.active {
    background: var(--erp-bg-surface);
    color: var(--erp-primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.unit-btn.active.unit-cafe {
    color: var(--cafe-primary);
}

.unit-btn.active.unit-salao {
    color: var(--salao-primary);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--erp-border);
    background: var(--erp-bg-surface);
    color: var(--erp-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--erp-bg-base);
    color: var(--erp-text-main);
}

.theme-toggle-btn {
    color: var(--erp-amber);
}

/* PÍLULA DE USUÁRIO / TOPBAR RIGHT */
.user-pill-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 14px 4px 5px;
    background: var(--erp-primary-light);
    border: 1px solid rgba(0, 125, 138, 0.2);
    border-radius: 999px;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

body.dark-theme .user-pill-btn {
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.25);
}

.user-pill-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.user-pill-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--erp-primary), var(--erp-teal));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.user-pill-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--erp-text-main);
    white-space: nowrap;
}

.user-pill-role {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 2px 7px;
    border-radius: 6px;
    background: rgba(0, 125, 138, 0.15);
    color: var(--erp-primary);
}

body.dark-theme .user-pill-role {
    background: rgba(56, 189, 248, 0.2);
    color: var(--erp-primary);
}

.btn-logout {
    color: var(--erp-rose);
}

.btn-logout:hover {
    background: var(--erp-rose-light);
    color: var(--erp-rose);
    border-color: rgba(239, 68, 68, 0.3);
}

/* CONTEÚDO PRINCIPAL */
.erp-content {
    flex: 1;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* CARDS DE KPI / MÉTRICAS */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.kpi-card {
    background: var(--erp-bg-card);
    border: 1px solid var(--erp-border);
    border-radius: 14px;
    padding: 20px;
    box-shadow: var(--card-shadow);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

.kpi-card:hover {
    box-shadow: var(--card-hover-shadow);
    transform: translateY(-2px);
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--kpi-color, var(--erp-primary));
}

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.kpi-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--erp-text-muted);
}

.kpi-icon-box {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: var(--kpi-bg, var(--erp-primary-light));
    color: var(--kpi-color, var(--erp-primary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
}

.kpi-value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 24px;
    font-weight: 700;
    color: var(--erp-text-main);
    letter-spacing: -0.5px;
}

.kpi-footer {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--erp-text-dim);
}

.kpi-trend {
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.kpi-trend.positive { color: var(--erp-emerald); }
.kpi-trend.negative { color: var(--erp-rose); }

/* GRID DE CARDS DO HUB (MENU PRINCIPAL) */
.portal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.portal-card {
    background: var(--erp-bg-card);
    border: 1px solid var(--erp-border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--card-shadow);
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

.portal-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--card-hover-shadow);
    border-color: var(--card-accent, var(--erp-primary));
}

.portal-card-top {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}

.portal-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--card-icon-bg, var(--erp-primary-light));
    color: var(--card-icon-color, var(--erp-primary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.portal-card-titles h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 17px;
    font-weight: 700;
    color: var(--erp-text-main);
    margin-bottom: 4px;
}

.portal-card-titles p {
    font-size: 13px;
    color: var(--erp-text-muted);
    line-height: 1.45;
}

.portal-card-features {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 16px 0 20px;
    border-top: 1px solid var(--erp-border-light);
    padding-top: 14px;
}

.portal-card-features li {
    font-size: 12.5px;
    color: var(--erp-text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.portal-card-features li i {
    font-size: 11px;
    color: var(--card-accent, var(--erp-primary));
}

.portal-card-btn {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--erp-bg-base);
    color: var(--erp-text-main);
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s;
}

.portal-card:hover .portal-card-btn {
    background: var(--card-accent, var(--erp-primary));
    color: #fff;
}

/* TABELAS */
.table-card {
    background: var(--erp-bg-card);
    border: 1px solid var(--erp-border);
    border-radius: 14px;
    box-shadow: var(--card-shadow);
    overflow: hidden;
}

.table-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--erp-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.table-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: var(--erp-text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

table.erp-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: left;
}

table.erp-table th {
    background: var(--erp-bg-base);
    color: var(--erp-text-muted);
    font-weight: 600;
    padding: 12px 16px;
    border-bottom: 1px solid var(--erp-border);
    white-space: nowrap;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
}

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

table.erp-table tbody tr:hover {
    background: var(--sidebar-hover-bg);
}

/* BADGES */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-cafe {
    background: var(--cafe-light);
    color: var(--cafe-primary);
}

.badge-salao {
    background: var(--salao-light);
    color: var(--salao-primary);
}

.badge-cf {
    background: var(--erp-blue-light);
    color: var(--erp-blue);
}

.badge-cv {
    background: var(--erp-amber-light);
    color: var(--erp-amber);
}

.badge-success {
    background: var(--erp-emerald-light);
    color: var(--erp-emerald);
}

.badge-danger {
    background: var(--erp-rose-light);
    color: var(--erp-rose);
}

/* FORMULÁRIOS & BOTÕES */
.form-control, .form-select {
    width: 100%;
    padding: 9px 13px;
    border: 1px solid var(--erp-border);
    border-radius: 8px;
    background: var(--erp-bg-surface);
    color: var(--erp-text-main);
    font-size: 13.5px;
    font-family: inherit;
    transition: all 0.2s;
}

.form-control:focus, .form-select:focus {
    outline: none;
    border-color: var(--erp-primary);
    box-shadow: 0 0 0 3px var(--erp-primary-light);
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    background: var(--erp-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: var(--erp-primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    background: var(--erp-bg-base);
    color: var(--erp-text-main);
    border: 1px solid var(--erp-border);
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--erp-border);
}

/* MODAL */
.modal-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-backdrop.show {
    display: flex;
}

.modal-box {
    background: var(--erp-bg-card);
    border: 1px solid var(--erp-border);
    border-radius: 16px;
    width: 100%;
    max-width: 620px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    overflow: hidden;
    animation: modalSlide 0.2s ease-out;
}

@keyframes modalSlide {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--erp-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--erp-text-muted);
    font-size: 18px;
    cursor: pointer;
}

.modal-body {
    padding: 24px;
    max-height: 75vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--erp-border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    background: var(--erp-bg-base);
}

/* ==============================================================
   RESPONSIVIDADE & MOBILE FIRST (Smartphones e Tablets)
   ============================================================== */

/* CLASSE UTILITÁRIA PARA GRIDS DE GRÁFICOS */
.ops-comparative-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(460px, 1fr));
    gap: 20px;
}

/* TABLETS E SMARTPHONES (<= 992px) */
@media (max-width: 992px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: flex !important; }
    .mobile-menu-btn { display: flex !important; }

    /* LAYOUT GERAL */
    .erp-layout, .erp-container {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    .erp-main {
        width: 100%;
        max-width: 100vw;
        min-width: 0;
    }

    /* SIDEBAR EM FORMATO DRAWER SLIDE-IN */
    .erp-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 290px;
        max-width: 86vw;
        height: 100vh;
        z-index: 200;
        transform: translateX(-105%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s;
        box-shadow: none;
    }

    .erp-sidebar.open-mobile {
        transform: translateX(0);
        box-shadow: 10px 0 40px rgba(0, 0, 0, 0.35);
    }

    .erp-sidebar.collapsed {
        width: 290px;
    }

    .erp-sidebar.collapsed .sidebar-brand-text,
    .erp-sidebar.collapsed .sidebar-nav-label,
    .erp-sidebar.collapsed .nav-item span,
    .erp-sidebar.collapsed .nav-item .nav-badge,
    .erp-sidebar.collapsed .sidebar-user-info {
        display: flex !important;
    }

    .sidebar-close-btn {
        width: 32px;
        height: 32px;
        border-radius: 8px;
        border: 1px solid var(--erp-border);
        background: var(--erp-bg-surface);
        color: var(--erp-text-muted);
        align-items: center;
        justify-content: center;
        cursor: pointer;
        font-size: 15px;
        transition: all 0.2s;
    }

    .sidebar-close-btn:hover {
        background: var(--erp-rose-light);
        color: var(--erp-rose);
    }

    /* TOPBAR RESPONSIVA */
    .erp-topbar {
        height: auto;
        min-height: 58px;
        padding: 8px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .topbar-left {
        gap: 10px;
        flex: 1;
        min-width: 0;
    }

    .topbar-title {
        font-size: 15px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .topbar-title-text {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 150px;
    }

    .topbar-right {
        gap: 6px;
        flex-shrink: 0;
    }

    /* PÍLULA DE USUÁRIO COMPACTA NO MOBILE */
    .user-pill-btn {
        padding: 3px !important;
        gap: 0 !important;
        background: transparent !important;
        border-color: transparent !important;
    }

    .user-pill-name,
    .user-pill-role {
        display: none !important;
    }

    .user-pill-avatar {
        width: 32px !important;
        height: 32px !important;
        font-size: 13px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }

    /* SELETOR DE UNIDADES NO MOBILE */
    .unit-switcher {
        width: 100%;
        order: 3;
        display: flex;
        justify-content: space-between;
        margin-top: 4px;
        padding: 2px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .unit-btn {
        flex: 1;
        justify-content: center;
        padding: 6px 8px;
        font-size: 11.5px;
        white-space: nowrap;
    }

    /* ÁREA DE CONTEÚDO */
    .erp-content {
        padding: 14px 12px;
        gap: 16px;
    }

    /* GRIDS DO SISTEMA */
    .portal-grid {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }

    .insights-grid {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }

    .ops-comparative-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    .profile-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    .form-row-2 {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* KPI GRID */
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .kpi-card {
        padding: 14px 12px;
    }

    .kpi-value {
        font-size: 19px;
    }

    .kpi-label {
        font-size: 10.5px;
    }

    .kpi-icon-box {
        width: 30px;
        height: 30px;
        font-size: 13px;
    }

    /* BANNERS */
    .welcome-banner {
        padding: 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .welcome-text h2 {
        font-size: 18px;
    }

    .quick-badges {
        width: 100%;
    }

    .quick-tag {
        flex: 1;
        justify-content: center;
        font-size: 11px;
        padding: 6px 8px;
    }

    /* TABELAS RESPONSIVAS */
    .table-responsive {
        border-radius: 8px;
        box-shadow: inset 0 0 0 1px var(--erp-border);
    }

    table.erp-table th, table.erp-table td {
        padding: 8px 10px;
        font-size: 12px;
    }

    /* MODAL RESPONSIVO */
    .modal-box {
        width: 95% !important;
        max-width: 95% !important;
        margin: 10px;
        max-height: 90vh;
    }

    .modal-header {
        padding: 14px 16px;
    }

    .modal-body {
        padding: 16px;
    }

    .modal-footer {
        padding: 12px 16px;
        flex-wrap: wrap;
    }
}

/* SMARTPHONES PEQUENOS (<= 480px) */
@media (max-width: 480px) {
    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .topbar-title-text {
        max-width: 110px;
    }

    .unit-btn-text {
        font-size: 11px;
    }

    .btn-submit, .btn-primary, .btn-secondary {
        width: 100%;
        justify-content: center;
    }
}
