:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --col: #eef0f3;
  --line: #dde1e7;
  --text: #1c2129;
  --muted: #667085;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --feature: #2f6fdf;
  --bug: #d93838;
  --idea: #c98a00;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --code: #f1f3f6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --col: #13161c;
    --line: #272c36;
    --text: #e6e8ec;
    --muted: #8b93a3;
    --accent: #7c74ff;
    --feature: #5b93f5;
    --bug: #f06363;
    --idea: #e2a72a;
    --code: #0c0e12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--bad); }
button.icon { padding: 6px 8px; line-height: 1; display: inline-flex; align-items: center; }
button.link { background: none; border: none; padding: 0; color: var(--muted); text-decoration: underline dotted; }
button.small { padding: 2px 8px; font-size: 12px; }
input, select, textarea {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
}
textarea { resize: vertical; }
textarea.mono, pre { font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); font-weight: normal; }

/* ---- Header ---- */
.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand strong { font-size: 16px; }
.project { max-width: 32ch; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.agent { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 200px; color: var(--muted); }
.agent .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.agent.running .dot { background: var(--ok); animation: pulse 1.4s infinite; }
.agent.idle .dot { background: var(--ok); }
.agent.waiting .dot { background: var(--warn); }
.agent.halted .dot { background: var(--bad); }
.agent span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes pulse { 50% { opacity: .35; } }
.actions { display: flex; gap: 8px; }

.notice {
  margin: 10px 16px 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--warn) 14%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
}
.notice.bad {
  background: color-mix(in srgb, var(--bad) 12%, var(--panel));
  border-color: color-mix(in srgb, var(--bad) 45%, transparent);
}

/* ---- Generated tray ---- */
.tray {
  margin: 10px 16px 0;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.tray-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 8px; }
.tray-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; max-height: 30vh; overflow: auto; }
.tray-group h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.gen {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 0;
  border-top: 1px solid var(--line);
}
.gen span { flex: 1; min-width: 0; }
.gen .note { display: block; color: var(--muted); font-size: 12px; }

/* ---- Board ---- */
.board {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(6, minmax(200px, 1fr));
  gap: 12px;
  padding: 12px 16px 16px;
  overflow-x: auto;
  min-height: 0;
}
.column {
  background: var(--col);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 200px;
  max-height: calc(100vh - 110px);
}
.column > header { padding: 10px 12px 6px; }
.column h2 { margin: 0; font-size: 13px; display: flex; justify-content: space-between; }
.column h2 .count { color: var(--muted); font-weight: normal; }
.column .hint { font-size: 12px; color: var(--muted); }
.column .list { flex: 1; overflow-y: auto; padding: 4px 8px 10px; display: flex; flex-direction: column; gap: 8px; }
.column.drop-ok { outline: 2px dashed var(--accent); outline-offset: -2px; }
.column .empty { color: var(--muted); font-size: 12px; text-align: center; padding: 16px 0; }
.drop-marker { height: 3px; border-radius: 2px; background: var(--accent); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.card:hover { border-color: var(--muted); }
.card[draggable="true"] { cursor: grab; }
.card.dragging { opacity: .4; }
.card.kind-feature { border-left-color: var(--feature); }
.card.kind-bug { border-left-color: var(--bug); }
.card.kind-idea { border-left-color: var(--idea); }
.card.dim { opacity: .65; }
.card-title { font-weight: 550; overflow-wrap: anywhere; }
.card-title .pos { color: var(--muted); font-weight: normal; margin-right: 4px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.card .phase { margin-top: 6px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--code);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.badge.feature { color: var(--feature); }
.badge.bug { color: var(--bug); }
.badge.idea { color: var(--idea); }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.badge.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.badge.ask { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.badge.spin::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%; background: currentColor; animation: pulse 1s infinite; }

/* ---- Dialogs ---- */
.dlg {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.dlg.wide { width: min(860px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(10, 12, 16, .45); }
.dlg form, #task-body { padding: 16px 20px 18px; display: flex; flex-direction: column; gap: 12px; }
.dlg header { display: flex; align-items: center; gap: 10px; }
.dlg header h2 { margin: 0; font-size: 17px; flex: 1; }
.dlg header .title-input { font-size: 16px; font-weight: 600; flex: 1; }
.dlg label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 550; }
.dlg label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: normal; }
.dlg label.check input { width: auto; }
.dlg .row { display: flex; gap: 12px; flex-wrap: wrap; }
.dlg .row > * { flex: 1; min-width: 160px; }
.dlg footer { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.dlg footer .spacer { flex: 1; }
.dlg section { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.dlg section h3 { margin: 0; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.dlg section h3 .muted { font-size: 12px; }
.info { margin: 0; font-size: 12.5px; color: var(--muted); }
.statusline { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); }

.questions { background: color-mix(in srgb, var(--accent) 8%, var(--panel)); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); border-radius: var(--radius); padding: 12px; }
.questions label { font-weight: normal; }
.clar { font-size: 12.5px; }
.clar dt { font-weight: 550; }
.clar dd { margin: 0 0 6px; color: var(--muted); }

.deps { max-height: 150px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.deps label { font-weight: normal; flex-direction: row; align-items: center; gap: 8px; }
.deps input { width: auto; }

pre {
  margin: 0;
  background: var(--code);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 340px;
  overflow: auto;
}
.runs { display: flex; flex-direction: column; gap: 6px; }
.run { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-size: 12.5px; }
.run .what { flex: 1; min-width: 200px; color: var(--muted); overflow-wrap: anywhere; }

/* ---- Toasts ---- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 10; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 12px; box-shadow: var(--shadow); }
.toast.error { border-left-color: var(--bad); }
.toast.warn { border-left-color: var(--warn); }

@media (max-width: 720px) {
  .top { gap: 10px; }
  .actions { width: 100%; overflow-x: auto; }
  .board { grid-template-columns: repeat(6, minmax(78vw, 1fr)); scroll-snap-type: x mandatory; }
  .column { scroll-snap-align: start; }
}

/* ---- Sign in (login.html) ---- */
body.login { align-items: center; justify-content: center; padding: 16px; }
.login-box {
  width: min(340px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-box h1 { margin: 0; font-size: 18px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 550; }
.login-box .error { margin: 0; color: var(--bad); font-size: 13px; }
