:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #1c2333;
  --muted: #667085;
  --border: #e3e7ef;
  --brand: #1f4fd1;
  --brand-ink: #ffffff;
  --green: #12805c; --green-bg: #e3f6ee;
  --amber: #a15c00; --amber-bg: #fff2d9;
  --red: #b42318;   --red-bg: #fde8e7;
  --blue-bg: #e7eefe;
  --grey-bg: #eef0f4;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151f; --surface: #1a2030; --text: #e6e9f0; --muted: #98a2b3; --border: #2b3346;
    --brand: #5b8cff; --green: #4cd39b; --green-bg: #12352a; --amber: #f5b649; --amber-bg: #3a2c10;
    --red: #ff7b72; --red-bg: #3d1a1a; --blue-bg: #1d2a4d; --grey-bg: #262d3d;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }

.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.topbar nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: .4rem .7rem; border-radius: 8px; color: var(--text); }
.topbar nav a.active, .topbar nav a:hover { background: var(--blue-bg); text-decoration: none; }
.me { display: flex; align-items: center; gap: .75rem; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); }
.brand small { font-weight: 500; color: var(--muted); }
.brand.big { font-size: 1.3rem; justify-content: center; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); }

.container { max-width: 1240px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.container.narrow { max-width: 420px; padding-top: 12vh; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; overflow-x: auto; }
.narrow-card { max-width: 480px; }
.login { text-align: center; }
.login form { text-align: left; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.crumbs { margin: 0; font-size: .85rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.right { text-align: right; white-space: nowrap; }
.pre { white-space: pre-wrap; margin: 0; }

.grid.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 1rem; }
.grid.two .card { margin: 0; }
@media (max-width: 520px) { .grid.two { grid-template-columns: 1fr; } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; display: flex; flex-direction: column; gap: .2rem; color: var(--text); }
a.stat:hover { text-decoration: none; border-color: var(--brand); }
.stat b { font-size: 1.6rem; line-height: 1.1; }
.stat b.small-b { font-size: 1.05rem; }
.stat span:last-child { color: var(--muted); font-size: .85rem; }
.stat.warn b { color: var(--amber); }
.stat.bad b { color: var(--red); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tr.done td { opacity: .55; }
.overdue { color: var(--red); font-weight: 600; }

.badge { display: inline-block; padding: .08rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--grey-bg); white-space: nowrap; }
.health-green { background: var(--green-bg); color: var(--green); }
.health-amber { background: var(--amber-bg); color: var(--amber); }
.health-red { background: var(--red-bg); color: var(--red); }
.status-in-progress { background: var(--blue-bg); color: var(--brand); }
.status-completed { background: var(--green-bg); color: var(--green); }
.status-on-hold { background: var(--amber-bg); color: var(--amber); }
.status-cancelled { color: var(--muted); }
.prio-urgent { background: var(--red-bg); color: var(--red); }
.prio-high { background: var(--amber-bg); color: var(--amber); }
.prio-low { color: var(--muted); }

.btn { display: inline-block; padding: .45rem .9rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.btn:hover { text-decoration: none; border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.small { padding: .15rem .5rem; font-size: .8rem; }
button.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }

input, select, textarea { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: .5rem; }
label.check input { width: auto; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1.25rem; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.actions { display: flex; gap: .5rem; }
.danger-zone { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px dashed var(--border); }
form.inline { display: inline; }
form.inline select { width: auto; padding: .15rem .4rem; font-size: .8rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; flex: 1 1 150px; }
.alert { background: var(--red-bg); color: var(--red); padding: .6rem .8rem; border-radius: 8px; }
.notice { background: var(--green-bg); color: var(--green); padding: .6rem .8rem; border-radius: 8px; }

.list, .feed, .bars { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.feed li { padding: .55rem 0; border-bottom: 1px solid var(--border); }
.list li:last-child, .feed li:last-child { border-bottom: 0; }
.bars li { display: grid; grid-template-columns: 90px 1fr 30px; align-items: center; gap: .75rem; padding: .3rem 0; }
meter, progress { width: 100%; height: 10px; }
progress { width: 80px; vertical-align: middle; }

.add-task summary { cursor: pointer; font-weight: 600; color: var(--brand); }
.add-task[open] summary { margin-bottom: 1rem; }
.board { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: .75rem; margin-bottom: 1rem; overflow-x: auto; }
.column { background: var(--grey-bg); border-radius: var(--radius); padding: .75rem; min-height: 120px; }
.column h3 { display: flex; justify-content: space-between; }
.col-blocked { background: var(--red-bg); }
.col-done { background: var(--green-bg); }
.count { color: var(--muted); font-weight: 500; }
.task { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem; margin-bottom: .5rem; display: flex; flex-direction: column; gap: .35rem; }
.task-title { color: var(--text); font-weight: 600; }
.task .meta { display: flex; justify-content: space-between; align-items: center; gap: .5rem; font-size: .8rem; }
.stat .badge { align-self: flex-start; }

/* Phase 1: plan view */
.notice-soft { background: var(--blue-bg); padding: .6rem .8rem; border-radius: 8px; }
.timeline { display: flex; gap: 3px; margin-bottom: 1rem; overflow-x: auto; }
.timeline .seg { flex: 1 1 0; min-width: 90px; padding: .45rem .5rem; border-radius: 6px; background: var(--grey-bg); color: var(--text); font-size: .8rem; display: flex; justify-content: space-between; gap: .4rem; }
.timeline .seg:hover { text-decoration: none; outline: 2px solid var(--brand); }
.timeline .seg span { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg-in-progress { background: var(--blue-bg) !important; }
.seg-done { background: var(--green-bg) !important; }
.state-in-progress { background: var(--blue-bg); color: var(--brand); }
.state-done { background: var(--green-bg); color: var(--green); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .5rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-bottom-color: var(--brand); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.phase-head { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; flex-wrap: wrap; }
.phase-head h2 { margin: 0; }
.milestone { display: flex; justify-content: space-between; gap: .75rem; flex-wrap: wrap; align-items: flex-start; padding: .6rem .7rem; margin: .6rem 0; border: 1px solid var(--border); border-radius: 8px; }
.milestone .diamond { color: var(--brand); }
.milestone.reached { background: var(--green-bg); }
.milestone.reached .diamond { color: var(--green); }
.milestone.late { border-color: var(--red); }
.ms-actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.ms-actions input[type=date], .add-inline input[type=date] { width: auto; padding: .2rem .4rem; font-size: .85rem; }
.tasklist li { padding: .4rem 0; }
.tasklist li.done a { text-decoration: line-through; color: var(--muted); }
.add-inline { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .5rem; }
.add-inline input:not([type=date]):not([type=hidden]), .add-inline select { flex: 1 1 200px; width: auto; }
.inline-details { margin-top: .5rem; }
.inline-details summary { cursor: pointer; color: var(--brand); }
.inline-details[open] summary { margin-bottom: .5rem; }
code { background: var(--grey-bg); padding: 0 .3rem; border-radius: 4px; font-size: .85em; }
.card h3 { margin-top: 1rem; }
@media (max-width: 640px) {
  .topbar { gap: .5rem 1rem; padding: .5rem .75rem; }
  .topbar nav { order: 3; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; }
  .topbar nav a { white-space: nowrap; }
  .me { margin-left: auto; font-size: .9rem; }
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
