:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2330; --muted: #5f6b7a; --line: #dfe3e8;
  --accent: #1f5fae; --accent-soft: #e8f0fb; --warn: #8a5a00; --warn-bg: #fff4d6;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171c; --panel: #1c2027; --text: #e6e9ee; --muted: #9aa4b2; --line: #2d333d;
          --accent: #7fb0f0; --accent-soft: #1f2a3a; --warn: #f0c060; --warn-bg: #3a2f14; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
main { padding: 16px 24px 48px; max-width: 1600px; margin: 0 auto; }
main.wide { max-width: none; }  /* grids: every column on a widescreen monitor */
h1 { font-size: 20px; margin: 8px 0 16px; }

.top { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.spacer { flex: 1; }
.who { color: var(--muted); }
.inline { display: inline; }
button { font: inherit; padding: 6px 14px; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 6px; cursor: pointer; }
button.link { background: none; border: none; color: var(--accent); padding: 0; }
.btn { border: 1px solid var(--line); background: var(--panel); padding: 5px 12px; border-radius: 6px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 10px; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }

.cards { list-style: none; padding: 0; display: flex; gap: 16px; flex-wrap: wrap; }
.cards a { display: flex; flex-direction: column; gap: 4px; padding: 20px 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; min-width: 200px; }
.cards strong { font-size: 18px; color: var(--text); }

.login { max-width: 340px; margin: 48px auto; background: var(--panel); padding: 24px; border: 1px solid var(--line); border-radius: 10px; display: grid; gap: 12px; }
.login label { display: grid; gap: 4px; color: var(--muted); }
.login input { font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); }
.screen-form { margin: 16px 0; }  /* screens.py forms: same card as the login, aligned with the page */
.screen-form h1 { margin: 0; }
button:disabled { opacity: .5; cursor: not-allowed; }
.msg { background: var(--warn-bg); color: var(--warn); padding: 8px; border-radius: 6px; margin: 0; }
.caption { margin: 0; color: var(--muted); }
td.alerta { color: #d32f2f; font-weight: 600; }
td.destaque { background: rgba(51, 255, 153, 0.25); }
.hint { color: var(--muted); font-size: 12px; margin: 0; }

.tree { list-style: none; padding-left: 16px; margin: 4px 0; }
.tree.d0 { padding-left: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.tree.d0 > li { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.tree li { margin: 3px 0; }
.tree summary { cursor: pointer; font-weight: 600; }
.tree .d1 summary, .tree .d2 summary { font-weight: 500; }
.soon { color: var(--muted); }
.soon em { font-size: 11px; font-style: normal; border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; margin-left: 4px; }

.crumbs { color: var(--muted); margin-bottom: 4px; }
.head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.meta { color: var(--muted); }
.toolbar { display: flex; align-items: center; gap: 12px; margin: 8px 0 12px; flex-wrap: wrap; }
.toolbar select { font: inherit; padding: 4px; }
.cols { position: relative; }
.cols summary { cursor: pointer; border: 1px solid var(--line); background: var(--panel); padding: 5px 12px; border-radius: 6px; list-style: none; }
.cols form { position: absolute; z-index: 5; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; gap: 4px; max-height: 60vh; overflow: auto; min-width: 260px; box-shadow: 0 6px 24px rgba(0,0,0,.12); }

/* the table scrolls inside its box, so the header (and the Resumo's first column) stay in view */
.scroll { overflow: auto; max-height: calc(100vh - 96px); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table.grid { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.grid th, .grid td { padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid th { position: sticky; top: 0; z-index: 2; background: var(--accent-soft); text-align: left; }
/* rows of the grid: compact, and long text wraps (as in the old BIS) instead of pushing columns off screen */
table.rows { font-size: 13px; }
table.rows th, table.rows td { padding: 5px 8px; vertical-align: top; }
table.rows th { vertical-align: bottom; }
table.rows th.left, table.rows td.left { white-space: normal; overflow-wrap: break-word; }
.stick { position: sticky; left: 8px; display: inline-block; }  /* break label stays visible when scrolled sideways */
.grid th a { color: var(--text); }
.grid tbody tr:hover { background: var(--accent-soft); }
.right { text-align: right !important; } .center { text-align: center !important; }
.empty { text-align: center; color: var(--muted); padding: 24px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 12px; }
.reasons { color: var(--muted); }

@media (max-width: 640px) { main { padding: 12px 16px 32px; } .top { padding: 10px 16px; } }

.filters { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; margin: 8px 0 12px; }
.filters summary { cursor: pointer; font-weight: 600; }
.filters .count { font-weight: 400; font-size: 12px; color: var(--accent); margin-left: 6px; }
.filters form { display: grid; gap: 12px; margin-top: 10px; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 10px 16px; }
.ffield { display: grid; gap: 4px; align-content: start; }
.flabel { color: var(--muted); font-size: 12px; }
.fop { font-size: 12px; color: var(--muted); }
.range { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.range input { flex: 1 1 130px; min-width: 0; }
.filters input, .filters select { font: inherit; padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); }
.quick { display: grid; gap: 4px; color: var(--muted); font-size: 12px; max-width: 420px; }
.factions { display: flex; gap: 8px; align-items: center; }
.ffield.wide { grid-column: 1 / -1; }
.dual { display: flex; gap: 8px; align-items: center; }
.dual select { flex: 1 1 0; min-width: 0; }
.dual-btns { display: grid; gap: 4px; }
.dual-btns button { padding: 0 10px; font-size: 16px; line-height: 1.5; }
@media (max-width: 640px) { .dual { flex-direction: column; align-items: stretch; } .dual select { flex: none; } .dual-btns { grid-auto-flow: column; justify-content: center; } }

.crumbs .back { margin-left: 12px; }
.drillp { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12px; margin: 0 0 8px; }
a.drill { text-decoration: underline dotted; }
tr.grp td { background: var(--accent-soft); font-weight: 600; padding-top: 10px; }
tr.grp.l1 td { padding-left: 24px; font-weight: 500; }
tr.sub td { font-weight: 600; border-bottom: 2px solid var(--line); }
tr.grand td { font-weight: 700; border-top: 2px solid var(--text); background: var(--accent-soft); }
tr.sub-label td { font-weight: 600; font-size: 12px; color: var(--muted); border-bottom: none; padding-bottom: 0; }
tr.grand-label td { font-weight: 700; background: var(--accent-soft); border-top: 2px solid var(--text); border-bottom: none; padding-bottom: 0; }
tr.grand-label + tr.grand td { border-top: none; }

table.summary td:first-child, table.summary th:first-child { position: sticky; left: 0; background: var(--panel); }
table.summary th:first-child { background: var(--accent-soft); }
table.summary tr.s0 td { font-weight: 600; background: var(--accent-soft); }
table.summary tr.s0 td:first-child { background: var(--accent-soft); }
table.summary tr.s1 td:first-child { padding-left: 26px; font-weight: 500; }
table.summary tr.s2 td:first-child { padding-left: 42px; }
table.summary tr.s3 td:first-child { padding-left: 58px; }
table.summary tr.grand td:first-child { background: var(--accent-soft); }
table.summary thead tr.labels th { top: 31px; }
table.summary th:first-child { z-index: 3; }
table.summary a.line { color: inherit; }
table.summary a.line:hover { color: var(--accent); text-decoration: underline; }
.linep { display: inline-flex; gap: 6px 14px; flex-wrap: wrap; align-items: baseline; font-size: 12px; color: var(--muted);
         background: var(--accent-soft); border-radius: 6px; padding: 5px 10px; }
.linep strong { color: var(--text); font-weight: 600; }

/* loading (loading.js): bar on top, current results dimmed while the next page comes, busy buttons, notices */
.busy-bar { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 50; overflow: hidden; background: var(--accent-soft); }
.busy-bar::before { content: ""; position: absolute; top: 0; bottom: 0; width: 30%; background: var(--accent); animation: busy-slide 1.1s ease-in-out infinite; }
@keyframes busy-slide { from { left: -30%; } to { left: 100%; } }
body.is-loading { cursor: progress; }
body.is-loading main .scroll, body.is-loading main .pager, body.is-loading main .toolbar,
body.is-loading main .tree, body.is-loading main .crumbs { opacity: .5; pointer-events: none; transition: opacity .2s; }
.is-busy { cursor: progress; pointer-events: none; display: inline-flex; align-items: center; gap: 6px; }
.is-busy::before { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; flex: none; }
button.is-busy { opacity: .85; }
@keyframes spin { to { transform: rotate(360deg); } }
.is-disabled { opacity: .5; pointer-events: none; }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; background: var(--panel); color: var(--text);
         border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.14); }
.toast span { flex: 1; }
.toast.ok { border-left-color: #2e7d32; }
.toast.warn { border-left-color: var(--warn); }
.toast.error { border-left-color: #d32f2f; }
.toast button.link { white-space: nowrap; }
.toast button[aria-label="Fechar aviso"] { font-size: 16px; line-height: 1; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .busy-bar::before { animation: none; left: 0; width: 100%; opacity: .6; }
  .is-busy::before { animation-duration: 2s; }
}
