/* SmartStock - tema visual web (identidade JFA Eletrônicos: azul da marca
   extraído do logo oficial, #0095DA) */

:root {
    --teal: #0095DA;
    --teal-bg: #E2F2FB;
    --purple: #7A2170;
    --purple-bg: #F5E9F3;
    --amber: #C2760A;
    --amber-bg: #FBF0DF;
    --red: #C23B2E;
    --red-bg: #FBEAE7;
    --dark: #16211F;
    --muted: #5B6B69;
    --bg: #F5F7F7;
    --white: #FFFFFF;
    --line: #E2E8E7;
    --dark-panel: #00344C;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    font-family: 'IBM Plex Sans', -apple-system, Segoe UI, sans-serif;
    color: var(--dark);
}

a { color: inherit; text-decoration: none; }

h1, h2, h3, .brand-font {
    font-family: 'Space Grotesk', -apple-system, Segoe UI, sans-serif;
}

/* ---------- Layout geral ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    flex: 0 0 auto;
    background: var(--white);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    padding: 24px 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 24px 24px 24px;
}

.logo-badge {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--dark-panel);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 13px;
    flex: 0 0 auto;
}

.logo-badge-img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    flex: 0 0 auto;
}

.brand-name {
    font-weight: 700;
    font-size: 16px;
    color: var(--dark);
    line-height: 1.2;
}

.brand-sub {
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
    line-height: 1.2;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 16px;
}

.nav-link {
    height: 44px;
    border-radius: 10px;
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}

.nav-link:hover {
    background: var(--bg);
}

.nav-link.active {
    background: var(--teal-bg);
    color: var(--dark-panel);
    font-weight: 600;
}

.nav-link svg { flex: 0 0 auto; }

.sidebar-spacer { flex-grow: 1; }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 24px 0 24px;
    border-top: 1px solid var(--line);
    margin-top: 8px;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: var(--teal-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 700;
    color: var(--dark-panel);
}

.user-name { font-size: 12px; font-weight: 600; color: var(--dark); }
.user-role { font-size: 11px; color: #8A9694; }
.logout-link { font-size: 11px; color: var(--muted); margin-left: auto; }

.content {
    flex-grow: 1;
    min-width: 0; /* deixa o conteudo encolher ao lado do menu: tabelas largas rolam dentro do card em vez de alargar a pagina toda */
    padding: 32px 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 1200px;
}

.page-title { font-size: 24px; font-weight: 700; margin: 0; color: var(--dark); }
.page-subtitle { font-size: 13px; color: var(--muted); margin: 2px 0 0 0; }

/* ---------- Cartoes / cards ---------- */

.card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 20px;
}

.section-label { font-size: 12px; font-weight: 700; color: var(--purple); text-transform: uppercase; letter-spacing: .02em; margin: 0 0 12px 0; }
.section-label-teal { font-size: 12px; font-weight: 700; color: var(--teal); text-transform: uppercase; letter-spacing: .02em; margin: 0 0 12px 0; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
}

.stat-tile {
    background: var(--bg);
    border-radius: 12px;
    padding: 16px;
}

.stat-tile-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.stat-tile-value { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 24px; color: var(--dark); margin-top: 4px; }

.dark-banner {
    background: var(--dark);
    border-radius: 12px;
    padding: 18px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.dark-banner-label { font-size: 14px; color: #CFEAE7; font-weight: 500; }
.dark-banner-value { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 22px; }

.alert-banner {
    background: var(--red-bg);
    border: 1px solid #F3C9C2;
    border-radius: 12px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #8A2E23;
    font-size: 13px;
}

.info-banner {
    background: var(--dark-panel);
    color: white;
    border-radius: 12px;
    padding: 16px 20px;
    font-size: 13px;
}

.info-banner b { color: #6EE0D6; }

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 999px;
}

.badge-ruptura { color: var(--red); background: var(--red-bg); }
.badge-atencao { color: var(--amber); background: var(--amber-bg); }
.badge-excesso { color: var(--purple); background: var(--purple-bg); }
.badge-normal { color: var(--teal); background: var(--teal-bg); }

.badge-classe-a { color: var(--teal); background: var(--teal-bg); }
.badge-classe-b { color: var(--amber); background: var(--amber-bg); }
.badge-classe-c { color: var(--red); background: var(--red-bg); }
.badge-categoria { color: var(--dark-panel); background: var(--teal-bg); font-weight: 600; }

.badge-segmento-campeao { color: var(--teal); background: var(--teal-bg); }
.badge-segmento-fiel { color: var(--purple); background: var(--purple-bg); }
.badge-segmento-em-risco { color: var(--amber); background: var(--amber-bg); }
.badge-segmento-inativo { color: var(--red); background: var(--red-bg); }

.badge-status-cumprido { color: var(--teal); background: var(--teal-bg); }
.badge-status-parcial { color: var(--amber); background: var(--amber-bg); }
.badge-status-abaixo-do-plano { color: var(--red); background: var(--red-bg); }
.badge-status-fora-do-plano { color: var(--purple); background: var(--purple-bg); }
.badge-status-sem-movimento { color: var(--muted); background: var(--bg); }

.badge-assistencia-aberto { color: var(--red); background: var(--red-bg); }
.badge-assistencia-em-reparo { color: var(--amber); background: var(--amber-bg); }
.badge-assistencia-concluido { color: var(--teal); background: var(--teal-bg); }

/* ---------- Abas de filtro (Curva ABC) ---------- */

.tab-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tab-link {
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    background: var(--white);
    border: 1px solid var(--line);
}

.tab-link:hover { background: var(--bg); }

.tab-link.active {
    background: var(--dark-panel);
    color: white;
    border-color: var(--dark-panel);
}

.tab-link-teal.active {
    background: var(--teal);
    border-color: var(--teal);
}

/* ---------- Caixas de filtro estilo "slicer" (grade de botões,
   seleção múltipla) - usadas em Carteira/Faturamento pra imitar os
   slicers do relatório em Excel que essas telas substituem. ---------- */

.slicer-caixa {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px;
    flex: 1 1 220px;
    min-width: 200px;
    max-height: 220px;
    overflow-y: auto;
}

.slicer-titulo {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .02em;
    margin: 0 0 8px 0;
}

.slicer-grade {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.slicer-btn {
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--white);
    color: var(--dark);
    font-size: 12px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.slicer-btn:hover { background: var(--bg); }

.slicer-btn.ativo {
    background: var(--teal-bg);
    border-color: var(--teal);
    color: var(--teal);
}

/* ---------- Botoes ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    padding: 0 18px;
    border-radius: 9px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
}

.btn-primary { background: var(--teal); color: white; border: none; }
.btn-primary:hover { background: #187a75; }

.btn-secondary { background: white; color: var(--dark); border: 1px solid var(--line); }
.btn-secondary:hover { background: var(--bg); }

.btn-block { width: 100%; }

/* ---------- Formularios ---------- */

label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }

input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], select, textarea {
    width: 100%;
    height: 38px;
    border-radius: 9px;
    border: 1px solid var(--line);
    padding: 0 12px;
    font-size: 13px;
    color: var(--dark);
    font-family: inherit;
    background: white;
}

input:focus, select:focus, textarea:focus { outline: none; border-color: var(--teal); }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
}

.field { display: flex; flex-direction: column; gap: 4px; }

/* ---------- Tabela ---------- */

table { width: 100%; border-collapse: collapse; }

thead th {
    background: var(--teal);
    color: white;
    font-size: 12px;
    text-align: left;
    padding: 12px 14px;
    font-weight: 700;
}

thead th:first-child { border-radius: 10px 0 0 0; }
thead th:last-child { border-radius: 0 10px 0 0; }

tbody td {
    padding: 12px 14px;
    font-size: 13px;
    border-bottom: 1px solid #F0F2F2;
}

tbody tr:nth-child(odd) { background: #FAFBFB; }
tbody tr:hover { background: var(--teal-bg); }

/* ---------- Tabela com rolagem própria ----------
   Limita a altura de tabelas longas para que o scroll fique contido
   dentro da tabela (vertical e horizontal), em vez de esticar a página
   inteira. O cabeçalho fica fixo (sticky) durante a rolagem vertical. */

.table-scroll {
    max-height: 560px;
    overflow: auto;
    border-radius: 10px;
    border: 1px solid var(--line);
}

.table-scroll-sm { max-height: 260px; }

.table-scroll table { margin: 0; }

.table-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.table-scroll thead th:first-child { border-radius: 0; }
.table-scroll thead th:last-child { border-radius: 0; }

/* Destaque de diferença (ex: Estoque − Apontamento, Realizado − Planejado):
   vermelho quando negativa, azul da marca quando positiva. */
.dif-neg { color: var(--red); font-weight: 600; }
.dif-pos { color: var(--teal); font-weight: 600; }
.dif-zero { color: var(--muted); }

/* O congelamento das colunas (Produto/Código/Estoque/Carteira/Forecast) da
   grade diária e semanal do Dashboard é feito via CSS inline no próprio
   DashboardController (escopado corretamente a thead tr:first-child, para
   não grudar também a primeira célula das linhas de dia/semana do
   cabeçalho) - ver comentário "Colunas fixas" lá. As regras antigas que
   existiam aqui usavam um seletor :first-child sem esse escopo e acabavam
   grudando a primeira célula de TODAS as linhas do cabeçalho (inclusive a
   linha de datas), fazendo o cabeçalho "flutuar" errado ao rolar - por
   isso foram removidas em vez de mantidas lado a lado com as novas regras. */

/* ---------- Lista de busca (Consulta) ---------- */

.search-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 560px;
    overflow: auto;
}

.search-item {
    padding: 12px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.search-item:hover { background: var(--bg); }
.search-item.active { background: var(--teal-bg); }

.search-item-name { font-size: 13px; font-weight: 600; color: var(--dark); }
.search-item-code { font-size: 11px; color: var(--muted); }

.two-col { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.col-narrow { width: 340px; flex: 0 0 auto; }
.col-wide { flex: 1 1 0%; min-width: 0; }

/* ---------- Login ---------- */

.login-backdrop {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #00344C, #0095DA);
    padding: 24px;
}

.login-panel {
    background: white;
    border-radius: 18px;
    padding: 40px;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 24px 60px rgba(13, 59, 58, 0.35);
}

.login-title { font-size: 22px; font-weight: 700; margin: 18px 0 4px 0; }
.login-subtitle { font-size: 13px; color: var(--muted); margin: 0 0 20px 0; }
.login-error { font-size: 12px; color: var(--red); margin: 8px 0; }
.login-hint { font-size: 11px; color: #8A9694; margin-top: 14px; text-align: center; }

/* ---------- Utilidades ---------- */

.flash-success {
    background: var(--teal-bg);
    color: var(--dark-panel);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
}

.muted { color: var(--muted); }
.mt-0 { margin-top: 0; }
.gap-col { display: flex; flex-direction: column; gap: 16px; }

@media (max-width: 860px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 12px 16px; overflow-x: auto; }
    .sidebar-nav { flex-direction: row; padding: 0; }
    .sidebar-user, .sidebar-spacer { display: none; }
    .content { padding: 20px; }
    .col-narrow { width: 100%; }
}

/* ---------- Tabelas com colunas ajustaveis e ordenaveis (global) ---------- */

/* width:auto (em vez do width:100% global de "table") deixa a tabela
   crescer pela soma da largura das colunas (definida via JS no colgroup)
   quando o conteudo pede mais espaco que a tela - o .table-scroll em
   volta assume a rolagem horizontal nesse caso, em vez de o navegador
   espremer todas as colunas pra caber em 100% do container. min-width
   garante que ela ainda preenche a largura toda quando sobra espaco. */
table.tabela-ajustavel { table-layout: fixed; width: auto; min-width: 100%; }
table.tabela-ajustavel th {
    position: relative;
    cursor: pointer;
    user-select: none;
    padding-right: 16px;
}
/* hover só clareia por cima (antes o "background" era trocado por quase transparente e o cabeçalho ficava branco com letra branca) */
table.tabela-ajustavel th:hover { box-shadow: inset 0 0 0 100px rgba(255, 255, 255, 0.14); }
table.tabela-ajustavel th.ordenado-asc::after,
table.tabela-ajustavel th.ordenado-desc::after {
    position: absolute;
    right: 14px;
    font-size: 10px;
    opacity: 0.85;
}
table.tabela-ajustavel th.ordenado-asc::after { content: "▲"; }
table.tabela-ajustavel th.ordenado-desc::after { content: "▼"; }
.resize-handle-coluna {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 5;
    user-select: none;
    touch-action: none;
}
.resize-handle-coluna:hover,
.resize-handle-coluna.ativo { background: rgba(0, 0, 0, 0.18); }
body.redimensionando-coluna,
body.redimensionando-coluna * { cursor: col-resize !important; user-select: none !important; }

/* ===== Filtro de seleção múltipla (multifiltro.js) ===== */
.mf { position: relative; min-width: 0; }
.mf-rotulo { display: block; font-size: 12px; font-weight: 600; color: var(--muted, #5B6B69); margin-bottom: 4px; }
.mf-botao { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; padding: 9px 12px; border: 1px solid #C9D3D1; background: #fff; border-radius: 8px; font-size: 14px; text-align: left; color: inherit; }
.mf-botao.mf-ativo { border-color: var(--teal); background: var(--teal-bg, #E6F4FB); font-weight: 600; }
.mf-resumo { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mf-seta { font-size: 11px; opacity: .6; }
.mf-painel { position: absolute; z-index: 60; top: 100%; left: 0; margin-top: 4px; min-width: 100%; width: 280px; max-width: 360px; background: #fff; border: 1px solid #C9D3D1; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 8px; }
.mf-painel[hidden] { display: none; }
.mf-busca { width: 100%; box-sizing: border-box; padding: 7px 9px; border: 1px solid #C9D3D1; border-radius: 6px; font-size: 13px; }
.mf-acoes { display: flex; justify-content: space-between; margin: 6px 2px; }
.mf-acoes button { border: none; background: none; color: var(--teal); font-weight: 600; font-size: 12px; cursor: pointer; padding: 2px 4px; }
.mf-lista { max-height: 240px; overflow: auto; }
.mf-item { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.mf-item:hover { background: #F3F6F5; }
.mf-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mf-item.mf-indisp span { color: #9AA6A4; }
.mf-vazio { padding: 10px; color: #8A9694; font-size: 13px; text-align: center; }
.mf-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.mf-chip { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; background: #DCEEF9; color: #00344C; border-radius: 12px; padding: 2px 4px 2px 9px; font-size: 12px; }
.mf-chip-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.mf-chip button { border: none; background: rgba(0,0,0,.08); border-radius: 50%; width: 16px; height: 16px; line-height: 14px; cursor: pointer; font-size: 12px; padding: 0; }
.mf-chip button:hover { background: rgba(0,0,0,.2); }

/* trechos de codigo (nomes de colunas) quebram de linha em vez de alargar a pagina */
code { overflow-wrap: anywhere; word-break: break-word; }
