:root {
  --bg: #f7f5ef;
  --surface: #ffffff;
  --surface-2: #f1eee5;
  --ink: #1d2420;
  --muted: #5d665f;
  --line: #e2ddd0;
  --green: #14532d;
  --green-2: #1f7a45;
  --olive: #7c8a3e;
  --red: #b4321f;
  --amber: #a15c07;
  --blue: #1d4f91;
  --ok-bg: #e7f3ea;
  --warn-bg: #fdf3e2;
  --bad-bg: #fbe9e6;
  --info-bg: #e8eef8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 20, .06), 0 4px 16px rgba(20, 30, 20, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Naskh Arabic", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --surface: #1a201c; --surface-2: #222a25; --ink: #e8ece8; --muted: #a2aca5; --line: #2f3833;
    --green: #4fbf7d; --green-2: #6fd197; --olive: #b6c46f; --red: #f0806c; --amber: #f0b45c; --blue: #8fb3ec;
    --ok-bg: #18301f; --warn-bg: #33281a; --bad-bg: #3a1f1a; --info-bg: #1b2638;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--green-2); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
.container { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
main.container { padding-top: 22px; padding-bottom: 40px; min-height: 70vh; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--green); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; margin-right: auto; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand small { opacity: .8; font-size: .75rem; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a, .nav button { color: #fff; text-decoration: none; padding: 7px 11px; border-radius: 8px; font: inherit; background: none; border: 0; cursor: pointer; }
.nav a:hover, .nav button:hover, .nav a.active { background: rgba(255, 255, 255, .14); }
.menu-btn { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }
@media (max-width: 760px) {
  .menu-btn { display: block; }
  .nav { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; background: var(--green); padding: 8px 16px 14px; }
  .nav.open { display: flex; }
  .brand small { display: none; }
}

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.8rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { color: var(--muted); margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.pre { white-space: pre-wrap; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 15px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--green-2); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-2); }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }
label .hint { display: block; font-weight: 400; color: var(--muted); font-size: .85rem; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green-2); outline-offset: 1px; border-color: transparent; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
.filters { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 860px) { .filters { grid-template-columns: 1fr 1fr; } .filters input[type=search] { grid-column: 1 / -1; } }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.open, .badge.eligible { background: var(--ok-bg); color: var(--green-2); }
.badge.upcoming, .badge.likely { background: var(--info-bg); color: var(--blue); }
.badge.closed, .badge.not_eligible { background: var(--bad-bg); color: var(--red); }
.badge.unconfirmed, .badge.unclear { background: var(--warn-bg); color: var(--amber); }
.badge.federal { background: #e9e4f6; color: #4b3a8c; }
.badge.provincial { background: #e3f0f4; color: #23606f; }
.badge.municipal { background: #f4ece1; color: #7a4b16; }
.badge.foundation { background: #f3e5ea; color: #7d2e48; }
@media (prefers-color-scheme: dark) {
  .badge.federal, .badge.provincial, .badge.municipal, .badge.foundation { background: var(--surface-2); color: var(--ink); }
}

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.prog { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 10px; color: inherit; text-decoration: none; box-shadow: var(--shadow); }
.prog:hover { border-color: var(--green-2); }
.prog h3 { margin: 0; }
.prog .meta { color: var(--muted); font-size: .88rem; }
.prog .right { text-align: right; font-size: .88rem; }
.prog .right b { display: block; font-size: 1rem; }
@media (max-width: 600px) { .prog { grid-template-columns: 1fr; } .prog .right { text-align: left; } }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

dl.facts { display: grid; grid-template-columns: 190px 1fr; gap: 8px 16px; margin: 0; }
dl.facts dt { color: var(--muted); font-weight: 600; }
dl.facts dd { margin: 0; white-space: pre-wrap; }
@media (max-width: 600px) { dl.facts { grid-template-columns: 1fr; } dl.facts dd { margin-bottom: 8px; } }

.notice { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid transparent; }
.notice.info { background: var(--info-bg); }
.notice.warn { background: var(--warn-bg); }
.notice.bad { background: var(--bad-bg); }
.notice.ok { background: var(--ok-bg); }

/* auth */
.auth { max-width: 440px; margin: 40px auto; }
.auth .tabs { display: flex; gap: 6px; margin-bottom: 12px; }

/* application builder */
.steps { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.steps span { padding: 6px 12px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: .88rem; }
.steps span.on { background: var(--green); color: #fff; }
.steps span.done { background: var(--ok-bg); color: var(--green-2); }
.q { padding: 12px 0; border-bottom: 1px dashed var(--line); }
.q:last-child { border-bottom: 0; }
.q .why { color: var(--muted); font-size: .85rem; margin: 2px 0 6px; }
.q.followup label::after { content: "Follow-up"; margin-left: 8px; font-size: .7rem; padding: 1px 6px; border-radius: 999px; background: var(--warn-bg); color: var(--amber); vertical-align: middle; }
.score { display: flex; align-items: center; gap: 10px; }
.bar { flex: 1; height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; min-width: 80px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--olive), var(--green-2)); }
.section-edit { margin-bottom: 18px; }
.section-edit h3 { display: flex; align-items: center; gap: 8px; }
.section-edit textarea { min-height: 160px; }
.placeholder-warn { color: var(--amber); font-size: .85rem; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--green-2); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.working { display: flex; gap: 12px; align-items: center; padding: 22px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: 90vw; }
.ideas { margin: 6px 0 0; padding-left: 18px; }
.copy-link { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; word-break: break-all; background: var(--surface-2); padding: 8px; border-radius: 8px; }

.footer { color: var(--muted); font-size: .8rem; padding-bottom: 30px; }

@media print {
  .topbar, .footer, .no-print, .steps, .btn { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .card { border: 0; box-shadow: none; padding: 0; }
  textarea { border: 0; padding: 0; resize: none; height: auto; overflow: visible; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
