:root {
    --green: #1e6b34;
    --green-dark: #154d25;
    --bg: #f5f6f4;
    --card: #ffffff;
    --text: #1d221f;
    --muted: #5f6b63;
    --border: #dfe3df;
    --error-bg: #fdecea;
    --error: #a3271c;
    --success-bg: #e8f5ec;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--green); }

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 24px;
    padding: 12px 16px;
    background: var(--green);
    color: #fff;
}
.topbar a { color: #fff; text-decoration: none; }
.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: .02em; }
.nav { display: flex; gap: 16px; flex: 1; }
.nav a { opacity: .85; }
.nav a.active, .nav a:hover { opacity: 1; text-decoration: underline; text-underline-offset: 4px; }
.account { display: flex; align-items: center; gap: 16px; font-size: .9rem; }
.who small { opacity: .8; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; }
h1 { font-size: 1.5rem; margin: 0 0 16px; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.card.narrow { max-width: 420px; margin: 32px auto; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card.module { display: block; color: inherit; text-decoration: none; transition: border-color .15s; }
.card.module:hover { border-color: var(--green); }
.card.module h2 { margin: 0 0 4px; font-size: 1.1rem; color: var(--green); }
.card.module p { margin: 0 0 8px; color: var(--muted); }

.badge { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); }
.muted { color: var(--muted); }

label { display: block; margin-bottom: 14px; font-weight: 500; }
input {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 9px 10px;
    font: inherit;
    border: 1px solid var(--border);
    border-radius: 6px;
}
input:focus { outline: 2px solid var(--green); outline-offset: 1px; border-color: transparent; }

button { font: inherit; cursor: pointer; }
button.primary {
    width: 100%;
    padding: 10px;
    border: 0;
    border-radius: 6px;
    background: var(--green);
    color: #fff;
    font-weight: 600;
}
button.primary:hover { background: var(--green-dark); }
button.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; }
form.inline { display: inline; }

.flash { padding: 10px 12px; border-radius: 6px; margin-bottom: 16px; }
.flash-error { background: var(--error-bg); color: var(--error); }
.flash-success { background: var(--success-bg); color: var(--green-dark); }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--bg); font-weight: 600; }
tr.inactive td { color: var(--muted); }

/* ---- shared building blocks for module pages ---- */
h2 { font-size: 1.1rem; margin: 24px 0 12px; }
.card h2 { margin-top: 0; }
section { margin-bottom: 24px; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 8px; }
.page-head h1 { margin: 0; }

select {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    font: inherit;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}
td select, td input { margin-top: 0; min-width: 140px; }
input[type="checkbox"] { display: inline-block; width: auto; margin: 0 6px 0 0; }
label.check { display: flex; align-items: center; }

.button, button.secondary, button.primary.auto {
    display: inline-block;
    width: auto;
    padding: 8px 14px;
    border-radius: 6px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}
.button.primary { background: var(--green); color: #fff; border: 0; }
.button.primary:hover { background: var(--green-dark); }
.button.secondary, button.secondary { background: #fff; color: var(--green); border: 1px solid var(--green); }
.button.secondary:hover, button.secondary:hover { background: var(--success-bg); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.link.danger, .danger { color: var(--error); }

.row-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.row-form label { flex: 1 1 160px; margin-bottom: 0; }
.row-form button { flex: 0 0 auto; }
.stack > * + * { margin-top: 12px; }

.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-bottom: 24px; }
details.card summary, .inline-details summary { cursor: pointer; font-weight: 600; color: var(--green); }
details.card[open] summary { margin-bottom: 16px; }
details.new-report { margin-bottom: 16px; }
.inline-details { display: inline-block; }
.inline-details[open] { display: block; flex-basis: 100%; }
.inline-details form { margin-top: 12px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.filters select { width: auto; margin: 0; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { display: flex; gap: 12px; align-items: center; }
tfoot th { border-top: 2px solid var(--border); }
tr.needs-category td { background: #fff8e6; }
.narrow-table { max-width: 480px; }
.card.narrow-left { max-width: 640px; margin-top: 24px; }

.badge.status-draft { background: #fff3cd; color: #7a5b00; }
.badge.status-submitted { background: var(--success-bg); color: var(--green-dark); }
.badge-preview { background: #e8eefc; color: #2b4a99; }
.flash-info { background: #e8eefc; color: #2b4a99; }
.field-error { display: block; margin-top: 4px; color: var(--error); font-weight: 400; font-size: .85rem; }
input.short { min-width: 70px; width: 90px; }
td input[name="name"] { min-width: 240px; }
code.password { font-size: 1.05rem; padding: 2px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; user-select: all; }
textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; font: inherit; border: 1px solid var(--border); border-radius: 6px; }
.row-form label.wide { flex: 3 1 320px; }
.row-form label.narrow-field { flex: 0 1 120px; }
.small { font-size: .85rem; }
table.lines { width: 100%; }
table.lines tfoot td { border-bottom: 0; padding-top: 4px; padding-bottom: 4px; }
table.lines tr.grand td { font-weight: 700; border-top: 2px solid var(--border); }
fieldset.zones { border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; margin: 0; }
fieldset.zones label.check { margin: 4px 0; font-weight: 400; }
body.print { background: #fff; }
@media print { .container { max-width: none; padding: 0; } a { color: inherit; text-decoration: none; } }
input.zone-name { min-width: 320px; }
ul.impact { padding-left: 20px; }
ul.impact li { margin-bottom: 8px; }
button.danger-button { width: auto; padding: 10px 16px; border: 0; border-radius: 6px; background: var(--error); color: #fff; font-weight: 600; }
button.danger-button:hover { background: #7d1d15; }
input.num { text-align: right; }
.nav { flex-wrap: wrap; row-gap: 4px; } .nav a { white-space: nowrap; }
.flash-pilot { background: #fff3cd; color: #5c4400; border: 1px solid #f0d58a; }
.flash-pilot a { color: inherit; font-weight: 600; }
.card.module .module-main { display: block; color: inherit; text-decoration: none; }
.card.module p.try { margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--border); }
.signatures { display: flex; gap: 48px; margin-top: 56px; }
.signatures div { flex: 1; text-align: center; border-top: 1px solid var(--text); padding-top: 6px; font-size: .9rem; }
.signatures span { color: var(--muted); }
@media print { .no-print { display: none; } table { font-size: 10pt; } th { background: #eee; } }
.zone-summary h3 { margin: 16px 0 4px; font-size: 1rem; }
.zone-summary ul { margin: 4px 0 0; padding-left: 20px; }
tr.zone-unassigned td:first-child { border-left: 3px solid var(--error); }
tr:target td { background: var(--success-bg); }

/* Tables with class "stack": on phones each row becomes a card of "label: value" lines (the label comes
   from the cell's data-label; the cell with class "title" heads the card). Screen only: print and email keep the table. */
.phone-only { display: none; }
@media screen and (max-width: 640px) {
    .phone-only { display: inline; }
    table.stack thead { display: none; }
    table.stack, table.stack tbody, table.stack tfoot, table.stack tr { display: block; width: 100%; }
    table.stack tr { display: flex; flex-direction: column; padding: 10px 14px; border-bottom: 1px solid var(--border); }
    table.stack td, table.stack th { display: flex; justify-content: space-between; align-items: center; gap: 12px;
        padding: 3px 0; border: 0; white-space: normal; text-align: right; background: none; }
    table.stack td[data-label]::before, table.stack th[data-label]::before {
        content: attr(data-label); color: var(--muted); font-weight: 400; text-align: left; flex: none; }
    table.stack .title { display: block; order: -1; text-align: left; font-weight: 600; font-size: 1rem; padding-bottom: 4px; }
    table.stack td:empty, table.stack th:empty { display: none; }
    table.stack td.actions { justify-content: flex-start; padding-top: 6px; }
    table.stack td select { min-width: 0; flex: 1; max-width: 70%; }
    table.stack tr.needs-category { background: #fff8e6; }
    table.stack tfoot tr { background: var(--bg); }
    table.stack tfoot td[colspan] { text-align: left; }
    table.lines.stack tfoot tr { flex-direction: row; justify-content: space-between; padding: 4px 14px; border: 0; }
    table.lines.stack tfoot tr.grand td { border-top: 0; }
    table.lines.stack tfoot tr.grand { border-top: 2px solid var(--border); padding-top: 8px; }
}
