/* Tokens: light by default, dark from the system or from the toggle (data-theme). */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1b1f27;
  --muted: #5b6372;
  --border: #d9dde5;
  --accent: #2459d6;
  --accent-text: #ffffff;
  --focus: #f0a500;
  --danger: #b42318;
  --late: #b54708;
  --s-defining: #7a5af8;
  --s-ready: #0e7490;
  --s-in_progress: #2459d6;
  --s-in_revision: #b54708;
  --s-done: #067647;
  --s-closed: #667085;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #202633;
    --text: #e7eaf0;
    --muted: #9aa3b2;
    --border: #2c3442;
    --accent: #6d95ff;
    --accent-text: #0b0f17;
    --danger: #ff8a80;
    --late: #fdb022;
    --s-defining: #a48afb;
    --s-ready: #22b8cf;
    --s-in_progress: #6d95ff;
    --s-in_revision: #fdb022;
    --s-done: #47cd89;
    --s-closed: #98a2b3;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1218;
  --surface: #171b23;
  --surface-2: #202633;
  --text: #e7eaf0;
  --muted: #9aa3b2;
  --border: #2c3442;
  --accent: #6d95ff;
  --accent-text: #0b0f17;
  --danger: #ff8a80;
  --late: #fdb022;
  --s-defining: #a48afb;
  --s-ready: #22b8cf;
  --s-in_progress: #6d95ff;
  --s-in_revision: #fdb022;
  --s-done: #47cd89;
  --s-closed: #98a2b3;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1, h2, h3, h4 { line-height: 1.25; }
.muted { color: var(--muted); font-weight: normal; }
.error { color: var(--danger); margin: 0.25rem 0; }
.error:empty { display: none; }
.empty { color: var(--muted); font-style: italic; margin: 0.5rem 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 1rem; top: 0.5rem; background: var(--surface); padding: 0.5rem; z-index: 10; }

button, select, input { font: inherit; color: inherit; }
button {
  background: var(--accent);
  color: var(--accent-text);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
}
button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
button[aria-pressed="false"] { background: var(--surface); color: var(--text); border-color: var(--border); }
button.link {
  background: none; border: 0; padding: 0; color: var(--accent);
  text-decoration: underline; font-weight: 600;
}
select, input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  min-width: 0;
}

/* Top bar */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.25rem;
  padding: 0.6rem 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-size: 1.1rem; margin: 0; display: flex; align-items: center; gap: 0.5rem; }
.ro { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 0.05rem 0.45rem; }
.tabs { display: flex; gap: 0.35rem; }
.session { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }

main { padding: 0.75rem 16px 2rem; }
main:focus { outline: none; }

/* Login */
.login { max-width: 26rem; margin: 3rem auto; background: var(--surface); padding: 1.25rem 1.5rem;
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.login form { display: grid; gap: 0.5rem; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: end; }
.filters .field { display: grid; gap: 0.15rem; }
.filters label { font-size: 0.8rem; color: var(--muted); }
.filters select, .filters input { color: var(--text); font-size: 0.95rem; }
.filters .grow { flex: 1 1 14rem; }
.status-line { color: var(--muted); font-size: 0.85rem; margin: 0.5rem 0; }

/* Board */
.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(13.5rem, 1fr);
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  align-items: start;
}
.column {
  background: var(--surface-2); border-radius: var(--radius); padding: 0.5rem;
  border-top: 4px solid var(--col, var(--border)); min-height: 6rem;
}
.column-head { display: flex; justify-content: space-between; align-items: center;
  font-size: 0.95rem; margin: 0.15rem 0.25rem 0.5rem; }
.count { background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 0 0.5rem; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.card {
  display: grid; gap: 0.3rem; width: 100%; text-align: left;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.55rem 0.65rem; box-shadow: var(--shadow);
}
.card:hover { border-color: var(--accent); }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.card-key { font: 600 0.8rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); margin: 0; }
.card-title { font-weight: 600; }
.card-meta { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.card-wait { font-size: 0.8rem; color: var(--late); }
.card-diary { font-size: 0.8rem; color: var(--text); display: -webkit-box; -webkit-line-clamp: 3;
  -webkit-box-orient: vertical; overflow: hidden; }
.chip { font-size: 0.75rem; border: 1px solid var(--border); border-radius: 999px; padding: 0 0.45rem;
  background: var(--surface); color: var(--muted); white-space: nowrap; }
.chip.person { color: var(--text); font-weight: 600; }

/* Parent (epic) chip: a footer of the card, its own button so it opens the parent, not the card. */
/* min-width 0: the chip's no-wrap title must truncate, not widen the card past its column. */
.column, .cards > .card-item { min-width: 0; }
.card-item.has-parent .card { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.card-parent {
  display: flex; gap: 0.3rem; align-items: baseline; width: 100%; min-width: 0; text-align: left;
  font-size: 0.75rem; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-top: 1px dashed var(--border);
  border-radius: 0 0 8px 8px; padding: 0.2rem 0.65rem; box-shadow: var(--shadow); overflow: hidden;
}
button.card-parent:hover { border-color: var(--accent); }
.card-parent-type { color: var(--s-defining); font-weight: 700; white-space: nowrap; }
.card-parent-key { font: 600 0.72rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); white-space: nowrap; }
.card-parent-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-parent.hidden-parent { color: var(--muted); font-style: italic; }
.parent-banner {
  margin: 0 0 0.6rem; padding: 0.4rem 0.7rem; background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--s-defining); border-radius: 8px; font-size: 0.9rem;
}
.detail-parent { margin: 0.25rem 0 0; }
.children { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.3rem; }
.children li { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: baseline; }
.detail-body h2:focus, .detail-body p:focus { outline: none; }
.login-field { display: grid; gap: 0.5rem; }
.chip.late, .chip.prio-high, .chip.prio-highest { color: var(--late); border-color: currentColor; }
.more { text-align: center; }

.status-defining { --col: var(--s-defining); }
.status-ready { --col: var(--s-ready); }
.status-in_progress { --col: var(--s-in_progress); }
.status-in_revision { --col: var(--s-in_revision); }
.status-done { --col: var(--s-done); }
.status-closed { --col: var(--s-closed); }
.badge { font-size: 0.72rem; font-weight: 700; border-radius: 6px; padding: 0.05rem 0.4rem;
  color: var(--col, var(--muted)); border: 1px solid currentColor; white-space: nowrap; }
.astatus-open { color: var(--s-in_progress); }
.astatus-done { color: var(--s-done); }
.astatus-dropped { color: var(--s-closed); }
.diary-badge { color: var(--accent); }

/* Detail dialog */
dialog {
  width: min(46rem, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog-close { position: sticky; top: 0; display: flex; justify-content: flex-end; padding: 0.5rem;
  background: var(--surface); }
.detail-body { padding: 0 1.25rem 1.25rem; }
.detail-body h2 { margin: 0.25rem 0; }
.detail-body h3 { font-size: 1rem; margin: 1rem 0 0.4rem; }
.prose, .comment-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.comments { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.6rem; }
.comment { border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.7rem; }
.comment.diary { border-left: 4px solid var(--accent); }
.comment-head { margin: 0 0 0.3rem; font-size: 0.85rem; }
.comment-head time { color: var(--muted); }
.plain { padding-left: 1.1rem; }

/* Weekly */
.weekly-head h2 { margin: 0.25rem 0 0; }
.weekly-grid { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
  align-items: start; margin-top: 0.75rem; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.75rem 1rem; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.panel h3 .muted { font-size: 0.85rem; }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 0.6rem; }
.progress span { display: block; height: 100%; background: var(--s-done); }
.actions { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.action { border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.6rem; }
.action.overdue { border-color: var(--late); }
.action-done .action-text, .action-dropped .action-text { color: var(--muted); }
.action-dropped .action-text { text-decoration: line-through; }
.action-main { display: flex; gap: 0.5rem; align-items: baseline; }
.action-meta { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; margin-top: 0.3rem; font-size: 0.85rem; }
.mentions { margin: 0.4rem 0 0; padding-left: 1rem; font-size: 0.85rem; }
.daily { border-top: 1px solid var(--border); padding-top: 0.4rem; margin-top: 0.4rem; }
.daily:first-of-type { border-top: 0; margin-top: 0; }
.daily h4 { margin: 0 0 0.25rem; font-size: 0.9rem; }
.decisions { padding-left: 1.2rem; margin: 0; display: grid; gap: 0.3rem; }

/* Phones: columns stack, one under the other, no sideways scroll. */
@media (max-width: 720px) {
  .board { grid-auto-flow: row; grid-auto-columns: auto; overflow-x: visible; }
  .filters .field { flex: 1 1 45%; }
  .filters select, .filters input { width: 100%; }
  .session { margin-left: 0; }
}
