/* =====================================================================
   Future Decisions onboarding portal.

   One horizontal navigation bar, one full-width content column. Spacing,
   colour and type come from the scales below rather than ad-hoc values, so
   pages built in different phases still line up with each other.
   ===================================================================== */

:root {
    /* Surfaces — a faint green cast so the app reads as part of the brand image. */
    --fd-bg: #f2f6f3;
    --fd-surface: #ffffff;
    --fd-surface-sunken: #f5f9f6;

    /* Ink */
    --fd-ink: #15211b;
    --fd-ink-soft: #41524a;
    --fd-muted: #67766e;

    /*
     * Brand greens sampled from the background image: near-black green for the
     * bar, and the headline green (#81de6f) as the accent on dark. That green is
     * far too light to carry white text, so buttons and links use a darker shade
     * of the same hue — #177a39 gives 5.4:1 against white, clearing WCAG AA.
     */
    --fd-shell: #06170f;
    --fd-primary: #177a39;
    --fd-primary-dark: #12692f;
    --fd-primary-ink: #ffffff;
    --fd-accent: #81de6f;

    /* Feedback */
    --fd-error: #b3261e;
    --fd-error-bg: #fdeceb;
    --fd-error-border: #f2bdb9;
    --fd-success: #1c7a3e;
    --fd-success-bg: #e8f6ec;
    --fd-success-border: #b5ddc2;
    --fd-notice: #12692f;

    /* Lines and shape */
    --fd-border: #dce5df;
    --fd-border-strong: #c3d0c8;
    --fd-radius: 10px;
    --fd-radius-sm: 7px;
    --fd-shadow: 0 1px 2px rgba(6, 23, 15, 0.05), 0 1px 3px rgba(6, 23, 15, 0.04);

    /* Layout — content spans 80% of the viewport, so the bar and footer line up
       with the page below them. Only phones fall back to full width. */
    --fd-content: 80%;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--fd-ink);
    background: var(--fd-bg);
    line-height: 1.55;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;

    /* Sticky footer: see .site-footer. dvh first so mobile browser chrome does not
       push the footer below the fold. */
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

a { color: var(--fd-primary); text-underline-offset: 2px; }
a:hover { color: var(--fd-primary-dark); }

h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 0.35rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; line-height: 1.3; margin: 0 0 0.5rem; }
h3 { font-size: 0.95rem; margin: 0 0 0.35rem; }

.muted { color: var(--fd-muted); }

/* ---------------------------------------------------------------- Top bar */

.topbar {
    background: var(--fd-shell);
    color: #fff;
}
.topbar-inner {
    max-width: var(--fd-content);
    margin: 0 auto;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    min-height: 56px;
}

.brand {
    text-decoration: none;
    color: #fff;
    font-weight: 600;
    font-size: 1rem;
    white-space: nowrap;
}
.brand:hover { color: #fff; }

/* A button that has to read as a link — used for Sign out, which is a POST
   (so it cannot be an anchor) but should not look like a call to action. */
.linkbutton {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-size: 0.88rem;
    color: rgba(255, 255, 255, 0.75);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.linkbutton:hover { color: #fff; }

.mainnav {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex: 1 1 auto;
    flex-wrap: wrap;
}
.mainnav a {
    padding: 0.4rem 0.7rem;
    border-radius: var(--fd-radius-sm);
    color: rgba(255, 255, 255, 0.78);
    text-decoration: none;
    font-size: 0.9rem;
    white-space: nowrap;
}
.mainnav a:hover { background: rgba(255, 255, 255, 0.09); color: #fff; }
.mainnav a.is-active { background: rgba(129, 222, 111, 0.16); color: var(--fd-accent); font-weight: 600; }

/* Pushed right; margin-left:auto also covers the case where there is no main
   nav at all, as on a client user's pages. */
.usernav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
}
.usernav-name { color: rgba(255, 255, 255, 0.75); font-size: 0.88rem; white-space: nowrap; }
.logout-form { margin: 0; }

/* ---------------------------------------------------------------- Layout */

.page {
    width: 100%;
    max-width: var(--fd-content);
    margin: 0 auto;
    padding: 1.75rem 1.25rem 4rem;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.page-head h1, .page-head h2 { margin-bottom: 0; }
.page-head p { margin: 0.15rem 0 0; }
/* Small "up one level" link above a page title. */
.crumb { font-size: 0.85rem; margin: 0 0 0.1rem !important; }
.head-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.head-actions form { margin: 0; }

.card {
    background: var(--fd-surface);
    border: 1px solid var(--fd-border);
    border-radius: var(--fd-radius);
    box-shadow: var(--fd-shadow);
    padding: 1.25rem 1.4rem;
    margin: 0 0 1.1rem;
}
.card > :last-child { margin-bottom: 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }

/* ------------------------------------------------------------ Auth screens */

/*
 * Signed-out pages sit on the brand image. It is a busy graphic with its own
 * copy, so a dark scrim goes over it: the artwork reads as atmosphere while the
 * card stays legible. The image carries the Future Decisions logo itself, so the
 * bar and footer go transparent rather than stacking a second one on top.
 */
.auth-page {
    background-image:
        linear-gradient(rgba(6, 23, 15, 0.55), rgba(6, 23, 15, 0.80)),
        url('/images/onboarding-background-8c7a8aa44da04eb54249f869833a4616.webp');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
}
/* The artwork carries the Future Decisions logo itself, so our bar would print a
   second one straight on top of it. */
.auth-page .topbar { display: none; }
.auth-page .site-footer { background: transparent; border-top-color: rgba(255, 255, 255, 0.18); }
.auth-page .site-footer .muted { color: rgba(255, 255, 255, 0.65); }
.auth-page .site-footer a { color: rgba(255, 255, 255, 0.85); }

.auth-shell {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2.5rem 1.25rem;
    /* Grow to fill, so the backdrop is not a thin strip behind a top-aligned card. */
    flex: 1;
}
.auth-card {
    background: var(--fd-surface);
    border: 1px solid var(--fd-border);
    border-radius: var(--fd-radius);
    /* Lifted off the artwork rather than the flat shadow used on plain backgrounds. */
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
    padding: 2rem;
    width: 100%;
    max-width: 430px;
}
.auth-card h1 { margin-top: 0; text-align: center; }
.auth-card .form-actions { justify-content: center; }
.secondary-action { margin-top: 1rem; }

/* ----------------------------------------------------------------- Tabs */

.workspace-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem;
    margin: 0 0 1.5rem;
    border-bottom: 1px solid var(--fd-border);
}
.workspace-tabs a, .tab-disabled {
    padding: 0.55rem 0.85rem;
    font-size: 0.9rem;
    text-decoration: none;
    color: var(--fd-ink-soft);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.workspace-tabs a:hover { color: var(--fd-primary); }
.workspace-tabs a.is-active {
    color: var(--fd-primary);
    border-bottom-color: var(--fd-primary);
    font-weight: 600;
}
.tab-disabled { color: #9aa4b0; cursor: default; }

/* ---------------------------------------------------------------- Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    border-radius: var(--fd-radius-sm);
    border: 1px solid var(--fd-border-strong);
    background: #eaf0ec;
    color: var(--fd-ink);
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    line-height: 1.4;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: #dee7e1; border-color: var(--fd-muted); color: var(--fd-ink); }

.btn-primary {
    background: var(--fd-primary);
    border-color: var(--fd-primary);
    color: var(--fd-primary-ink);
    font-weight: 600;
}
.btn-primary:hover { background: var(--fd-primary-dark); border-color: var(--fd-primary-dark); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-danger { border-color: var(--fd-error-border); color: var(--fd-error); }
.btn-danger:hover { background: var(--fd-error-bg); color: var(--fd-error); }

/* Text-only button, for inline row actions. */
.btn-link {
    background: none;
    border-color: transparent;
    color: var(--fd-primary);
    padding: 0.25rem 0.35rem;
}
.btn-link:hover { background: rgba(23, 122, 57, 0.09); color: var(--fd-primary-dark); }

/* --------------------------------------------------------- Searchable select */

.combobox { position: relative; max-width: 100%; }
/* The native select stays for submit and no-JS fallback, but out of sight. */
.combobox-native {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); border: 0;
}
.combobox-input { width: 100%; }
.combobox-panel {
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    margin: 0.25rem 0 0;
    padding: 0.25rem;
    list-style: none;
    max-height: 16rem;
    overflow-y: auto;
    background: var(--fd-surface);
    border: 1px solid var(--fd-border-strong);
    border-radius: var(--fd-radius-sm);
    box-shadow: 0 6px 20px rgba(6, 23, 15, 0.16);
}
.combobox-option {
    padding: 0.45rem 0.6rem;
    border-radius: var(--fd-radius-sm);
    cursor: pointer;
    font-size: 0.95rem;
}
.combobox-option:hover, .combobox-option.is-active {
    background: var(--fd-primary);
    color: var(--fd-primary-ink);
}

/* ----------------------------------------------------------------- Forms */

label { display: block; font-weight: 600; font-size: 0.9rem; margin: 1.1rem 0 0.35rem; }

input[type="email"], input[type="text"], input[type="number"],
input[type="date"], select, textarea {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--fd-border-strong);
    border-radius: var(--fd-radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--fd-ink);
    background: var(--fd-surface);
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
    outline: 2px solid var(--fd-primary);
    outline-offset: 1px;
}
input:disabled, textarea:disabled, select:disabled {
    background: var(--fd-surface-sunken);
    color: var(--fd-muted);
}
input[type="file"] { padding: 0.4rem 0; border: none; }

.stack-form { max-width: 640px; }
.stack-form textarea { min-height: 5rem; }

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 400;
    font-size: 0.95rem;
    margin: 0.6rem 0 0;
}
.checkbox-row input { width: auto; }

.form-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-top: 1.4rem;
}
.form-actions form { margin: 0; }

.fieldset {
    border: 1px solid var(--fd-border);
    border-radius: var(--fd-radius);
    padding: 0.5rem 1.1rem 1.1rem;
    margin-top: 1.5rem;
}
.fieldset legend {
    padding: 0 0.4rem;
    color: var(--fd-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin: 0 0 1.1rem;
    padding: 0.75rem 1rem;
    background: var(--fd-surface);
    border: 1px solid var(--fd-border);
    border-radius: var(--fd-radius);
}
.filter-bar label { margin: 0; font-size: 0.85rem; }
.filter-bar select, .filter-bar input[type="text"] { width: auto; min-width: 11rem; }

.detail-inline {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding: 0.6rem 0.85rem;
    background: var(--fd-surface-sunken);
    border-radius: var(--fd-radius-sm);
    margin-bottom: 0.5rem;
}

/* --------------------------------------------------------- Field messages */

.field-hint { color: var(--fd-muted); font-size: 0.85rem; margin: 0.3rem 0 0; }
.field-error { color: var(--fd-error); font-size: 0.85rem; margin: 0.3rem 0 0; }
.notice { color: var(--fd-notice); }

.form-error, .flash {
    padding: 0.7rem 0.95rem;
    border-radius: var(--fd-radius-sm);
    margin: 0 0 1.1rem;
    font-size: 0.92rem;
}
.form-error { color: var(--fd-error); background: var(--fd-error-bg); border: 1px solid var(--fd-error-border); }
.flash { color: var(--fd-success); background: var(--fd-success-bg); border: 1px solid var(--fd-success-border); }

.draft-banner {
    background: #fff6e5;
    border: 1px solid #f0c96b;
    padding: 0.7rem 0.95rem;
    border-radius: var(--fd-radius-sm);
    font-size: 0.88rem;
}

/* ---------------------------------------------------------------- Tables */

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--fd-surface);
    border: 1px solid var(--fd-border);
    border-radius: var(--fd-radius);
    box-shadow: var(--fd-shadow);
    overflow: hidden;
    margin-bottom: 1.1rem;
}
.data-table th, .data-table td {
    text-align: left;
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--fd-border);
    vertical-align: top;
}
.data-table thead th {
    background: var(--fd-surface-sunken);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--fd-muted);
    font-weight: 700;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--fd-surface-sunken); }
.data-table td.wrap-any { overflow-wrap: anywhere; }
.data-table .muted { display: block; font-size: 0.82rem; margin-top: 0.15rem; }
/* Timestamps read badly broken across lines, so they alone keep their nowrap. */
.data-table .nowrap, .data-table td.when { white-space: nowrap; width: 1%; }

/* Keeps a wide table inside the page instead of overflowing it. */
.table-scroll { overflow-x: auto; margin-bottom: 1.1rem; }
.table-scroll .data-table { margin-bottom: 0; }


.row-actions { display: flex; align-items: center; gap: 0.25rem; white-space: nowrap; }
.row-actions form { display: inline; margin: 0; }

/* Select + button on one line, e.g. the building-access role picker. */
.inline-form { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; }

.pager { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.5rem; }
.data-table td.detail { max-width: 34rem; overflow-wrap: anywhere; }

/* Status pill */
.pill {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    background: #e6ede8;
    color: var(--fd-ink-soft);
    font-size: 0.76rem;
    font-weight: 600;
    white-space: nowrap;
}
.pill-ok { background: var(--fd-success-bg); color: var(--fd-success); }
.pill-alert { background: var(--fd-error-bg); color: var(--fd-error); }

/* Definition lists */
.detail-list {
    display: grid;
    grid-template-columns: minmax(140px, 220px) 1fr;
    gap: 0.5rem 1.25rem;
    margin: 0;
    font-size: 0.93rem;
}
.detail-list dt { color: var(--fd-muted); }
.detail-list dd { margin: 0; }

/* -------------------------------------------------------- Building header */

.building-banner { margin-bottom: 1.1rem; }
.building-banner h1 { margin-bottom: 0.2rem; }
.building-banner p { margin: 0 0 0.5rem; font-size: 0.92rem; }

/* --------------------------------------------------------- Questionnaire */

.progress-bar {
    height: 8px;
    background: #e0e9e3;
    border-radius: 999px;
    overflow: hidden;
    margin: 0.75rem 0 0.35rem;
    max-width: 960px;
}
.progress-fill { height: 100%; background: var(--fd-primary); transition: width 0.2s ease; }

.question-list { max-width: 1080px; margin-left: auto; margin-right: auto; }
.question {
    border: 1px solid var(--fd-border);
    border-radius: var(--fd-radius);
    background: var(--fd-surface);
    box-shadow: var(--fd-shadow);
    padding: 1.1rem 1.25rem;
    margin-bottom: 0.85rem;
}
.question-text { display: block; font-weight: 600; margin: 0 0 0.2rem; font-size: 0.98rem; }
.required-marker { color: var(--fd-error); margin-left: 0.15rem; }

.question .answer-input { margin-top: 0.55rem; }
.question .choice-group .answer-input,
.question .number-row .answer-input { width: auto; margin-top: 0; }
.number-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.55rem; }
.number-row .answer-input { flex: 0 1 12rem; }
.unit { color: var(--fd-muted); font-size: 0.9rem; }
.choice-group { display: block; margin-top: 0.35rem; }

.answer-aside {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-top: 0.75rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--fd-border);
    font-size: 0.84rem;
}
.save-state { color: var(--fd-muted); }
.save-state.is-saved { color: var(--fd-success); font-weight: 600; }
.save-state.is-error, .save-state.is-conflict { color: var(--fd-error); font-weight: 600; }

/* A selected "not known" / "not applicable" reads as pressed, so the choice is obvious. */
.mark-btn.is-active {
    background: var(--fd-primary);
    color: var(--fd-primary-ink);
    font-weight: 600;
}
.mark-btn.is-active:hover { background: var(--fd-primary-dark); color: var(--fd-primary-ink); }
/* The field shows the status label; grey it so it does not read as a typed answer. */
.answer-input.is-status { color: var(--fd-muted); font-style: italic; background: var(--fd-surface-sunken); }

/* Template preview: section headings between the question cards. The reading-width
   cap that suits answering is dropped here, so review uses the full page. */
.preview-section .question-list { max-width: none; }
.preview-section { margin-bottom: 2rem; }
.preview-section h2 { margin-bottom: 0.2rem; }
.preview-section > .muted { margin-top: 0; margin-bottom: 0.9rem; }

/* Floating save state. Fixed so it stays in view down a long section, and given
   room below the question column so it never covers an answer. */
.save-bar {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.7rem 0.6rem 1rem;
    background: var(--fd-surface);
    border: 1px solid var(--fd-border-strong);
    border-radius: 999px;
    box-shadow: 0 4px 16px rgba(6, 23, 15, 0.18);
}
.save-bar-state { font-size: 0.88rem; color: var(--fd-muted); white-space: nowrap; }
.save-bar.is-pending { border-color: var(--fd-primary); }
.save-bar.is-pending .save-bar-state { color: var(--fd-ink); font-weight: 600; }
.save-bar.is-saving .save-bar-state { color: var(--fd-ink); }
.save-bar.is-error { border-color: var(--fd-error-border); background: var(--fd-error-bg); }
.save-bar.is-error .save-bar-state { color: var(--fd-error); font-weight: 600; }

/* So the last question is never hidden behind the bar. */
.question-list { padding-bottom: 4rem; }

@media (max-width: 600px) {
    .save-bar { right: 0.75rem; left: 0.75rem; bottom: 0.75rem; justify-content: space-between; }
}

/* ------------------------------------------------- Documents and review */

.response-block {
    border-left: 3px solid var(--fd-border-strong);
    background: var(--fd-surface-sunken);
    padding: 0.6rem 0.9rem;
    border-radius: 0 var(--fd-radius-sm) var(--fd-radius-sm) 0;
    margin: 0.75rem 0;
}
.response-block p:last-child { margin-bottom: 0; }

/* ------------------------------------------------------------ Prose pages */

.prose { max-width: 760px; }
.prose h2 { margin-top: 1.9rem; font-size: 1.05rem; }
.prose li { margin-bottom: 0.3rem; }

/* ---------------------------------------------------------------- Footer */

.site-footer {
    border-top: 1px solid var(--fd-border);
    background: var(--fd-surface);
    /* Absorbs any spare vertical space, so a short page still has its footer at the
       bottom of the window. On a long page there is no spare space and it simply
       follows the content. */
    margin-top: auto;
    flex-shrink: 0;
}
.topbar { flex-shrink: 0; }
.footer-inner {
    max-width: var(--fd-content);
    margin: 0 auto;
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-size: 0.85rem;
}
.footer-links { display: flex; gap: 1rem; }

/* -------------------------------------------------------------- Utilities */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* --------------------------------------------------------- Print report */

.print-shell { width: 100%; max-width: 900px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
.print-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.print-header { border-bottom: 2px solid var(--fd-primary); padding-bottom: 0.75rem; margin-bottom: 1.5rem; }
.print-header h1 { margin: 0; }
.print-section { margin-top: 2rem; }
.print-section h2 { border-bottom: 1px solid var(--fd-border); padding-bottom: 0.3rem; }
.print-request { border-left: 3px solid var(--fd-border-strong); padding-left: 0.9rem; margin-bottom: 1rem; }
.print-footer { margin-top: 2.5rem; border-top: 1px solid var(--fd-border); padding-top: 0.75rem; }

@media print {
    /* Chrome that helps on screen only gets in the way on paper. */
    .no-print, .topbar, .site-footer { display: none !important; }
    body { background: #fff; font-size: 11pt; }
    .print-shell { max-width: none; padding: 0; }
    .data-table { border: 1px solid #999; box-shadow: none; }
    .data-table thead { display: table-header-group; }
    .data-table tr { page-break-inside: avoid; }
    a { text-decoration: none; color: inherit; }
}

/* ---------------------------------------------------------------- Narrow */

/* 80% holds at every usable window size. Only on a phone, where 10% gutters
   each side would leave too little room to read, does it go full width. */
@media (max-width: 600px) {
    .page, .topbar-inner, .footer-inner { max-width: 100%; }
}

@media (max-width: 860px) {
    .topbar-inner { flex-wrap: wrap; padding-top: 0.6rem; padding-bottom: 0.6rem; gap: 0.6rem; }
    .mainnav { order: 3; width: 100%; overflow-x: auto; }
    .usernav { margin-left: auto; }
    .detail-list { grid-template-columns: 1fr; gap: 0.15rem 0; }
    .detail-list dd { margin-bottom: 0.6rem; }
}
