:root {
  --paper: #f6f1e7;
  --paper-2: #efe8d9;
  --card: #fffdf8;
  --ink: #1d2a24;
  --ink-2: #4a584f;
  --line: #ddd4c1;
  --green: #173d33;
  --green-2: #1f5c4a;
  --amber: #f2c14e;
  --focus: #1f5c4a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --rail-w: 248px;
  --detail-w: 460px;
}

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

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

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; margin: -1px; padding: 0; border: 0;
}
.skip {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 6px;
}
.skip:focus { top: 8px; }

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

.rail {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--green); color: #f3eee1;
  padding: 28px 18px 20px;
  display: flex; flex-direction: column; gap: 28px;
}
.rail :focus-visible { outline-color: var(--amber); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.brand-mark { width: 38px; height: 38px; color: #f6f1e7; flex: none; }
.brand-name { font-family: var(--serif); font-size: 1.45rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.1; }
.brand-sub { font-size: .8rem; color: #bfd0c6; letter-spacing: .08em; text-transform: uppercase; }

.rail-label { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: #a9c0b4; margin: 0 6px 8px; }

.status-nav ul { display: flex; flex-direction: column; gap: 2px; }
.nav-btn {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: transparent; border: 0; border-radius: 8px;
  padding: 9px 10px; min-height: 40px; text-align: left; color: inherit;
}
.nav-btn:hover { background: rgba(255,255,255,.09); }
.nav-btn[aria-pressed="true"] { background: #f6f1e7; color: var(--green); font-weight: 650; }
.nav-btn svg { width: 18px; height: 18px; flex: none; }
.nav-btn .n { margin-left: auto; font-variant-numeric: tabular-nums; font-size: .85rem; opacity: .85; }

.progress-figure { font-family: var(--serif); font-size: 1.6rem; margin: 0 6px 10px; line-height: 1.2; }
.progress-figure small { font-family: var(--sans); font-size: .85rem; color: #bfd0c6; display: block; }
.bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: rgba(255,255,255,.12); margin: 0 6px; gap: 2px; }
.bar span { display: block; height: 100%; transition: flex-grow .3s; }
.bar [data-s="todo"] { background: #9fb0e0; }
.bar [data-s="in-progress"] { background: #f2c14e; }
.bar [data-s="blocked"] { background: #ee8a80; }
.bar [data-s="done"] { background: #7fd1a0; }
.rail-foot { margin-top: auto; font-size: .78rem; color: #a9c0b4; padding: 0 6px; }

.main { padding: 36px clamp(20px, 3vw, 44px) 80px; min-width: 0; }
.top { margin-bottom: 22px; }
.eyebrow { font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--green-2); font-weight: 650; }
h1 { font-family: var(--serif); font-size: clamp(2rem, 3.2vw, 2.7rem); line-height: 1.1; letter-spacing: -.02em; }

/* ---------- toolbar ---------- */
.toolbar {
  display: grid; grid-template-columns: minmax(0, 1fr) 180px 160px; gap: 14px;
  padding: 16px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 14px;
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: .78rem; font-weight: 650; color: var(--ink-2); letter-spacing: .02em; }
.toolbar input, .toolbar select {
  width: 100%; min-height: 44px; padding: 8px 12px;
  background: var(--card); border: 1.5px solid #b9ae95; border-radius: 10px;
}
.toolbar select { appearance: none; padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 12px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: var(--ink-2); pointer-events: none; }
.search-wrap input { padding-left: 38px; }
.toolbar input:focus-visible, .toolbar select:focus-visible { outline-offset: 1px; border-radius: 10px; }

.list-heading { font-size: .95rem; font-weight: 600; color: var(--ink-2); margin: 24px 0 12px; outline: none; }

/* ---------- list ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.row {
  position: relative; display: block;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 18px 14px 22px;
  transition: border-color .15s, box-shadow .15s, background-color .4s;
}
.row::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 5px; border-radius: 0 4px 4px 0; background: var(--st); }
.row:hover { border-color: #b9ae95; box-shadow: 0 2px 10px rgba(23,61,51,.08); }
.row[aria-current="true"] { border-color: var(--green-2); box-shadow: 0 0 0 2px var(--green-2); }
.row.flash { background: #fff3c9; }
.row-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.row-top .due { margin-left: auto; font-size: .85rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.row-title { font-size: 1.08rem; line-height: 1.3; font-weight: 650; }
.open-btn {
  background: none; border: 0; padding: 0; text-align: left; font: inherit; font-weight: inherit; color: inherit;
}
.open-btn::after { content: ""; position: absolute; inset: 0; border-radius: 14px; }
.open-btn:focus-visible { outline: none; }
.open-btn:focus-visible::after { outline: 3px solid var(--focus); outline-offset: 2px; }
.open-btn mark { background: #f7d97a; color: inherit; border-radius: 3px; padding: 0 1px; }
.row-summary {
  color: var(--ink-2); font-size: .92rem; margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 10px; font-size: .85rem; color: var(--ink-2); }
.who { display: inline-flex; align-items: center; gap: 7px; }
.avatar {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  display: inline-grid; place-items: center; font-size: .68rem; font-weight: 700; letter-spacing: .02em;
  background: var(--av-bg, #d8e4dc); color: var(--av-fg, #173d33);
}
.dot-sep::before { content: "·"; margin-right: 14px; color: #9a917c; }

/* status & priority tags */
[data-status="todo"] { --st: #4a5f9c; --st-fg: #34457a; --st-bg: #e4e9f6; }
[data-status="in-progress"] { --st: #d58a00; --st-fg: #7d4900; --st-bg: #fbebcf; }
[data-status="blocked"] { --st: #c8392f; --st-fg: #9c2720; --st-bg: #fbdedb; }
[data-status="done"] { --st: #2f8a52; --st-fg: #22603a; --st-bg: #dcefe2; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px 2px 7px; border-radius: 99px; font-size: .8rem; font-weight: 650;
  background: var(--st-bg); color: var(--st-fg); white-space: nowrap;
}
.badge svg { width: 15px; height: 15px; }
.prio { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; color: var(--ink-2); }
.prio i { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.prio i b { width: 3px; background: #c9bfa8; border-radius: 1px; }
.prio i b:nth-child(1) { height: 5px; } .prio i b:nth-child(2) { height: 8px; } .prio i b:nth-child(3) { height: 12px; }
.prio[data-p="low"] i b:nth-child(1),
.prio[data-p="medium"] i b:nth-child(-n+2),
.prio[data-p="high"] i b { background: var(--ink); }
.prio[data-p="high"] { color: var(--ink); }

/* ---------- empty ---------- */
.empty {
  text-align: center; padding: 48px 20px; border: 2px dashed #b9ae95; border-radius: 16px; background: var(--card);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.empty svg { width: 64px; height: 64px; color: var(--green-2); }
.empty h3 { font-family: var(--serif); font-size: 1.4rem; overflow-wrap: anywhere; }
.empty p { color: var(--ink-2); max-width: 44ch; margin-bottom: 8px; overflow-wrap: anywhere; }

.btn {
  min-height: 44px; padding: 8px 18px; border-radius: 10px; font-weight: 650;
  background: var(--green); color: #fff; border: 1.5px solid var(--green);
}
.btn:hover { background: var(--green-2); }
.btn.ghost { background: transparent; color: var(--green); }
.btn.ghost:hover { background: rgba(23,61,51,.08); }

/* ---------- detail ---------- */
.detail-host { min-width: 0; }
.detail {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--card); border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  animation: slide-in .22s ease-out;
}
.detail-bar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line);
}
.detail-id { font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); font-weight: 650; }
.close-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 14px;
  background: var(--paper-2); border: 1.5px solid #b9ae95; border-radius: 10px; font-weight: 650;
}
.close-btn:hover { background: var(--paper); }
.close-btn svg { width: 14px; height: 14px; }
.detail-body { padding: 24px 24px 48px; display: flex; flex-direction: column; gap: 22px; }
.detail h2 { font-family: var(--serif); font-size: 1.75rem; line-height: 1.2; letter-spacing: -.01em; overflow-wrap: anywhere; outline: none; }
.detail-status {
  border: 1.5px solid var(--line); border-left: 6px solid var(--st); border-radius: 12px; padding: 12px 14px;
  background: var(--st-bg); display: grid; gap: 6px;
}
.detail-status label { font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--st-fg); }
.detail-status select {
  width: 100%; min-height: 46px; padding: 8px 36px 8px 12px; border: 1.5px solid #8f8670; border-radius: 10px; background-color: #fff; appearance: none; font-weight: 650;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat;
}
.detail-status select:focus-visible { outline-offset: 1px; border-radius: 10px; }
.saved { font-size: .88rem; color: var(--st-fg); font-weight: 600; min-height: 1.3em; display: flex; align-items: center; gap: 6px; }
.saved svg { width: 16px; height: 16px; flex: none; }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); font-weight: 650; margin-bottom: 3px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: .8rem; padding: 2px 10px; border-radius: 6px; background: var(--paper-2); border: 1px solid var(--line); }
.section-label { font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); font-weight: 650; margin-bottom: 6px; }
.body-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1.02rem; line-height: 1.6; }
.activity { display: flex; flex-direction: column; gap: 8px; font-size: .9rem; }
.activity li { display: flex; gap: 8px; align-items: baseline; padding: 8px 10px; background: var(--paper); border-radius: 8px; }
.activity time { margin-left: auto; color: var(--ink-2); font-size: .8rem; white-space: nowrap; }
.activity .none { color: var(--ink-2); background: none; padding: 0; }

@keyframes slide-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  display: flex; align-items: center; gap: 12px; max-width: min(560px, calc(100vw - 24px));
  background: var(--ink); color: #fff; padding: 10px 10px 10px 18px; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.28);
  animation: pop .2s ease-out;
}
.toast:focus-within, .toast :focus-visible { outline-color: var(--amber); }
.toast-undo { background: transparent; border: 1.5px solid #fff; color: #fff; border-radius: 8px; min-height: 40px; padding: 4px 14px; font-weight: 650; }
.toast-undo:hover { background: rgba(255,255,255,.15); }
.toast-undo[hidden] { display: none; }
.toast-x { background: transparent; border: 0; color: #fff; font-size: 1.4rem; line-height: 1; width: 40px; height: 40px; border-radius: 8px; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- mid widths ---------- */
@media (max-width: 1240px) {
  :root { --rail-w: 208px; --detail-w: 400px; }
  .toolbar { grid-template-columns: minmax(0, 1fr) 160px 140px; }
}

/* ---------- mobile & tablet ---------- */
@media (max-width: 999px) {
  .app, .app[data-detail="open"] { display: block; }
  .rail {
    position: static; height: auto; padding: 16px 16px 14px; gap: 12px;
  }
  .brand-mark { width: 32px; height: 32px; }
  .brand-name { font-size: 1.25rem; }
  .progress, .rail-foot { display: none; }
  .status-nav .rail-label { display: none; }
  .status-nav ul { flex-direction: row; overflow-x: auto; gap: 8px; padding: 2px 2px 6px; margin: 0 -16px; padding-inline: 16px; scrollbar-width: thin; }
  .nav-btn { width: auto; flex: none; border: 1.5px solid rgba(255,255,255,.3); border-radius: 99px; padding: 6px 12px; min-height: 44px; }
  .nav-btn .n { margin-left: 4px; }
  .nav-btn svg { width: 16px; height: 16px; }

  .main { padding: 20px 16px 96px; }
  .top { margin-bottom: 14px; }
  h1 { font-size: 1.9rem; }
  .toolbar { grid-template-columns: 1fr 1fr; padding: 12px; gap: 10px; }
  .field-search { grid-column: 1 / -1; }
  .list-heading { margin-top: 18px; }
  .row { padding: 14px 14px 14px 18px; }

  .detail-host:not(:empty) { position: fixed; inset: 0; z-index: 50; background: var(--card); }
  .detail { position: static; height: 100%; border-left: 0; animation: rise .22s ease-out; }
  .detail-bar { padding: 10px 16px; }
  .detail-body { padding: 18px 16px 40px; }
  .detail h2 { font-size: 1.5rem; }
  .toast { bottom: 16px; }
}
@keyframes rise { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }

@media (max-width: 420px) {
  .facts { grid-template-columns: 1fr 1fr; gap: 12px; }
  .toast { left: 12px; right: 12px; transform: none; max-width: none; animation: none; }
}

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