:root {
    color-scheme: light dark;
    --bg: #f4f1ea;
    --surface: #fffdf8;
    --surface-2: #ebe6da;
    --text: #26231d;
    --muted: #6b6558;
    --border: #d8d1c1;
    --accent: #2f5d50;
    --accent-text: #ffffff;
    --danger: #a3341f;
    --danger-bg: #f8e4de;
    --notice-bg: #e0ecdf;
    --shadow: 0 1px 2px rgb(38 35 29 / 12%);
    --radius: 8px;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1b1a17;
        --surface: #262420;
        --surface-2: #211f1c;
        --text: #ece7dc;
        --muted: #a39c8c;
        --border: #3d3a33;
        --accent: #7fb8a4;
        --accent-text: #10201b;
        --danger: #f0907b;
        --danger-bg: #40211a;
        --notice-bg: #203329;
        --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
a { color: var(--accent); }
ul, ol { margin: 0; padding: 0; list-style: none; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.9em; }
.muted, small { color: var(--muted); font-size: 0.87rem; }

/* ---- Controls ---- */

input, select, textarea, button { font: inherit; color: inherit; }

input[type="text"], input[type="password"], input[type="search"], input[type="date"], select, textarea {
    width: 100%;
    padding: 0.45rem 0.6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}
textarea { resize: vertical; }
input[type="color"] {
    width: 2.4rem;
    height: 2.2rem;
    padding: 2px;
    flex: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

button, .button {
    padding: 0.45rem 0.9rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}
.button { display: inline-block; color: var(--text); text-decoration: none; }
button:hover:not(:disabled), a.button:hover { border-color: var(--muted); }
.button[aria-disabled="true"] { opacity: 0.4; cursor: default; }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
button.link { padding: 0; background: none; border: none; color: var(--accent); text-decoration: underline; text-align: left; white-space: normal; }
button.icon { padding: 0.1rem 0.5rem; font-size: 1.1rem; line-height: 1.3; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

label { display: grid; gap: 0.25rem; font-weight: 600; font-size: 0.87rem; }
label > * { font-weight: 400; font-size: 1rem; }
label > small { font-size: 0.87rem; }
label.check { display: flex; align-items: center; gap: 0.4rem; font-weight: 400; font-size: 1rem; white-space: nowrap; }
.field-error { color: var(--danger); font-weight: 400; }
[aria-invalid="true"] { border-color: var(--danger); outline-color: var(--danger); }
.row-form > .field-error { flex-basis: 100%; }

fieldset { margin: 0; padding: 0; border: none; display: grid; gap: 0.35rem; }
legend { padding: 0; margin-bottom: 0.25rem; font-weight: 600; font-size: 0.87rem; }

.stack { display: grid; gap: 0.9rem; }
.actions { display: flex; align-items: center; gap: 0.75rem; }

.alert { padding: 0.6rem 0.8rem; border-radius: 6px; }
.alert.error { background: var(--danger-bg); color: var(--danger); }
.alert.notice { background: var(--notice-bg); }
.messages { display: grid; gap: 0.5rem; }
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 10; max-width: calc(100vw - 2rem); box-shadow: var(--shadow); border: 1px solid currentColor; }

/* ---- Page chrome ---- */

.topbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    padding: 0.6rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.version { color: var(--muted); font-size: 0.75em; font-weight: 400; }
.topbar nav { display: flex; gap: 0.25rem; flex: 1; }
.topbar nav a { padding: 0.3rem 0.7rem; border-radius: 6px; color: var(--muted); text-decoration: none; }
.topbar nav a:hover { color: var(--text); }
.topbar nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.topbar .account { display: flex; align-items: center; gap: 1rem; }

.page { max-width: 54rem; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; display: grid; gap: 1.25rem; }
.panel { display: grid; gap: 0.9rem; padding: 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.narrow { max-width: 24rem; }
body.centered { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
body.centered .panel { width: 100%; }

.rows { display: grid; }
.rows li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; padding: 0.6rem 0; border-top: 1px solid var(--border); }
.rows li:first-child { border-top: none; }
.row-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; flex: 1 1 18rem; min-width: 0; }
.row-form.wide { flex-basis: 100%; }
.row-form.add { flex: none; max-width: 30rem; }
.row-form input[type="text"], .row-form input[type="password"] { flex: 1; min-width: 7rem; }
.row-form select { width: auto; }
.row-form input.capacity { flex: 0 0 7rem; min-width: 0; }
.row-actions { display: flex; gap: 0.25rem; }
.row-form .save-status { min-width: 4rem; }

/* ---- Board ---- */

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.9rem 1.25rem 0; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.filters input, .filters select { width: auto; max-width: 13rem; }
.board-page .messages { padding: 0.9rem 1.25rem 0; }

.drafts { display: grid; gap: 0.5rem; margin: 0.9rem 1.25rem 0; padding: 0.7rem 0.9rem; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); }
.drafts ul { display: grid; gap: 0.4rem; }
.drafts li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.75rem; }
.drafts li span:first-child { font-weight: 600; overflow-wrap: anywhere; }
.drafts li .muted { flex: 1; }

.board { display: flex; align-items: flex-start; gap: 0.9rem; padding: 0.9rem 1.25rem 2rem; overflow-x: auto; }
.column { flex: 1 0 17rem; max-width: 26rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.column > header { display: flex; align-items: center; gap: 0.5rem; padding: 0.7rem 0.8rem 0.3rem; }
.column > header h2 { font-size: 0.95rem; overflow-wrap: anywhere; }
.column .count { flex: 1; color: var(--muted); font-size: 0.87rem; }
.cards { display: grid; gap: 0.5rem; align-content: start; min-height: 6rem; padding: 0.5rem; }
.cards .empty { padding: 1.2rem 0.5rem; text-align: center; color: var(--muted); font-size: 0.87rem; }

.card { display: grid; gap: 0.4rem; padding: 0.65rem 0.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow); cursor: grab; }
.card:hover { border-color: var(--muted); }
.card.epic { border-left: 4px solid var(--accent); }
.card.dragging { opacity: 0.35; }
.card h3 { font-weight: 600; overflow-wrap: anywhere; }
.card .kicker { color: var(--muted); font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; overflow-wrap: anywhere; }
.card.epic .kicker { color: var(--accent); }
.card footer { display: flex; align-items: center; gap: 0.6rem; color: var(--muted); font-size: 0.82rem; }
.card .deadline.overdue { color: var(--danger); font-weight: 600; }
.card .avatar { margin-left: auto; }
.estimate { padding: 0 0.4rem; border-radius: 4px; background: var(--surface-2); color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

.avatar { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: 0.72rem; font-weight: 700; }

.labels { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.label { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.05rem 0.5rem; border-radius: 999px; background: color-mix(in srgb, var(--label) 18%, var(--surface)); border: 1px solid color-mix(in srgb, var(--label) 55%, var(--surface)); font-size: 0.8rem; }
.label::before { content: ""; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--label); }

.progress { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.82rem; }
.progress progress { flex: 1; height: 0.4rem; accent-color: var(--accent); }

/* ---- Rendered Markdown ---- */

.markdown { overflow-wrap: anywhere; }
.markdown > * { margin: 0 0 0.6rem; }
.markdown > :last-child { margin-bottom: 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { font-size: 1rem; margin-top: 0.9rem; }
.markdown h1 { font-size: 1.15rem; }
.markdown h2 { font-size: 1.05rem; }
.markdown > :first-child { margin-top: 0; }
.markdown ul, .markdown ol { padding-left: 1.4rem; }
.markdown ul { list-style: disc; }
.markdown ol { list-style: decimal; display: block; }
.markdown li { margin: 0.15rem 0; padding: 0; background: none; }
.markdown li > p { margin: 0; }
.markdown li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.4rem; }
.markdown li > input[type="checkbox"] { margin: 0 0.4rem 0 0; }
.markdown code { padding: 0.05rem 0.3rem; background: var(--surface-2); border-radius: 4px; }
.markdown pre { padding: 0.6rem 0.75rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; overflow-x: auto; }
.markdown pre code { padding: 0; background: none; }
.markdown blockquote { padding-left: 0.75rem; border-left: 3px solid var(--border); color: var(--muted); }
.markdown table { display: block; overflow-x: auto; border-collapse: collapse; }
.markdown th, .markdown td { padding: 0.25rem 0.6rem; border: 1px solid var(--border); text-align: left; }
.markdown img { max-width: 100%; }
.markdown hr { border: none; border-top: 1px solid var(--border); }
.comments .markdown code, .comments .markdown pre { background: var(--surface); }
.markdown.boxed { padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: 6px; }

/* ---- Attachments ---- */

.attachment-thumb { display: inline-block; vertical-align: top; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface-2); line-height: 0; }
.attachment-thumb img { max-width: min(100%, 15rem); max-height: 11rem; object-fit: contain; }
.attachment-thumb:hover { border-color: var(--muted); }
.attachment-chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.1rem 0.55rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; text-decoration: none; overflow-wrap: anywhere; }
.attachment-chip::before { content: "\1F4CE"; font-size: 0.85em; }
.attachment-chip:hover { border-color: var(--muted); }
.comments .attachment-chip { background: var(--surface); }
.attachment-missing { padding: 0.1rem 0.55rem; border: 1px dashed var(--border); border-radius: 6px; color: var(--muted); font-style: italic; }

.attachments ul { display: grid; gap: 0.4rem; }
.attachments li { display: flex; align-items: center; gap: 0.5rem 0.75rem; flex-wrap: wrap; }
.attachments .attachment-thumb, .file-badge { flex: none; width: 3rem; height: 3rem; }
.attachments .attachment-thumb img { width: 100%; height: 100%; max-width: none; max-height: none; object-fit: cover; }
.file-badge { display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; color: var(--muted); font-size: 0.72rem; font-weight: 700; }
.attachment-info { display: grid; flex: 1 1 12rem; min-width: 0; }
.attachment-info a { overflow-wrap: anywhere; }
.attachments li button { font-size: 0.87rem; }

#preview-dialog { width: auto; max-width: calc(100vw - 2rem); flex-direction: column; }
#preview-dialog.document { width: min(70rem, calc(100vw - 2rem)); height: calc(100vh - 2rem); }
#preview-dialog header { display: flex; align-items: center; gap: 1rem; padding: 0.6rem 1rem; border-bottom: 1px solid var(--border); }
#preview-dialog h2 { flex: 1; min-width: 0; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-body { display: flex; flex: 1; min-height: 0; justify-content: center; background: var(--surface-2); }
.preview-body img { max-width: 100%; max-height: calc(100vh - 6rem); object-fit: contain; }
.preview-body iframe { flex: 1; border: none; }

/* ---- Issue popup ---- */

dialog { width: min(58rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); padding: 0; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 40px rgb(0 0 0 / 30%); }
dialog::backdrop { background: rgb(20 18 14 / 55%); }
dialog[open] { display: flex; }

.issue { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.issue > header, .issue > footer { display: flex; align-items: center; gap: 0.6rem; padding: 0.8rem 1.1rem; }
.issue > header { border-bottom: 1px solid var(--border); }
.issue > header [data-close] { margin-left: auto; }
.save-status { color: var(--muted); font-size: 0.87rem; }
.issue > footer { border-top: 1px solid var(--border); }
.issue .spacer { flex: 1; }
.issue-body { display: grid; grid-template-columns: minmax(0, 1fr) 16rem; gap: 1.5rem; padding: 1.1rem; overflow-y: auto; }
.issue-main, .issue-side { display: grid; gap: 0.9rem; align-content: start; min-width: 0; }
.issue section { display: grid; gap: 0.6rem; min-width: 0; }
.issue section > button { justify-self: start; }
.section-head { display: flex; align-items: baseline; gap: 0.75rem; }
.inline-edit { display: grid; gap: 0.4rem; }
.issue-side > button { justify-self: start; }
.tasks ul { display: grid; gap: 0.3rem; }
.tasks li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.6rem; }

.comments ol { display: grid; gap: 0.7rem; }
.comments li { padding: 0.6rem 0.75rem; background: var(--surface-2); border-radius: 6px; }
.comment-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.6rem; margin-bottom: 0.2rem; }
.comment-head time { color: var(--muted); font-size: 0.82rem; }
.comment-head .spacer { flex: 1; }
.comment-head button { font-size: 0.82rem; }
.comments li .inline-edit textarea { background: var(--surface); }

/* ---- Week overview ---------------------------------------------------- */

.week-page .toolbar h1 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.6rem; }
.week-page .toolbar h1 .muted { font-size: 1rem; font-weight: 400; }
.week-wrap { padding: 0.9rem 1.25rem 2rem; overflow-x: auto; }
.week { width: 100%; min-width: 60rem; border-collapse: separate; border-spacing: 0; table-layout: fixed; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.week th, .week td { padding: 0.45rem 0.5rem; vertical-align: top; text-align: left; border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.week thead th { border-top: none; font-size: 0.87rem; }
.week thead th span { display: block; }
.week tr > :first-child { width: 12rem; border-left: none; }
.week .overdue-col { width: 9rem; background: var(--danger-bg); }
.week thead .overdue-col { color: var(--danger); }
.week .today { background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
.week tfoot td, .week tfoot th { font-size: 0.87rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.person { display: grid; gap: 0.2rem; font-weight: 400; }
.person .load { font-size: 0.87rem; font-variant-numeric: tabular-nums; }
.person a { font-size: 0.82rem; }
.meter { display: block; height: 0.35rem; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); }
.week tr.over .load { color: var(--danger); font-weight: 600; }
.week tr.over .meter span { background: var(--danger); }
.week-tasks { display: grid; gap: 0.3rem; }
.week-tasks button { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.1rem 0.4rem; width: 100%; padding: 0.3rem 0.45rem; font-size: 0.85rem; text-align: left; white-space: normal; box-shadow: var(--shadow); }
.week-tasks button > span:first-child { overflow-wrap: anywhere; }
.week-tasks button.done { opacity: 0.6; box-shadow: none; }
.week-tasks button.done > span:first-child { text-decoration: line-through; }
.week-tasks button.late { border-color: var(--danger); }
.week-note { margin-top: 0.6rem; }

@media (max-width: 720px) {
    .issue-body { grid-template-columns: minmax(0, 1fr); }
    .column { flex-basis: 80vw; }

    /* The week becomes a list: per person, the days that have work. */
    .week-wrap { overflow-x: visible; padding-inline: 1rem; }
    .week, .week tbody, .week tr, .week th, .week td { display: block; width: auto; min-width: 0; }
    .week { border: none; background: none; }
    .week thead, .week tfoot { display: none; }
    .week tbody tr { margin-bottom: 0.9rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
    .week th, .week td { border-left: none; }
    .week tr > :first-child { width: auto; border-top: none; }
    .week .overdue-col { width: auto; }
    .week td:not(:has(li)) { display: none; }
    .week td::before { content: attr(data-day); display: block; margin-bottom: 0.3rem; color: var(--muted); font-size: 0.82rem; font-weight: 600; }
}
