:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c2330;
  --muted: #6b7686;
  --line: #dde1e7;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --done: #2e9e5b;
  --doing: #d98b0b;
  --danger: #c93838;
  --hover: #eef1f6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --card: #1d2129;
    --text: #e6e9ee;
    --muted: #8f99a8;
    --line: #2f3541;
    --accent: #5b93f5;
    --accent-text: #0d1320;
    --done: #4cc07c;
    --doing: #eba938;
    --danger: #ef6b6b;
    --hover: #262b35;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: .5rem 0 0; }
[hidden] { display: none !important; }

input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]), select, textarea {
  width: 100%;
  padding: .45rem .6rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { resize: vertical; }
button {
  padding: .4rem .8rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
button:hover { background: var(--hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.1); background: var(--accent); }
button.danger { color: var(--danger); }

/* ---- layout */
header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem 1.5rem;
  padding: .75rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1;
}
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; flex: 1; }
.filters input[type=search] { width: 14rem; max-width: 100%; }
.filters label { white-space: nowrap; color: var(--muted); }
.user { display: flex; align-items: center; gap: .5rem; }
#whoami { font-weight: 600; margin-right: .25rem; }

.layout { max-width: 60rem; margin: 0 auto; padding: 1rem; }
main { min-width: 0; }

/* ---- detail panel: beside the tree when there is room, over it when not */
#detail {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
}
.detail-head, .detail-foot { display: flex; align-items: center; gap: .5rem; }
.detail-head { margin-bottom: .75rem; }
.detail-head h2 { margin: 0; }
.detail-foot { margin-top: 1rem; padding-top: .75rem; border-top: 1px solid var(--line); font-size: .85rem; flex-wrap: wrap; }
.row.selected, .row.selected:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }
@media (min-width: 900px) {
  .with-detail .layout {
    max-width: 92rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(22rem, 30rem);
    gap: 1rem;
    align-items: start;
  }
  #detail { position: sticky; top: 4.75rem; max-height: calc(100vh - 5.75rem); overflow-y: auto; }
}
@media (max-width: 899px) {
  #detail { position: fixed; inset: 0; z-index: 2; border: 0; border-radius: 0; overflow-y: auto; }
  body.with-detail { overflow: hidden; }
}
.add-row { display: flex; gap: .5rem; margin-bottom: 1rem; }

/* ---- tree */
.node.depth-0 {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: .75rem;
  padding: .35rem .5rem;
}
.row {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .2rem .25rem;
  border-radius: 6px;
}
.row:hover { background: var(--hover); }
.children { margin-left: 1.6rem; }
.depth-0 > .row .title { font-weight: 650; font-size: 1.05rem; }

.caret, .add, .title {
  border: 0;
  background: none;
  padding: .15rem .3rem;
}
.caret { color: var(--muted); width: 1.4rem; flex: none; }
.add { color: var(--muted); font-size: 1.15rem; line-height: 1; flex: none; opacity: 0; }
.row:hover .add, .add:focus-visible { opacity: 1; }
@media (hover: none) { .add { opacity: 1; } }
.title { flex: 1; min-width: 0; text-align: left; overflow-wrap: anywhere; }
.title:hover { background: none; text-decoration: underline; }

/* The three states are drawn, not typed: glyphs like ◐ and ✓ come out a
   different size and weight in every font. */
.status {
  flex: none;
  position: relative;
  width: 1.05rem;
  height: 1.05rem;
  margin: 0 .15rem;
  padding: 0;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
  background: none;
}
.status:hover { border-color: var(--accent); background: none; }
.status-doing > .row .status {
  border-color: var(--doing);
  background: linear-gradient(90deg, var(--doing) 50%, transparent 50%);
}
.status-done > .row .status { border-color: var(--done); background: var(--done); }
.status-done > .row .status::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 45%;
  width: .26rem;
  height: .5rem;
  border: solid var(--card);
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -50%) rotate(45deg);
}
.status-done > .row .title { color: var(--muted); text-decoration: line-through; }

.meta { display: flex; align-items: center; gap: .6rem; flex: none; color: var(--muted); font-size: .85rem; }
.progress { display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap; }
.progress progress { width: 4rem; height: .45rem; accent-color: var(--done); }
.due.late { color: var(--danger); font-weight: 600; }
.assignee {
  padding: 0 .5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}
.confirm { display: flex; align-items: center; gap: .35rem; flex: none; font-size: .85rem; }
.confirm button { padding: .1rem .55rem; }
.comment-count {
  padding: 0 .4rem;
  border: 1px solid var(--line);
  border-radius: 6px 6px 6px 0;
  font-size: .78rem;
}
.add-child { padding: .25rem .25rem .25rem 1.9rem; }

@media (max-width: 600px) {
  .row { flex-wrap: wrap; }
  .meta { flex-basis: 100%; order: 1; padding-left: 3.4rem; }
  .meta:empty { display: none; }
  .confirm { order: 2; flex-basis: 100%; padding-left: 3.4rem; }
  .children { margin-left: .9rem; }
  .progress progress { width: 3rem; }
}

/* ---- dialogs */
dialog {
  width: min(36rem, calc(100vw - 2rem));
  padding: 1.25rem;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog label, #detail label, .login label { display: block; margin-bottom: .75rem; color: var(--muted); font-size: .85rem; }
dialog label > *, #detail label > *, .login label > * { margin-top: .2rem; color: var(--text); font-size: 15px; }
label.check { display: flex; align-items: center; gap: .4rem; align-self: end; }
label.check > * { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 0 1rem; }
.buttons { display: flex; gap: .5rem; margin-top: 1rem; }
.spacer { flex: 1; }

#comment-list { margin-bottom: .5rem; }
.comment { padding: .45rem 0; border-top: 1px solid var(--line); }
.comment:first-child { border-top: 0; }
.comment-head { display: flex; align-items: center; gap: .5rem; font-size: .85rem; }
.comment-body { white-space: pre-wrap; overflow-wrap: anywhere; }
#comments .buttons { margin-top: .4rem; }
button.link { border: 0; background: none; padding: 0; color: var(--muted); font-size: .85rem; }
button.link:hover { background: none; color: var(--danger); text-decoration: underline; }

#users-table { width: 100%; border-collapse: collapse; }
#users-table td { padding: .35rem .25rem; border-bottom: 1px solid var(--line); }
#users-table td:last-child { text-align: right; white-space: nowrap; }
#users-table button { margin-left: .35rem; padding: .2rem .55rem; }

/* ---- login */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.card {
  width: min(22rem, 100%);
  padding: 1.5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.card h1 { margin-bottom: 1rem; }
.card button { width: 100%; margin-top: .75rem; }
