/* Tubexpy — estilos */
:root {
  --bg: #f4f6f9; --painel: #ffffff; --borda: #d9dee6; --texto: #1d2733; --suave: #5b6878;
  --pri: #0b5cad; --pri-esc: #08467f; --pri-claro: #e6f0fb;
  --ok: #1a7f37; --ok-bg: #e7f5ec; --nok: #b42318; --nok-bg: #fdecea;
  --atn: #9a6700; --atn-bg: #fff6dd; --info: #0b5cad; --info-bg: #e6f0fb;
  --sec-bg: #eef2f7; --sombra: 0 1px 3px rgba(16, 24, 40, .08);
  --raio: 8px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d; --painel: #1a212b; --borda: #2e3846; --texto: #e4e9f0; --suave: #9aa6b5;
    --pri: #4c9df0; --pri-esc: #7db8f5; --pri-claro: #1c2b3d;
    --ok: #4ac26b; --ok-bg: #16301f; --nok: #ff7b72; --nok-bg: #3a1d1b;
    --atn: #e3b341; --atn-bg: #352a10; --info: #79b8ff; --info-bg: #1c2b3d;
    --sec-bg: #222b37; --sombra: none;
  }
  /* gráficos e espelho mantêm fundo branco para leitura */
  svg.grafico { border-radius: var(--raio); }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--texto);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
button, input, select { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ topo */
.topo {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 18px; background: var(--painel); border-bottom: 1px solid var(--borda); box-shadow: var(--sombra);
}
.marca { display: flex; align-items: center; gap: 10px; margin-right: auto; text-decoration: none; color: inherit; }
.marca img { width: 34px; height: 34px; }
.marca b { font-size: 19px; letter-spacing: .2px; }
.marca small { display: block; color: var(--suave); font-size: 12px; }
.acoes { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.btn {
  border: 1px solid var(--borda); background: var(--painel); border-radius: 6px;
  padding: 6px 11px; cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--texto); display: inline-flex; align-items: center; gap: 5px;
}
.btn:hover { border-color: var(--pri); color: var(--pri); }
.btn:focus-visible, .tip:focus-visible, select:focus-visible, input:focus-visible, tr[tabindex]:focus-visible {
  outline: 2px solid var(--pri); outline-offset: 1px;
}
.btn.pri { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.pri:hover { background: var(--pri-esc); color: #fff; }
.btn.lang { font-weight: 700; min-width: 44px; justify-content: center; }
.btn.mini { padding: 2px 8px; font-size: 12px; }

/* ------------------------------------------------------------------ layout */
main.grade {
  display: grid; grid-template-columns: minmax(320px, 400px) 1fr; gap: 16px;
  padding: 16px 18px; max-width: 1600px; margin: 0 auto;
}
@media (max-width: 960px) { main.grade { grid-template-columns: 1fr; padding: 10px; } }
.cartao { background: var(--painel); border: 1px solid var(--borda); border-radius: var(--raio); box-shadow: var(--sombra); }
.cartao > h2 { font-size: 15px; margin: 0; padding: 10px 14px; border-bottom: 1px solid var(--borda); }

aside.param { align-self: start; position: sticky; top: 70px; max-height: calc(100vh - 86px); display: flex; flex-direction: column; }
@media (max-width: 960px) { aside.param { position: static; max-height: none; } }

.abas { display: flex; border-bottom: 1px solid var(--borda); overflow-x: auto; }
.abas button {
  flex: 1 0 auto; border: 0; background: none; padding: 9px 12px; cursor: pointer; color: var(--suave);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.abas button.ativo { color: var(--pri); border-bottom-color: var(--pri); font-weight: 600; }
.abas button:hover { color: var(--texto); }

#pcorpo { padding: 6px 14px 14px; overflow-y: auto; }
h4.sub { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--suave); }
.campo { display: block; margin: 7px 0; }
.campo .lab { display: flex; align-items: center; gap: 5px; font-size: 13px; margin-bottom: 3px; }
.campo .linha { display: flex; align-items: center; gap: 8px; }
.campo input[type=number], .campo select {
  border: 1px solid var(--borda); border-radius: 6px; padding: 5px 7px; background: var(--bg); min-width: 0;
}
.campo select { width: 100%; }
.campo input[type=number] { width: 110px; text-align: right; }
.campo input[type=range] { flex: 1; min-width: 60px; accent-color: var(--pri); }
.campo input:disabled { opacity: .6; }
.campo .un { color: var(--suave); font-size: 12px; min-width: 62px; }
.campo.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.campo.chk input { accent-color: var(--pri); }
p.fonte { margin: 2px 0 8px; font-size: 12px; color: var(--suave); font-style: italic; }

.tip {
  display: inline-flex; align-items: center; justify-content: center; position: relative;
  width: 16px; height: 16px; border-radius: 50%; font-size: 11px; font-weight: 700;
  background: var(--pri-claro); color: var(--pri); cursor: help; flex: none;
}
.campo .linha .tip::after { left: auto; right: 0; transform: none; }
.tip::after {
  content: attr(data-tip); position: absolute; left: 50%; top: 22px; transform: translateX(-50%);
  width: max-content; max-width: 280px; padding: 8px 10px; border-radius: 6px; z-index: 30;
  background: #1d2733; color: #fff; font-weight: 400; font-size: 12px; line-height: 1.4; white-space: normal;
  opacity: 0; pointer-events: none; transition: opacity .12s;
}
.tip:hover::after, .tip:focus::after, .tip.aberto::after { opacity: 1; }

/* ------------------------------------------------------------------ resultados */
section.result { min-width: 0; }
.cab-res { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--borda); flex-wrap: wrap; }
.cab-res h2 { margin: 0; font-size: 15px; margin-right: auto; }
.status-chip { padding: 3px 10px; border-radius: 99px; font-weight: 600; font-size: 13px; }
.status-chip.ok { background: var(--ok-bg); color: var(--ok); }
.status-chip.nok { background: var(--nok-bg); color: var(--nok); }
#avisos { padding: 10px 14px 0; }
#rcorpo { padding: 12px 14px 18px; overflow-x: auto; }

.aviso { padding: 7px 10px; border-radius: 6px; margin: 0 0 6px; font-size: 13px; border-left: 4px solid; }
.aviso.ok { background: var(--ok-bg); border-color: var(--ok); }
.aviso.erro { background: var(--nok-bg); border-color: var(--nok); }
.aviso.atencao { background: var(--atn-bg); border-color: var(--atn); }
.aviso.info { background: var(--info-bg); border-color: var(--info); }
.erro-box { padding: 14px; border-radius: 6px; background: var(--nok-bg); color: var(--nok); border: 1px solid var(--nok); }
.status { font-weight: 700; }
.status.ok { color: var(--ok); }
.status.nok { color: var(--nok); }

table.folha { border-collapse: collapse; width: 100%; max-width: 900px; font-size: 13px; }
table.folha td, table.folha th { padding: 5px 9px; border-bottom: 1px solid var(--borda); text-align: left; vertical-align: top; }
table.folha td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.folha tr.sec th { background: var(--sec-bg); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; padding-top: 8px; }

.memoria { max-width: 1000px; }
.memoria h3 { font-size: 15px; margin: 22px 0 6px; padding-bottom: 4px; border-bottom: 2px solid var(--pri-claro); color: var(--pri); }
.memoria p.nota { color: var(--suave); font-size: 13px; margin: 4px 0 8px; }
.memoria p.mem-cab { font-weight: 600; margin: 10px 0 4px; }
table.mem { border-collapse: collapse; width: 100%; font-size: 13px; margin-bottom: 6px; }
table.mem td { padding: 6px 8px; border-bottom: 1px solid var(--borda); vertical-align: top; }
table.mem td.rot { width: 28%; color: var(--suave); }
table.mem td.form { font-family: "Cambria Math", "STIX Two Math", Georgia, serif; font-size: 14px; }
table.mem .subst { color: var(--suave); font-size: 13px; }
table.mem td.res { width: 22%; white-space: nowrap; text-align: right; }

.alt-top { display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap; margin-bottom: 8px; }
.alt-top p { margin: 0; color: var(--suave); }
.tabela-rolagem { overflow-x: auto; border: 1px solid var(--borda); border-radius: 6px; }
table.alt { border-collapse: collapse; font-size: 12.5px; width: 100%; }
table.alt th { position: sticky; top: 0; background: var(--sec-bg); padding: 6px 7px; text-align: right; white-space: nowrap; }
table.alt td { padding: 5px 7px; text-align: right; border-top: 1px solid var(--borda); white-space: nowrap; font-variant-numeric: tabular-nums; }
table.alt td:last-child, table.alt th:last-child { text-align: left; }
table.alt tr[tabindex] { cursor: pointer; }
table.alt tr.ok td:last-child { color: var(--ok); }
table.alt tr.nok td:last-child { color: var(--nok); }
table.alt tr.sem { color: var(--suave); }
table.alt tr:hover td { background: var(--pri-claro); }
table.alt tr.ativo td { background: var(--pri-claro); font-weight: 600; }
table.alt tr.melhor td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
p.resumo { margin: 10px 0 0; font-weight: 600; }

.graficos { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 14px; }
@media (max-width: 520px) { .graficos { grid-template-columns: 1fr; } }
.gcard { margin: 0; border: 1px solid var(--borda); border-radius: var(--raio); overflow: hidden; background: #fff; }
.gcard figcaption { padding: 6px 8px; text-align: right; background: var(--painel); border-top: 1px solid var(--borda); }
svg.grafico { display: block; width: 100%; height: auto; }

/* ------------------------------------------------------------------ rodapé e diálogo */
footer.rodape { text-align: center; color: var(--suave); font-size: 12px; padding: 10px 18px 24px; }
footer.rodape a { color: var(--pri); }
dialog#sobre {
  max-width: 620px; width: calc(100% - 24px); border: 1px solid var(--borda); border-radius: 10px;
  background: var(--painel); color: var(--texto); padding: 0;
}
dialog#sobre::backdrop { background: rgba(0, 0, 0, .45); }
dialog#sobre header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--borda); }
dialog#sobre header h2 { margin: 0; font-size: 17px; }
#sobre-corpo { padding: 4px 16px 14px; font-size: 13.5px; }
#sobre-corpo .pequeno { color: var(--suave); font-size: 12px; }
.oculto { display: none !important; }
#relatorio { display: none; }

/* ------------------------------------------------------------------ impressão (relatório PDF) */
@media print {
  @page { size: A4; margin: 14mm 12mm; }
  :root { --bg: #fff; --painel: #fff; --texto: #000; --suave: #444; --borda: #bbb; --sec-bg: #eee; --pri: #0b5cad; --pri-claro: #e6f0fb; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .topo, main.grade, footer.rodape, dialog { display: none !important; }
  #relatorio { display: block; }
  .rel-cab { border-bottom: 2px solid #0b5cad; margin-bottom: 8px; }
  .rel-cab h1 { margin: 0; font-size: 20pt; color: #0b5cad; }
  .rel-cab p { margin: 2px 0 6px; font-size: 9pt; color: #444; }
  #relatorio h2 { font-size: 13pt; margin: 14px 0 6px; color: #0b5cad; }
  .quebra { break-before: page; }
  .rel-graf svg { width: 100%; max-width: 170mm; height: auto; display: block; margin: 0 auto 8mm; break-inside: avoid; }
  table.folha { max-width: none; font-size: 9.5pt; }
  table.folha tr, table.mem tr { break-inside: avoid; }
  .aviso { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.folha tr.sec th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rel-rodape { margin-top: 16px; font-size: 8.5pt; color: #555; border-top: 1px solid #bbb; padding-top: 6px; }
}
