:root {
  --navy-900: #0F2340;
  --navy-800: #16305A;
  --navy-700: #1F3F72;
  --page: #EDF1F6;
  --surface: #FFFFFF;
  --line: #D9E0EA;
  --line-soft: #E8EDF3;
  --ink: #132238;
  --muted: #5A6A80;
  --faint: #8592A5;
  --ok: #1D7A58;
  --warn: #A86312;
  --err: #B23B2E;
  --focus: #3B82D6;
  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 6px;
  --shadow: 0 1px 2px rgba(15, 35, 64, .06), 0 4px 14px rgba(15, 35, 64, .05);
  --font: "Hanken Grotesk", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--page); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
.num { font-variant-numeric: tabular-nums; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- topo ---------- */
.topo { background: var(--navy-900); color: #fff; }
.topo-in { max-width: 1440px; margin: 0 auto; padding: 14px 24px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.marca { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.marca svg { flex: none; }
.marca h1 { font-size: 18px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.marca span { color: #A9B8CF; font-size: 13px; }
.sync { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #C8D3E3; flex-wrap: wrap; }
.pilula { white-space: nowrap; display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px 5px 9px; border-radius: 999px; background: rgba(255,255,255,.08); color: #fff; font-weight: 600; }
.pilula::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.pilula[data-s="atualizada"]::before { background: #4CC38A; }
.pilula[data-s="sincronizando"]::before { background: #6DB3FF; animation: pulso 1.2s ease-in-out infinite; }
.pilula[data-s="erro"]::before { background: #FF7A6B; }
.pilula[data-s="desatualizada"]::before { background: #F2B05E; }
@keyframes pulso { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .pilula::before { animation: none !important; } }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); padding: 7px 13px; cursor: pointer; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: #B9C5D5; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-claro { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.22); color: #fff; }
.btn-claro:hover { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.35); }
.btn-pri { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
.btn-pri:hover { background: var(--navy-700); }
.link { background: none; border: 0; padding: 0; color: var(--navy-700); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; font-weight: 600; }

/* ---------- avisos ---------- */
.aviso { max-width: 1440px; margin: 12px auto 0; padding: 0 24px; }
.aviso > div { border-radius: var(--r-md); padding: 10px 14px; font-size: 14px; }
.aviso-demo > div { background: #FFF4DC; border: 1px solid #F0D49B; color: #6B4A08; }
.aviso-velho > div { background: #FDEDEA; border: 1px solid #F1C3BC; color: #7A2A20; }
.aviso strong { font-weight: 700; }

/* ---------- filtros ---------- */
.filtros { position: sticky; top: 0; z-index: 20; background: rgba(237, 241, 246, .94); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.filtros-in { max-width: 1440px; margin: 0 auto; padding: 12px 24px; display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; }
.campo { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.campo label { font-size: 12px; color: var(--muted); font-weight: 600; }
.campo select { max-width: 280px; }
.campo select, .campo input { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); padding: 7px 9px; font-size: 14px; min-width: 0; }
.campo input[type="date"] { width: 148px; }
.campo-forn input { width: 230px; }
.datas { display: flex; gap: 6px; align-items: center; }
.multi { position: relative; }
.multi > button { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); padding: 7px 30px 7px 9px; font-size: 14px; text-align: left; min-width: 190px; max-width: 260px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; }
.multi > button::after { content: ""; position: absolute; right: 11px; top: 50%; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-70%) rotate(45deg); }
.multi-lista { position: absolute; top: calc(100% + 4px); left: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow); padding: 6px; min-width: 240px; z-index: 30; max-height: 320px; overflow: auto; }
.multi-lista label { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: var(--r-sm); cursor: pointer; font-size: 14px; }
.multi-lista label:hover { background: var(--page); }
.ponto { width: 10px; height: 10px; border-radius: 3px; flex: none; background: var(--c, var(--faint)); }
.filtros-acoes { margin-left: auto; display: flex; gap: 8px; }

/* ---------- conteúdo ---------- */
main { max-width: 1440px; margin: 0 auto; padding: 18px 24px 48px; display: grid; gap: 18px; }
.painel { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.painel h2 { font-size: 16px; font-weight: 700; margin: 0; letter-spacing: -.005em; }
.painel-cab { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.painel-cab p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* resumo (bloco principal) */
.resumo { background: linear-gradient(135deg, var(--navy-900) 0%, var(--navy-800) 100%); color: #fff; border-radius: var(--r-lg); padding: 22px 24px; display: grid; grid-template-columns: minmax(260px, 1.35fr) repeat(3, minmax(150px, 1fr)); gap: 0; box-shadow: var(--shadow); }
.kpi { padding: 4px 22px; border-left: 1px solid rgba(255,255,255,.12); cursor: pointer; border-radius: var(--r-sm); background: none; border-top: 0; border-right: 0; border-bottom: 0; text-align: left; color: inherit; }
.kpi:first-child { border-left: 0; padding-left: 0; }
.kpi:hover .kpi-v { text-decoration: underline; text-decoration-color: rgba(255,255,255,.35); text-underline-offset: 4px; }
.kpi-r { font-size: 13px; color: #B5C3D8; font-weight: 500; }
.kpi-v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 6px; line-height: 1.15; }
.kpi:first-child .kpi-v { font-size: 38px; }
.kpi-c { font-size: 13px; color: #C8D3E3; }
.var { font-weight: 700; }
.var-up::before { content: "▲ "; font-size: 10px; }
.var-down::before { content: "▼ "; font-size: 10px; }

/* categorias */
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(225px, 1fr)); gap: 12px; }
.btn-filtros { display: none; }
.cat { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--r-md); padding: 14px 16px 14px 18px; text-align: left; cursor: pointer; position: relative; box-shadow: var(--shadow); overflow: hidden; }
.cat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c, var(--faint)); }
.cat:hover { border-color: var(--line); }
.cat[aria-pressed="true"] { border-color: var(--c); box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 30%, transparent), var(--shadow); }
.cat-n { font-weight: 700; font-size: 14px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cat-n small { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
.cat-v { font-size: 20px; font-weight: 700; margin: 6px 0 2px; letter-spacing: -.015em; }
.cat-c { font-size: 12.5px; color: var(--muted); }
.cat-barra { height: 4px; background: var(--line-soft); border-radius: 2px; margin-top: 10px; overflow: hidden; }
.cat-barra i { display: block; height: 100%; background: var(--c); border-radius: 2px; }
.nota-sobrep { font-size: 13.5px; color: #5C4410; background: #FFF7E6; border: 1px solid #F3DDAE; border-radius: var(--r-md); padding: 10px 14px; }

/* grade de gráficos */
.grade { display: grid; grid-template-columns: repeat(12, 1fr); gap: 18px; }
.s12 { grid-column: span 12; } .s7 { grid-column: span 7; } .s5 { grid-column: span 5; } .s6 { grid-column: span 6; }
.graf { position: relative; height: 290px; }
.graf-alto { height: 320px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 11px; font-size: 13px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--navy-800); color: #fff; }
.vazio, .erro-box { display: grid; place-items: center; text-align: center; color: var(--muted); font-size: 14px; min-height: 160px; padding: 16px; }
.erro-box { color: var(--err); }

/* ranking de fornecedores */
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rank button { width: 100%; display: grid; grid-template-columns: 22px 1fr auto; gap: 4px 10px; align-items: center; padding: 7px 8px; border: 0; background: none; border-radius: var(--r-sm); cursor: pointer; text-align: left; }
.rank button:hover { background: var(--page); }
.rank button[aria-pressed="true"] { background: #E3EBF7; }
.rank .pos { color: var(--faint); font-size: 13px; font-weight: 600; }
.rank .nm { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank .vl { font-size: 14px; font-weight: 700; }
.rank .br { grid-column: 2 / 4; height: 5px; background: var(--line-soft); border-radius: 3px; overflow: hidden; }
.rank .br i { display: block; height: 100%; background: var(--navy-700); border-radius: 3px; }
.rank .sub { grid-column: 2 / 4; font-size: 12px; color: var(--muted); }

/* fora do total */
.fora { display: flex; flex-wrap: wrap; gap: 10px; }
.fora button { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-md); padding: 9px 13px; cursor: pointer; text-align: left; }
.fora button:hover { border-color: #B9C5D5; }
.fora b { display: block; font-size: 14px; }
.fora span { font-size: 12.5px; color: var(--muted); }

/* tabela */
.tab-acoes { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.busca { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 7px 10px; width: 280px; max-width: 100%; }
.tabela-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th button { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; }
th button[data-dir="asc"]::after { content: " ↑"; }
th button[data-dir="desc"]::after { content: " ↓"; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: #F6F8FB; }
td.dir, th.dir { text-align: right; }
.cnpj { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.chave { font-size: 12px; color: var(--muted); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px 2px 6px; border-radius: 999px; background: color-mix(in srgb, var(--c, var(--faint)) 12%, white); color: color-mix(in srgb, var(--c, var(--faint)) 75%, black); white-space: nowrap; }
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c, var(--faint)); }
.sit { font-size: 12.5px; font-weight: 600; }
.sit-cancelada { color: var(--err); } .sit-denegada { color: var(--warn); }
.pag { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.pag div { display: flex; gap: 6px; align-items: center; }
.indisp { color: var(--faint); font-style: italic; }

/* carregamento */
.carregando { position: relative; }
.carregando::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent); background-size: 200% 100%; animation: brilho 1.1s linear infinite; border-radius: inherit; pointer-events: none; }
@keyframes brilho { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .carregando::after { animation: none; background: rgba(255,255,255,.4); } }

/* gaveta de detalhe e modal */
.veu { position: fixed; inset: 0; background: rgba(15, 35, 64, .35); z-index: 50; }
.gaveta { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100%); background: var(--surface); z-index: 51; overflow: auto; box-shadow: -10px 0 30px rgba(15,35,64,.15); display: flex; flex-direction: column; }
.gaveta header { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; position: sticky; top: 0; background: var(--surface); }
.gaveta h2 { margin: 0; font-size: 18px; }
.gaveta .corpo { padding: 18px 22px 30px; display: grid; gap: 18px; }
.gaveta h3 { font-size: 14px; margin: 0 0 8px; }
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 18px; margin: 0; }
.dl div { min-width: 0; }
.dl dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.dl dd { margin: 2px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.fechar { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: var(--r-sm); color: var(--muted); }
.fechar:hover { background: var(--page); }
.modal { position: fixed; z-index: 51; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(620px, calc(100% - 24px)); max-height: calc(100% - 40px); overflow: auto; background: var(--surface); border-radius: var(--r-lg); box-shadow: 0 20px 60px rgba(15,35,64,.25); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal h2 { margin: 0; font-size: 17px; }
.modal .corpo { padding: 16px 20px 22px; display: grid; gap: 14px; font-size: 14px; }
.lista-status { display: grid; gap: 8px; margin: 0; }
.lista-status div { display: flex; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line-soft); padding-bottom: 7px; }
.lista-status dt { color: var(--muted); }
.lista-status dd { margin: 0; font-weight: 600; text-align: right; }
.ok { color: var(--ok); } .pend { color: var(--warn); } .falha { color: var(--err); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy-900); color: #fff; padding: 10px 16px; border-radius: var(--r-md); font-size: 14px; z-index: 60; box-shadow: var(--shadow); }

/* login */
.login-pg { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--navy-900), var(--navy-800)); padding: 20px; }
.login { background: var(--surface); border-radius: var(--r-lg); padding: 30px 28px; width: min(380px, 100%); display: grid; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login h1 { font-size: 20px; margin: 0; }
.login p { margin: 0; color: var(--muted); font-size: 14px; }
.login input { width: 100%; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; font-size: 15px; }
.login .btn { justify-content: center; padding: 10px; }
.login .erro { color: var(--err); font-size: 14px; min-height: 1.2em; }

/* ---------- responsivo ---------- */
@media (max-width: 1100px) {
  .resumo { grid-template-columns: 1fr 1fr; gap: 18px 0; }
  .kpi:nth-child(3) { border-left: 0; padding-left: 0; }
  .s7, .s5, .s6 { grid-column: span 12; }
}
@media (max-width: 640px) {
  .topo-in, .filtros-in, main, .aviso { padding-left: 14px; padding-right: 14px; }
  .resumo { grid-template-columns: 1fr 1fr; padding: 18px; }
  .kpi { padding: 0 0 0 14px; }
  .kpi:first-child { grid-column: span 2; padding-bottom: 6px; }
  .kpi:nth-child(2) { border-left: 0; padding-left: 0; }
  .kpi:nth-child(3) { border-left: 1px solid rgba(255,255,255,.12); padding-left: 14px; }
  .kpi:nth-child(4) { border-left: 0; padding-left: 0; }
  .kpi-v { font-size: 21px; } .kpi:first-child .kpi-v { font-size: 30px; }
  .filtros { position: static; }
  .btn-filtros { display: inline-flex; width: 100%; justify-content: space-between; }
  .filtros:not(.aberto) .filtros-in > :not(.btn-filtros) { display: none; }
  .sync { gap: 8px; width: 100%; }
  .sync .btn { padding: 6px 10px; font-size: 13px; }
  .cats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .cat { padding: 12px 12px 12px 15px; }
  .cat-n { flex-direction: column; gap: 0; }
  .cat-v { font-size: 16px; overflow-wrap: anywhere; }
  .campo select { max-width: none; }
  .campo, .campo-forn input, .multi > button { width: 100%; max-width: none; }
  .campo input[type="date"] { width: 100%; }
  .datas { width: 100%; } .datas .campo { flex: 1; }
  .filtros-acoes { width: 100%; margin: 0; }
  .painel { padding: 16px 14px; }
  .tabela-wrap { margin: 0 -14px; padding: 0 14px; }
  .col-opc { display: none; }
  .graf { height: 240px; }
  .sync .quando { display: none; }
}
