:root {
  --paper: #e9eeeb;
  --panel: #f8faf8;
  --ink: #15242b;
  --ink-soft: #4a5b63;
  --line: #c9d3cf;
  --brand: #2b3fd6;
  --brand-ink: #ffffff;

  --todo: #4f6270;
  --todo-tint: #dbe3e8;
  --progress: #b97b00;
  --progress-tint: #f8e6b8;
  --blocked: #b8265a;
  --blocked-tint: #f6d6e1;
  --done: #1a7a50;
  --done-tint: #cfeadc;

  --slab: Rockwell, "Roboto Slab", "Courier Prime", "Cambria", Georgia, serif;
  --sans: "Avenir Next", Avenir, "Segoe UI", "Helvetica Neue", Ubuntu, system-ui, sans-serif;

  --rail-w: 264px;
  --detail-w: 500px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 var(--sans);
}
h1, h2 { font-family: var(--slab); margin: 0; line-height: 1.2; }
p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

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

[data-status="todo"] { --c: var(--todo); --t: var(--todo-tint); }
[data-status="in-progress"] { --c: var(--progress); --t: var(--progress-tint); }
[data-status="blocked"] { --c: var(--blocked); --t: var(--blocked-tint); }
[data-status="done"] { --c: var(--done); --t: var(--done-tint); }

/* ---------- layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  min-height: 100vh;
}
.app.has-detail { grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--detail-w); }

.rail {
  position: sticky; top: 0; align-self: start;
  height: 100vh;
  padding: 28px 22px;
  background: var(--ink);
  color: #e9eeeb;
  display: flex; flex-direction: column; gap: 18px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; border-radius: 6px; }
.brand:focus-visible { outline-color: #fff; }
.brand-mark { color: var(--brand); flex: none; }
.rail .brand-mark { color: #8c98ff; }
.brand-name { font: 700 26px/1 var(--slab); letter-spacing: -0.01em; }
.rail-note { color: #b4c2c8; font-size: 14px; max-width: 30ch; }

/* The cubby wall: status counts that double as filters */
.cubbies ul {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-top: 6px;
}
.cubby {
  width: 100%;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between;
  gap: 10px;
  min-height: 108px; padding: 12px 12px 10px;
  background: #1f333c;
  border: 2px solid #2d4651;
  border-bottom: 6px solid var(--c);
  border-radius: 4px;
  color: #e9eeeb; text-align: left; cursor: pointer;
}
.cubby:hover { background: #26404b; }
.cubby[aria-pressed="true"] { background: #f1f5f2; color: var(--ink); border-color: #f1f5f2; border-bottom-color: var(--c); }
.cubby:focus-visible { outline-color: #fff; outline-offset: 3px; }
.cubby-count { font: 700 40px/1 var(--slab); font-variant-numeric: tabular-nums; }
.cubby-label { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.cubby[aria-pressed="true"] .glyph { color: var(--c); }
.glyph { font-size: 13px; line-height: 1; }
.cubby:not([aria-pressed="true"]) .glyph { color: #fff; opacity: .85; }

/* ---------- main ---------- */
.main { padding: 28px 36px 64px; min-width: 0; }

.toolbar {
  display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap;
  padding-bottom: 20px; border-bottom: 2px solid var(--ink);
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.field.grow { flex: 1 1 260px; }
.field label { font-size: 14px; font-weight: 600; color: var(--ink-soft); }
input[type="text"], select {
  height: 44px; padding: 0 12px;
  background: #fff; border: 2px solid #9fb0aa; border-radius: 4px;
  width: 100%;
}
select { padding-right: 8px; cursor: pointer; }
input[type="text"]:hover, select:hover { border-color: var(--ink); }
input[type="text"]:focus-visible, select:focus-visible { outline-offset: 0; border-color: var(--brand); }

.list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin: 22px 0 12px; }
.list-head h1 { font-size: 28px; font-weight: 700; }
.count { color: var(--ink-soft); font-size: 14px; font-variant-numeric: tabular-nums; }

.tasks { display: flex; flex-direction: column; gap: 8px; }
.task {
  position: relative;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 20px; align-items: start;
  padding: 14px 18px 14px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.task::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 8px;
  background: var(--c); border-radius: 4px 0 0 4px;
}
.task:hover { border-color: var(--ink); background: #fff; }
.task.is-open { background: #fff; border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.task-main { min-width: 0; }
.open-item {
  all: unset; box-sizing: border-box;
  font: 700 18px/1.3 var(--slab); cursor: pointer; display: block;
}
.open-item::after { content: ""; position: absolute; inset: 0; border-radius: 4px; }
.open-item:focus-visible::after { outline: 3px solid var(--brand); outline-offset: 2px; }
.task-summary {
  color: var(--ink-soft); font-size: 15px; margin-top: 4px; max-width: 72ch;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.task-meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 14px; color: var(--ink-soft); margin-top: 4px; }
.task-meta b { font-weight: 600; color: var(--ink); }
.task-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 3px 10px 3px 8px; border-radius: 999px;
  background: var(--t); color: #15242b; font-size: 14px; font-weight: 600;
  border: 1.5px solid var(--c);
}
.pill .glyph { color: var(--c); }
.prio { font-size: 13px; color: var(--ink-soft); display: inline-flex; align-items: center; gap: 6px; }
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.bars i { width: 4px; background: #b7c3be; display: block; }
.bars i:nth-child(1) { height: 5px; } .bars i:nth-child(2) { height: 8px; } .bars i:nth-child(3) { height: 12px; }
.bars i.on { background: var(--ink); }

/* ---------- empty ---------- */
.empty {
  margin-top: 8px; padding: 40px 28px;
  border: 2px dashed #8a9d96; border-radius: 4px; background: var(--panel);
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
}
.empty h2 { font-size: 22px; }
.empty p { color: var(--ink-soft); max-width: 52ch; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  background: var(--brand); color: var(--brand-ink);
  border: 2px solid var(--brand); border-radius: 4px;
  font-weight: 600; cursor: pointer;
}
.btn:hover { background: #1f30b5; border-color: #1f30b5; }
.btn.ghost { background: transparent; color: var(--ink); border-color: transparent; padding: 0 12px 0 8px; }
.btn.ghost:hover { background: #dde5e1; }

/* ---------- detail ---------- */
.detail {
  position: sticky; top: 0; align-self: start; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 2px solid var(--ink);
}
.detail-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.detail-id { font-size: 14px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.detail-scroll { padding: 24px 28px 48px; overflow-y: auto; flex: 1; }
.detail-scroll h2 { font-size: 28px; font-weight: 700; outline: none; overflow-wrap: anywhere; }

.status-box {
  margin: 20px 0 24px; padding: 14px 16px 12px;
  background: var(--t); border: 2px solid var(--c); border-radius: 4px;
}
.status-box label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.status-row { display: flex; align-items: center; gap: 10px; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); flex: none; }
.saved { margin-top: 8px; font-size: 14px; min-height: 21px; }
.saved.flash { animation: flash .9s ease-out; }
@keyframes flash { from { background: #fff; } to { background: transparent; } }

.body { white-space: pre-line; max-width: 62ch; font-size: 17px; line-height: 1.6; overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: 8.5em 1fr; gap: 10px 14px; margin: 28px 0 0; padding-top: 20px; border-top: 1px solid var(--line); font-size: 15px; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; font-weight: 600; }
.tag { display: inline-block; margin: 0 6px 4px 0; padding: 1px 8px; border: 1.5px solid var(--ink-soft); border-radius: 3px; font-size: 14px; font-weight: 500; }

/* ---------- toast ---------- */
.toast-region { position: fixed; left: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 40px); pointer-events: none; }
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 10px 10px 16px;
  background: var(--ink); color: #fff; border-left: 8px solid var(--c);
  border-radius: 4px; box-shadow: 0 6px 24px rgba(21, 36, 43, .35);
  animation: rise .22s ease-out;
}
.toast button {
  min-height: 40px; padding: 0 14px; background: transparent; color: #fff;
  border: 2px solid #8fa2aa; border-radius: 4px; font-weight: 600; cursor: pointer;
}
.toast button:hover { background: #26404b; }
.toast button:focus-visible { outline-color: #fff; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- narrower than 1180: detail becomes a full-screen sheet ---------- */
@media (max-width: 1179px) {
  .app, .app.has-detail { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; padding: 18px 20px 20px; gap: 12px; }
  .rail-note { display: none; }
  .cubbies ul { grid-template-columns: repeat(4, 1fr); margin-top: 0; }
  .cubby { min-height: 84px; }
  .main { padding: 20px 20px 56px; }
  .detail {
    position: fixed; inset: 0; z-index: 50; height: 100%; border-left: 0;
  }
  .detail:not([hidden]) { animation: sheet .22s ease-out; }
  @keyframes sheet { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
}

@media (max-width: 640px) {
  .rail { padding: 14px 14px 16px; }
  .brand-name { font-size: 22px; }
  .cubbies ul { gap: 6px; }
  .cubby { min-height: 76px; padding: 8px 8px 8px; gap: 6px; }
  .cubby-count { font-size: 28px; }
  .cubby-label { font-size: 12.5px; gap: 4px; }
  .cubby-label .glyph { display: none; }
  .main { padding: 16px 14px 48px; }
  .field { flex: 1 1 calc(50% - 7px); min-width: 0; }
  .field.grow { flex-basis: 100%; }
  .list-head h1 { font-size: 24px; }
  .task { grid-template-columns: minmax(0, 1fr); padding: 12px 14px 12px 20px; }
  .task-side { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; order: 3; grid-column: 1; }
  .task-meta { order: 4; }
  .detail-scroll { padding: 20px 18px 40px; }
  .detail-scroll h2 { font-size: 24px; }
  .facts { grid-template-columns: 7em 1fr; }
  .toast-region { left: 12px; right: 12px; bottom: 12px; }
  .toast { justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
