:root {
  --green: #1f4d3a; --green-2: #2e6b52; --gold: #c8a24a; --gold-2: #b8912f;
  --bg: #f7f5ef; --card: #ffffff; --ink: #23271f; --muted: #6b7167; --line: #e3e0d6;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
.topbar { display: flex; justify-content: space-between; align-items: center;
  background: var(--green); color: #fff; padding: 12px 22px; }
.brand { font-weight: 700; letter-spacing: .2px; }
.topbar nav a { color: #eaf1ec; text-decoration: none; margin-left: 18px; opacity: .9; }
.topbar nav a:hover { opacity: 1; border-bottom: 2px solid var(--gold); }
main { max-width: 1080px; margin: 22px auto; padding: 0 18px; }
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 24px; }

.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 16px; min-width: 120px; display: flex; flex-direction: column; }
.stat .n { font-size: 26px; font-weight: 700; color: var(--green); }
.stat .l { font-size: 12px; color: var(--muted); }
.stat.accent { border-color: var(--gold); }
.stat.accent .n { color: var(--gold-2); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px 22px; margin-bottom: 18px; }
.card h2 { margin: 0 0 14px; font-size: 18px; color: var(--green); }
.login { max-width: 420px; margin: 60px auto; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.filters label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 5px; }
.filters input, .filters select { padding: 9px 10px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; color: var(--ink); background: #fff; }
.filters input:focus, .filters select:focus { outline: 2px solid var(--green-2); border-color: var(--green-2); }
.actions { grid-column: 1 / -1; display: flex; gap: 12px; align-items: center; margin-top: 4px; }
button { background: var(--green); color: #fff; border: 0; border-radius: 8px;
  padding: 10px 20px; font-size: 15px; font-weight: 600; cursor: pointer; }
button:hover { background: var(--green-2); }
button:disabled { opacity: .55; cursor: progress; }
.btn-ghost { color: var(--green); text-decoration: none; border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 16px; font-weight: 600; }
.btn-ghost:hover { border-color: var(--green); }
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
.error { color: #a3372e; } .ok { color: var(--green-2); font-weight: 600; }

.badge { font-size: 12px; padding: 2px 10px; border-radius: 999px; background: #eef2ea; color: var(--green); }
.badge.run { background: #fff4d9; color: var(--gold-2); }
.badge.done { background: #e4f0e7; color: var(--green-2); }
.badge.err { background: #fbe6e2; color: #a3372e; }

.log { background: #12281f; color: #cfe4d6; border-radius: 8px; padding: 12px 14px;
  font: 12.5px/1.55 "SF Mono", Menlo, Consolas, monospace; max-height: 300px; overflow: auto; white-space: pre-wrap; }
.log .k { color: var(--gold); } .log .ok { color: #7fd18f; } .log .dup { color: #f0c674; } .log .err { color: #f2907f; }
.summary { margin-top: 12px; padding: 12px 14px; background: #f2f5ef; border-radius: 8px; font-size: 14px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
td .tier { font-size: 11px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.tier.A { background: #e4f0e7; color: var(--green-2); }
.tier.B { background: #fff4d9; color: var(--gold-2); }
.tier.Adicional { background: #eee; color: var(--muted); }
.tier.soon { background: #fdeecf; color: #9a6b12; }
.tier.closed { background: #efe7e4; color: #8a5a4e; }
td a { color: var(--green-2); }

/* ---- grants table (paginated, click-to-open) ---- */
.gtable { table-layout: fixed; width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.gtable col.c-status { width: 118px; }
.gtable col.c-funder { width: 22%; }
.gtable col.c-amount { width: 130px; }
.gtable col.c-deadline { width: 96px; }
.gtable th, .gtable td { padding: 11px 14px; vertical-align: middle; border-bottom: 1px solid var(--line);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gtable thead th { background: #f4f5f0; }
.gtable tbody tr.grow { cursor: pointer; transition: background .12s; }
.gtable tbody tr.grow:hover { background: #f2f6f1; }
.gtable tbody tr.grow:focus { outline: 2px solid var(--green-2); outline-offset: -2px; }
.gtable tbody tr:last-child td { border-bottom: 0; }
.gtable .g-name { font-weight: 600; color: var(--ink); max-width: 260px; }
.gtable .g-funder, .gtable .g-region { color: var(--muted); max-width: 190px; }
.gtable .g-name, .gtable .g-funder, .gtable .g-region {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gtable .g-amount, .gtable .g-deadline { white-space: nowrap; }
.gtable .dim { color: var(--muted); }

.pager { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 18px 0; }
.pager button { background: #fff; color: var(--green); border: 1px solid var(--line); padding: 7px 16px; border-radius: 8px; font-size: 13.5px; }
.pager button:hover:not(:disabled) { background: #fff; border-color: var(--green); }
.pager button:disabled { opacity: .38; cursor: default; }
.pg-info { color: var(--muted); font-size: 13px; }

/* ---- detail modal ---- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20,25,20,.5); }
.modal-box { position: relative; z-index: 1; width: 100%; max-width: 560px; margin: 6vh 16px; max-height: 88vh;
  overflow: auto; animation: modalin .2s ease both; }
#modal-body .gcard { box-shadow: 0 14px 48px rgba(0,0,0,.24); border-radius: 14px; }
#modal-body .gcard-top { padding-right: 34px; }  /* clear the modal ✕ button */
.modal-x { position: absolute; top: 12px; right: 12px; z-index: 2; width: 30px; height: 30px; padding: 0;
  border-radius: 999px; background: #fff; color: var(--muted); border: 1px solid var(--line); font-size: 14px; line-height: 1; }
.modal-x:hover { background: #f2f2ee; color: var(--ink); }
@keyframes modalin { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---- user guide (Help page) ---- */
.help { max-width: 860px; margin: 0 auto; }
.help-hero { background: linear-gradient(135deg, var(--green), var(--green-2)); color: #fff;
  border-radius: 14px; padding: 26px 30px; margin-bottom: 22px; }
.help-hero h1 { margin: 0 0 8px; font-size: 24px; }
.help-hero p { margin: 0; opacity: .92; line-height: 1.6; max-width: 62ch; }
.help-sec { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 22px 26px;
  margin-bottom: 18px; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.help-sec h2 { display: flex; align-items: center; gap: 12px; margin: 0 0 14px; font-size: 18px; color: var(--green); }
.step-n { flex: 0 0 auto; width: 28px; height: 28px; border-radius: 999px; background: var(--gold); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700; }
.help-sec p { line-height: 1.6; color: var(--ink); }
.help-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-top: 14px; }
.help-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: #fbfbf8; }
.help-card.accent { border-color: var(--gold); background: #fffdf6; }
.help-card p { margin: 8px 0 0; font-size: 13.5px; line-height: 1.5; color: var(--muted); }
.help-card .tier { margin-right: 5px; font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.help-table { table-layout: auto; }
.help-table th, .help-table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 13.5px; }
.help-table thead th { background: #f4f5f0; color: var(--muted); font-weight: 600; }
.help-table code, .help p code, .help-list code { background: #eef2ea; color: var(--green-2); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }
.help-list { margin: 10px 0 0; padding-left: 0; list-style: none; }
.help-list li { padding: 7px 0; line-height: 1.6; border-bottom: 1px solid #f0efe8; }
.help-list li:last-child { border-bottom: 0; }
.help-list.plain li { padding: 5px 0 5px 20px; position: relative; border-bottom: 0; }
.help-list.plain li::before { content: "→"; position: absolute; left: 0; color: var(--gold-2); font-weight: 700; }
.help-list .verif, .help-list .tier { margin-right: 6px; }
.callout { background: #eef5ef; border-left: 4px solid var(--green-2); border-radius: 8px; padding: 12px 16px; margin-top: 14px; }
.help-live { background: #fffdf6; border: 1px dashed var(--gold); border-radius: 8px; padding: 12px 16px; margin-top: 14px; }
.help-sec.tips { background: #fbfaf5; }

/* ---- grants browse view + cards ---- */
a.stat { text-decoration: none; color: inherit; transition: transform .08s, box-shadow .12s; }
a.stat:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(31,77,58,.12); border-color: var(--green-2); }

.back { display: inline-block; color: var(--green-2); text-decoration: none; margin-bottom: 10px; font-size: 14px; }
.back:hover { text-decoration: underline; }
.grants-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.grants-head h1 { margin: 0; color: var(--green); font-size: 22px; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.head-actions { display: flex; gap: 10px; }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tab { text-decoration: none; color: var(--muted); background: #fff; border: 1px solid var(--line);
  border-radius: 999px; padding: 7px 15px; font-size: 13.5px; font-weight: 600; }
.tab:hover { border-color: var(--green-2); color: var(--green); }
.tab.on { background: var(--green); color: #fff; border-color: var(--green); }
.tab.archive { color: #8a5a4e; }
.tab.archive.on { background: #8a5a4e; color: #fff; border-color: #8a5a4e; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.gcard { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--muted);
  border-radius: 12px; padding: 16px 18px; display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.gcard.A { border-left-color: var(--green-2); }
.gcard.B { border-left-color: var(--gold); }
.gcard.Adicional { border-left-color: #c7c9c1; }
.gcard.closed { border-left-color: #b79c93; background: #faf8f6; opacity: .82; }
.gcard.closed h3 { color: var(--muted); }
.closed-note { font-size: 12.5px; color: #8a5a4e; margin: 4px 0 0; line-height: 1.5; }
.gcard-top { display: flex; justify-content: space-between; align-items: center; }
.gcard h3 { margin: 2px 0 0; font-size: 16px; line-height: 1.35; color: var(--ink); }
.gcard .funder { color: var(--muted); font-size: 13px; }
.verif { font-size: 10.5px; font-weight: 700; letter-spacing: .4px; padding: 2px 8px; border-radius: 999px; }
.verif.YES { background: #e4f0e7; color: var(--green-2); }
.verif.PARTIAL { background: #fff4d9; color: var(--gold-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.chip { background: #f4f5f0; border: 1px solid var(--line); border-radius: 8px; padding: 3px 9px; font-size: 12px; color: var(--ink); }
.elig { font-size: 12.5px; color: var(--muted); margin: 4px 0 0; line-height: 1.5; }
.elig b { color: var(--ink); }
.notes { font-size: 12.5px; color: var(--muted); }
.notes summary { cursor: pointer; color: var(--green-2); font-weight: 600; }
.notes p { margin: 6px 0 0; line-height: 1.5; }
.go { margin-top: auto; padding-top: 6px; color: var(--green); font-weight: 600; text-decoration: none; font-size: 13.5px; }
.go:hover { text-decoration: underline; }

.foot .build { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); opacity: .7; }

/* ---- live search: progress + animations ---- */
.progress { height: 7px; background: #e6e9e1; border-radius: 999px; overflow: hidden; margin: 4px 0 12px; }
.progress .bar { height: 100%; width: 38%; border-radius: 999px;
  background: linear-gradient(90deg, var(--green-2), var(--gold)); animation: sweep 1.15s ease-in-out infinite; }
@keyframes sweep { 0% { margin-left: -38%; } 100% { margin-left: 100%; } }
.progress.done .bar { animation: none; width: 100%; margin-left: 0; background: var(--green-2); }
.run-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.found-chip { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: var(--green); }
.found-chip .cnt { background: var(--gold); color: #fff; border-radius: 999px; padding: 2px 11px; font-size: 15px; min-width: 26px; text-align: center; display: inline-block; }
.found-chip .cnt.pop { animation: pop .45s ease; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.45); } 100% { transform: scale(1); } }
.log-wrap { margin-top: 4px; }
.log-wrap summary { cursor: pointer; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.log-wrap[open] summary { margin-bottom: 8px; }
.gcard.enter { animation: cardin .45s ease both, glow 1.5s ease-out both; }
@keyframes cardin { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes glow { 0% { box-shadow: 0 0 0 3px rgba(200,162,74,.75); } 100% { box-shadow: 0 1px 3px rgba(0,0,0,.04); } }

.run-right { display: flex; align-items: center; gap: 12px; }
.btn-stop { background: #a3372e; color: #fff; border: 0; border-radius: 8px; padding: 6px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.btn-stop:hover { background: #8f2f27; }
.btn-stop:disabled { opacity: .6; cursor: progress; }
