/**
 * Estilos Globais - Distrilentes
 */

/* Reset e Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    line-height: var(--line-height-normal);
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    overflow-x: hidden;
}

/* Scrollbar customizada */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--gray-100);
}

::-webkit-scrollbar-thumb {
    background: var(--gray-400);
    border-radius: var(--border-radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-500);
}

/* Links */
a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary-dark);
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-tight);
    margin-bottom: var(--spacing-md);
}

h1 { font-size: var(--font-size-4xl); }
h2 { font-size: var(--font-size-3xl); }
h3 { font-size: var(--font-size-2xl); }
h4 { font-size: var(--font-size-xl); }
h5 { font-size: var(--font-size-lg); }
h6 { font-size: var(--font-size-md); }

/* Container */
.container {
    width: 100%;
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: 0 var(--spacing-lg);
}

/* Layout Principal */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding-top: var(--topbar-height);
    transition: margin-left var(--transition-normal);
}

.main-content.sidebar-collapsed {
    margin-left: var(--sidebar-collapsed-width);
}

.content-wrapper {
    padding: var(--spacing-xl);
}

/* Utilitários de Texto */
.text-xs { font-size: var(--font-size-xs); }
.text-sm { font-size: var(--font-size-sm); }
.text-md { font-size: var(--font-size-md); }
.text-lg { font-size: var(--font-size-lg); }
.text-xl { font-size: var(--font-size-xl); }

.text-light { font-weight: var(--font-weight-light); }
.text-normal { font-weight: var(--font-weight-normal); }
.text-medium { font-weight: var(--font-weight-medium); }
.text-semibold { font-weight: var(--font-weight-semibold); }
.text-bold { font-weight: var(--font-weight-bold); }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success-color); }
.text-warning { color: var(--warning-color); }
.text-error { color: var(--error-color); }
.text-info { color: var(--info-color); }

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

/* Utilitários de Espaçamento */
.mt-xs { margin-top: var(--spacing-xs); }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mt-xl { margin-top: var(--spacing-xl); }

.mb-xs { margin-bottom: var(--spacing-xs); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }
.mb-xl { margin-bottom: var(--spacing-xl); }

.p-xs { padding: var(--spacing-xs); }
.p-sm { padding: var(--spacing-sm); }
.p-md { padding: var(--spacing-md); }
.p-lg { padding: var(--spacing-lg); }
.p-xl { padding: var(--spacing-xl); }

/* Grid System */
.grid {
    display: grid;
    gap: var(--spacing-lg);
}

.grid-cols-1 { grid-template-columns: repeat(1, 1fr); }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

/* Flexbox */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-xs { gap: var(--spacing-xs); }
.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }
.gap-lg { gap: var(--spacing-lg); }

/* Cards */
.card {
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--spacing-lg);
    transition: box-shadow var(--transition-normal);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    margin: 0;
}

.card-body {
    padding: var(--spacing-sm) 0;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: var(--font-weight-medium);
    border-radius: var(--border-radius-full);
    background: var(--gray-200);
    color: var(--text-primary);
}

.badge-success { background: var(--success-color); color: white; }
.badge-warning { background: var(--warning-color); color: white; }
.badge-error { background: var(--error-color); color: white; }
.badge-info { background: var(--info-color); color: white; }
.badge-primary { background: var(--primary-color); color: white; }
.badge-secondary { background: var(--secondary-color); color: white; }

/* ===== Resumo de confirmação =====
   Reaproveitado em qualquer modal que precise mostrar "confira os dados
   antes de confirmar" antes de executar uma movimentação difícil de
   desfazer (ex.: Retirada Manual do Almoxarifado, Saída Manual de
   Fornecedor). Estrutura esperada:
   <div class="confirmacao-resumo">
       <div class="confirmacao-resumo-aviso">...</div>
       <dl class="confirmacao-resumo-lista">
           <div class="confirmacao-resumo-linha"><dt>Label</dt><dd>Valor</dd></div>
           ...
       </dl>
   </div> */
.confirmacao-resumo-aviso {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    margin-bottom: var(--spacing-md);
    border-radius: var(--border-radius-md);
    background: rgba(255, 152, 0, 0.1);
    color: var(--warning-color);
    font-size: var(--font-size-sm);
    font-weight: 500;
}

.confirmacao-resumo-lista {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    overflow: hidden;
}

.confirmacao-resumo-linha {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
}

.confirmacao-resumo-linha:nth-child(even) {
    background: var(--gray-50);
}

.confirmacao-resumo-linha dt {
    color: var(--text-secondary);
    flex-shrink: 0;
}

.confirmacao-resumo-linha dd {
    color: var(--text-primary);
    font-weight: 600;
    text-align: right;
}

.confirmacao-resumo-linha--destaque {
    border-top: 1px dashed var(--border-color);
}

@media (max-width: 480px) {
    .confirmacao-resumo-linha {
        flex-direction: column;
        gap: 2px;
    }

    .confirmacao-resumo-linha dd {
        text-align: left;
    }
}

/* Responsividade */
@media (max-width: 1400px) {
    .content-wrapper {
        padding: var(--spacing-lg);
    }
}

@media (max-width: 1024px) {
    .main-content {
        margin-left: 0;
    }
    
    .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .content-wrapper {
        padding: var(--spacing-md) var(--spacing-lg);
    }
}

@media (max-width: 768px) {
    .content-wrapper {
        padding: var(--spacing-md);
    }
    
    .grid-cols-2,
    .grid-cols-3 {
        grid-template-columns: 1fr;
    }
    
    h1 { font-size: var(--font-size-3xl); }
    h2 { font-size: var(--font-size-2xl); }
    h3 { font-size: var(--font-size-xl); }
}

@media (max-width: 480px) {
    .content-wrapper {
        padding: var(--spacing-sm) var(--spacing-md);
    }
}

/* Loading e Estados */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--gray-200);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.skeleton {
    background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--border-radius-md);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================
   Skeleton genérico de tabela e KPI - usado enquanto uma tabela/KPI espera a
   resposta da API, no lugar do texto solto "Carregando...". Gerado via
   criarSkeletonLinhas()/aplicarSkeletonKpis() em assets/js/main.js. Prefixo "skel-"
   (em vez de "table-skeleton-") de propósito: assets/css/pages/conciliacao.css já
   define .table-skeleton-row/.table-skeleton-cell com outra implementação (flex,
   larguras fixas por coluna) - nomes iguais aqui colidiriam nas páginas que carregam
   os dois arquivos.
   ============================================ */
.skel-row {
    animation: skeletonPulse 1.5s ease-in-out infinite;
}

.skel-bar {
    display: inline-block;
    height: 14px;
    width: 100%;
    max-width: 140px;
    /* --gray-200/--gray-100 (#EEEEEE/#F5F5F5) são claros demais e ficavam
       praticamente invisíveis sobre o fundo branco das tabelas/KPIs - #e5e7eb é o
       mesmo tom já usado (e comprovadamente visível) no skeleton de
       assets/css/pages/conciliacao.css. */
    background: #e5e7eb;
    border-radius: var(--border-radius-sm, 4px);
}

.skel-bar.curta { max-width: 60px; }
.skel-bar.media { max-width: 100px; }
.skel-bar.longa { max-width: 180px; }

@keyframes skeletonPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* KPI em carregamento: mostra uma barrinha no lugar do valor, em vez de piscar "0" e
   depois trocar pelo valor real assim que a resposta chega. Usa a mesma cor/animação de
   .skel-bar (não a classe .skeleton, cujo gradiente --gray-200/--gray-100 é claro demais
   e some sobre o fundo branco dos cards de KPI). */
.kpi-skeleton {
    display: inline-block;
    width: 70px;
    height: 22px;
    vertical-align: middle;
    background: #e5e7eb;
    border-radius: var(--border-radius-sm, 4px);
    animation: skeletonPulse 1.5s ease-in-out infinite;
}

/* Acessibilidade */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus visible */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Loading Spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f4f6;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}


/* Resumo e painel de descrição dos históricos de fornecedores e almoxarifado. */
.movimentacao-descricao {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    width: 100%;
    max-width: 240px;
    max-height: 3em;
    overflow: hidden;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 0.875em;
    line-height: 1.5;
    text-align: left;
    overflow-wrap: anywhere;
    cursor: help;
}
.movimentacao-descricao:hover {
    color: var(--primary-color);
}
.movimentacao-descricao:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 3px;
    border-radius: 3px;
}
.movimentacao-descricao-tooltip {
    position: fixed;
    z-index: 100010;
    box-sizing: border-box;
    width: max-content;
    max-width: min(460px, calc(100vw - 24px));
    max-height: min(360px, calc(100dvh - 24px));
    overflow-y: auto;
    padding: 14px 16px;
    border: 1px solid #334155;
    border-radius: 10px;
    background: #0f172a;
    color: #f8fafc;
    box-shadow: 0 8px 24px #0003;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    user-select: text;
}
.movimentacao-descricao-tooltip[hidden] { display: none; }


/* Busca de produto compartilhada entre cadastros e filtros. */
.produto-busca-controle { position: relative; min-width: 0; width: 100%; }
.produto-busca-controle > select[hidden] { display: none !important; }
.produto-busca-lista {
    position: fixed; z-index: 100020; box-sizing: border-box;
    overflow-y: auto; background: #fff; color: #1e293b;
    border: 1px solid #cbd5e1; border-radius: 10px;
    box-shadow: 0 8px 24px #0f172a26; padding: 4px;
}
.produto-busca-lista[hidden], .produto-busca-vazio[hidden], .produto-busca-oculto { display: none !important; }
.produto-busca-opcao { padding: 10px 12px; font-size: 13px; line-height: 1.5; cursor: pointer; border-radius: 6px; overflow-wrap: anywhere; }
.produto-busca-opcao:hover, .produto-busca-opcao.ativo { background: #eef2ff; color: #4338ca; }
.produto-busca-opcao[aria-selected="true"] { font-weight: 600; }
.produto-busca-vazio { padding: 12px; color: #64748b; font-size: 13px; }
.multi-select-menu .produto-busca-multi { position: sticky; top: 0; z-index: 1; background: #fff; margin-bottom: 8px; }
.pedido-externo-item-linha .produto-busca-controle { flex: 1; min-width: 0; }
.pedido-externo-item-linha .produto-busca-controle .produto-busca-input { width: 100%; max-width: none; }

.pedido-externo-item-linha > .produto-busca-controle { flex: 3; }
.pedido-externo-item-linha > .item-quantidade-input { flex: 0 0 80px; width: 80px; }
