/* Farm For the Future Budget System — colours follow the SRS mock-ups (dark farm green). */
:root {
    --green-900: #1d4535;
    --green-800: #245a44;
    --green-700: #2f6f54;
    --green-100: #dbe8df;
    --green-50: #eef5f0;
    --ink: #1f2a24;
    --muted: #5f6d65;
    --line: #d5ded8;
    --bg: #f5f7f5;
    --card: #ffffff;
    --calc: #fff6d6;        /* system-calculated cells (yellow in Figure 4) */
    --edit: #2f6fd0;        /* editable cells (blue outline in Figure 3) */
    --red: #b3261e;
    --red-bg: #fdecea;
    --amber: #9a6700;
    --amber-bg: #fff4d6;
    --ok: #1e6b3a;
    --ok-bg: #e3f3e8;
    --radius: 8px;
}

* { box-sizing: border-box; }
html { font-size: 14px; }
body { margin: 0; font-family: "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); line-height: 1.45; }
a { color: var(--green-700); }
h1 { font-size: 1.45rem; margin: 0; color: var(--green-900); }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; color: var(--green-900); }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
small, .muted { color: var(--muted); }

/* Shell */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; height: 52px; padding: 0 16px; background: var(--green-900); color: #fff; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; letter-spacing: .02em; }
.brand span { font-weight: 400; opacity: .8; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-chip { color: #fff; text-decoration: none; display: flex; flex-direction: column; line-height: 1.15; text-align: right; }
.user-chip small { color: #cfe2d6; font-size: .75rem; }
.btn-link { background: none; border: 0; color: #cfe2d6; cursor: pointer; font: inherit; text-decoration: underline; }
.nav-toggle { display: none; background: none; border: 0; color: #fff; font-size: 1.3rem; cursor: pointer; }
.shell { display: flex; min-height: calc(100vh - 52px); }
.sidebar { width: 220px; flex: 0 0 220px; background: #fff; border-right: 1px solid var(--line); padding: 12px 0; }
.nav-group { font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--green-900); background: var(--green-100); border-left: 3px solid var(--green-700); padding: 7px 15px; margin-top: 10px; }
.nav-group:first-child { margin-top: 0; }
.nav-group-no { color: var(--green-700); }
.nav-link { display: block; padding: 7px 18px; color: var(--ink); text-decoration: none; border-left: 3px solid transparent; }
.nav-link:hover { background: var(--green-50); }
.nav-link.active { background: var(--green-50); border-left-color: var(--green-700); font-weight: 600; color: var(--green-900); }
.nav-foot { font-size: .72rem; color: var(--muted); padding: 24px 18px; }
.main { flex: 1; min-width: 0; padding: 20px 24px 48px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 2px; }
.crumbs a { color: var(--muted); }

/* Cards, KPIs */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .label { font-size: .78rem; color: var(--muted); }
.kpi .value { font-size: 1.35rem; font-weight: 700; color: var(--green-900); font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .78rem; color: var(--muted); }
.kpi.accent { border-color: var(--green-700); border-width: 2px; }
.kpis.inset { margin-bottom: 12px; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); }
.kpis.inset .kpi { background: #fafcfa; }

/* Dashboard */
.dash-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.dash-bar select { width: auto; }
.section-title { margin: 8px 0 10px; font-size: 1rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.action-card { border-left: 4px solid #d9a400; }
.action-list { list-style: none; margin: 0; padding: 0; }
.action-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.action-list li:first-child { border-top: 0; padding-top: 0; }
.action-list .txt { flex: 1; }
.action-list .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; background: #d9a400; }
.action-list li.bad .dot { background: var(--red); }
.action-list li.info .dot { background: var(--green-700); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 10px; margin-top: 14px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; }
.stat:hover { border-color: var(--green-700); background: var(--green-50); }
.stat .label { font-size: .78rem; color: var(--muted); }
.stat .value { font-size: 1.2rem; font-weight: 700; color: var(--green-900); font-variant-numeric: tabular-nums; }
.stat .value.neg { color: var(--red); }
.stat .value.warnc { color: var(--amber); }
.stat .sub { font-size: .78rem; color: var(--muted); }

/* Utilisation meter: actual (solid) then committed (light) against budget */
.meter-wrap { display: flex; align-items: center; gap: 8px; }
.meter { flex: 1; display: flex; height: 10px; min-width: 60px; border-radius: 999px; background: #e7ece9; overflow: hidden; }
.meter span { display: block; height: 100%; }
.meter .actual { background: var(--green-700); }
.meter .committed { background: #8fbfa3; }
.meter.warn .actual { background: #c98a00; }
.meter.warn .committed { background: #eccb7a; }
.meter.bad .actual { background: var(--red); }
.meter.bad .committed { background: #e79a95; }
.meter-pct { font-size: .8rem; font-weight: 600; min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ok); }
.meter-pct.warn { color: var(--amber); }
.meter-pct.bad { color: var(--red); }
.meter-legend { display: flex; align-items: center; gap: 6px; font-size: .75rem; color: var(--muted); margin-top: 6px; }
.meter-legend .k { width: 10px; height: 10px; border-radius: 2px; margin-left: 8px; }
.meter-legend .k:first-child { margin-left: 0; }
.meter-legend .k.actual { background: var(--green-700); }
.meter-legend .k.committed { background: #8fbfa3; }
.meter-legend .k.free { background: #e7ece9; }
@media print { .meter, .meter span, .meter-legend .k { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
@media (max-width: 860px) { .action-list li { flex-wrap: wrap; } .action-list .txt { flex-basis: calc(100% - 20px); } }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; background: #fff; font-size: .9rem; }
table.data th { background: var(--green-900); color: #fff; font-weight: 600; text-align: left; padding: 7px 8px; white-space: nowrap; position: sticky; top: 0; }
table.data td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr:hover { background: #fafcfa; }
table.data .num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr.total td { font-weight: 700; background: var(--green-50); border-top: 2px solid var(--green-700); }
table.data tr.subtotal td { font-weight: 600; background: #f7faf8; }
table.data tr.group td { background: var(--green-100); font-weight: 700; color: var(--green-900); }
table.data td.sub { padding-left: 22px; }
table.data td.calc { background: var(--calc); }
table.data td.adjusted { background: #e8f0fd; }
table.data tr.inactive td { color: #9aa59f; }
table.compact td, table.compact th { padding: 4px 6px; }

[hidden] { display: none !important; }   /* .badge, .note etc. set display, which would otherwise override the hidden attribute */

/* Forms */
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
    width: 100%; padding: 7px 9px; border: 1px solid #b9c6be; border-radius: 6px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--edit); outline-offset: -1px; border-color: var(--edit); }
input.cell { padding: 4px 6px; text-align: right; min-width: 70px; border-color: var(--edit); }
input.cell.text { text-align: left; }
input.cell.changed { background: #e8f0fd; }
/* Searchable dropdowns (app.js): the select stays underneath for the form, the box takes the typing. */
.ss { position: relative; display: inline-block; width: 100%; vertical-align: middle; }
.dash-bar .ss { width: auto; min-width: 12em; }
.ss > select { position: absolute; left: 0; bottom: 0; width: 100%; height: 1px; opacity: 0; pointer-events: none; }
input.ss-box { padding-right: 26px; text-overflow: ellipsis;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%235f6d65'/%3E%3C/svg%3E") no-repeat right 9px center; }
input.ss-box:disabled { background-color: #f0f2f0; }
.ss-list { position: fixed; z-index: 50; margin: 0; padding: 4px 0; list-style: none; width: max-content; max-width: min(560px, 90vw);
    max-height: 280px; overflow-y: auto; background: #fff; border: 1px solid #b9c6be; border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, .12); }
.ss-list li { padding: 6px 10px; cursor: pointer; font-size: .9rem; color: var(--ink); }
.ss-list li.active, .ss-list li[data-i]:hover { background: var(--green-50); }
.ss-list li.ss-none { color: var(--muted); cursor: default; }
.ss-list li.ss-group { position: sticky; top: -4px; padding: 6px 10px 3px; background: #fff; color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; cursor: default; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.form-row { margin-bottom: 12px; }
.form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.check { display: flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--ink); }
.check input { width: auto; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.help { font-size: .8rem; color: var(--muted); margin-top: 3px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--green-700); background: #fff; color: var(--green-800); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--green-50); }
.btn-primary { background: var(--green-800); color: #fff; }
.btn-primary:hover { background: var(--green-900); }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { padding: 3px 9px; font-size: .82rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; }

/* Status */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #eceff1; color: #37474f; white-space: nowrap; }
.badge.draft { background: #eceff1; }
.badge.submitted, .badge.reviewed, .badge.recommended { background: var(--amber-bg); color: var(--amber); }
.badge.approved, .badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.superseded { background: #f1f1f1; color: #888; }
.badge.warn { background: var(--amber-bg); color: var(--amber); }
.badge.bad { background: var(--red-bg); color: var(--red); }
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid; }
.alert-error { background: var(--red-bg); border-color: #f2b8b5; color: var(--red); }
.alert-ok { background: var(--ok-bg); border-color: #a8d5b5; color: var(--ok); }
.note { background: var(--amber-bg); border-left: 4px solid #d9a400; padding: 8px 12px; border-radius: 4px; font-size: .85rem; margin: 10px 0; }
.note.info { background: var(--green-50); border-left-color: var(--green-700); }

/* Tabs (step navigation, Figure 7) */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a { padding: 5px 12px; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; color: var(--ink); background: #fff; font-size: .88rem; }
.tabs a.active { background: var(--green-800); color: #fff; border-color: var(--green-800); }

/* Modal-free inline editor */
details.editor { margin-top: 10px; }
details.editor > summary { cursor: pointer; color: var(--green-700); font-weight: 600; }
details.editor[open] > summary { margin-bottom: 10px; }
/* A row button that opens a short form in place (e.g. remove a line, with the reason) */
details.row-action { display: inline-block; vertical-align: top; }
details.row-action > summary { list-style: none; }
details.row-action > summary::-webkit-details-marker { display: none; }
details.row-action[open] > form { display: flex; gap: 6px; margin-top: 6px; }
details.row-action[open] > form input { min-width: 220px; }

/* Auth pages */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, var(--green-900), var(--green-700)); }
.auth-card { width: 100%; max-width: 380px; background: #fff; border-radius: 12px; padding: 28px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.auth-card h1 { margin-bottom: 4px; }
.auth-card .btn { width: 100%; justify-content: center; margin-top: 8px; }

.empty { padding: 24px; text-align: center; color: var(--muted); }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
code { background: #eef2ef; padding: 1px 5px; border-radius: 4px; font-size: .85em; }

@media (max-width: 860px) {
    .nav-toggle { display: block; }
    .sidebar { position: fixed; top: 52px; left: 0; bottom: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; overflow-y: auto; box-shadow: 4px 0 20px rgba(0,0,0,.15); }
    body.nav-open .sidebar { transform: none; }
    .main { padding: 14px 16px 40px; }
    .user-chip small { display: none; }
}

@media print {
    .topbar, .sidebar, .page-actions, .no-print, form .btn, details.editor { display: none !important; }
    .main { padding: 0; }
    .card { border: 0; padding: 0; }
    table.data th { background: #ddd !important; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    body { background: #fff; }
}

/* Notifications bell */
.bell { position: relative; color: #fff; text-decoration: none; font-size: 1.15rem; }
.bell-count { position: absolute; top: -6px; right: -10px; background: #d93025; color: #fff; border-radius: 999px; font-size: .68rem; padding: 1px 5px; font-weight: 700; }
.approval-card h2 a { text-decoration: none; }
.approval-facts { padding: 12px 0; border-top: 1px solid var(--line, #e3e7e3); border-bottom: 1px solid var(--line, #e3e7e3); margin-bottom: 10px; }
.approval-facts label, .approval-purpose label { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted, #6b7280); margin-bottom: 2px; }
.approval-purpose { margin: 0 0 12px; }
.approval-sub { font-size: .95rem; margin: 6px 0 6px; }
.approval-note { margin: 0 0 10px; }
.approval-charges { margin: 4px 0 6px; }
.approval-charges td { vertical-align: top; }
.approval-charges td.neg, .approval-charges td.neg strong { color: var(--red); }
@media (max-width: 860px) {
    .approval-card .form-actions .btn { flex: 1 1 auto; justify-content: center; padding: 10px; }
}

/* Full-year budget: a wide month grid whose first column stays in view */
table.year-grid { font-size: .82rem; }
table.year-grid td:first-child, table.year-grid th:first-child { position: sticky; left: 0; z-index: 1; min-width: 230px; max-width: 340px; }
table.year-grid td:first-child { background: #fff; }
table.year-grid th:first-child { z-index: 2; }
table.year-grid td.sub { padding-left: 22px; font-weight: 400; }
table.year-grid th a { color: #fff; }

/* Roles & permissions: the grid scrolls in its own box so the role names stay on top and the pages on the left */
.roles-grid-wrap { max-height: calc(100vh - 140px); overflow: auto; }
table.roles-grid thead th { position: sticky; top: 0; z-index: 3; white-space: normal; vertical-align: bottom; }
table.roles-grid tbody th { position: sticky; left: 0; top: auto; z-index: 2; }
table.roles-grid tbody td:first-child { position: sticky; left: 0; z-index: 1; background: #fff; min-width: 200px; }
table.roles-grid thead th:first-child { left: 0; z-index: 4; min-width: 200px; }
table.roles-grid select { min-width: 135px; }
table.year-grid th small { font-weight: 400; opacity: .8; }
table.year-grid th.act { background: var(--green-700); }
table.year-grid td.act { background-image: linear-gradient(rgba(47, 111, 84, .07), rgba(47, 111, 84, .07)); }
table.year-grid td.year { border-left: 2px solid var(--line); font-weight: 600; }
table.year-grid th.year { border-left: 2px solid rgba(255, 255, 255, .5); }
table.year-grid th.yhead { text-align: center; border-left: 2px solid rgba(255, 255, 255, .5); }
table.year-grid td.neg { color: var(--red); }
@media print { table.year-grid { font-size: 6.5pt; } table.year-grid td, table.year-grid th { padding: 2px 3px; } }
table.year-grid th small { color: inherit; }

/* Reports built from the data (Reports page) */
.report-meta { margin: -6px 0 12px; color: var(--muted); font-size: .85rem; }
@media print { .report-section { break-inside: auto; margin-bottom: 14px; } .report-section h2 { break-after: avoid; } }

/* Comprehensive report: preview (black and white house style, FMT-02) */
.comp-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .comp-layout { grid-template-columns: 1fr; } }
.comp-side .card { margin-bottom: 12px; }
.comp-doc { position: relative; font-family: Arial, Helvetica, sans-serif; color: #000; font-size: 13px; overflow: hidden; }
.comp-watermark { position: absolute; top: 260px; left: 0; right: 0; text-align: center; font-size: 140px; font-weight: bold; color: rgba(0,0,0,.06); transform: rotate(-30deg); pointer-events: none; }
.comp-cover { border-bottom: 2px solid #000; padding-bottom: 12px; margin-bottom: 16px; }
.comp-cover h1 { margin: 4px 0; font-size: 24px; }
.comp-co { font-weight: bold; font-size: 15px; }
.comp-sub { font-size: 15px; margin: 4px 0 10px; }
.comp-tag { font-weight: bold; }
.comp-toc ol { list-style: none; padding-left: 0; columns: 2; }
.comp-toc .lvl2 { padding-left: 16px; }
.comp-h1 { font-size: 19px; border-top: 1px solid #000; padding-top: 14px; margin-top: 26px; }
.comp-h2 { font-size: 15px; margin: 14px 0 6px; }
.comp-lead { font-weight: bold; }
.comp-note { font-size: 11px; font-style: italic; margin: 4px 0 10px; }
.comp-empty { font-style: italic; color: #333; }
.comp-tw { overflow-x: auto; }
.comp-t { border-collapse: collapse; width: 100%; font-size: 12px; margin: 4px 0; }
.comp-t caption { text-align: left; font-style: italic; padding: 4px 0; }
.comp-t th { background: #000; color: #fff; font-weight: bold; padding: 4px 6px; border: 1px solid #000; text-align: left; }
.comp-t td { border: 1px solid #000; padding: 3px 6px; vertical-align: top; }
.comp-t .num { text-align: right; white-space: nowrap; }
.comp-t tr.total td, .comp-t tr.subtotal td { font-weight: bold; border-top: 2px solid #000; }
.comp-t tr.group td { font-weight: bold; }
.comp-kv th { width: 30%; }
.comp-expl { border: 1px solid #000; padding: 6px 8px; margin: 8px 0; }
.comp-expl-label { font-weight: bold; margin-bottom: 4px; }
.comp-fig { margin: 10px 0 18px; }
.comp-fig figcaption { font-style: italic; margin-bottom: 4px; }
.comp-chart { width: 100%; height: auto; background: #fff; }
.comp-break { border: 0; border-top: 1px dashed #000; }
table.year-grid.pva td.mstart, table.year-grid.pva th.mstart { border-left: 2px solid var(--line); }
table.year-grid.pva thead th.mstart { border-left-color: rgba(255, 255, 255, .5); }
table.year-grid td.diff.pos { color: var(--green-700); }
