/* ERP — azul, branco, cinza */
:root {
    --erp-blue: #1e4f8c;
    --erp-blue-dark: #153a66;
    --erp-gray-50: #f4f6f9;
    --erp-gray-100: #e9eef4;
    --erp-accent: #0d6efd;
}

html {
    scroll-behavior: smooth;
}

body.erp-body {
    min-height: 100vh;
    background: var(--erp-gray-50);
}

.navbar-erp {
    background: linear-gradient(135deg, var(--erp-blue) 0%, var(--erp-blue-dark) 100%);
}

.brand-icon {
    width: 2.25rem;
    height: 2.25rem;
    background: rgba(255, 255, 255, 0.15);
}

.brand-logo {
    height: 40px;
    width: auto;
    display: block;
    object-fit: contain;
}

@media (max-width: 576px) {
    .brand-logo { height: 32px; }
}

/* Login — sem barra de rolagem / sem “bounce” ao arrastar no celular */
html.auth-page {
    height: 100%;
    height: -webkit-fill-available;
    overflow: hidden;
    overscroll-behavior: none;
}

body.auth-body {
    margin: 0;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
    touch-action: manipulation;
    background: var(--erp-gray-50);
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
}

/* Gradiente fora do fluxo flex — não empurra o card para baixo */
body.auth-body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    background: linear-gradient(160deg, #e8f0fb 0%, #f4f6f9 45%, #dfe8f3 100%);
    pointer-events: none;
}

.auth-wrap {
    position: relative;
    z-index: 1;
}

/* Centraliza o card no meio da tela (vertical e horizontal) */
.auth-main {
    flex: 0 1 auto;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.auth-card {
    border-radius: 1rem;
    box-shadow: 0 0.75rem 2rem rgba(30, 79, 140, 0.12) !important;
}

.auth-logo {
    width: 4rem;
    height: 4rem;
    background: linear-gradient(135deg, var(--erp-blue) 0%, var(--erp-accent) 100%);
    box-shadow: 0 0.35rem 1rem rgba(13, 110, 253, 0.35);
}

/* Logo login: proporção natural, limitada só pela largura do card (responsivo) */
.auth-logo-img {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: min(320px, calc(100vw - 2.5rem));
    margin-left: auto;
    margin-right: auto;
}

.auth-logo-img__pic {
    width: auto;
    max-width: 100%;
    height: auto;
    object-fit: contain;
    object-position: center;
    /* Altura máxima só para logos muito altas; não força achatamento horizontal */
    max-height: min(160px, 35vh);
}

@media (min-width: 576px) {
    .auth-logo-img {
        max-width: min(340px, 100%);
    }

    .auth-logo-img__pic {
        max-height: min(180px, 32vh);
    }
}

/* Tabela ERP */
.table-erp thead th {
    background: var(--erp-gray-100);
    color: #495057;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid #dee2e6;
    white-space: nowrap;
}

.table-erp tbody td {
    font-size: 0.925rem;
    vertical-align: middle;
}

.badge-stock-ok {
    background-color: #198754;
}

.badge-stock-low {
    background-color: #dc3545;
}

.text-qty-ok {
    color: #198754;
    font-weight: 600;
}

.text-qty-low {
    color: #dc3545;
    font-weight: 600;
}

/* Loading overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    background: rgba(30, 79, 140, 0.35);
    backdrop-filter: blur(1px);
}

.loading-overlay:not(.d-none) {
    display: flex !important;
}

/* Cards — consulta no celular (dashboard) */
.product-card {
    border-radius: 0.75rem;
    border: 1px solid rgba(30, 79, 140, 0.08);
}

.product-card__title {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-card__price {
    color: var(--erp-blue-dark);
    letter-spacing: -0.02em;
}

.product-card__code-num {
    background: var(--erp-gray-100);
    padding: 0.15rem 0.45rem;
    border-radius: 0.35rem;
}

/* Mobile: toque abre modal de detalhes */
.product-card--clickable {
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(30, 79, 140, 0.12);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.product-card--clickable:active {
    transform: scale(0.992);
}

@media (hover: hover) and (pointer: fine) {
    .product-card--clickable:hover {
        box-shadow: 0 0.35rem 1rem rgba(30, 79, 140, 0.12) !important;
    }
}

.product-card__hint {
    font-size: 0.7rem;
    letter-spacing: 0.02em;
}

.whatsapp-template-preview {
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 14rem;
    overflow: auto;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.45;
}

/* Etiquetas (PC) */
.labels-sheet-wrap {
    background: #fff;
    border: 1px solid rgba(30, 79, 140, 0.12);
    border-radius: 0.75rem;
    padding: 0.75rem;
    overflow: auto;
    max-height: 72vh;
}

/* folha A4 aproximada para preview (sem travar impressão) */
.labels-sheet {
    /* Etiqueta 40x25mm (largura x altura) */
    --label-w: 40mm;
    --label-h: 25mm;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--label-w), var(--label-w)));
    gap: 2mm;
    align-content: start;
    justify-content: start;
    padding: 2mm;
    background: #fff;
}

.label-item {
    width: var(--label-w);
    height: var(--label-h);
    border: 1px dashed rgba(0, 0, 0, 0.2);
    border-radius: 2mm;
    padding: 1.2mm;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: 1fr;
    /* 1) Logo + nome (2 linhas), 2) EAN, 3) código interno */
    /* Altura útil = 25mm - 2.4mm (padding) = 22.6mm */
    grid-template-rows: 7.0mm 12.8mm 2.8mm;
    overflow: hidden;
}

.label-logo {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
    display: flex;
    align-items: center;
    gap: 1mm;
    min-height: 5mm;
    overflow: hidden;
}

.label-logo img {
    height: 5.2mm;
    width: auto;
    object-fit: contain;
    display: block;
}

.label-title {
    font-size: 2.5mm;
    line-height: 1.12;
    font-weight: 700;
    color: #111;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.label-barcode {
    grid-column: 1 / 2;
    grid-row: 2 / 3;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.label-barcode svg {
    width: 100%;
    height: 8.6mm;
    display: block;
}

.label-code-text {
    grid-column: 1 / 2;
    grid-row: 3 / 4;
    font-size: 2.35mm;
    line-height: 1.05;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #000;
    text-align: center;
}

@media print {
    body.erp-body {
        background: #fff !important;
    }
    nav.navbar,
    .card,
    #productCardsMount,
    #modalQr,
    #modalProductDetail,
    #modalLabels .modal-header,
    #modalLabels .col-lg-4 {
        display: none !important;
    }
    #modalLabels {
        position: static !important;
    }
    #modalLabels .modal-dialog,
    #modalLabels .modal-content,
    #modalLabels .modal-body,
    .labels-sheet-wrap {
        all: unset;
    }
    #labelsSheet.labels-sheet {
        gap: 2mm;
        padding: 0;
    }
    .label-item {
        border: none;
    }
}

@media (max-width: 575.98px) {
    .table-erp thead th:nth-child(4),
    .table-erp tbody td:nth-child(4) {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* Leitor QR (html5-qrcode) */
.qr-reader-wrap {
    width: 100%;
    min-height: 260px;
    background: #0d1117;
}

#qr-reader {
    width: 100%;
    min-height: 260px;
}

/* Vídeo da câmera visível e responsivo dentro do modal */
#qr-reader video {
    width: 100% !important;
    max-height: 55vh;
    object-fit: cover;
    border-radius: 0.375rem;
    display: block !important;
}

/* Painel injetado pelo Html5QrcodeScanner */
#qr-reader .html5-qrcode-element {
    width: 100% !important;
}

/* Evita cortar o vídeo / seletor de câmera dentro do modal Bootstrap */
#modalQr .modal-body {
    overflow: visible;
}
