/* Palette — see AGENTS.md: use these custom properties, no hard-coded hex elsewhere */
:root {
    --color-main: #90323d;
    --color-dark: #5e0b15;
    --color-accent: #8c7a6b;
    --color-bg: #d9cab3;
    --color-highlight: #d9a857;

    --color-white: #ffffff;
    --color-text: #1e2a2c;
    --color-muted: #5d6b6d;
    --color-danger: #a33a2a;
}

* { box-sizing: border-box; }

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

/* ---------- Layout shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--color-dark);
    color: var(--color-bg);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 1rem;
    background: var(--color-main);
    text-align: center;
}
.sidebar-brand img {
    width: 130px;
    height: auto;
    display: block;
    margin: 0 auto;
}

.sidebar-nav { display: flex; flex-direction: column; padding: 0.5rem 0; flex: 1; }
.sidebar-nav a {
    color: var(--color-bg);
    text-decoration: none;
    padding: 0.65rem 1rem;
}
.sidebar-nav a:hover { background: var(--color-main); color: var(--color-white); }
.sidebar-nav .nav-divider {
    border: 0;
    border-top: 1px solid rgba(230, 225, 214, 0.25);
    margin: 0.35rem 1rem;
}

/* ---------- Sidebar footer: admin accordion + user block ---------- */
.sidebar-footer {
    border-top: 1px solid rgba(230, 225, 214, 0.25);
    padding: 0.75rem 1rem 1rem;
}

.sidebar-admin { margin-bottom: 0.75rem; }

.sidebar-admin-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: none;
    border: none;
    color: var(--color-highlight);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.25rem 0;
    cursor: pointer;
}

.sidebar-admin-chevron { transition: transform 0.15s ease; }
.sidebar-admin.open .sidebar-admin-chevron { transform: rotate(90deg); }

.sidebar-admin-links { display: none; flex-direction: column; padding: 0.25rem 0; }
.sidebar-admin.open .sidebar-admin-links { display: flex; }
.sidebar-admin-links a {
    color: var(--color-bg);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.9rem;
}
.sidebar-admin-links a:hover { background: var(--color-main); color: var(--color-white); }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(230, 225, 214, 0.15);
    color: var(--color-white);
}
.sidebar-user-icon { width: 26px; height: 26px; flex-shrink: 0; }
.sidebar-user-name { font-size: 0.95rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }

.sidebar-user-actions { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.6rem; padding-left: 2.1rem; }
.sidebar-user-actions form { margin: 0; }

.sidebar-user-btn {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-radius: 4px;
    padding: 0.4rem 0.6rem;
    color: var(--color-bg);
    font-size: 0.8rem;
    cursor: pointer;
    text-decoration: none;
    opacity: 0.9;
}
.sidebar-user-btn:hover {
    background: var(--color-main);
    color: var(--color-white);
    opacity: 1;
}

.sidebar-last-login {
    margin-top: 0.6rem;
    padding-left: 2.1rem;
    font-size: 0.7rem;
    color: var(--color-bg);
    opacity: 0.6;
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    display: none; /* desktop: only shown on mobile for the menu toggle */
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1.25rem;
    background: var(--color-white);
    border-bottom: 1px solid rgba(11, 58, 66, 0.15);
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--color-main);
    cursor: pointer;
}

.content { padding: 1.5rem; width: 100%; }

/* ---------- Auth screens ---------- */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.auth-card {
    background: var(--color-main);
    border-top: 4px solid var(--color-highlight);
    border-radius: 6px;
    box-shadow: 0 4px 18px rgba(11, 58, 66, 0.18);
    padding: 2rem;
    width: 100%;
    max-width: 420px;
    color: var(--color-white);
}

.auth-card h2 { color: var(--color-white); }
.auth-card .muted { color: rgba(255, 255, 255, 0.75); }
.auth-card .form-group label { color: var(--color-white); }
.auth-card .btn-primary { background: var(--color-highlight); color: var(--color-dark); }
.auth-card .btn-primary:hover:not(:disabled) { background: var(--color-dark); color: var(--color-white); }
/* Messages on the auth card: sand, not the global red/gold flash colours —
   those clash with the card's main colour and the highlight button. */
.auth-card .flash { background: var(--color-bg); color: var(--color-dark); }

.auth-brand {
    margin: 0 0 1rem;
    color: var(--color-main);
    font-size: 1.4rem;
}

.auth-logo {
    width: 110px;
    height: auto;
    display: block;
    margin: 0 auto 1.25rem;
}

.auth-center { text-align: center; }

/* ---------- Cards, tables, forms ---------- */
.card {
    background: var(--color-white);
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(11, 58, 66, 0.12);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}
.card-header h3 { margin: 0; }
.card-header-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid rgba(11, 58, 66, 0.12);
}
.table th { color: var(--color-accent); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; }
.table-actions { white-space: nowrap; text-align: right; }
/* Sortable table headers (click handler in app.js): key is the cell's
   data-sort attribute when present, else its text. */
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]:hover { color: var(--color-main); }
.table th[data-sort][data-dir="asc"]::after { content: " \25B2"; font-size: 0.75em; }
.table th[data-sort][data-dir="desc"]::after { content: " \25BC"; font-size: 0.75em; }
/* Table text filter input (handler in app.js) */
.js-table-filter { max-width: 14rem; }
/* Per-column alignment utilities */
.table .col-centre { text-align: center; }
.table .col-right { text-align: right; }
/* Cars show page: the per-card entry tables have different columns, so pin
   the trailing Files + actions columns to fixed widths — they then line up
   vertically across all the cards. */
.car-entries .col-files { width: 4rem; }
.car-entries .table-actions { width: 4.5rem; }
/* Row hover for every table site-wide: a soft tint of the palette highlight colour */
.table tbody tr:hover { background: color-mix(in srgb, var(--color-highlight) 18%, transparent); }
/* Clickable rows (data-href handled in app.js) */
.table tbody tr[data-href] { cursor: pointer; }
.table tbody tr[data-href]:focus { outline: 2px solid var(--color-main); outline-offset: -2px; }
/* Late backup highlighting (backups index table cells + show-page info rows):
   light red wash */
.cell-late { background: color-mix(in srgb, var(--color-danger) 14%, var(--color-white)); }
/* Monitor index row highlighting: light red while the site is down, light
   tan while high-usage, light yellow while it is slow. Row-level (on the tr,
   after the hover rule so it wins over it) so a cell-late SSL expiry cell
   still shows its own colour. */
.table tbody tr.row-down { background: color-mix(in srgb, var(--color-danger) 12%, var(--color-white)); }
.table tbody tr.row-usage { background: color-mix(in srgb, var(--color-accent) 18%, var(--color-white)); }
.table tbody tr.row-slow { background: color-mix(in srgb, var(--color-highlight) 22%, var(--color-white)); }

.form-group { margin-bottom: 1rem; }
.form-group-narrow { max-width: 360px; }

/* Section divider inside a settings-style form (e.g. /monitor/settings). */
.form-divider {
    border: 0;
    border-top: 1px solid color-mix(in srgb, var(--color-muted) 30%, var(--color-white));
    margin: 1.25rem 0;
}

.form-subgroup {
    border: 1px solid rgba(11, 58, 66, 0.2);
    border-radius: 4px;
    padding: 1rem;
    margin-bottom: 1rem;
}
.form-subgroup legend {
    padding: 0 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-accent);
}

.cash-balance { font-size: 1.4rem; font-weight: 600; color: var(--color-main); margin: 0; }

/* ---------- Stat cards (portfolio summary) ---------- */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}
.stat-cards .card { margin-bottom: 0; }
.stat-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-muted);
    margin-bottom: 0.4rem;
}
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--color-main); }
.stat-card-total { border-top: 3px solid var(--color-main); }
.stat-card-total .stat-value { color: var(--color-dark); }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 58, 66, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.modal-overlay[hidden] { display: none; }

.modal {
    background: var(--color-white);
    border-radius: 6px;
    border-top: 4px solid var(--color-main);
    box-shadow: 0 8px 30px rgba(11, 58, 66, 0.3);
    padding: 1.5rem;
    max-width: 400px;
    width: calc(100% - 2rem);
}
.modal-message { margin-top: 0; }

/* Wider modal variant for table content (e.g. energy rate averages): sizes
   to its content up to near-viewport, scrolls vertically when tall. */
.modal.modal-wide {
    max-width: min(720px, calc(100% - 2rem));
    width: auto;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
}

.amount-pos { color: var(--color-main); font-weight: 600; }
.amount-neg { color: var(--color-danger); font-weight: 600; }

.table-totals td { border-top: 2px solid var(--color-dark); }

.holding-row { cursor: pointer; }
.holding-row:hover td { background: rgba(0, 95, 102, 0.06); }
.holding-row:focus { outline: 2px solid var(--color-main); outline-offset: -2px; }
/* Days whose half-hourly data is still incomplete (sync lag) */
.table tr.usage-row-incomplete td { background: color-mix(in srgb, var(--color-highlight) 25%, transparent); }

/* Direct child only: a descendant selector would also hit the sub-table's
   cells (beige backgrounds, red borders on every column). */
.holding-detail > td {
    background: var(--color-bg);
    border-left: 3px solid var(--color-main);
    padding: 0.5rem 0.75rem;
}

.table-sub-wrap {
    background: var(--color-white);
    border: 1px solid rgba(11, 58, 66, 0.2);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(11, 58, 66, 0.1);
    overflow: hidden;
}
.table-sub { margin: 0; }
.table-sub th { background: rgba(11, 58, 66, 0.07); }
/* Tight rows with light palette striping; the explicit hover rule keeps the
   site-wide hover tint working over the stripes (same specificity, later in
   the cascade). */
.table-sub th, .table-sub td { padding: 0.25rem 0.75rem; }
.table-sub tbody tr:nth-child(odd) { background: var(--color-white); }
.table-sub tbody tr:nth-child(even) { background: color-mix(in srgb, var(--color-bg) 30%, var(--color-white)); }
.table-sub tbody tr:hover { background: color-mix(in srgb, var(--color-highlight) 18%, transparent); }
.table-sub tr:last-child td { border-bottom: none; }
.form-group label { display: block; margin-bottom: 0.3rem; font-weight: 600; font-size: 0.9rem; }
.form-group input:not([type="checkbox"]):not([type="radio"]), .form-group select, .form-group textarea,
.member-emails-table input[type="email"] {
    width: 100%;
    padding: 0.55rem 0.65rem;
    border: 1px solid rgba(11, 58, 66, 0.3);
    border-radius: 4px;
    font: inherit;
    font-size: 1rem;
}
.form-group input:not([type="checkbox"]):not([type="radio"]):focus, .form-group select:focus, .form-group textarea:focus,
.member-emails-table input[type="email"]:focus {
    outline: 2px solid var(--color-main);
    outline-offset: 1px;
}

.form-row { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 180px; margin-bottom: 0; }
.form-group-actions { flex: 0 0 auto; }

/* Horizontal form rows: label on the left, input on the right.
   The whole row tints on hover (same palette tint as table rows). */
.form-grid-row {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 0 1.25rem;
    align-items: center;
    padding: 0.45rem 0.6rem;
    border-radius: 4px;
}
.form-grid-row:hover { background: color-mix(in srgb, var(--color-highlight) 18%, transparent); }
.form-grid-row[hidden] { display: none; }
.form-grid-row > label { font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.form-grid-row .form-group { margin-bottom: 0; min-width: 0; }
.form-grid-row-top { align-items: start; }
.form-grid-row-top > label { padding-top: 0.55rem; }

/* Editable email rows inside a form (member add/edit) */
.member-emails-table { margin-bottom: 0.75rem; }
.member-emails-table .member-email-primary { text-align: center; white-space: nowrap; }

/* Full-address preview under the location dropdown (member add/edit) */
.member-location-address { margin-top: 0.4rem; font-size: 0.9rem; }

/* Create/delete order selection mode (medication member page): the tickbox
   column and the mode's submit button stay hidden until the mode is switched
   on; the toggle button stays visible and becomes the cancel. The .card prefix
   keeps these rules ahead of the later .btn/.btn-row display rules. */
.card .med-select-cell, .card .med-select-go { display: none; }
.card.med-selecting .med-select-cell { display: table-cell; width: 2rem; }
.card.med-selecting .med-select-go { display: inline-block; }
.card.med-selecting .btn-row.med-select-go { display: flex; }
/* Print-list selection mode: same pattern with its own column/submit bar, so
   the two modes never show their controls at the same time. */
.card .med-print-cell, .card .med-print-go { display: none; }
.card.med-print-selecting .med-print-cell { display: table-cell; width: 2rem; }
.card.med-print-selecting .btn-row.med-print-go { display: flex; }
.med-review-row { justify-content: center; margin-top: 1rem; }
/* Spacing between the provider picker and its order-reference input on the create-order form. */
.med-ref-field { margin-top: 0.4rem; }
.med-select-cell input[type="checkbox"], .med-print-cell input[type="checkbox"] { accent-color: var(--color-main); }

/* Tickbox rows inside the print-list column modal */
.modal .form-check { margin-bottom: 0.5rem; }
.modal .form-check label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.modal .form-check input[type="checkbox"] { accent-color: var(--color-main); }
/* Modals aren't inside .card, so their button row needs its own top spacing. */
.modal .btn-row { margin-top: 1rem; }

/* Order-history date group row: date on the left, per-date print button right */
.med-history-date { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }

/* Inline content links site-wide: palette dark red, underline only on hover.
   Buttons (.btn) and badges (.badge) keep their own styling. */
.content a:not(.btn):not(.badge) { color: var(--color-dark); text-decoration: none; font-weight: 600; }
.content a:not(.btn):not(.badge):hover { text-decoration: underline; }

/* Copy-to-clipboard button next to drug names (medication section) */
.btn-copy { background: none; border: none; padding: 0.1rem 0.25rem; cursor: pointer; color: var(--color-muted); vertical-align: middle; }
.btn-copy:hover, .btn-copy.is-copied { color: var(--color-main); }
.btn-copy .icon-done { display: none; }
.btn-copy.is-copied .icon-copy { display: none; }
.btn-copy.is-copied .icon-done { display: inline-block; }

/* Colour palette swatch (projects section): square matching the palette's
   three-line rows, centred in its cell; hovering pops a larger preview
   (the ::after inherits the swatch's inline background colour) */
.colour-swatch-cell { width: 3.4rem; }
.colour-swatch-cell .colour-swatch { width: 3.4rem; height: 3.4rem; }
.colour-name { font-weight: 600; margin-bottom: 0.1rem; }
.colour-swatch { display: block; width: 2.5rem; height: 2.5rem; border-radius: 4px; border: 1px solid var(--color-accent); position: relative; }
.colour-swatch::after {
    content: '';
    position: absolute;
    bottom: calc(100% + 0.5rem);
    left: 50%;
    transform: translateX(-50%);
    width: 8rem;
    height: 8rem;
    background-color: inherit;
    border: 1px solid var(--color-accent);
    border-radius: 6px;
    box-shadow: 0 8px 30px rgba(11, 58, 66, 0.3);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    pointer-events: none;
    z-index: 50;
}
.colour-swatch:hover::after { opacity: 1; visibility: visible; }

/* Select-and-copy mode: checkbox column and Copy selected button stay hidden
   until the card gets .colour-selecting */
.colour-check-cell, .js-colours-copy-selected { display: none; }
.colour-selecting .colour-check-cell { display: table-cell; }
.colour-selecting .js-colours-copy-selected { display: inline-block; }
.colour-selecting tbody tr { cursor: pointer; }

/* Security reviews card (projects section): tab switcher + prompt text in
   the "Suggested prompt" modal; the copied state flashes the label button */
.prompt-tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.prompt-tabs .js-prompt-tab.active { background: var(--color-main); }
.prompt-text {
    white-space: pre-wrap; word-break: break-word; margin: 0 0 0.75rem;
    max-height: 50vh; overflow-y: auto; padding: 0.75rem;
    background: color-mix(in srgb, var(--color-bg) 40%, var(--color-white));
    border: 1px solid var(--color-bg); border-radius: 6px;
    font-size: 0.85rem; font-family: inherit;
}
.btn.js-copy.is-copied { background: var(--color-highlight); color: var(--color-dark); }
.btn-icon:disabled { opacity: 0.3; cursor: default; }
.btn-icon:disabled:hover { color: var(--color-accent); }

/* Icon-only action buttons (backup run pin/delete/download — inline SVGs use fill="currentColor") */
.btn-icon, .content a.btn-icon { background: none; border: none; padding: 0.1rem 0.25rem; cursor: pointer; color: var(--color-accent); font-weight: normal; vertical-align: middle; }
.btn-icon:hover, .content a.btn-icon:hover { color: var(--color-main); text-decoration: none; }
.btn-icon-danger, .content a.btn-icon-danger { color: var(--color-danger); }
.btn-icon-danger:hover, .content a.btn-icon-danger:hover { color: var(--color-dark); }

/* Vault badge: marks a backup run/file saved to the offline backup (not a button) */
.vault-badge { color: var(--color-highlight); vertical-align: middle; display: inline-block; padding: 0.1rem 0.25rem; }

/* Download-in-progress spinner (backup download modal) */
.spinner { display: inline-block; width: 1.25rem; height: 1.25rem; border: 3px solid color-mix(in srgb, var(--color-muted) 30%, transparent); border-top-color: var(--color-main); border-radius: 50%; vertical-align: middle; animation: spin 0.8s linear infinite; }
.spinner-lg { width: 2.5rem; height: 2.5rem; }
@keyframes spin { to { transform: rotate(360deg); } }
/* Author display rules (e.g. .btn-row) beat the UA [hidden] rule — restore it. */
.btn-row[hidden], .form-check[hidden], .download-progress[hidden] { display: none; }
.download-progress { text-align: center; padding: 1rem 0.5rem; }
.download-progress .spinner { display: block; margin: 0 auto 0.75rem; }

/* Share modal (backups): copyable presigned link / bucket path rows */
.share-file { margin-bottom: 0.9rem; }
.share-file-name { font-weight: 600; font-size: 0.85rem; margin-bottom: 0.25rem; overflow-wrap: anywhere; }
.share-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.3rem; }
.share-row-label { flex-shrink: 0; width: 2.8rem; font-size: 0.85rem; color: var(--color-muted); }
.share-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8rem; background: color-mix(in srgb, var(--color-bg) 40%, var(--color-white)); padding: 0.3rem 0.5rem; border-radius: 4px; }
/* Encryption-key reminder in the share modal: full-width gold tint of the palette highlight */
.share-key-note { display: block; text-align: center; background: color-mix(in srgb, var(--color-highlight) 35%, var(--color-white)); color: var(--color-dark); font-weight: 600; font-size: 0.85rem; padding: 0.3rem 0.6rem; border-radius: 4px; margin: 0.2rem 0 0.6rem; }

/* Quantity input on the create-order review page */
.med-qty { width: 6rem; }

/* Notes sub-row under a medication row (medication member page) */
.med-notes { font-size: 0.85rem; font-style: italic; white-space: pre-line; }
.med-notes-row td { padding-top: 0; }
.med-row-has-notes td { border-bottom: none; }
/* Each medication is its own tbody so a notes sub-row shares the main row's
   hover tint (the site-wide rule tints rows individually). */
.table tbody.med-group:hover tr { background: color-mix(in srgb, var(--color-highlight) 18%, transparent); }

/* Section header rows (Medications/Appliances/Supplements) carry a permanent
   tint so the groups read at a glance. */
.table tr.med-type-row td { background: color-mix(in srgb, var(--color-highlight) 25%, transparent); }

/* Notes sub-row under an appointment row (appointments member page) */
.appt-notes { font-size: 0.85rem; font-style: italic; white-space: pre-line; }
.appt-notes-row td { padding-top: 0; }
.appt-row-has-notes td { border-bottom: none; }
/* Each appointment is its own tbody so a notes sub-row shares the main row's
   hover tint (the site-wide rule tints rows individually). */
.table tbody.appt-group:hover tr { background: color-mix(in srgb, var(--color-highlight) 18%, transparent); }

/* Combo field: text input filtering a list of saved options (e.g. appointment
   locations). The list drops below the input; anything typed that isn't picked
   stays as ad hoc free text (hidden id input left empty). */
.combo-field { position: relative; }
.combo-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 20;
    margin-top: 2px;
    max-height: 14rem;
    overflow-y: auto;
    background: var(--color-white);
    border: 1px solid rgba(11, 58, 66, 0.3);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.combo-option { padding: 0.5rem 0.65rem; cursor: pointer; }
.combo-option:hover, .combo-option.is-active { background: color-mix(in srgb, var(--color-highlight) 25%, transparent); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    padding: 0.55rem 1.1rem;
    border: none;
    border-radius: 4px;
    font: inherit;
    font-size: 0.95rem;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn[hidden] { display: none; }
/* Inline SVG icons inside buttons: centre on the text instead of the baseline */
.btn svg { vertical-align: middle; margin-top: -0.15em; }

/* Notes read/edit toggle: sits in the label column of the .form-grid-row
   grid (task/idea edit forms), so keep its natural width. */
.js-notes-toggle { justify-self: start; margin-top: 0.35rem; }

.btn-primary { background: var(--color-main); color: var(--color-white); }
.btn-primary:hover:not(:disabled) { background: var(--color-accent); }

.btn-secondary { background: var(--color-highlight); color: var(--color-dark); }
.btn-secondary:hover:not(:disabled) { background: var(--color-accent); color: var(--color-white); }

.btn-row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.card form .btn-row, .card > .btn-row { margin-top: 1rem; }
.btn-row-end { margin-left: auto; }

.btn-small { padding: 0.3rem 0.7rem; font-size: 0.85rem; background: var(--color-accent); color: var(--color-white); }
.btn-small:hover:not(:disabled) { background: var(--color-main); }
.btn-danger { background: var(--color-danger); color: var(--color-white); }
.btn-danger:hover:not(:disabled) { background: var(--color-dark); }

.btn-link { background: none; color: var(--color-main); padding: 0; text-decoration: underline; }

/* ---------- Badges & flash ---------- */
.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.8rem; text-decoration: none; }
.badge-active { background: var(--color-main); color: var(--color-white); }
.badge-inactive { background: var(--color-muted); color: var(--color-white); }
.badge-pending { background: var(--color-highlight); color: var(--color-dark); }
.badge-stale { background: var(--color-highlight); color: var(--color-dark); }

.flash { padding: 0.75rem 1rem; border-radius: 4px; margin-bottom: 1rem; word-break: break-word; }
.flash-success { background: var(--color-main); color: var(--color-white); }
.flash-error { background: var(--color-danger); color: var(--color-white); }
.flash-info { background: var(--color-accent); color: var(--color-white); }
.flash-warning { background: var(--color-highlight); color: var(--color-dark); }

.muted { color: var(--color-muted); }
.text-danger { color: var(--color-danger); font-weight: 600; }
.inline-form { display: inline; }

/* Backups section: one <details> per database backup run */
.backup-run { border-top: 1px solid color-mix(in srgb, var(--color-muted) 30%, transparent); }
.backup-run summary { cursor: pointer; padding: 0.6rem 1rem; overflow-wrap: anywhere; }
.backup-run summary::marker { color: var(--color-dark); }
.backup-run summary:hover { background: color-mix(in srgb, var(--color-highlight) 18%, transparent); }
/* Run-selection checkboxes reuse the files-card .js-file-check hooks but sit
   inline in the run summary, not absolutely positioned on a tile */
.backup-run .js-file-check { position: static; margin-right: 0.5rem; }
.backup-run .js-file-check:disabled { opacity: 0.4; }

/* Retention policy editors (backups settings / project edit): sentence-style
   lines with inline controls inside the otherwise full-width .form-group */
.retention-policy { border: 1px solid color-mix(in srgb, var(--color-muted) 35%, transparent); border-radius: 4px; padding: 0.75rem 1rem; margin: 0 0 1rem; }
.retention-policy legend { font-weight: 600; padding: 0 0.35rem; }
.retention-line { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.form-group .retention-line select { width: auto; min-width: 9rem; margin: 0; }
.form-group .retention-line input[type="number"] { width: 6rem; margin: 0; }
.retention-policy .muted { display: block; margin: 0; }
h2 { color: var(--color-dark); margin-top: 0; }
h3 { color: var(--color-accent); margin-top: 0; }

.page-subtitle {
    margin: -0.4rem 0 1.25rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-accent);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.btn-quick.active {
    background: var(--color-main);
    outline: 2px solid var(--color-dark);
}

code {
    background: rgba(11, 58, 66, 0.08);
    border-radius: 3px;
    padding: 0.1rem 0.35rem;
    font-size: 0.85em;
}

/* Long code snippets (e.g. device webhook URLs) wrap instead of
   overflowing their card */
.form-group code {
    overflow-wrap: anywhere;
    word-break: break-all;
}

/* PWA install card is mobile-only */
@media (min-width: 769px) {
    #pwa-install-card { display: none; }
}

/* ---------- Invite / QR blocks ---------- */
.invite-block { margin-top: 0.5rem; font-size: 0.8rem; word-break: break-all; }
.invite-block a { color: var(--color-accent); }
.qr { display: block; margin-top: 0.5rem; background: var(--color-white); }

.rename-form { display: flex; gap: 0.5rem; align-items: center; }
.rename-form[hidden] { display: none; }
.rename-form input {
    padding: 0.3rem 0.5rem;
    border: 1px solid rgba(11, 58, 66, 0.3);
    border-radius: 4px;
    font-size: 0.9rem;
    max-width: 220px;
}

.truncate {
    display: block;
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(11, 58, 66, 0.45);
    z-index: 15;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .shell { flex-direction: column; }
    .stat-cards { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        z-index: 20;
        height: 100vh;
        height: 100dvh;
        left: -240px;
        transition: left 0.2s ease;
    }
    .sidebar.open { left: 0; }
    .topbar { display: flex; }
    .nav-toggle { display: block; }
    .content { padding: 1rem; }

    /* Tables: keep their layout and scroll horizontally inside the card */
    .card { overflow-x: auto; }
    .table { min-width: 560px; }
    .truncate { max-width: 150px; }

    /* Horizontal form rows collapse to stacked; the in-form email table can shrink */
    .form-grid-row { grid-template-columns: 1fr; }
    .form-grid-row-top > label { padding-top: 0; }
    .form-grid-row .form-group { margin-bottom: 0.5rem; }
    .member-emails-table.table { min-width: 0; }

    /* Page headers stack; action buttons sit neatly below the title */
    .page-header { flex-direction: column; align-items: flex-start; }
}

/* Date/time fields: visible text input + hidden native picker.
   The picker trigger sits inside the input on the right, greyed out. */
.date-field, .time-field { position: relative; }
.date-field input.date-display, .time-field input.time-display { padding-right: 2rem; }
.date-field .date-picker-btn, .time-field .time-picker-btn {
    position: absolute;
    right: 0.35rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 0 0.3rem;
    line-height: 1;
    color: #8a8a8a;              /* muted grey; hover below darkens it */
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}
.date-field .date-picker-btn:hover, .time-field .time-picker-btn:hover { color: #333; }
.date-field .date-picker-btn svg, .time-field .time-picker-btn svg { width: 1.1rem; height: 1.1rem; }
.date-field input.date-native, .time-field input.time-native {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 1px;
    height: 1px;
    min-width: 0;
    padding: 0;
    border: none;
    opacity: 0;
    pointer-events: none;
}

/* ---------- Website projects: dropzone, attachments, task statuses ---------- */
.dropzone {
    border: 2px dashed var(--color-accent);
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1rem;
    text-align: center;
    cursor: pointer;
}
.dropzone:focus { outline: 2px solid var(--color-main); outline-offset: 1px; }
.dropzone.is-dragover {
    border-color: var(--color-main);
    background: color-mix(in srgb, var(--color-highlight) 18%, transparent);
}
.dropzone.is-uploading { opacity: 0.6; cursor: default; }
.dropzone-message { margin: 0.5rem 0 0; color: var(--color-danger); font-size: 0.9rem; }

.attachment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}
.attachment-tile {
    position: relative;
    border: 1px solid rgba(11, 58, 66, 0.2);
    border-radius: 6px;
    overflow: hidden;
    background: var(--color-white);
}
.attachment-thumb {
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
}
.attachment-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attachment-thumb a { display: block; width: 100%; height: 100%; }
.attachment-ext { font-weight: 700; color: var(--color-accent); }
.attachment-meta { padding: 0.5rem; font-size: 0.85rem; }
.attachment-meta .badge { padding: 0.05rem 0.4rem; font-size: 0.65rem; vertical-align: middle; }
.attachment-name { font-weight: 600; word-break: break-all; }
.attachment-actions { display: flex; gap: 0.4rem; margin-top: 0.4rem; flex-wrap: wrap; }

/* Files card selection mode (mass delete) */
.js-file-check { display: none; position: absolute; top: 0.4rem; left: 0.4rem; z-index: 1; accent-color: var(--color-main); }
.file-selecting .js-file-check { display: block; }
.file-selecting .attachment-tile { cursor: pointer; }
.file-selecting .attachment-actions { display: none; }
.attachment-tile.is-selected { outline: 3px solid var(--color-main); }
.js-files-batch-delete { display: none; }
.file-selecting .js-files-batch-delete { display: inline-block; }

/* Task status rendered as a coloured pill (read-only badge on list pages) */
.status-badge { display: inline-block; border: none; border-radius: 999px; padding: 0.15rem 0.55rem; font-size: 0.8rem; }
.status-pending { background: var(--color-highlight); color: var(--color-dark); }
.status-in_progress { background: var(--color-accent); color: var(--color-white); }
.status-on_hold { background: var(--color-muted); color: var(--color-white); }
.status-complete { background: var(--color-main); color: var(--color-white); }
.status-cancelled { background: var(--color-dark); color: var(--color-white); }
.status-archived { background: var(--color-muted); color: var(--color-white); }

/* Sensor & plug history charts (home automation detail pages) */
#sensor-history-chart, #plug-history-chart { width: 100%; display: block; }
