/* ====================================================================
   DESIGN SYSTEM & GLOBAL STYLES - SISTEMA COMERCIAL PRO
   Tipografia Premium, Paleta Limpa, Temas Claro / Escuro & Responsivo
   ==================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ====================================================================
   TOKENS DO DESIGN SYSTEM
   ==================================================================== */

:root, [data-theme="dark"] {
    /* Cores de Fundo e Superfície - Tema Escuro (Navy / Deep Slate) */
    --bg-main: #0B1120;
    --bg-surface: #111827;
    --bg-surface-elevated: #1E293B;
    --bg-surface-glass: rgba(17, 24, 39, 0.85);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-subtle: rgba(255, 255, 255, 0.04);
    --border-focus: rgba(37, 99, 235, 0.5);

    /* Textos */
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    --text-inverse: #0F172A;

    /* Sombras */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.55), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px var(--primary-glow);

    /* Gradiente sutil para cartões de destaque */
    --card-bg-gradient: linear-gradient(135deg, var(--bg-surface) 0%, var(--bg-surface-elevated) 100%);
    --topbar-bg: rgba(17, 24, 39, 0.88);
    --input-bg: #1E293B;
    --table-header-bg: #1A2234;
    --table-row-hover: rgba(255, 255, 255, 0.03);

    /* Cores de Destaque - Azul Royal de Alto Padrão */
    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --primary-active: #1E40AF;
    --primary-light: rgba(37, 99, 235, 0.15);
    --primary-glow: rgba(37, 99, 235, 0.25);
    --primary-contrast: #FFFFFF;

    /* Cores de Apoio */
    --secondary: #0284C7;
    --secondary-hover: #0369A1;

    --success: #10B981;
    --success-bg: rgba(16, 185, 129, 0.14);
    --warning: #F59E0B;
    --warning-bg: rgba(245, 158, 11, 0.14);
    --danger: #EF4444;
    --danger-bg: rgba(239, 68, 68, 0.14);
    --info: #3B82F6;
    --info-bg: rgba(59, 130, 246, 0.14);

    /* Tipografia e Raios */
    --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --sidebar-width: 260px;
}

/* ====================================================================
   TEMA CLARO (LIGHT MODE) - Moderno, Limpo, Espaçoso e Agradável
   ==================================================================== */
[data-theme="light"] {
    /* Cores de Fundo e Superfície */
    --bg-main: #F8FAFC;
    --bg-surface: #FFFFFF;
    --bg-surface-elevated: #F1F5F9;
    --bg-surface-glass: rgba(255, 255, 255, 0.9);
    --border-color: #E2E8F0;
    --border-subtle: #F1F5F9;
    --border-focus: rgba(37, 99, 235, 0.45);

    /* Textos com Alto Contraste e Conforto Visual */
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;
    --text-inverse: #F8FAFC;

    /* Sombras Suaves */
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    --shadow-glow: 0 0 20px rgba(37, 99, 235, 0.18);

    --card-bg-gradient: linear-gradient(135deg, #FFFFFF 0%, #F8FAFC 100%);
    --topbar-bg: rgba(255, 255, 255, 0.92);
    --input-bg: #FFFFFF;
    --table-header-bg: #F8FAFC;
    --table-row-hover: #F1F5F9;

    /* Cores de Destaque */
    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --primary-active: #1E40AF;
    --primary-light: #EFF6FF;
    --primary-glow: rgba(37, 99, 235, 0.18);
    --primary-contrast: #FFFFFF;

    --secondary: #0284C7;
    --secondary-hover: #0369A1;

    --success: #059669;
    --success-bg: #ECFDF5;
    --warning: #D97706;
    --warning-bg: #FFFBEB;
    --danger: #DC2626;
    --danger-bg: #FEF2F2;
    --info: #2563EB;
    --info-bg: #EFF6FF;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* Transições suaves para os principais blocos na troca de tema */
.sidebar, .topbar, .card, .modal-box, .form-input, .form-select, .form-textarea, .btn-secondary, .nav-link {
    transition: background-color var(--transition-normal), color var(--transition-normal), border-color var(--transition-normal), box-shadow var(--transition-normal);
}

/* Scrollbar estilizada e elegante */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    opacity: 0.4;
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ====================================================================
   LAYOUT ESTRUTURAL (Sidebar + Topbar + Content)
   ==================================================================== */
.app-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
}

/* Sidebar Fixa no Desktop */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    min-height: 72px;
}

.sidebar-brand-group {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.sidebar-logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #FFF;
    flex-shrink: 0;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.sidebar-logo-text {
    min-width: 0;
}

.sidebar-logo-text h1 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-logo-text p {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Botão Fechar Sidebar no Mobile */
.sidebar-close-btn {
    display: none;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    transition: var(--transition-fast);
}
.sidebar-close-btn:hover {
    color: var(--text-primary);
    border-color: var(--primary);
}

.sidebar-nav {
    flex: 1;
    padding: 14px 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.nav-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    padding: 14px 12px 6px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: var(--transition-fast);
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--primary-light);
}

.nav-link.active {
    color: #FFFFFF;
    background: var(--primary);
    box-shadow: 0 4px 12px var(--primary-glow);
    font-weight: 600;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--bg-surface);
}

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

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    color: var(--primary);
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.user-details {
    min-width: 0;
}

.user-details h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-details p {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Área Principal (Main Wrapper) */
.main-wrapper, .main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
}

/* Topbar Sticky Moderna */
.topbar, .content-header {
    min-height: 64px;
    background: var(--topbar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 28px;
    position: sticky;
    top: 0;
    z-index: 40;
    gap: 14px;
}

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

.topbar-title, .header-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.topbar-title h1, .topbar-title h2, .header-title h1, .header-title h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.topbar-title p, .header-title p {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions, .header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* Botão do Menu Hambúrguer (Mobile) */
.menu-toggle-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    transition: var(--transition-fast);
    flex-shrink: 0;
}
.menu-toggle-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

/* Botão de Alternância de Tema (Claro / Escuro) */
.theme-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    height: 34px;
    border-radius: var(--radius-full);
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}
.theme-toggle-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-light);
}
.theme-toggle-icon {
    font-size: 15px;
    line-height: 1;
}

/* Backdrop Escuro para Drawer Mobile */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 45;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}
.sidebar-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.content-body {
    padding: 24px 28px;
    flex: 1;
    min-width: 0;
}

/* ====================================================================
   UTILITÁRIOS, CARDS E GRIDS
   ==================================================================== */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 22px;
    box-shadow: var(--shadow-sm);
    position: relative;
}

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

.card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.grid-cols-4 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 18px;
}

.grid-cols-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 18px;
}

.grid-cols-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 18px;
}

/* ====================================================================
   BOTÕES MODERNOS
   ==================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    font-size: 13.5px;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition-fast);
    text-decoration: none;
    line-height: 1.2;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--primary);
    color: #FFFFFF;
    box-shadow: 0 2px 8px var(--primary-glow);
}
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 14px var(--primary-glow);
    color: #FFFFFF;
}

.btn-secondary {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    border-color: var(--border-color);
}
.btn-secondary:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-success {
    background: var(--success);
    color: #FFFFFF;
}
.btn-success:hover {
    filter: brightness(1.08);
}

.btn-danger {
    background: var(--danger);
    color: #FFFFFF;
}
.btn-danger:hover {
    filter: brightness(1.08);
}

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

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

/* ====================================================================
   BADGES & STATUS CHIPS
   ==================================================================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    line-height: 1.4;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--bg-surface-elevated); color: var(--text-secondary); }

/* ====================================================================
   INPUTS & FORMULÁRIOS
   ==================================================================== */
.form-group {
    margin-bottom: 16px;
}
.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 9px 13px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13.5px;
    transition: var(--transition-fast);
    outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.form-input::placeholder, .form-textarea::placeholder {
    color: var(--text-muted);
}

/* ====================================================================
   TABELAS RESPONSIVAS & ELEGANTES
   ==================================================================== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    margin-bottom: 16px;
}

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

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

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

tr:last-child td {
    border-bottom: none;
}

tbody tr {
    transition: background-color var(--transition-fast);
}

tbody tr:hover {
    background-color: var(--table-row-hover);
}

/* ====================================================================
   MODAIS
   ==================================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-normal);
    padding: 16px;
}
.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}
.modal-box {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 620px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 26px;
    transform: scale(0.96);
    transition: var(--transition-normal);
    box-shadow: var(--shadow-lg);
}
.modal-overlay.active .modal-box {
    transform: scale(1);
}

/* ====================================================================
   RESPONSIVIDADE (MEDIA QUERIES)
   ==================================================================== */

/* Tablet & Telas Menores (<= 1024px) */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        max-width: 85vw;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: var(--shadow-lg);
    }

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

    .sidebar-close-btn {
        display: inline-flex;
    }

    .main-wrapper, .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .menu-toggle-btn {
        display: inline-flex;
    }

    .topbar, .content-header {
        padding: 12px 18px;
    }

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

    /* Ajuste para PDV em telas médias */
    .pdv-container {
        grid-template-columns: 1fr !important;
        height: auto !important;
    }
}

/* Mobile (<= 768px) */
@media (max-width: 768px) {
    .topbar, .content-header {
        padding: 10px 14px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .topbar-title h1, .topbar-title h2, .header-title h1, .header-title h2 {
        font-size: 16px;
    }

    .topbar-title p, .header-title p {
        display: none; /* Simplifica o cabeçalho no celular para limpar o visual */
    }

    .topbar-actions, .header-actions {
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .theme-toggle-btn .theme-toggle-text {
        display: none; /* Apenas ícone no mobile */
    }
    .theme-toggle-btn {
        padding: 6px 8px;
    }

    .content-body {
        padding: 14px 12px;
    }

    .grid-cols-4, .grid-cols-3, .grid-cols-2 {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .card {
        padding: 16px;
    }

    .modal-box {
        padding: 18px 14px;
        max-height: 94vh;
        border-radius: var(--radius-md);
    }

    /* Botões adaptados no mobile */
    .btn {
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* Mobile Pequeno (<= 480px) */
@media (max-width: 480px) {
    .topbar-actions .btn {
        font-size: 12px;
        padding: 6px 10px;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
}
