/* Settlr layout. Brand colours arrive as --primary and --secondary from base.html,
   with --on-primary, --on-secondary (text to put on each) and --link. */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --text: #1f2430;
    --muted: #5d6475;
    --bg: #f6f6f9;
    --surface: #ffffff;
    --border: #dcdde5;
    --error: #8a1c1c;
}

body {
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

/* Header and navigation */
.site-header { background: var(--primary); color: var(--on-primary); }
.bar {
    max-width: 1320px; margin: 0 auto; padding: 12px 16px;
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px;
}
.brand { color: var(--on-primary); text-decoration: none; display: flex; align-items: center; }
.brand-name { font-size: 1.25rem; font-weight: 600; }
.brand-logo { height: 36px; display: block; }
.nav { display: flex; gap: 16px; flex: 1; }
.nav a { color: var(--on-primary); text-decoration: none; font-weight: 500; padding: 4px 0; }
.nav a:hover { text-decoration: underline; }
.who { margin-left: auto; display: flex; gap: 12px; align-items: center; font-size: 0.9rem; }
.signout { color: var(--on-primary); }

/* Page body */
.container { max-width: 1320px; width: 100%; margin: 0 auto; padding: 24px 16px; flex: 1; }
h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 4px; }
h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 8px; }
.sub, .muted { color: var(--muted); }
.sub { margin-bottom: 20px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-top: 3px solid var(--secondary); border-radius: 6px; padding: 16px;
}

/* Messages */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; border: 1px solid var(--border); background: var(--surface); }
.flash-error { border-color: var(--error); color: var(--error); }
.flash-success { border-color: var(--secondary); }

/* Forms */
.form { max-width: 640px; }
.form label { display: block; font-weight: 500; margin: 14px 0 4px; }
.form input[type=text], .form textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--border);
    border-radius: 4px; font: inherit; background: #fff;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.btn {
    margin-top: 20px; padding: 10px 18px; border: 0; border-radius: 4px;
    background: var(--primary); color: var(--on-primary); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { opacity: 0.9; }

/* Footer */
.site-footer { background: var(--surface); border-top: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; }

@media (max-width: 600px) {
    .row { grid-template-columns: 1fr; }
    .who { margin-left: 0; width: 100%; }
}

/* Shown on every page while signed in with the break-glass account. */
.break-glass-notice { background: var(--primary); color: var(--on-primary); padding: 10px 16px; font-weight: 600; text-align: center; }


/* Stage 3: clients, jobs and units */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 4px; }
.btn-inline { margin-top: 0; padding: 6px 14px; text-decoration: none; display: inline-block; }
.block { margin-top: 20px; }
.group { margin-top: 20px; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-weight: 600; background: var(--bg); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { white-space: nowrap; }
.table.compact th, .table.compact td { padding: 3px 8px; font-size: 0.9rem; }
.muted-row { color: var(--muted); }
.offset-row td { font-style: italic; }
.offset-row td:first-child { border-left: 3px solid var(--primary); }
.tag { font-size: 0.75rem; font-weight: 600; color: var(--primary); border: 1px solid var(--primary); border-radius: 3px; padding: 0 5px; font-style: normal; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 4px 0; }
.form select, .form input[type=date], .form input[type=number] {
    width: 100%; padding: 8px 10px; border: 1px solid var(--border);
    border-radius: 4px; font: inherit; background: #fff;
}
.form h2 { margin-top: 24px; padding-top: 12px; border-top: 1px solid var(--border); }
.form h2:first-of-type { margin-top: 0; border-top: 0; padding-top: 0; }
.form .check { display: flex; align-items: center; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.row3 input[type=text] { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; font: inherit; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 12px 0; }
.filters select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; font: inherit; }
.terms { display: grid; grid-template-columns: max-content 1fr; gap: 4px 20px; }
.terms dt { color: var(--muted); }
.totals { margin-top: 12px; }
.link-btn { background: none; border: 0; padding: 0 4px; font: inherit; color: var(--link); text-decoration: underline; cursor: pointer; }
.inline-form { display: inline-flex; align-items: center; gap: 8px; }
.inline-form label { white-space: nowrap; }
.card .inline-form input[type=date] { width: auto; }
.move-form { display: inline-flex; align-items: center; gap: 2px; }
.move-form .pos { width: 3.2em; padding: 1px 4px; border: 1px solid var(--border); border-radius: 3px; font: inherit; font-size: 0.85rem; }
.card textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; font: inherit; }
details summary { cursor: pointer; margin-top: 10px; }
code { background: var(--bg); padding: 0 4px; border-radius: 3px; }
@media (max-width: 600px) {
    .row3 { grid-template-columns: 1fr; }
    .terms { grid-template-columns: 1fr; }
    .table { display: block; overflow-x: auto; }
}

/* Variations */
.var-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.var-figure { display: flex; flex-direction: column; gap: 4px; }
.var-label { font-size: 0.85rem; color: var(--muted); }
.var-amount { font-size: 1.3rem; font-weight: 600; }
.var-figure-pending { border-style: dashed; border-color: var(--secondary); }
.var-figure-revised { border-color: var(--primary); border-width: 2px; }
.var-group { margin-bottom: 28px; }
.var-group-approved { border-left: 4px solid var(--primary); padding-left: 12px; }
.var-group-pending { border-left: 4px dashed var(--secondary); padding-left: 12px; }
.var-group-rejected { border-left: 4px solid var(--border); padding-left: 12px; color: var(--muted); }
.var-table { width: 100%; border-collapse: collapse; background: var(--surface); }
.var-table th, .var-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.var-table .num { text-align: right; white-space: nowrap; }
.var-negative { color: var(--error); font-weight: 600; }
.var-tag { display: inline-block; margin-left: 6px; padding: 1px 6px; border: 1px solid var(--border); border-radius: 4px; font-size: 0.75rem; color: var(--muted); }
.var-actions { white-space: nowrap; }
.var-actions form.inline { display: inline; margin-left: 10px; }
.btn-link { background: none; border: 0; padding: 0; font: inherit; color: var(--link); text-decoration: underline; cursor: pointer; }
.form .check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.form .help { margin: 4px 0 0; font-size: 0.9rem; }
.form select, .form input[type=date] { padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; font: inherit; background: #fff; }
@media (max-width: 600px) {
    .var-summary { grid-template-columns: 1fr; }
    .var-actions { white-space: normal; }
}

/* Stage 5: valuations */
.val-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 12px; margin-bottom: 8px; }
/* The figure takes the room it needs and the label gives way, so no figure is cut off. */
.val-summary .terms { grid-template-columns: minmax(0, 1fr) max-content; gap: 4px 12px; }
.val-summary .terms dd { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* The list of valuations: every row on one line, scrolling sideways on a narrow screen. */
.val-list th, .val-list td { white-space: nowrap; }
.export-links { display: inline-flex; gap: 10px; align-items: center; }
.export-icon { color: var(--link); display: inline-flex; padding: 2px; border-radius: 4px; }
.export-icon:hover { background: var(--bg); }
.val-scroll { overflow-x: auto; }
.val-entry { font-size: 0.85rem; }
.val-entry .pct { width: 4.5em; }
.val-entry .val-stage-value { border-left: 1px solid var(--border); }
.val-entry .val-stage-head { text-align: center; border-left: 1px solid var(--border); }
.val-subhead th { font-weight: 500; color: var(--muted); }
.val-entry tfoot td, .strong-row td { font-weight: 600; }
.val-entry tbody tr:hover td { background: var(--bg); }
.pct { padding: 2px 4px; border: 1px solid var(--border); border-radius: 3px; font: inherit; text-align: right; width: 5em; }
.val-bulk .inline-form { flex-wrap: wrap; }
.val-bulk select { padding: 4px 6px; border: 1px solid var(--border); border-radius: 4px; font: inherit; }
.val-bulk .check { display: inline-flex; align-items: center; gap: 4px; }
.val-figures { max-width: 640px; }
.val-figures td:first-child { width: 55%; }
.val-notes, .card input[type=date] { padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; font: inherit; width: 100%; }
.val-superseded { opacity: 0.85; border-left: 4px solid var(--border); padding-left: 12px; }
.val-superseded-note { font-weight: 600; }
.val-pending-head { margin-top: 16px; }
.val-pending { margin-left: 20px; color: var(--muted); }
.val-actions form { display: inline-block; margin-right: 16px; }
.val-delete { margin-top: 12px; }
.val-secondary { background: var(--secondary); color: var(--on-secondary); margin-left: 8px; }
.val-default-submit { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.val-row-draft td { font-style: italic; }

/* Stage 7: payments */
.pay-summary .terms { max-width: 640px; }
.pay-summary .terms dd { text-align: right; font-variant-numeric: tabular-nums; }
.pay-credit-note { margin-top: 10px; padding: 8px 12px; border-left: 4px solid var(--primary); background: var(--bg); }
.pay-figures { max-width: 420px; }
.pay-figures dd { text-align: right; font-variant-numeric: tabular-nums; }
.pay-row td { border-top: 2px solid var(--border); }
.pay-alloc-row td { color: var(--muted); font-size: 0.85rem; border-bottom: 0; }
.pay-state-paid td { color: var(--muted); }
.pay-state-credit td { font-style: italic; }
.pay-state-credit td:first-child { border-left: 3px solid var(--primary); }
.pay-state-part_paid td:first-child { border-left: 3px solid var(--secondary); }
.pay-amount { width: 8em; padding: 2px 4px; border: 1px solid var(--border); border-radius: 3px; font: inherit; text-align: right; }
.pay-delete { border-top-color: var(--border); }

/* Stage 8: retention */
.ret-summary .terms { max-width: 640px; }
.ret-summary .terms dd, .ret-preview .terms dd { text-align: right; font-variant-numeric: tabular-nums; }
.ret-warning { margin: 0 0 16px; padding: 10px 14px; border: 1px solid var(--error); border-left-width: 4px; border-radius: 6px; color: var(--error); background: var(--surface); }
.ret-awaiting { margin-top: 10px; padding: 8px 12px; border-left: 4px solid var(--secondary); background: var(--bg); }
.ret-blocked { padding: 8px 12px; border-left: 4px solid var(--error); background: var(--bg); }
.ret-preview { margin: 8px 0 16px; padding: 10px 14px; border: 1px dashed var(--primary); border-radius: 6px; max-width: 640px; }
.ret-preview h3 { margin-top: 0; }
.ret-capped { margin: 8px 0 0; font-weight: 600; }
.ret-credit td { font-style: italic; }
.ret-save { background: var(--secondary); color: var(--on-secondary); margin-left: 8px; }

/* Home dashboard: three lists, side by side when there is room. */
.dash { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 16px; align-items: start; }
.dash .table { border: 0; }
.dash .card { overflow-x: auto; }
.dash-overdue { color: var(--error); font-weight: 600; margin-bottom: 8px; }


/* Jobs list: one table with fixed column widths, a heavier line where a new client starts. */
.jobs-table { table-layout: fixed; }
.jobs-table th:nth-child(1) { width: 24%; }
.jobs-table th:nth-child(2) { width: 46%; }
.jobs-table th:nth-child(3) { width: 18%; }
.jobs-table th:nth-child(4) { width: 12%; }
.jobs-table tr.group-first td { border-top: 2px solid var(--border); }
