:root {
  --bg: #f0f1f4;
  --surface: #ffffff;
  --surface-2: #f1f1f3;
  --sub-bg: #f8f8fa;
  --line: #ececf0;
  --sidebar: #fbfbfc;
  --border: #e4e4e8;
  --text: #1d1e22;
  --muted: #6b6e76;
  --accent: #6d5dfc;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --hover: rgba(0, 0, 0, .045);
  --shadow: 0 8px 30px rgba(0, 0, 0, .10);
  --radius: 8px;
  --mix: 16%;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131416; --surface: #1f2024; --surface-2: #26272c; --sidebar: #18191c; --border: #33353b; --sub-bg: #1b1c20; --line: #2a2c31;
    --text: #e7e7ea; --muted: #9a9ca5; --accent: #8b7dff; --danger: #f87171;
    --hover: rgba(255, 255, 255, .05); --shadow: 0 8px 30px rgba(0, 0, 0, .5); --mix: 24%;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131416; --surface: #1f2024; --surface-2: #26272c; --sidebar: #18191c; --border: #33353b; --sub-bg: #1b1c20; --line: #2a2c31;
  --text: #e7e7ea; --muted: #9a9ca5; --accent: #8b7dff; --danger: #f87171;
  --hover: rgba(255, 255, 255, .05); --shadow: 0 8px 30px rgba(0, 0, 0, .5); --mix: 24%;
  color-scheme: dark;
}

/* status colors */
.st-todo { --c: #87909e; } .st-planned { --c: #5b8def; } .st-testing { --c: #a855f7; }
.st-in_progress { --c: #f59e0b; } .st-question { --c: #06b6d4; } .st-stuck { --c: #ef4444; }
.st-pending { --c: #ec4899; } .st-done { --c: #22c55e; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: -1px; border-color: var(--accent); }
button, .btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px;
}
button:hover, .btn:hover { filter: brightness(.97); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.link { background: none; border: 0; padding: 0; color: var(--muted); }
button.link:hover { color: var(--text); }
kbd {
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 1px 5px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
}
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer; list-style: none; font-size: 15px;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
summary.icon-btn::-webkit-details-marker { display: none; }

/* ---------- layout ---------- */
.app { display: flex; height: 100vh; height: 100dvh; }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.scrim { display: none; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 250px; flex-shrink: 0; background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; padding: 12px 10px;
}
.sb-top { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 10px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.brand.big { font-size: 22px; justify-content: center; margin-bottom: 18px; }
.search { position: relative; margin-bottom: 12px; }
.search input { width: 100%; padding-right: 28px; background: var(--surface); }
.search kbd { position: absolute; right: 7px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.folders { flex: 1; }
.folder { margin-bottom: 4px; }
.folder-head { display: flex; align-items: center; gap: 2px; padding: 2px 0; border-radius: 6px; cursor: grab; }
.folder-head:hover { background: var(--hover); }
.folder-toggle { width: 20px; height: 22px; border: 0; padding: 0; background: none; color: var(--muted); cursor: pointer; justify-content: center; }
.folder.collapsed .caret { transform: rotate(-90deg); }
.folder-name { flex: 1; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-head .menu summary { opacity: 0; }
.folder-head:hover .menu summary, .folder-head .menu[open] summary { opacity: 1; }
.lists { list-style: none; margin: 0; padding: 0 0 0 14px; min-height: 6px; }
.folder.collapsed .lists, .folder.collapsed .folder-empty { display: none; }
.lists a { display: block; padding: 5px 10px; border-radius: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lists a:hover { background: var(--hover); }
.lists a.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-weight: 600; }
.folder-empty { margin: 2px 0 6px 24px; font-size: 12px; color: var(--muted); }
.new-folder { margin: 8px 4px; }
.new-folder summary { cursor: pointer; color: var(--muted); list-style: none; padding: 4px 6px; border-radius: 6px; }
.new-folder summary:hover { background: var(--hover); color: var(--text); }
.new-folder form { display: flex; gap: 6px; margin-top: 6px; }
.new-folder input { flex: 1; }
.sb-bottom { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; border-top: 1px solid var(--border); padding: 10px 6px 4px; color: var(--muted); }
.sb-bottom a:hover { color: var(--text); }
.sb-user { padding: 4px 6px 0; font-size: 12px; color: var(--muted); }

/* dropdown menus */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu-body {
  position: absolute; z-index: 30; top: 100%; left: 0; min-width: 240px; margin-top: 4px; padding: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px; cursor: default;
}
.menu.right .menu-body { left: auto; right: 0; }
.folder .menu-body { left: auto; right: 0; }
.menu-body form { display: flex; gap: 6px; }
.menu-body input { flex: 1; }
.menu-body form + form { border-top: 1px solid var(--border); padding-top: 8px; }

/* ---------- main / board ---------- */
.main { flex: 1; display: flex; min-height: 0; }
.board { flex: 1; min-width: 0; overflow-y: auto; padding: 22px 28px 80px; }
.board-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.crumb { font-size: 12px; color: var(--muted); }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 10px; }
.quick-add { display: flex; gap: 6px; align-items: center; margin-bottom: 18px; max-width: 760px; }
.quick-add input[name=title] { flex: 1; padding: 8px 11px; }
.quick-add select { width: auto; }
.empty-hint { color: var(--muted); }

.group { margin-bottom: 10px; }
.group-head { display: flex; align-items: center; gap: 4px; }
.group-toggle {
  display: flex; align-items: center; gap: 8px; border: 0; background: none; padding: 4px 6px 4px 2px; text-align: left; border-radius: 6px;
}
.group-toggle:hover { background: var(--hover); filter: none; }

/* "+" buttons: subtask on rows, task on status headers */
.add-btn {
  display: inline-grid; place-items: center; width: 22px; height: 22px; padding: 0; flex-shrink: 0;
  border: 1px solid transparent; border-radius: 5px; background: none; color: var(--muted);
  font-size: 16px; line-height: 1; opacity: 0; transition: opacity .1s;
}
.add-btn:hover { border-color: var(--border); background: var(--surface); color: var(--accent); filter: none; }
.group-head:hover .add-btn, .row-main:hover > .row-add, .add-btn:focus-visible { opacity: 1; }
.group.empty .group-head .add-btn { opacity: .7; }

/* inline add input (opened by the "+" buttons) */
.inline-add { list-style: none; }
.inline-add form { display: flex; align-items: center; padding: 5px 8px 5px 30px; }
.tasks > .inline-add form { background: var(--surface); border: 1px dashed var(--border); border-radius: 7px; }
.children .inline-add form { border-top: 1px solid var(--line); }
.inline-add form.d1 { padding-left: 62px; }
.inline-add form.d2 { padding-left: 88px; }
.sub-list .inline-add form { padding-left: 30px; }
.inline-add input { flex: 1; padding: 5px 8px; }
/* CSS chevrons (pointing down; rotated when collapsed) */
.caret, .expander { display: inline-grid; place-items: center; transition: transform .12s; }
.caret { width: 14px; height: 14px; color: var(--muted); }
.caret::before, .expander::before {
  content: ""; width: 5px; height: 5px; border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor;
  transform: translateY(-1px) rotate(45deg);
}
span.expander::before { display: none; }
.group.collapsed .caret { transform: rotate(-90deg); }
.group-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px; border-radius: 4px;
  background: var(--c); color: #fff;
}
.group-count { color: var(--muted); font-size: 12px; }
.group.empty { opacity: .55; margin-bottom: 2px; }
.group.empty .group-label { background: transparent; color: var(--c); border: 1px solid var(--c); }
.group.collapsed .tasks { display: none; }
.tasks { list-style: none; margin: 6px 0 0; padding: 0; min-height: 6px; display: flex; flex-direction: column; gap: 6px; }
.group.empty .tasks { min-height: 8px; }
.group { margin-bottom: 18px; }
.group.empty { margin-bottom: 4px; }
.sortable-ghost { opacity: .35; }

.row { list-style: none; }
.row-main {
  display: flex; align-items: center; gap: 6px; padding: 5px 8px;
  background: var(--surface); min-height: 38px;
}
/* each top-level task is its own card; the left stripe shows its status */
.tasks > .row {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--c);
  border-radius: 7px; overflow: hidden; box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
.tasks > .row > .row-main { min-height: 44px; padding: 7px 10px 7px 8px; }
.tasks > .row > .row-main > .title { font-weight: 500; }
.row-main:hover { background: color-mix(in srgb, var(--surface) 94%, var(--text)); }
.row.active > .row-main { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.tasks > .row.active { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); border-left-color: var(--c); }
/* subtasks inside the card: lighter, smaller, with an indent guide */
.board .children { background: var(--sub-bg); }
.board .children .row-main { background: transparent; border-top: 1px solid var(--line); min-height: 34px; font-size: 13.5px; position: relative; }
.board .children .row-main:hover { background: color-mix(in srgb, var(--sub-bg) 92%, var(--text)); }
.board .children .row.active > .row-main { background: color-mix(in srgb, var(--accent) 10%, var(--sub-bg)); }
.board .children .row-main::before { content: ""; position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--border); }
.row-main.d1 { padding-left: 38px; }
.row-main.d1::before { left: 27px; }
.row-main.d2 { padding-left: 64px; }
.row-main.d2::before { left: 53px; }
.board .children .pill { width: 88px; }
.sub-list .row-main { border-bottom: 1px solid var(--line); }
.sub-list .row-main.d1, .sub-list .row-main.d2 { padding-left: 8px; }
.sub-list .children .row-main { padding-left: 30px; }
.handle { cursor: grab; color: var(--muted); opacity: 0; font-size: 13px; width: 12px; user-select: none; touch-action: none; }
.row-main:hover .handle { opacity: .8; }
.expander { width: 18px; height: 18px; flex-shrink: 0; border: 0; padding: 0; border-radius: 4px; background: none; color: var(--muted); transform: rotate(-90deg); }
button.expander:hover { color: var(--text); background: var(--hover); }
.row.open > .row-main > .expander { transform: none; }
.children { display: none; margin: 0; padding: 0; }
.row.open > .children { display: block; }
.title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 2px 0; }
.title:hover { color: var(--accent); }
.badges { display: flex; gap: 6px; flex-shrink: 0; }
.badge { font-size: 11px; color: var(--muted); padding: 0 6px; border-radius: 10px; border: 1px solid var(--border); line-height: 18px; }
.badge.progress.full { color: #16a34a; border-color: color-mix(in srgb, #22c55e 50%, transparent); }

/* status pill select */
.pill {
  appearance: none; -webkit-appearance: none; cursor: pointer; flex-shrink: 0;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 4px; border: 0; width: 96px; text-align: center; text-align-last: center;
  background: color-mix(in srgb, var(--c) var(--mix), transparent); color: color-mix(in srgb, var(--c) 75%, var(--text));
}
.pill:hover { background: color-mix(in srgb, var(--c) 28%, transparent); }
.pill option { background: var(--surface); color: var(--text); text-transform: none; }
.pill-static {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 4px;
  background: color-mix(in srgb, var(--c) var(--mix), transparent); color: color-mix(in srgb, var(--c) 75%, var(--text)); white-space: nowrap;
}

/* ---------- task panel ---------- */
.panel {
  width: min(520px, 46vw); flex-shrink: 0; border-left: 1px solid var(--border); background: var(--surface);
  overflow-y: auto; padding: 14px 22px 40px; display: flex; flex-direction: column; gap: 14px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; color: var(--muted); min-width: 0; }
.crumbs a { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs a:hover { color: var(--accent); }
.title-input {
  width: 100%; font-size: 20px; font-weight: 650; border: 1px solid transparent; padding: 4px 6px; margin-left: -7px;
  resize: none; overflow: hidden; background: transparent; line-height: 1.3;
}
.title-input:hover { border-color: var(--border); }
.panel-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.panel-meta .pill { width: auto; padding: 4px 10px; font-size: 11px; }
.meta { font-size: 12px; color: var(--muted); }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.save-state { font-size: 12px; color: var(--muted); }
.desc { width: 100%; min-height: 140px; resize: vertical; line-height: 1.55; padding: 10px 12px; background: var(--bg); }
.sub-list { list-style: none; margin: 0 0 6px; padding: 0; border-top: 1px solid var(--border); }
.sub-add input { width: 100%; border-style: dashed; background: transparent; }
.panel-foot { display: flex; gap: 8px; flex-wrap: wrap; justify-content: space-between; border-top: 1px solid var(--border); padding-top: 14px; margin-top: auto; }
.move { display: flex; gap: 6px; min-width: 0; flex: 1; }
.move select { min-width: 0; flex: 1; max-width: 260px; }

/* ---------- pages ---------- */
.page { padding: 26px 30px 60px; overflow-y: auto; max-width: 1000px; width: 100%; }
.page.narrow { max-width: 620px; }
.page > h1 { margin-bottom: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.stack input { color: var(--text); padding: 8px 10px; }
.inline-form { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 120px; }
.notice { background: color-mix(in srgb, #22c55e 14%, transparent); border: 1px solid color-mix(in srgb, #22c55e 40%, transparent); padding: 8px 12px; border-radius: 6px; }
.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); padding: 8px 12px; border-radius: 6px; margin: 0 0 12px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table.compact td { padding: 5px 8px; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); font-weight: 500; }
.search-big { display: flex; gap: 8px; margin-bottom: 14px; }
.search-big input { flex: 1; padding: 9px 12px; }
.results { list-style: none; padding: 0; margin: 0; }
.results a {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: center; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 6px;
}
.results a:hover { border-color: var(--accent); }
.r-title { font-weight: 600; }
.r-where, .r-snippet { grid-column: 2; font-size: 12px; color: var(--muted); }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.login-card button { justify-content: center; padding: 9px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; box-shadow: var(--shadow);
  transition: opacity .15s, transform .15s; z-index: 100; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .topbar {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border);
    background: var(--sidebar); position: sticky; top: 0; z-index: 10;
  }
  .topbar-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50; width: 280px; max-width: 85vw;
    transform: translateX(-100%); transition: transform .18s ease;
  }
  .sidebar-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .sidebar-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 40; }
  .board { padding: 14px 16px 80px; }
  .board-head h1 { font-size: 19px; }
  .quick-add kbd, .search kbd { display: none; }
  .quick-add select { max-width: 110px; }
  .handle { opacity: .6; }
  .add-btn, .row-main > .row-add { opacity: .55; }
  .pill { width: 92px; letter-spacing: 0; padding: 2px 4px; }
  .folder-head .menu summary { opacity: 1; }
  .panel {
    position: fixed; inset: 0; width: 100%; z-index: 45; padding: 12px 16px 40px;
  }
  .page { padding: 16px; }
  .table .actions { flex-direction: column; align-items: stretch; }
  .table th:nth-child(3), .table td:nth-child(3).muted { display: none; }
}
