:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --text: #1d2330;
    --muted: #677085;
    --line: #e2e5ec;
    --accent: #2f5bd3;
    --accent-text: #ffffff;

    --green: #2f9e5b;
    --yellow: #e0a514;
    --red: #d9473f;
    --critical: #7c1424;
    --waiting: #9aa2b3;
    --plan-opacity: 0.25;
    --mark: #1d2330;

    --radius: 10px;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12151b;
        --surface: #1b1f27;
        --text: #e6e8ee;
        --muted: #9199ab;
        --line: #2b313d;
        --accent: #6f93ff;
        --accent-text: #0d1220;
        --critical: #c0304a;
        --plan-opacity: 0.3;
        --mark: #ffffff;
    }
}

* { box-sizing: border-box; }

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

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

main {
    max-width: 860px;
    margin: 0 auto;
    padding: 16px;
}

h1 { font-size: 1.6rem; margin: 0.4em 0; }
h2 { font-size: 1.15rem; margin: 0 0 0.5em; }

.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 860px;
    margin: 0 auto;
    padding: 12px 16px;
}

.brand {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text);
    text-decoration: none;
}

.top nav { display: flex; align-items: center; gap: 16px; }
.top nav a { text-decoration: none; }
.primary-link { font-weight: 600; }

footer {
    max-width: 860px;
    margin: 0 auto;
    padding: 24px 16px;
    color: var(--muted);
    font-size: 0.85rem;
}

/* Forms and buttons */

form.inline { display: inline; }

button, .button {
    font: inherit;
    cursor: pointer;
}

.button, button.done {
    display: inline-block;
    border: 0;
    border-radius: 8px;
    padding: 8px 16px;
    background: var(--accent);
    color: var(--accent-text);
    text-decoration: none;
    font-weight: 600;
}

.button.secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line);
}

.button.danger { background: var(--red); color: #fff; }

button.done { background: var(--green); color: #fff; }
button.done.big { font-size: 1.1rem; padding: 12px 28px; }

button.link {
    border: 0;
    background: none;
    padding: 0;
    color: var(--accent);
    text-decoration: underline;
}

.field { display: flex; flex-direction: column; gap: 4px; margin: 12px 0; }
.field > span { font-weight: 600; font-size: 0.9rem; }

input, textarea, select {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    width: 100%;
}

input[type="radio"], input[type="checkbox"] { width: auto; }

fieldset {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin: 16px 0;
    padding: 8px 16px 12px;
}

legend { font-weight: 700; padding: 0 6px; }

.radio, .checkbox { display: block; margin: 8px 0; }
.radio small { display: block; margin-left: 1.6em; color: var(--muted); }

.phases {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.s-green-edge input { border-left: 4px solid var(--green); }
.s-yellow-edge input { border-left: 4px solid var(--yellow); }
.s-red-edge input { border-left: 4px solid var(--red); }

/* The interval matters only for a periodic task. */
.repeat .periodic { display: none; margin-left: 1.6em; }
.repeat:has(input[value="Periodic"]:checked) .periodic { display: block; }

.hint, .muted { color: var(--muted); font-size: 0.9rem; }
.error, .errors { color: var(--red); font-size: 0.9rem; }
.errors ul { margin: 0; padding-left: 1.2em; }

.actions { display: flex; align-items: center; gap: 16px; margin: 20px 0; }
.row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin: 8px 0; }
.row .field { margin: 0; flex: 1 1 220px; }

details { margin: 12px 0; }
summary { cursor: pointer; color: var(--accent); }

/* Flash message */

.flash {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    background: color-mix(in srgb, var(--green) 15%, var(--surface));
}

.flash.error { background: color-mix(in srgb, var(--red) 15%, var(--surface)); }

/* Status colors */

.s-green { --status: var(--green); }
.s-yellow { --status: var(--yellow); }
.s-red { --status: var(--red); }
.s-critical { --status: var(--critical); }
.s-waiting { --status: var(--waiting); }

.badge, .tag, .chip {
    display: inline-block;
    border-radius: 999px;
    padding: 1px 10px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    background: color-mix(in srgb, var(--status, var(--waiting)) 18%, var(--surface));
    color: var(--text);
    border: 1px solid color-mix(in srgb, var(--status, var(--waiting)) 55%, transparent);
}

.tag { font-weight: 500; }
.chip.zero { opacity: 0.45; }

.summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }

/* Bars: SVG rects, colored here. Geometry is in the markup; the CSP allows no inline styles. */

svg.bar {
    display: block;
    width: 100%;
    height: 14px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--line);
}

svg.bar rect.s-green { fill: var(--green); }
svg.bar rect.s-yellow { fill: var(--yellow); }
svg.bar rect.s-red { fill: var(--red); }
svg.bar rect.s-critical { fill: var(--critical); }
svg.bar rect.plan { opacity: var(--plan-opacity); }
svg.bar rect.now, svg.bar rect.mark { fill: var(--mark); }
svg.bar rect.grid { fill: var(--surface); opacity: 0.6; }

/* Board */

.cards {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 12px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 6px solid var(--status, var(--line));
    border-radius: var(--radius);
    padding: 12px 16px;
}

.cards .card {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "head action" "next action" "bar bar";
    gap: 6px 16px;
    align-items: center;
}

.card-head { grid-area: head; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.cards .next { grid-area: next; }
.cards svg.bar { grid-area: bar; }
.card-action { grid-area: action; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.card .title { font-weight: 600; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.card .title:hover { text-decoration: underline; }
.next { color: var(--muted); font-size: 0.92rem; }

.card.s-critical { background: color-mix(in srgb, var(--critical) 7%, var(--surface)); }

.waiting > summary { margin: 20px 0 12px; }

/* Paused by its work hours: nothing to do now. */
.card.paused { opacity: 0.7; }
.card.paused.s-critical { background: var(--surface); }

/* Work hours form: one field per day of the week. */
.week { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0 12px; }
.week .field { margin: 6px 0; }

.landing, .empty {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    margin-top: 16px;
}

table.sources { margin-bottom: 16px; }

/* Task page */

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.meta { color: var(--muted); margin-top: 0; }
.notes { white-space: pre-wrap; }
.crumbs { margin: 0; }

.current { margin: 16px 0 24px; }
.current svg.bar { height: 18px; margin: 10px 0; }

.boundaries {
    list-style: none;
    margin: 12px 0;
    padding: 0;
    display: grid;
    gap: 4px;
}

.boundaries li { padding-left: 10px; border-left: 4px solid var(--line); }
.boundaries li span { display: inline-block; min-width: 8.5em; color: var(--muted); }
.boundaries li small { color: var(--muted); }
.boundaries .s-green-edge { border-color: var(--green); }
.boundaries .s-yellow-edge { border-color: var(--yellow); }
.boundaries .s-red-edge { border-color: var(--red); }
.boundaries .s-critical-edge { border-color: var(--critical); }

.done-form { margin: 16px 0 8px; }

/* On hold: the notice and the button that lifts it. */
.hold {
    margin: 12px 0;
    padding: 10px 14px;
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--waiting) 18%, var(--surface));
}
.hold p { margin: 0 0 8px; }

/* History chart: one row per cycle, all on the same time axis from the cycle's start. */

ol.chart {
    list-style: none;
    margin: 12px 0;
    padding: 0;
    display: grid;
    gap: 6px;
}

ol.chart li {
    display: grid;
    grid-template-columns: 7.5em 1fr 6.5em;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
}

ol.chart .when { color: var(--muted); white-space: nowrap; }
ol.chart .took { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.history { margin-top: 32px; }
.history table { margin-top: 16px; }
.undo { margin-top: 12px; }

.danger { margin-top: 40px; border-top: 1px solid var(--line); padding-top: 8px; }
.danger form { margin: 16px 0; }

@media (max-width: 560px) {
    main { padding: 12px; }
    .phases { grid-template-columns: 1fr; }
    .cards .card {
        grid-template-columns: 1fr;
        grid-template-areas: "head" "next" "bar" "action";
    }
    .card-action button { width: 100%; }
    ol.chart li { grid-template-columns: 5.5em 1fr 5em; gap: 6px; }
    table.cycles th:nth-child(6), table.cycles td:nth-child(6),
    table.cycles th:nth-child(2), table.cycles td:nth-child(2) { display: none; }
}

.error:empty { display: none; }
.top nav button.link { text-decoration: none; }
