/* ===== Tokens ===== */
:root {
    --surface-1: #fcfcfb;
    --page: #f4f4f1;
    --ink-1: #0b0b0b;
    --ink-2: #52514e;
    --muted: #898781;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --border: rgba(11, 11, 11, .10);
    /* Classes ABC: escala ordinal de uma só cor (azul) */
    --classe-a: #1c5cab;
    --classe-a-ink: #ffffff;
    --classe-b: #86b6ef;
    --classe-b-ink: #0d366b;
    --classe-c: #e6e5df;
    --classe-c-ink: #52514e;
    --serie-1: #2a78d6;
    --good: #0ca30c;
    --good-ink: #006300;
    --warning: #fab219;
    --warning-ink: #7a5200;
}

[data-bs-theme="dark"] {
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --ink-1: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, .10);
    --classe-a: #3987e5;
    --classe-a-ink: #ffffff;
    --classe-b: #184f95;
    --classe-b-ink: #cde2fb;
    --classe-c: #2c2c2a;
    --classe-c-ink: #c3c2b7;
    --serie-1: #3987e5;
    --good-ink: #0ca30c;
    --warning-ink: #fab219;
}

html, body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--page);
    color: var(--ink-1);
}

.carregando-app {
    display: flex; gap: .75rem; align-items: center; justify-content: center;
    height: 100vh; color: var(--ink-2);
}

/* ===== Layout ===== */
.topo {
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 1020;
}
.topo .marca { font-weight: 700; color: var(--ink-1); text-decoration: none; display: flex; align-items: center; gap: .5rem; }
.topo .nav-link { color: var(--ink-2); border-radius: .5rem; padding: .4rem .75rem; }
.topo .nav-link.active { color: var(--ink-1); background: var(--page); font-weight: 600; }
.conteudo { max-width: 1440px; margin: 0 auto; padding: 1rem; }
@media (min-width: 768px) {
    .conteudo { padding: 1.5rem; }
    .topo .conteudo { padding-top: .5rem; padding-bottom: .5rem; }
    .topo .nav { width: auto !important; }
}

.cartao {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: .75rem;
    padding: 1rem;
}
.cartao-titulo { font-size: .95rem; font-weight: 600; margin-bottom: .75rem; }
.texto-2 { color: var(--ink-2); }
.texto-mudo { color: var(--muted); font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ===== KPIs ===== */
.kpi-rotulo { color: var(--ink-2); font-size: .8rem; }
.kpi-valor { font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.kpi-sub { color: var(--muted); font-size: .8rem; }

/* ===== Filtros ===== */
.filtros .form-label { font-size: .75rem; color: var(--ink-2); margin-bottom: .2rem; }
.chip-loja {
    border: 1px solid var(--border); background: var(--surface-1); color: var(--ink-2);
    border-radius: 999px; padding: .15rem .6rem; font-size: .8rem; font-variant-numeric: tabular-nums;
}
.chip-loja.ativa { background: var(--classe-a); color: var(--classe-a-ink); border-color: transparent; }

/* ===== Classes ABC ===== */
.classe {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 1.6rem; height: 1.4rem; padding: 0 .35rem; border-radius: .35rem;
    font-size: .75rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.classe-A { background: var(--classe-a); color: var(--classe-a-ink); }
.classe-B { background: var(--classe-b); color: var(--classe-b-ink); }
.classe-C { background: var(--classe-c); color: var(--classe-c-ink); }

.lojas-a { display: flex; flex-wrap: wrap; gap: .2rem; }
.lojas-a span {
    font-size: .72rem; padding: 0 .35rem; border-radius: .3rem; font-variant-numeric: tabular-nums;
    background: var(--classe-a); color: var(--classe-a-ink);
}

.lojas-lista { display: flex; flex-wrap: wrap; gap: .2rem; }
.lojas-lista span {
    font-size: .72rem; padding: 0 .35rem; border-radius: .3rem; font-variant-numeric: tabular-nums;
    border: 1px solid var(--border); color: var(--ink-2); background: var(--surface-1);
}

/* Barras horizontais (Top 20, lojas, categorias): posição | rótulo | barra | valor */
.barra-h { display: grid; grid-template-columns: 2.6rem minmax(0, 1.4fr) minmax(60px, 2fr) 4.8rem; gap: .6rem; align-items: center; font-size: .85rem; }
.barra-h-pos { color: var(--muted); text-align: right; font-size: .8rem; }
.barra-h-trilho { height: 14px; background: var(--grid); border-radius: 4px; overflow: hidden; display: block; }
.barra-h-trilho > span { display: block; height: 100%; background: var(--serie-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.barra-h-valor { text-align: right; font-weight: 600; }
.barra-h:hover .barra-h-trilho > span { filter: brightness(1.12); }
@media (max-width: 575.98px) {
    .barra-h { grid-template-columns: 2rem minmax(0, 1fr) 4.2rem; row-gap: .2rem; }
    .barra-h-trilho { grid-column: 2 / 4; grid-row: 2; }
}

/* Escala de calor sequencial (um só tom de azul) */
:root {
    --calor-1: #cde2fb; --calor-1-ink: #0d366b;
    --calor-2: #9ec5f4; --calor-2-ink: #0d366b;
    --calor-3: #6da7ec; --calor-3-ink: #0b0b0b;
    --calor-4: #2a78d6; --calor-4-ink: #ffffff;
    --calor-5: #184f95; --calor-5-ink: #ffffff;
}
[data-bs-theme="dark"] {
    --calor-1: #0d366b; --calor-1-ink: #cde2fb;
    --calor-2: #184f95; --calor-2-ink: #cde2fb;
    --calor-3: #256abf; --calor-3-ink: #ffffff;
    --calor-4: #3987e5; --calor-4-ink: #0b0b0b;
    --calor-5: #86b6ef; --calor-5-ink: #0b0b0b;
}
.calor { display: inline-block; min-width: 2.6rem; padding: .1rem .35rem; border-radius: .35rem; font-size: .75rem; font-weight: 600; text-align: center; }
.calor-1 { background: var(--calor-1); color: var(--calor-1-ink); }
.calor-2 { background: var(--calor-2); color: var(--calor-2-ink); }
.calor-3 { background: var(--calor-3); color: var(--calor-3-ink); }
.calor-4 { background: var(--calor-4); color: var(--calor-4-ink); }
.calor-5 { background: var(--calor-5); color: var(--calor-5-ink); }

/* Motivo do item no mix */
.tag-motivo {
    display: inline-flex; align-items: center; gap: .2rem; font-size: .72rem; padding: .05rem .4rem;
    border: 1px solid var(--border); border-radius: 999px; color: var(--ink-2); background: var(--surface-1); white-space: nowrap;
}
.tag-motivo.forte { border-color: var(--classe-a); color: var(--ink-1); font-weight: 600; }

/* Lista de compra */
.qtd-compra { width: 5.2rem; display: inline-block; }
.tabela tr.selecionado td { background: color-mix(in srgb, var(--classe-a) 7%, var(--surface-1)); }
.barra-compra {
    position: sticky; bottom: 0; z-index: 1010; margin: 1rem -1rem -1rem;
    background: var(--surface-1); border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgba(0, 0, 0, .08);
}
@media (min-width: 768px) { .barra-compra { margin: 1.5rem -1.5rem -1.5rem; } }
.barra-compra .conteudo { padding-left: 1rem; padding-right: 1rem; }
.so-impressao { display: none; }
.aba-oculta { display: none; }
.badge-aba {
    display: inline-block; min-width: 1.4rem; padding: 0 .35rem; margin-left: .25rem; border-radius: 999px;
    font-size: .72rem; font-weight: 600; font-variant-numeric: tabular-nums; background: var(--grid); color: var(--ink-2);
}
.nav-link.active .badge-aba { background: rgba(255, 255, 255, .25); color: inherit; }
@media print {
    .topo, .sem-impressao, .barra-compra, #blazor-error-ui { display: none !important; }
    .so-impressao { display: inline; }
    .aba-oculta { display: block !important; }
    .qtd-compra { display: none; }
    body, .cartao { background: #fff !important; color: #000 !important; }
    .cartao { border: 1px solid #ccc; break-inside: avoid; }
    .conteudo { max-width: none; padding: 0; }
}

/* Importação */
.log-importacao {
    max-height: 280px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .75rem;
    background: var(--page); border: 1px solid var(--border); border-radius: .5rem; padding: .5rem; white-space: pre-wrap;
}
.calendario th, .calendario td { font-size: .72rem; padding: .25rem; }
.calendario .fixa { position: sticky; left: 0; background: var(--surface-1); z-index: 2; }
.dia-ok { color: var(--good-ink); font-weight: 700; }
.dia-falta { color: var(--muted); }

/* Cabeçalho ordenável */
.th-ordem {
    border: 0; background: none; padding: 0; color: inherit; font: inherit; text-transform: inherit;
    letter-spacing: inherit; white-space: nowrap; cursor: pointer;
}
.th-ordem:hover, .th-ordem.ativa { color: var(--ink-1); }

.status-ok { color: var(--good-ink); font-weight: 600; font-size: .8rem; white-space: nowrap; }
.status-op { color: var(--warning-ink); font-weight: 600; font-size: .8rem; white-space: nowrap; }

/* Barra de proporção (presença, aderência, votos) */
.barra { height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; min-width: 60px; }
.barra > div { height: 100%; background: var(--serie-1); border-radius: 3px; }
.barra-alta { height: 10px; border-radius: 5px; }
.barra-alta > div { border-radius: 5px; }

/* ===== Tabelas ===== */
.tabela { width: 100%; font-size: .85rem; border-collapse: separate; border-spacing: 0; }
.tabela th {
    color: var(--ink-2); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .02em;
    border-bottom: 1px solid var(--axis); padding: .5rem; position: sticky; top: 0; background: var(--surface-1); z-index: 1;
    white-space: nowrap;
}
.tabela td { border-bottom: 1px solid var(--grid); padding: .5rem; vertical-align: middle; }
.tabela tbody tr.clicavel { cursor: pointer; }
.tabela tbody tr.clicavel:hover td { background: var(--page); }
.tabela .detalhe td { background: var(--page); }
.rolagem { overflow: auto; max-height: 70vh; border-radius: .5rem; }

/* Matriz produto x loja */
.matriz th.fixa, .matriz td.fixa { position: sticky; left: 0; background: var(--surface-1); z-index: 2; min-width: 220px; max-width: 280px; }
.matriz th.fixa { z-index: 3; }
.matriz td.celula { text-align: center; padding: .25rem; }
.matriz .classe { min-width: 2.4rem; }
.matriz .vazio { color: var(--muted); }

/* ===== Cartões de produto (mobile) ===== */
.produto-card { border-bottom: 1px solid var(--grid); padding: .75rem 0; }
.produto-card:last-child { border-bottom: 0; }
.produto-pos { font-size: 1.1rem; font-weight: 700; min-width: 2.5rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ===== Gráfico ===== */
.grafico svg { width: 100%; height: auto; display: block; }
.grafico .grade { stroke: var(--grid); stroke-width: 1; }
.grafico .eixo { stroke: var(--axis); stroke-width: 1; }
.grafico .rotulo { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.grafico .linha { fill: none; stroke: var(--serie-1); stroke-width: 2; }
.grafico .zona-a { fill: var(--classe-a); opacity: .08; }
.grafico .zona-b { fill: var(--classe-b); opacity: .10; }
.grafico .corte { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 4 4; }
.grafico .zona-txt { fill: var(--ink-2); font-size: 12px; font-weight: 600; }
.grafico .mira { stroke: var(--ink-2); stroke-width: 1; }
.grafico .ponto { fill: var(--serie-1); stroke: var(--surface-1); stroke-width: 2; }
.tooltip-grafico {
    position: absolute; pointer-events: none; background: var(--surface-1); color: var(--ink-1);
    border: 1px solid var(--border); border-radius: .5rem; padding: .5rem .65rem; font-size: .8rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .12); max-width: 260px; z-index: 5;
}

/* ===== Pesquisa (voto do cliente) ===== */
.voto-opcao {
    width: 100%; text-align: left; padding: 1rem 1.25rem; font-size: 1.1rem; font-weight: 600;
    border-radius: .75rem; border: 2px solid var(--border); background: var(--surface-1); color: var(--ink-1);
}
.voto-opcao:hover, .voto-opcao.selecionada { border-color: var(--classe-a); }
.voto-opcao.selecionada { background: var(--classe-a); color: var(--classe-a-ink); }

/* ===== Logos de marca ===== */
/* Fundo sempre branco: logos costumam ser feitos para fundo claro, inclusive no tema escuro */
.logo-marca {
    width: var(--logo-tam); height: var(--logo-tam); flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    background: #fff; border: 1px solid var(--border); border-radius: .6rem; overflow: hidden;
}
.logo-marca img { max-width: 88%; max-height: 88%; object-fit: contain; }
.logo-iniciais { font-weight: 700; color: #52514e; font-size: calc(var(--logo-tam) * .32); letter-spacing: .02em; }

/* Menu de ações do cartão */
.dropdown-ish { position: relative; }
.menu-acoes {
    position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; min-width: 150px;
    background: var(--surface-1); border: 1px solid var(--border); border-radius: .5rem;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .15); padding: .25rem; display: flex; flex-direction: column; text-align: left;
}
.menu-acoes button { background: none; border: 0; padding: .4rem .6rem; border-radius: .35rem; color: var(--ink-1); text-align: left; font-size: .85rem; }
.menu-acoes button:hover { background: var(--page); }

/* Marcas escolhidas numa pergunta (editor) */
.chip-marca {
    display: inline-flex; align-items: center; gap: .4rem; padding: .2rem .35rem .2rem .2rem;
    border: 1px solid var(--border); border-radius: .6rem; background: var(--surface-1); font-size: .85rem;
}
.chip-marca .remover { border: 0; background: none; color: var(--muted); padding: 0 .2rem; line-height: 1; }
.chip-marca .remover:hover { color: var(--ink-1); }

/* Seletor de marcas (modal) */
.seletor-grade { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: .5rem; max-height: 50vh; overflow: auto; padding: 2px; }
.seletor-item {
    display: flex; flex-direction: column; align-items: center; gap: .35rem; padding: .5rem .35rem;
    border: 2px solid var(--border); border-radius: .6rem; background: var(--surface-1); color: var(--ink-1); font-size: .8rem;
}
.seletor-item.marcado { border-color: var(--classe-a); background: var(--page); }

/* Opções de marca para o cliente */
.grade-logos { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
@media (min-width: 480px) { .grade-logos { grid-template-columns: repeat(3, 1fr); } }
.opcao-logo {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem;
    padding: .75rem .5rem; border: 2px solid var(--border); border-radius: .9rem; background: var(--surface-1);
    color: var(--ink-1); font-weight: 600; font-size: .95rem; min-height: 132px; position: relative;
}
.opcao-logo:hover { border-color: var(--classe-b); }
.opcao-logo.selecionada { border-color: var(--classe-a); box-shadow: 0 0 0 3px color-mix(in srgb, var(--classe-a) 30%, transparent); }
.opcao-logo.selecionada::after {
    content: "✓"; position: absolute; top: .4rem; right: .5rem; width: 1.5rem; height: 1.5rem; border-radius: 50%;
    background: var(--classe-a); color: var(--classe-a-ink); font-size: .85rem; display: flex; align-items: center; justify-content: center;
}

/* Resultado com logo */
.resultado-linha { display: grid; grid-template-columns: auto 1fr auto; gap: .6rem; align-items: center; }

#blazor-error-ui {
    background: #fff3cd; color: #664d03; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none; left: 0; padding: .6rem 1.25rem .7rem 1.25rem; position: fixed; width: 100%; z-index: 1030;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }
