:root {
    --fg: #1b1f24;
    --bg: #ffffff;
    --muted: #57606a;
    --line: #d0d7de;
    --link: #0969da;
    --accent: #1f6feb;
    --accent-soft: #e7f0fe;
    --panel: #f3f5f7;
}

@media (prefers-color-scheme: dark) {
    :root {
        --fg: #e6edf3;
        --bg: #0d1117;
        --muted: #9198a1;
        --line: #30363d;
        --link: #4493f8;
        --accent: #4493f8;
        --accent-soft: #15233a;
        --panel: #161b22;
    }
}

* { box-sizing: border-box; }

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

.site-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--line);
}

.brand {
    font-weight: 600;
    color: inherit;
    text-decoration: none;
}

main {
    max-width: 48rem;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

p { color: var(--muted); }

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

/* Long words (emails, report titles, handles) break instead of widening the page on a phone. */
main { overflow-wrap: break-word; }
img, svg { max-width: 100%; }

/* App frame (option C, M6). Phone: top bar, page, tab bar; "Menu" opens the sidebar as a full-screen sheet.
   Computer (60rem and wider): the sidebar stays on the left; the bars are hidden. */
.brand { display: inline-flex; align-items: center; gap: 0.5rem; }
.brand-mark { width: 1.4rem; height: 1.4rem; border-radius: 6px; background: var(--accent); flex: none; }
.icon { flex: none; }

body.app { padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px)); } /* room for the tab bar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem max(1rem, env(safe-area-inset-right, 0px)) 0.6rem max(1rem, env(safe-area-inset-left, 0px));
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}
.topbar .context-label { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
    flex: none;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-weight: 700;
    text-decoration: none;
    color: var(--accent);
    background: var(--accent-soft);
}

.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    background: var(--bg);
    border-top: 1px solid var(--line);
}
.tabbar a, .tabbar button {
    display: grid;
    justify-items: center;
    gap: 0.15rem;
    margin: 0;
    padding: 0.55rem 0.25rem 0.5rem;
    font: inherit;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--muted);
    background: none;
    border: 0;
    border-radius: 0;
    text-decoration: none;
    cursor: pointer;
}
.tabbar [aria-current="page"] { color: var(--accent); }

/* The menu: a sheet over the page on a phone (when opened), the sidebar on a computer. */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem max(1rem, env(safe-area-inset-right, 0px)) calc(1rem + env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
    color: var(--fg);
    background: var(--panel);
    overflow-y: auto;
}
.sidebar[popover] { inset: 0; width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; border: 0; }
.sidebar[popover]:not(:popover-open) { display: none; }
.sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.sidebar-top .brand { font-weight: 700; color: inherit; text-decoration: none; }
.icon-button { display: grid; place-items: center; margin: 0; padding: 0.4rem; color: var(--fg); background: transparent; border: 1px solid var(--line); border-radius: 6px; }
.sidebar .context { margin: 0; font-weight: 600; color: var(--fg); overflow-wrap: anywhere; }
.sidebar .switcher select { max-width: none; }
.nav-section h2 { margin: 0 0 0.25rem; padding: 0 0.5rem; font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); overflow-wrap: anywhere; }
.nav-section ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.1rem; }
.nav-section a, .nav-section .nav-button {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    margin: 0;
    padding: 0.55rem 0.5rem;
    border-radius: 6px;
    font: inherit;
    font-weight: 400;
    text-align: left;
    color: var(--fg);
    background: none;
    text-decoration: none;
}
.nav-section a:hover, .nav-section .nav-button:hover { background: var(--bg); }
.nav-section a[aria-current="page"] { font-weight: 600; background: var(--bg); box-shadow: inset 3px 0 0 var(--accent); }
.nav-section .icon { color: var(--muted); }
.nav-section form { margin: 0; }
.signed-in-as { margin: auto 0 0; padding: 0.75rem 0.5rem 0; border-top: 1px solid var(--line); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (min-width: 60rem) {
    body.app {
        padding-bottom: 0;
        display: grid;
        grid-template-columns: 16rem minmax(0, 1fr);
        grid-template-areas: "menu content";
        min-height: 100vh;
    }
    body.app .topbar, body.app .tabbar, .menu-close { display: none; }
    body.app > main { grid-area: content; width: 100%; max-width: 60rem; padding: 2rem 2.5rem; }
    .sidebar[popover], .sidebar[popover]:not(:popover-open) {
        grid-area: menu;
        display: flex;
        position: sticky;
        top: 0;
        inset: auto;
        width: auto;
        height: 100vh;
        border-right: 1px solid var(--line);
    }
}

/* A browser without popovers ignores the attribute: the menu then sits at the end of the page on a phone. */
@supports not selector(:popover-open) {
    .tabbar button[popovertarget] { display: none; }
}

.stack { display: flex; flex-direction: column; gap: 0.5rem; max-width: 24rem; }
.stack label { font-weight: 600; margin-top: 0.5rem; }

input {
    font: inherit;
    padding: 0.6rem 0.7rem;
    color: var(--fg);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    width: 100%;
}

button {
    font: inherit;
    font-weight: 600;
    margin-top: 1rem;
    padding: 0.6rem 1rem;
    border: 0;
    border-radius: 6px;
    color: #fff;
    background: #1f6feb;
    cursor: pointer;
}

button.link {
    margin: 0;
    padding: 0;
    font-weight: 400;
    color: inherit;
    background: none;
    text-decoration: underline;
}

.form-error, .field-error { color: #cf222e; }
.form-error ul { margin: 0; padding-left: 1.2rem; }
.validation-summary-valid { display: none; }

button.secondary, a.button.secondary, label.button.secondary {
    color: var(--fg);
    background: transparent;
    border: 1px solid var(--line);
}

a.button, label.button {
    display: inline-block;
    font-weight: 600;
    padding: 0.6rem 1rem;
    border-radius: 6px;
    color: #fff;
    background: #1f6feb;
    text-decoration: none;
}

.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.actions button { margin-top: 0; }

.or { margin: 0.5rem 0; text-align: center; color: var(--muted); }

.notice {
    padding: 0.75rem 1rem;
    border: 1px solid var(--line);
    border-left: 4px solid #1f6feb;
    border-radius: 6px;
    color: var(--fg);
}

/* A list without bullets whose items line up a link, a note and a small button (a line's receipts). */
ul.plain { list-style: none; padding: 0; }
ul.plain li { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }

/* A small marker after a name ("Pilot", "SoD off"). */
.tag {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0 0.45rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.8rem;
    white-space: nowrap;
}

.steps { padding-left: 1.2rem; }
.steps > li { margin-bottom: 1.5rem; }

.qr { width: min(240px, 100%); background: #fff; padding: 0.5rem; border-radius: 6px; }
.qr svg { display: block; width: 100%; height: auto; }

kbd { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }

.codes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
    gap: 0.25rem 1.5rem;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.facts dt { font-weight: 600; margin-top: 1rem; }
.facts dd { margin: 0.25rem 0 0; color: var(--muted); }

.passkeys { list-style: none; padding: 0; }
.passkeys li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--line);
}

form.inline { display: flex; gap: 0.5rem; align-items: center; margin: 0; }
form.inline input { width: auto; flex: 1 1 10rem; }
form.inline button { margin-top: 0; }

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

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

@media print {
    .site-header, .topbar, .actions, nav { display: none; }
    body.app { display: block; padding: 0; }
    body { color: #000; background: #fff; }
}

select {
    font: inherit;
    padding: 0.6rem 0.7rem;
    color: var(--fg);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
}

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--line); }
/* At phone width a list table becomes one block per row; a cell with data-label="Total" shows "Total: " before its
   value, since the column headings are hidden. A table that must stay a grid goes in a .scroll-x box instead. */
@media (max-width: 40rem) {
    table.list thead { display: none; }
    table.list tr { display: block; padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
    table.list td { display: block; border: 0; padding: 0.15rem 0; }
    table.list td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); }
    table.list td:empty { display: none; }
}
.scroll-x { overflow-x: auto; }

.hint { font-size: 0.9rem; color: var(--muted); }

.notice.success { border-left-color: #1a7f37; }
.notice.success strong { color: #1a7f37; }
@media (prefers-color-scheme: dark) {
    .notice.success { border-left-color: #3fb950; }
    .notice.success strong { color: #3fb950; }
}

input[type="checkbox"] { width: auto; margin-right: 0.5rem; }
.stack label:has(> input[type="checkbox"]),
.stack label:has(> input[type="radio"]) { font-weight: 400; }

textarea {
    font: inherit;
    padding: 0.6rem 0.7rem;
    color: var(--fg);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    width: 100%;
}

.switcher { display: flex; align-items: center; gap: 0.5rem; min-width: 0; flex: 1 1 auto; margin: 0; }
.switcher select { min-width: 0; width: 100%; max-width: 20rem; padding: 0.35rem 0.5rem; text-overflow: ellipsis; }
.switcher button { margin-top: 0; padding: 0.35rem 0.7rem; }

/* Question threads on a report: one bordered block per thread, messages keep their line breaks. */
.thread {
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    border: 1px solid var(--line);
    border-radius: 6px;
}
.thread h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.thread .message { margin: 0.75rem 0; }
.thread .message p { margin: 0.25rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Receipt upload: the area to drop files on (the file input inside it is the way to pick them, including on a phone). */
.drop-zone {
    display: grid;
    gap: 0.5rem;
    padding: 1rem;
    border: 2px dashed var(--line);
    border-radius: 6px;
}
.drop-zone.dragging { border-color: #1f6feb; background: rgba(31, 111, 235, 0.08); }
.upload-status { margin: 0; }
.upload-status progress { flex: 1 1 6rem; max-width: 10rem; }

/* One-page line form (M6, option 2): receipts beside the details on a computer, receipts first on a phone. */
.crumb { margin: 0; font-size: 0.9rem; }
.line-editor { display: grid; gap: 1.5rem; }
.line-editor h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }
.line-receipts, .line-details { min-width: 0; }
.line-details .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.line-details .field { display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }
.line-details .field label { font-weight: 600; margin-top: 0.5rem; }
.line-details { max-width: none; }
.no-receipt { margin-top: 0.75rem; }
.no-receipt summary { cursor: pointer; color: var(--link); }
.no-receipt[open] { display: flex; flex-direction: column; gap: 0.5rem; }
.no-receipt label { font-weight: 600; margin-top: 0.5rem; }
.drop-zone .actions label.button { cursor: pointer; }
.drop-zone input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.take-photo { display: none; }
@media (pointer: coarse) { label.take-photo { display: inline-block; } }
.receipt-viewer { display: none; margin: 0 0 1rem; }
.receipt-viewer img { display: block; width: 100%; max-height: 28rem; object-fit: contain; border-radius: 6px; background: var(--panel); }
.receipt-viewer figcaption { font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; }
.pdf-card { display: block; padding: 2rem 1rem; text-align: center; border: 1px solid var(--line); border-radius: 6px; }
.receipt-choices { list-style: none; margin: 0.5rem 0 1rem; padding: 0; display: grid; gap: 0.5rem; }
.receipt-choice {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.25rem 0.6rem;
    align-items: center;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.receipt-choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.receipt-choice input[type="checkbox"] { width: 1.2rem; height: 1.2rem; margin: 0; }
.receipt-choice .receipt-name { display: flex; flex-wrap: wrap; gap: 0 0.5rem; align-items: baseline; min-width: 0; }
.receipt-choice .receipt-name a { font-weight: 600; }
.receipt-choice > button.link { grid-column: 2 / -1; justify-self: start; font-size: 0.85rem; }
.preview-button { margin: 0; padding: 0.3rem 0.7rem; font-size: 0.85rem; }

/* The hover card: a computer with a mouse shows the receipt when the pointer is over it; nothing to click. */
.hover-card {
    display: none;
    position: absolute;
    z-index: 20;
    top: 0;
    left: calc(100% + 0.75rem);
    width: 18rem;
    padding: 0.5rem;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
    pointer-events: none;
    font-size: 0.8rem;
    color: var(--muted);
}
.hover-card img { display: block; width: 100%; max-height: 22rem; object-fit: contain; margin-bottom: 0.4rem; }
@media (hover: hover) and (pointer: fine) {
    .receipt-choice:hover .hover-card, .receipt-choice:focus-within .hover-card { display: block; }
    .preview-button { display: none; }
}

/* The preview sheet: a phone's Preview button opens the receipt over the page (an HTML popover, no script). */
.preview-sheet {
    inset: auto 0 0 0;
    width: 100%;
    max-width: none;
    max-height: 90vh;
    margin: 0;
    padding: 1rem max(1rem, env(safe-area-inset-right, 0px)) calc(1rem + env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
    border: 0;
    border-radius: 14px 14px 0 0;
    color: var(--fg);
    background: var(--bg);
}
.preview-sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.preview-sheet img { display: block; max-width: 100%; max-height: 62vh; margin: 0 auto; object-fit: contain; }
.preview-sheet .actions { margin-top: 0.75rem; }
.preview-sheet .actions > * { flex: 1; text-align: center; }

.remove-line { margin-top: 2.5rem; }

@media (min-width: 60rem) {
    .line-editor { grid-template-columns: minmax(0, 22rem) minmax(0, 1fr); gap: 2.5rem; align-items: start; }
    .receipt-viewer:not([hidden]) { display: block; }
}

/* People lists: the search and filter row, and the pager under a long list. */
form.filters { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; margin: 1rem 0; }
form.filters label { display: grid; gap: 0.25rem; }
form.filters button { margin-top: 0; }
.pager { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; margin: 1rem 0; }
form.filters label.check { display: flex; gap: 0.4rem; align-items: center; }
form.filters select { min-width: 12rem; }
