:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #1d1c1a; --muted: #6f6c66; --line: #e3e0d9;
  --accent: #3a5bd9; --high: #c8372d; --mid: #d08a12; --low: #4a8a5c; --review: #e0a526;
  --done: #9aa09a; --chip: #efede8;
  --radius: 10px; --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151514; --panel: #1f1e1c; --ink: #ecebe7; --muted: #9a978f; --line: #34322e;
          --chip: #2b2a27; --done: #5c605c; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: inherit; }
.muted { color: var(--muted); }
.pad { padding: 24px; }
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 4px 10px; }
button.ghost { border-color: transparent; background: transparent; }
button.active { background: var(--ink); color: var(--panel); }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px; padding: 10px 20px;
       background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: .02em; font-size: 16px; }
.brand .sub { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 4px; }
nav { display: flex; gap: 4px; }
nav a { text-decoration: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); }
nav a.on { background: var(--chip); color: var(--ink); font-weight: 600; }
.status { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 12px; }
.live { color: var(--done); }
.live.on { color: var(--low); animation: pulse 2.4s infinite; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--high); color: #fff; font-size: 11px; font-weight: 700; text-align: center; }

main { padding: 18px 20px 60px; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

/* ---- banner ---- */
.banner { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px;
          background: var(--panel); border: 1px solid var(--line); }
.banner.block { border-color: var(--high); background: color-mix(in srgb, var(--high) 10%, var(--panel)); }
.banner .big { font-size: 22px; font-weight: 700; }
.banner.ok .big { color: var(--low); }
.banner.block .big { color: var(--high); }

/* ---- board ---- */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 14px; align-items: start; }
.col { background: color-mix(in srgb, var(--chip) 55%, transparent); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.col header .n { color: var(--muted); font-size: 12px; }
.col .hint { font-size: 11.5px; color: var(--muted); margin: 0 0 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 8px;
        padding: 9px 10px; margin-bottom: 8px; cursor: pointer; transition: transform .1s; }
.card:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgb(0 0 0 / .08); }
.card.s3 { border-left-color: var(--high); }
.card.s2 { border-left-color: var(--mid); }
.card.s1 { border-left-color: var(--low); }
.card.fresh { animation: flash 1.6s ease-out 2; }
.card .t { font-weight: 600; margin: 2px 0 6px; }
.card .crumbs { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 11px; color: var(--muted); }
.alerts { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; }
.alert { font-size: 12px; padding: 2px 7px; border-radius: 6px; background: var(--chip); }
.alert.a3 { background: color-mix(in srgb, var(--high) 15%, var(--panel)); color: var(--high); font-weight: 600; }
.alert.a2 { background: color-mix(in srgb, var(--mid) 15%, var(--panel)); }
.unb { margin-left: auto; font-weight: 700; color: var(--high); }
.chip { display: inline-block; padding: 0 6px; border-radius: 5px; background: var(--chip); font-size: 11px; }
.id { font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); }
.empty { color: var(--muted); font-size: 12px; padding: 8px 2px; }

/* ---- timeline ---- */
.tl-head { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-bottom: 14px; }
.tl-head select { font: inherit; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
.pct b { font-size: 26px; margin-right: 4px; }
.counts { display: flex; gap: 8px; }
.count { padding: 4px 10px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); font-size: 12px; }
.count b { font-size: 15px; margin-right: 4px; }
.livebar { margin-left: auto; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; }
.stalled-n { color: var(--high); font-weight: 600; }
.live-tag { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 12px; font-size: 12px; cursor: pointer; white-space: nowrap;
            background: color-mix(in srgb, var(--accent) 10%, var(--panel)); border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line)); }
.live-tag.bad { background: color-mix(in srgb, var(--high) 10%, var(--panel)); border-color: color-mix(in srgb, var(--high) 40%, var(--line)); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--low); box-shadow: 0 0 0 0 var(--low); animation: ping 1.8s infinite; }
.dot.bad { background: var(--high); animation: none; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.progress { height: 8px; border-radius: 4px; background: var(--chip); overflow: hidden; display: flex; }
.progress span { display: block; height: 100%; }
.chart { overflow-x: auto; }
.chart svg { display: block; }
.chart .axis { font-size: 10.5px; fill: var(--muted); }
.chart .axis.strong { fill: var(--ink); font-weight: 700; }
.chart .grid { stroke: var(--line); }
.chart .now { stroke: var(--high); stroke-width: 1.5; }
.chart .scope { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart .donel { fill: none; stroke: var(--low); stroke-width: 2.2; }
.chart .area { fill: color-mix(in srgb, var(--low) 18%, transparent); }
.chart .mark line { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 2 3; opacity: .5; }
.chart .mark rect { fill: var(--ink); }
.legend { display: flex; gap: 14px; font-size: 11.5px; color: var(--muted); margin: 6px 2px 0; flex-wrap: wrap; }
.legend i { display: inline-block; width: 18px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.legend i.diamond { width: 8px; height: 8px; background: var(--ink); transform: rotate(45deg); border-radius: 0; }

.ms-live { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--low); }
.ms-live.bad { margin-left: 0; color: var(--high); }
.detail h2 { display: flex; align-items: center; gap: 8px; }
.detail .lists { margin-top: 8px; }
.wait { color: var(--mid); font-weight: 600; font-size: 12px; white-space: nowrap; }

.lists { display: grid; grid-template-columns: repeat(3, minmax(240px, 1fr)); gap: 14px; margin-top: 16px; }
.list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.row { display: flex; gap: 8px; align-items: baseline; padding: 6px 0; border-top: 1px solid var(--line); cursor: pointer; }
.row:first-of-type { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .who { font-weight: 600; }
.row .lease.bad { color: var(--high); font-weight: 600; }
.row .blocked { color: var(--mid); font-size: 11px; }
details.more { margin-top: 14px; }
details.more summary { cursor: pointer; color: var(--muted); }
.feed { font-size: 12px; }
.feed .row { cursor: default; }

/* ---- drawer ---- */
#drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--panel); border-left: 1px solid var(--line);
          box-shadow: -8px 0 24px rgb(0 0 0 / .12); z-index: 10; overflow-y: auto; padding: 18px 20px; }
#drawer .close { position: absolute; top: 10px; right: 10px; }
#drawer pre { white-space: pre-wrap; font: inherit; background: var(--chip); padding: 8px; border-radius: 6px; }
#drawer ul { padding-left: 18px; }
#drawer .note { border-top: 1px solid var(--line); padding: 6px 0; font-size: 12.5px; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel);
         padding: 8px 14px; border-radius: 8px; z-index: 20; font-size: 13px; }

@keyframes pulse { 50% { opacity: .35; } }
@keyframes ping { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--low) 70%, transparent); } 70%, 100% { box-shadow: 0 0 0 6px transparent; } }
@keyframes flash { 0% { box-shadow: 0 0 0 3px var(--high); } 100% { box-shadow: 0 0 0 0 transparent; } }

@media (max-width: 1000px) {
  .board, .lists { grid-template-columns: 1fr; }
}

/* ---- timeline: progress and ordered steps ---- */
.pct { display: flex; flex-direction: column; gap: 4px; min-width: 200px; }
.pct .progress { width: 200px; }
.progress.big { height: 12px; border-radius: 6px; }
.detail-progress { margin: 6px 0 14px; max-width: 720px; }
.dp-top { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.dp-top b { font-size: 20px; }
.steps { list-style: none; margin: 0; padding: 0; position: relative; }
.step { display: flex; align-items: center; gap: 10px; padding: 7px 4px 7px 0; position: relative; cursor: pointer; border-radius: 6px; }
.step:hover { background: var(--chip); }
.step::before { content: ""; position: absolute; left: 13px; top: -7px; bottom: -7px; width: 2px; background: var(--line); z-index: 0; }
.step:first-child::before { top: 50%; }
.step:last-child::before { bottom: 50%; }
.step.done::before { background: var(--low); }
.bullet { flex: 0 0 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; z-index: 1;
          background: var(--panel); border: 2px solid var(--line); color: var(--muted); }
.step.done .bullet { background: var(--low); border-color: var(--low); color: #fff; }
.step.work .bullet { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 0 var(--accent); animation: ping 1.8s infinite; }
.step.stalled .bullet { border-color: var(--high); color: var(--high); }
.step.review .bullet { border-color: var(--review); background: color-mix(in srgb, var(--review) 20%, var(--panel)); color: var(--ink); }
.step.blocked .bullet { border-style: dashed; }
.step.done .grow { color: var(--muted); }
.step .sn { color: var(--muted); font-variant-numeric: tabular-nums; }
.step.work .grow, .step.review .grow { font-weight: 600; }
.step .blocked { color: var(--mid); font-size: 11.5px; white-space: nowrap; }
.step .grow { flex: 1; min-width: 0; }

/* ---- timeline: milestone rail beside the selected milestone ---- */
.tl-body { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 14px; align-items: start; }
.tl-body > .panel { margin-bottom: 0; }
.rail { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow-y: auto; }
.mrail { list-style: none; margin: 0; padding: 0; }
.mnode { display: flex; gap: 10px; padding: 8px 6px 10px 0; position: relative; cursor: pointer; border-radius: 8px; }
.mnode:hover { background: var(--chip); }
.mnode.open { background: color-mix(in srgb, var(--accent) 9%, var(--panel)); }
.mnode::before { content: ""; position: absolute; left: 13px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.mnode:first-child::before { top: 22px; }
.mnode:last-child::before { bottom: calc(100% - 22px); }
.mnode.reached::before { background: var(--low); }
.mnode .bullet { margin-top: 2px; }
.mnode.reached .bullet { background: var(--low); border-color: var(--low); color: #fff; }
.mnode.current .bullet { border-color: var(--accent); color: var(--accent); }
.mnode.live .bullet { animation: ping 1.8s infinite; }
.mnode.to_split .bullet { border-style: dashed; }
.mbody { flex: 1; min-width: 0; }
.mt { font-weight: 600; line-height: 1.3; }
.mnode.reached .mt, .mnode.to_split .mt { color: var(--muted); font-weight: 500; }
.mnode.open .mt { color: var(--ink); }
.mmeta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.mnode.current .mstate { color: var(--accent); font-weight: 700; }
.mnode.reached .mstate { color: var(--low); }
.mmeta .ms-live { margin-left: 0; }
.mbar { display: flex; align-items: center; gap: 8px; margin-top: 5px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.mbar .progress { flex: 1; }

/* ---- actions ---- */
.acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.acts button.ok { border-color: var(--low); color: var(--low); font-weight: 600; }
.acts button.ok.confirm { background: var(--low); color: #fff; }
.acts button.no { border-color: var(--mid); color: var(--mid); font-weight: 600; }
.acts form { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.acts textarea { font: inherit; width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 6px; background: var(--bg); color: var(--ink); resize: vertical; }
.acts button:disabled { opacity: .5; cursor: wait; }
@media (max-width: 1000px) { .tl-body { grid-template-columns: 1fr; } .rail { position: static; max-height: none; } }
.acts form[hidden] { display: none; }

/* ---- review summaries and formatted bodies ---- */
.card .summary { font-size: 12.5px; line-height: 1.4; margin: 0 0 6px; padding: 6px 8px; border-radius: 6px; background: var(--chip); }
.card .summary.missing { color: var(--muted); font-style: italic; }
#drawer .body { font-size: 13.5px; line-height: 1.5; }
#drawer .body p { margin: 0 0 8px; }
#drawer .body ul, #drawer .body ol { margin: 0 0 10px; padding-left: 20px; }
#drawer .body li { margin-bottom: 3px; }
#drawer .body .lead { color: var(--ink); font-weight: 700; }
#drawer .body .lead.ok { color: var(--low); }
#drawer .body .lead.no { color: var(--mid); }
