:root {
    /* Paleta de Cores Nova e Profissional */
    --bg-color: #0b1017;
    --surface-color: #131b26;
    --surface-hover: #1c2738;
    --primary-color: #eab308;
    --primary-hover: #ca8a04;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --danger-color: #ef4444;
    --success-color: #10b981;
    --border-color: #1e293b;
    --radius: 6px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
}

.btn-switch-module {
    background: linear-gradient(90deg, rgba(234, 179, 8, 0.15) 0%, transparent 100%) !important;
    color: #eab308 !important;
    border-left: 4px solid #eab308 !important;
    font-weight: 700 !important;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 13px !important;
    padding: 14px 24px !important;
    margin: 10px 0;
    transition: all 0.2s ease;
}

.btn-switch-module:hover {
    background: linear-gradient(90deg, rgba(234, 179, 8, 0.3) 0%, transparent 100%) !important;
    color: #fef08a !important;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
}

h1,
h2,
h3 {
    color: var(--text-main);
    font-weight: 600;
}

h2 {
    margin-bottom: 20px;
    font-size: 22px;
}

button {
    cursor: pointer;
    border: none;
    outline: none;
    font-weight: 500;
    border-radius: var(--radius);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

input,
select {
    width: 100%;
    padding: 10px 12px;
    margin-top: 6px;
    margin-bottom: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    background-color: #0b1017;
    color: var(--text-main);
    font-size: 14px;
    transition: border-color 0.2s;
}

input:focus,
select:focus {
    border-color: var(--primary-color);
    outline: none;
}

label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Tabelas UI (Clean e Monocromática) */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 14px;
    white-space: nowrap;
    /* Evita que o texto quebre e deforme a tabela no mobile */
}

th,
td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: transparent;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border-color);
}

tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Layout Principal */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

@media (min-width: 768px) {
    .app-container {
        flex-direction: row;
    }
}

.sidebar {
    width: 100%;
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
}

@media (min-width: 768px) {
    .sidebar {
        width: 260px;
        display: flex;
        flex-direction: column;
        height: 100vh;
        /* Fixa a sidebar no desktop */
        position: sticky;
        top: 0;
    }
}

.logo-area {
    padding: 30px 24px;
}

.logo-area h1 {
    font-size: 22px;
    color: var(--primary-color);
    font-weight: 700;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-btn {
    width: 100%;
    padding: 12px 24px;
    background: transparent;
    color: var(--text-muted);
    border-radius: 0;
    border-left: 3px solid transparent;
    justify-content: flex-start;
    font-size: 14px;
}

.nav-btn:hover {
    background-color: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
}

.nav-btn.active {
    background-color: #1a2332;
    border-left-color: var(--primary-color);
    color: var(--primary-color);
    font-weight: 600;
}

.nav-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 16px 24px;
}

.main-content {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    overflow-x: hidden;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.tab-content.active {
    display: block;
}

.card {
    background-color: var(--surface-color);
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Rolagem suave no iOS */
}

/* Estilização da barra de rolagem nas tabelas/cards */
.card::-webkit-scrollbar {
    height: 6px;
}

.card::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

.card::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.card h3 {
    font-size: 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
}

.btn-primary {
    background-color: var(--primary-color);
    color: #000;
    padding: 10px 20px;
    font-weight: 600;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px 20px;
}

.btn-outline:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-danger {
    background-color: transparent;
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--danger-color);
    padding: 6px 12px;
    font-size: 12px;
}

.btn-danger:hover {
    background-color: var(--danger-color);
    color: #fff;
}

.flex {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

@media (min-width: 768px) {
    .grid-2 {
        grid-template-columns: 1fr 1fr;
    }
}

.mt-4 {
    margin-top: 15px;
}

.text-right {
    text-align: right;
}

/* BARRA FIXA DOS BOTÕES DE IMPRESSÃO */
.fixed-bottom-bar {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 100%;
    background-color: var(--bg-color);
    padding: 15px 30px;
    border-top: 1px solid var(--border-color);
    z-index: 100;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
}

@media (min-width: 768px) {
    .fixed-bottom-bar {
        width: calc(100% - 260px);
    }
}

/* MODAL */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--surface-color);
    padding: 30px;
    border-radius: var(--radius);
    width: 95%;
    /* Adaptado para mobile */
    max-width: 400px;
    text-align: center;
    border: 1px solid var(--border-color);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content p {
    margin: 15px 0;
    font-size: 15px;
    color: var(--text-main);
}

.modal-actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    /* Evita quebra de botões no modal */
    gap: 12px;
    margin-top: 24px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =========================================
    NOVO LAYOUT: TABELA DE PREÇOS (PREVIEW)
    ========================================= */
.preview-tabela-wrapper {
    background: white;
    color: black;
    padding: 30px;
    border-radius: var(--radius);
    margin-top: 20px;
    overflow-x: auto;
    font-family: Arial, sans-serif;
}

.tabela-precos-header {
    display: flex;
    align-items: baseline;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    /* Mobile friendly */
}

.tabela-precos-header h1 {
    font-size: 22px;
    font-weight: bold;
    color: black;
    margin: 0;
    text-transform: uppercase;
    font-family: Arial, sans-serif;
}

.tabela-precos-header h2 {
    font-size: 18px;
    font-weight: normal;
    color: black;
    margin: 0;
    font-family: Arial, sans-serif;
}

.tabela-precos-subheader {
    font-size: 14px;
    margin-bottom: 5px;
    color: black;
    font-family: Arial, sans-serif;
}

.tabela-precos-table {
    width: 100%;
    border-collapse: collapse;
}

.tabela-precos-table th {
    font-style: italic;
    font-weight: normal;
    border-bottom: 1.5px solid black;
    padding: 2px 0;
    font-size: 12px;
    color: black;
    text-transform: none;
    background: transparent;
}

.tabela-precos-table .valor-col-th {
    text-align: right;
    padding-right: 15px;
}

.tabela-precos-table td {
    border-bottom: 1.5px solid black;
    padding: 3px 0;
    font-size: 11px;
    color: black;
    font-weight: bold;
    white-space: normal;
    /* Permite quebra na impressão/preview */
}

.tabela-precos-table .produto-col {
    text-transform: uppercase;
    text-align: left;
}

.tabela-precos-table .valor-flex,
.tabela-precos-table .valor-reajuste-flex {
    display: flex;
    justify-content: flex-end;
    gap: 5px;
    padding-right: 15px;
}

/* =========================================
   MASTER RESPONSIVIDADE MOBILE (MENOR QUE 768px)
   ========================================= */
@media (max-width: 767px) {

    /* 1. Menu Lateral vira Menu Superior Rolável (Estilo App) */
    .sidebar {
        position: sticky;
        top: 0;
        z-index: 998;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        background: rgba(19, 27, 38, 0.95);
        backdrop-filter: blur(10px);
    }

    .logo-area {
        padding: 15px 15px 5px 15px;
        text-align: left;
        /* Alinhado à esquerda para não bater no botão */
    }

    .logo-area h1 {
        font-size: 18px;
    }

    .nav-menu {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        padding: 0 15px 10px 15px;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        align-items: center;
    }

    /* Barra de rolagem sutil para indicar o carrossel de botões */
    .nav-menu::-webkit-scrollbar {
        height: 4px;
        display: block;
    }

    .nav-menu::-webkit-scrollbar-track {
        background: transparent;
    }

    .nav-menu::-webkit-scrollbar-thumb {
        background: var(--border-color);
        border-radius: 4px;
    }

    .nav-btn {
        flex: 0 0 auto;
        width: auto !important;
        padding: 8px 16px;
        font-size: 13px;
        border-left: none !important;
        border-bottom: 2px solid transparent;
        justify-content: center;
        border-radius: var(--radius);
        margin-right: 5px;
    }

    .nav-btn.active {
        border-left-color: transparent !important;
        border-bottom-color: var(--primary-color) !important;
        background-color: rgba(234, 179, 8, 0.1) !important;
        color: var(--primary-color) !important;
    }

    .nav-divider {
        width: 1px;
        height: 20px;
        margin: 0 10px;
        flex-shrink: 0;
        background-color: var(--border-color);
    }

    /* Oculta o divisor logo após o botão de trocar módulo para não deixar espaço em branco */
    .nav-menu .nav-divider:nth-child(2) {
        display: none !important;
    }

    /* FIXA O BOTÃO DE TROCA DE MÓDULO NO TOPO DIREITO */
    nav.nav-menu .btn-switch-module {
        position: absolute !important;
        top: 12px !important;
        right: 15px !important;
        width: auto !important;
        padding: 6px 12px !important;
        /* Deixa o botão menor */
        font-size: 11px !important;
        /* Fonte menor */
        border-left: none !important;
        border: 1px solid #eab308 !important;
        background: transparent !important;
        margin: 0 !important;
        border-radius: var(--radius) !important;
        z-index: 1000;
    }

    /* Reduz os ícones de seta/user dentro desse botão para ficarem proporcionais */
    nav.nav-menu .btn-switch-module i,
    nav.nav-menu .btn-switch-module svg {
        width: 14px !important;
        height: 14px !important;
        margin-right: 4px !important;
    }

    /* 2. Ajustes de Espaçamento Principal */
    .main-content {
        padding: 15px;
    }

    .card {
        padding: 15px;
    }

    /* 3. Ajuste nos formulários em linha (Busca e Emissão de Nota) */
    #tab-nota .flex,
    #tab-busca .flex {
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px;
    }

    #tab-nota .flex>div,
    #tab-busca .flex>div {
        width: 100%;
        min-width: 100% !important;
    }

    #tab-nota .flex button,
    #tab-busca .flex button {
        width: 100%;
        height: 48px !important;
        margin-top: 5px;
    }

    input,
    select {
        margin-bottom: 10px;
    }

    /* 4. Barra Fixa Inferior (Emissão de Nota) */
    .fixed-bottom-bar {
        padding: 15px;
        flex-direction: column;
        border-radius: 16px 16px 0 0;
        /* Curva suave estilo app */
    }

    .fixed-bottom-bar button {
        width: 100%;
        margin-bottom: 10px;
    }

    .fixed-bottom-bar button:last-child {
        margin-bottom: 0;
    }

    /* Espaço extra no fim da página para a barra não cobrir conteúdo */
    #tab-nota {
        padding-bottom: 180px;
    }
}

/* =========================================
    LAYOUT DE IMPRESSÃO (NÃO ALTERADO)
    ========================================= */
.print-area {
    display: none;
}

@media print {

    .app-container,
    .modal-overlay {
        display: none !important;
    }

    @page {
        size: portrait;
        margin: 0mm !important;
    }

    body {
        background-color: white !important;
        color: black !important;
        margin: 0 !important;
        padding: 0 !important;
        font-family: 'Arial', sans-serif;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body.printing-nota #print-area-nota {
        display: flex !important;
        flex-direction: row;
        justify-content: space-between;
        width: 297mm !important;
        height: 210mm !important;
        position: absolute;
        top: 0;
        left: 210mm;
        -webkit-transform: rotate(90deg);
        transform: rotate(90deg);
        transform-origin: top left;
        padding: 4mm;
        box-sizing: border-box;
    }

    body.printing-nota #print-area-nota * {
        visibility: visible;
    }

    .print-half {
        width: 49%;
        height: 100%;
        display: flex;
        flex-direction: column;
        padding: 0;
        box-sizing: border-box;
    }

    .print-separator {
        width: 0px;
        border-left: 1px dashed #000;
        margin: 0;
        height: 100%;
    }

    body.printing-tabela #print-area-tabela {
        display: block !important;
        width: 100%;
        padding: 10mm;
        box-sizing: border-box;
    }

    body.printing-tabela #print-area-tabela * {
        visibility: visible;
    }

    .excel-view {
        padding: 0mm;
    }

    .tabela-precos-header {
        margin-bottom: 10px;
        gap: 10px;
    }

    .tabela-precos-header h1 {
        font-size: 18px;
    }

    .tabela-precos-header h2 {
        font-size: 16px;
    }

    .tabela-precos-subheader {
        font-size: 11px;
        margin-bottom: 2px;
    }

    .tabela-precos-table td {
        font-size: 9px;
        padding: 0.5px 0;
        border-bottom: 1px solid #333;
    }

    .tabela-precos-table th {
        font-size: 10px;
        padding: 1px 0;
        border-bottom: 1px solid black;
    }
}