/* Sistema de Gestão dos Ministérios — aparência sóbria e legível */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1d232b;
  --muted: #5d6673;
  --line: #e2ded5;
  --brand: #1d3557;
  --brand-2: #2b4a75;
  --brand-ink: #ffffff;
  --gold: #a9832f;
  --gold-soft: #f4ecd9;
  --ok: #24724a;   --ok-soft: #e3f2e9;
  --warn: #9a5b00; --warn-soft: #fbefd9;
  --bad: #a3322b;  --bad-soft: #f8e4e2;
  --info: #3d5a80; --info-soft: #e5ecf5;
  --grey-soft: #eceae5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 30, .06), 0 2px 10px rgba(20, 24, 30, .04);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181e; --surface: #1b2129; --surface-2: #1f262f; --ink: #e8e6e1; --muted: #a2a9b3; --line: #2e3640;
    --brand: #8fb0dc; --brand-2: #a9c3e6; --brand-ink: #10161f; --gold: #d4b26a; --gold-soft: #2c2719;
    --ok: #7fd1a4; --ok-soft: #173326; --warn: #f0b860; --warn-soft: #33270f; --bad: #f09a92; --bad-soft: #3a1c1a;
    --info: #9fbbe0; --info-soft: #1d2a3c; --grey-soft: #262d36; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14181e; --surface: #1b2129; --surface-2: #1f262f; --ink: #e8e6e1; --muted: #a2a9b3; --line: #2e3640;
  --brand: #8fb0dc; --brand-2: #a9c3e6; --brand-ink: #10161f; --gold: #d4b26a; --gold-soft: #2c2719;
  --ok: #7fd1a4; --ok-soft: #173326; --warn: #f0b860; --warn-soft: #33270f; --bad: #f09a92; --bad-soft: #3a1c1a;
  --info: #9fbbe0; --info-soft: #1d2a3c; --grey-soft: #262d36; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); -webkit-text-size-adjust: 100%; }
a { color: var(--brand-2); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.sr, .skip:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip:focus { position: fixed; top: 8px; left: 8px; z-index: 99; background: var(--surface); padding: 8px 12px; }

/* Barra superior */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: #1d3557; color: #fff; border-bottom: 3px solid #b8913c; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand strong { display: block; font-family: var(--serif); font-size: 1.15rem; }
.brand span { display: block; font-size: .78rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { display: none; background: transparent; color: #fff; border: 0; padding: 6px; border-radius: 8px; }
.ministry-pick select { background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; padding: 7px 10px; font: inherit; font-size: .9rem; max-width: 46vw; }
.ministry-pick option { color: #111; }

/* Estrutura */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: calc(100vh - 60px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar a { display: block; padding: 9px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active { background: var(--gold-soft); color: var(--ink); box-shadow: inset 3px 0 0 var(--gold); }
.whoami { margin-top: auto; padding: 12px; font-size: .82rem; color: var(--muted); border-top: 1px solid var(--line); }
main { padding: 24px clamp(16px, 3vw, 36px) 60px; min-width: 0; outline: none; }
.loading { color: var(--muted); padding: 40px 0; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head p { margin: 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Cartões e indicadores */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; box-shadow: var(--shadow); display: block; }
a.kpi:hover { border-color: var(--gold); }
.kpi .n { font-family: var(--serif); font-size: 2rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .86rem; }
.kpi.ok .n { color: var(--ok); } .kpi.warn .n { color: var(--warn); } .kpi.bad .n { color: var(--bad); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.notice { border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; font-size: .93rem; }
.notice.warn { background: var(--warn-soft); color: var(--ink); border-left: 4px solid var(--warn); }
.notice.info { background: var(--info-soft); border-left: 4px solid var(--info); }
.notice.bad { background: var(--bad-soft); border-left: 4px solid var(--bad); }

/* Filtros e formulários */
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; align-items: end; margin-bottom: 14px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: .86rem; font-weight: 600; color: var(--muted); }
label.f small { font-weight: 400; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; width: 100%; min-height: 42px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: .92rem; }
.check input { width: auto; min-height: 0; margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 6px 0 0; }
legend { font-weight: 600; padding: 0 6px; }
.hint { font-size: .84rem; color: var(--muted); margin: 2px 0 0; }

button, .btn { font: inherit; font-weight: 600; font-size: .92rem; border-radius: 8px; padding: 9px 14px; min-height: 40px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--brand-2); }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-2); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: .84rem; }
button[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; font-size: 1.1rem; min-height: 0; padding: 4px 8px; }

/* Tabelas */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .sub { display: block; color: var(--muted); font-size: .82rem; }
.empty { padding: 26px; text-align: center; color: var(--muted); }
.group-row td { background: var(--gold-soft); font-weight: 600; font-family: var(--serif); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.b-vigente { background: var(--ok-soft); color: var(--ok); }
.b-avencer { background: var(--warn-soft); color: var(--warn); }
.b-vencido, .b-encerrado { background: var(--bad-soft); color: var(--bad); }
.b-pendente { background: var(--grey-soft); color: var(--muted); }
.b-futuro, .b-sem_mandato { background: var(--info-soft); color: var(--info); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; color: var(--muted); font-size: .9rem; }

/* Histórico */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 3px solid var(--line); padding: 4px 0 14px 16px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 9px; width: 11px; height: 11px; border-radius: 50%; background: var(--surface); border: 2px solid var(--muted); }
.timeline li.s-vigente::before { border-color: var(--ok); background: var(--ok); }
.timeline li.s-vencido::before, .timeline li.s-encerrado::before { border-color: var(--bad); }
.timeline .meta { color: var(--muted); font-size: .88rem; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

/* Modal */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 24px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 22, 33, .45); }
.modal-inner { display: flex; flex-direction: column; max-height: calc(100vh - 24px); }
.modal-inner > header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 8px; }
.modal-inner > header h2 { margin: 0; }
#modalBody { padding: 4px 18px 10px; overflow-y: auto; }
.modal-inner > footer { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.form-error { margin: 0 18px 8px; background: var(--bad-soft); border-left: 4px solid var(--bad); padding: 8px 12px; border-radius: 6px; font-size: .92rem; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 50; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.err { background: var(--bad); color: #fff; }

.report-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: .9rem; margin-bottom: 10px; }
pre.csv-sample { background: var(--surface-2); border: 1px solid var(--line); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: .82rem; }

/* Responsivo */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .menu-btn { display: inline-flex; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: 260px; z-index: 30; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); padding-top: 70px; }
  .sidebar.open { transform: none; }
  .brand span { display: none; }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  h1 { font-size: 1.4rem; }
  /* Tabelas viram cartões no celular */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table.responsive td { border: 0; padding: 3px 10px; }
  table.responsive td[data-l]::before { content: attr(data-l) ": "; color: var(--muted); font-size: .8rem; }
  table.responsive td.num { text-align: left; }
}
@media print {
  .topbar, .sidebar, .actions, .filters, .pager, button { display: none !important; }
  .shell { display: block; } main { padding: 0; }
  .card, .table-wrap { box-shadow: none; border: 0; }
}

/* utilitários (sem estilos inline, por causa da política de segurança CSP) */
[data-u="mt"] { margin-top: 12px; }
[data-u="mt-xs"] { margin-top: 6px; }
[data-u="mb"] { margin-bottom: 10px; }
[data-u="end"] { justify-content: flex-end; }
.filters[data-u="narrow"] { grid-template-columns: minmax(160px, 220px) auto; }
[hidden] { display: none !important; }

/* Entrada / senha */
body.auth-mode .sidebar, body.auth-mode .ministry-pick, body.auth-mode .menu-btn { display: none !important; }
body.auth-mode .shell { grid-template-columns: 1fr; }
.auth-box { max-width: 440px; margin: 6vh auto 0; }
.auth-box form { display: flex; flex-direction: column; gap: 12px; margin: 12px 0; }
.auth-box .form-error { margin: 8px 0 0; }
.linklike { background: none; border: 0; padding: 0; min-height: 0; color: var(--brand-2); text-decoration: underline; font-weight: 500; font-size: inherit; cursor: pointer; }
.who-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.pw-row { display: flex; gap: 6px; }
.pw-row input { flex: 1; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.05em; letter-spacing: .02em; }
