:root {
  --bg: #0d0d0d;
  --surface: #161616;
  --surface-2: #1f1f1f;
  --border: #2a2a2a;
  --border-bright: #3a3a3a;
  --text: #e8e8e8;
  --text-muted: #888;
  --text-faint: #555;
  --pro: #7cb87c;
  --pro-dim: #4a6e4a;
  --con: #c87c7c;
  --con-dim: #6e4a4a;
  --ai: #d4a857;
  --ai-dim: #6e5a2e;
  --branch: #6da4c9;
  --branch-dim: #3a5a73;
  --danger: #c54343;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: var(--mono);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  letter-spacing: 0.02em;
}
button:hover { border-color: var(--border-bright); background: var(--surface-2); }
button:active { transform: translateY(1px); }
button.danger { border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: rgba(197, 67, 67, 0.1); }
button:disabled { cursor: wait; opacity: 0.6; }

input, textarea, select {
  font-family: var(--sans);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--ai);
}
textarea { resize: vertical; min-height: 80px; }

/* HEADER */
.app-header {
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
}
.brand-mark { color: var(--ai); font-family: var(--mono); }
.brand-name {
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.18em;
  font-size: 18px;
}
.brand-sub {
  font-family: var(--mono);
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.1em;
}
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter { padding: 4px 10px; font-size: 12px; }
.filter.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* MAIN */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 100px;
}

.section-h {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.small { font-size: 12px; }
.muted { color: var(--text-muted); }
.hidden { display: none !important; }

/* LIST */
.list-header { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.list-items {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
}
.list-item {
  background: var(--surface);
  padding: 16px 18px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: background 80ms;
}
.list-item:hover { background: var(--surface-2); }
.list-item-title { font-weight: 500; font-size: 16px; line-height: 1.3; }
.list-item-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}
.list-item-meta .pro-c { color: var(--pro-dim); }
.list-item-meta .con-c { color: var(--con-dim); }
.list-item-meta .ai-c { color: var(--ai-dim); }
.list-item-meta .branch-c { color: var(--branch-dim); }
.list-item-meta .child-c { color: var(--branch); }
.list-item-meta .status-decided { color: var(--text); }
.list-item-meta .status-parked { color: var(--text-faint); }

.empty { text-align: center; padding: 60px 20px; color: var(--text-muted); }

/* DETAIL */
.detail { display: flex; flex-direction: column; gap: 24px; }

.back-btn {
  align-self: flex-start;
  padding: 6px 10px;
  font-size: 12px;
  border-color: transparent;
  color: var(--text-muted);
}
.back-btn:hover { color: var(--text); border-color: var(--border); }

/* BREADCRUMB */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--branch-dim);
  font-family: var(--mono);
  font-size: 12px;
}
.breadcrumb:empty { display: none; }
.breadcrumb a {
  color: var(--branch);
  text-decoration: none;
  cursor: pointer;
}
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb-branch {
  color: var(--text-muted);
  font-style: italic;
}
.breadcrumb-sep { color: var(--text-faint); }

.detail-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.detail-header h1 {
  font-family: var(--sans);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.2;
  border: 1px solid transparent;
  padding: 6px 8px;
  margin: -6px -8px;
}
.detail-header h1:hover { border-color: var(--border); }
.detail-header h1:focus {
  outline: none;
  border-color: var(--ai);
  background: var(--surface);
}
.detail-meta { display: flex; gap: 10px; align-items: center; }
.detail-meta select {
  width: auto;
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

#d-context {
  background: transparent;
  border-color: var(--border);
  font-size: 14px;
  color: var(--text-muted);
}

/* COLUMNS (pros/cons) */
.columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 720px) {
  .columns { grid-template-columns: 1fr; }
}
.col {
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
}
.col-pro { border-top: 3px solid var(--pro-dim); }
.col-con { border-top: 3px solid var(--con-dim); }
.col-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.col-header h2 {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
}
.col-pro h2 { color: var(--pro); }
.col-con h2 { color: var(--con); }
.count { font-weight: 400; color: var(--text-faint); }

.items-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  min-height: 60px;
}
.item-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.45;
}
.item-row:last-child { border-bottom: none; }
.item-text { flex: 1; word-break: break-word; }
.item-row.ai-source { background: rgba(212, 168, 87, 0.04); }
.item-row.ai-source::before {
  content: "ai";
  font-family: var(--mono);
  font-size: 9px;
  color: var(--ai);
  border: 1px solid var(--ai-dim);
  padding: 1px 4px;
  letter-spacing: 0.1em;
  margin-top: 2px;
  flex-shrink: 0;
}
.item-remove {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text-faint);
  background: transparent;
  border: none;
  padding: 0 4px;
  cursor: pointer;
  opacity: 0;
}
.item-row:hover .item-remove { opacity: 1; }
.item-remove:hover { color: var(--danger); }

.add-form { display: flex; border-top: 1px solid var(--border); }
.add-form input {
  border: none;
  background: transparent;
  font-size: 14px;
  flex: 1;
}
.add-form input:focus { background: var(--surface-2); }
.add-form button {
  border: none;
  border-left: 1px solid var(--border);
  background: transparent;
  padding: 0 18px;
  font-size: 18px;
  font-weight: 700;
}
.col-pro .add-form button:hover { color: var(--pro); }
.col-con .add-form button:hover { color: var(--con); }

/* BRANCHES */
.branches-section {
  border: 1px solid var(--branch-dim);
  background: rgba(109, 164, 201, 0.03);
}
.branches-section .section-h {
  padding: 14px 16px;
  border-bottom: 1px solid var(--branch-dim);
  margin-bottom: 0;
  color: var(--branch);
}
.branches-list { list-style: none; }
.branch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.branch-row:last-child { border-bottom: none; }
.branch-row.chosen { background: rgba(109, 164, 201, 0.08); }

.branch-radio {
  width: 18px;
  height: 18px;
  border: 2px solid var(--branch-dim);
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  background: transparent;
  padding: 0;
}
.branch-radio.chosen { border-color: var(--branch); }
.branch-radio.chosen::after {
  content: "";
  position: absolute;
  inset: 3px;
  background: var(--branch);
  border-radius: 50%;
}

.branch-label {
  flex: 1;
  font-size: 14px;
  border: 1px solid transparent;
  padding: 4px 6px;
  margin: -4px -6px;
  border-radius: 0;
  cursor: text;
}
.branch-label[contenteditable]:hover { border-color: var(--border); }
.branch-label[contenteditable]:focus {
  outline: none;
  border-color: var(--branch);
  background: var(--surface);
}

.branch-child {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--branch);
  text-decoration: none;
  border: 1px solid var(--branch-dim);
  padding: 4px 8px;
  letter-spacing: 0.05em;
  cursor: pointer;
  background: transparent;
}
.branch-child:hover {
  background: var(--branch-dim);
  color: var(--text);
}
.branch-child.no-child { color: var(--text-muted); border-color: var(--border); }
.branch-child.no-child:hover { color: var(--branch); border-color: var(--branch-dim); background: transparent; }

.branch-remove {
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 16px;
  padding: 0 6px;
  cursor: pointer;
}
.branch-remove:hover { color: var(--danger); }

.branch-add input { font-size: 14px; padding: 12px 16px; }
.branch-add button:hover { color: var(--branch); }

/* DECISION BOX */
.decision-box {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 16px;
}
.decision-box label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: block;
  margin-bottom: 8px;
}
.decision-box textarea {
  background: transparent;
  border: 1px solid var(--border);
  min-height: 60px;
}

/* AI SECTION */
.ai-section {
  border: 1px solid var(--ai-dim);
  background: rgba(212, 168, 87, 0.03);
}
.ai-section summary {
  padding: 14px 16px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ai);
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none;
}
.ai-section summary::-webkit-details-marker { display: none; }
.ai-section summary::after {
  content: "▾";
  margin-left: 10px;
  transition: transform 120ms;
}
.ai-section[open] summary::after { transform: rotate(180deg); }
.ai-warning {
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: lowercase;
  font-weight: 400;
}

.ai-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1px;
  background: var(--ai-dim);
  border-top: 1px solid var(--ai-dim);
}
.ai-switch {
  background: var(--surface);
  border: none;
  padding: 14px 16px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}
.ai-switch:hover { background: var(--surface-2); }
.sw-name {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--ai);
  letter-spacing: 0.05em;
}
.sw-desc { font-size: 12px; color: var(--text-muted); }

.ai-outputs { display: flex; flex-direction: column; }
.ai-output {
  border-top: 1px solid var(--ai-dim);
  padding: 16px;
  background: var(--surface);
}
.ai-output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.ai-output-name { color: var(--ai); font-weight: 600; }
.ai-output-meta { color: var(--text-faint); font-size: 10px; }
.ai-output-body {
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text);
}
.ai-output-body strong { color: var(--ai); }
.ai-output-body em { color: var(--text-muted); }
.ai-output-body h3 {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ai);
  margin: 10px 0 6px;
}

/* TREE SECTION */
.tree-section {
  border: 1px solid var(--branch-dim);
  background: rgba(109, 164, 201, 0.03);
}
.tree-section summary {
  padding: 14px 16px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--branch);
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none;
}
.tree-section summary::-webkit-details-marker { display: none; }
.tree-section summary::after {
  content: "▾";
  margin-left: 10px;
  transition: transform 120ms;
}
.tree-section[open] summary::after { transform: rotate(180deg); }
.tree-container {
  padding: 16px;
  border-top: 1px solid var(--branch-dim);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  overflow-x: auto;
}
.tree-decision {
  display: block;
  margin-left: 0;
}
.tree-decision-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.tree-decision-link {
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  border-bottom: 1px dotted var(--text-faint);
}
.tree-decision-link:hover { color: var(--ai); border-bottom-color: var(--ai); }
.tree-status {
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.tree-branches {
  list-style: none;
  margin-left: 16px;
  border-left: 1px solid var(--branch-dim);
  padding-left: 14px;
}
.tree-branch {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 6px;
}
.tree-branch-label {
  color: var(--text-muted);
  font-style: italic;
}
.tree-branch.chosen .tree-branch-label { color: var(--branch); font-weight: 600; }

/* FAB */
.fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--ai);
  color: var(--bg);
  border: none;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  padding: 14px 20px;
  text-transform: lowercase;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  z-index: 20;
}
.fab:hover { background: #e5b964; }

/* MODAL */
dialog {
  background: var(--surface);
  border: 1px solid var(--border-bright);
  color: var(--text);
  max-width: 500px;
  width: calc(100% - 40px);
  padding: 0;
}
dialog::backdrop { background: rgba(0,0,0,0.7); }
dialog form { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
dialog h2 {
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ai);
  margin-bottom: 6px;
}
dialog label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
.modal-actions button[type="submit"] {
  background: var(--ai);
  color: var(--bg);
  border-color: var(--ai);
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border-bright);
  color: var(--text);
  padding: 10px 18px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.05em;
  z-index: 30;
  max-width: calc(100% - 40px);
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.ai { border-color: var(--ai); color: var(--ai); }
.toast.branch { border-color: var(--branch); color: var(--branch); }

/* MOBILE */
@media (max-width: 600px) {
  main { padding: 14px; padding-bottom: 100px; }
  .detail-header h1 { font-size: 22px; }
  .ai-grid { grid-template-columns: 1fr 1fr; }
  .fab { left: 20px; right: 20px; text-align: center; }
  .branch-row { flex-wrap: wrap; }
}
