/* The hidden attribute must win over the display rules below. */
[hidden] { display: none !important; }

:root {
  --bg: #f6efe3;
  --panel: #fffaf2;
  --line: #e6d8c4;
  --text: #2b2118;
  --muted: #7a6a58;
  --accent: #c8611c;
  --accent-soft: #f3dcc8;
  --danger: #b3261e;
  --ok: #2f7a3e;
  --canvas: #d9c7b4;
  --card: #f3f0eb;
  --ink: #1d1b1f;
  --edge: #5b5049;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code { background: var(--accent-soft); padding: 0 .25em; border-radius: 3px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.pad { padding: 16px; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 650; }
.topbar h1::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-right: 8px; }
.actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.busy-note { display: none; color: var(--accent); font-weight: 600; }
body.busy .busy-note { display: inline; }

.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 10px; cursor: pointer; text-decoration: none;
  display: inline-block;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #a94f13; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: none; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.d-delete { margin-top: 28px; }
.ctx-menu { position: fixed; z-index: 40; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 18px rgba(40, 25, 10, .25); padding: 4px; }
.ctx-menu button { display: block; width: 100%; border: 0; background: none; text-align: left; padding: 5px 14px; border-radius: 4px; cursor: pointer; }
.ctx-menu button:hover { background: #f7e3df; }
.ctx-danger { color: var(--danger); }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; padding: 2px 6px; border-radius: 4px; }
.icon-btn:hover { color: var(--danger); background: #f7e3df; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; text-align: left; }
.link-btn:hover { text-decoration: underline; }

/* messages */
#messages { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 20; max-width: min(480px, calc(100vw - 32px)); }
.msg { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(60, 40, 20, .12); }
.msg span { flex: 1; overflow-wrap: anywhere; }
.msg-error { border-color: var(--danger); background: #fbebe8; }
.msg-ok { border-color: var(--ok); }
.loader { flex-direction: column; align-items: stretch; gap: 5px; min-width: 240px; font-size: 12px; }
.loader-bar { display: block; height: 5px; border-radius: 3px; background: #e6dccd; overflow: hidden; }
.loader-bar i { display: block; height: 100%; width: 0; background: #6b4fa3; transition: width .2s; }
.msg-undo { position: relative; align-items: center; overflow: hidden; border-color: var(--danger); }
.msg-timer { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: var(--danger); transform-origin: left; animation: msg-timer linear forwards; }
@keyframes msg-timer { to { transform: scaleX(0); } }
.g-outcome.leaving { opacity: .35; }
.msg-close { border: 0; background: none; cursor: pointer; font-size: 16px; color: var(--muted); }

/* gate (setup / login) */
.gate { max-width: 560px; margin: 10vh auto; padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.gate h2 { margin-top: 0; }

/* layout */
#app { display: grid; grid-template-columns: 1fr; gap: 0; }
#app.with-detail { grid-template-columns: minmax(0, 1fr) 420px; }
#graph-pane { padding: 0; min-width: 0; }
#detail {
  border-left: 1px solid var(--line); background: var(--panel); padding: 14px 16px 40px;
  position: sticky; top: 53px; height: calc(100vh - 53px); overflow-y: auto;
}
body.busy #detail { opacity: .7; pointer-events: none; }

.open { text-decoration: none; }

.type { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 1px 5px; border-radius: 3px; flex: none; }
.type-epic { background: #e9e0f5; color: #5a3d8a; }
.type-task { background: #e6e1d8; color: #5d5246; }

.done-mark { color: var(--ok); font-weight: 700; flex: none; }
.done-note { color: var(--ok); font-weight: 600; flex: 1; }


/* detail panel */
.d-head { display: flex; align-items: center; gap: 10px; }
.d-head .icon-btn { margin-left: auto; }
.d-title { flex: 1; font-size: 17px; font-weight: 600; border: 1px solid transparent; background: transparent; padding: 4px 6px; border-radius: 5px; min-width: 0; }
.d-title:hover, .d-title:focus { border-color: var(--line); background: #fff; }
.d-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.d-row.end { justify-content: flex-end; }
.d-row > input, .d-row > select { flex: 1; min-width: 0; }
.d-meta { display: flex; gap: 16px; color: var(--muted); font-size: 12px; margin: 4px 6px 0; }
.d-section { margin-top: 18px; }
.d-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 6px; }
#detail input:not([type=checkbox]), #detail select, #detail textarea {
  border: 1px solid var(--line); border-radius: 5px; padding: 5px 7px; background: #fff;
}
.md { font-size: 13.5px; line-height: 1.45; overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: 6px; background: #fff; padding: 8px 12px; max-height: 420px; overflow-y: auto; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h3, .md h4, .md h5, .md h6 { margin: 14px 0 4px; line-height: 1.25; }
.md h3 { font-size: 16px; }
.md h4 { font-size: 14.5px; }
.md h5, .md h6 { font-size: 13.5px; }
.md p { margin: 6px 0; white-space: pre-line; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li { margin: 2px 0; }
.md li.md-check { list-style: none; margin-left: -20px; display: flex; gap: 7px; align-items: flex-start; }
.md-item { flex: 1; min-width: 0; }
.md-box { flex: none; width: 13px; height: 13px; margin-top: 3px; border: 1.5px solid var(--muted); border-radius: 3px; font-size: 9px; line-height: 10px; text-align: center; color: #fff; }
.md-box.on { background: var(--ok); border-color: var(--ok); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: #f3ece1; border-radius: 3px; padding: 0 3px; }
.md pre { background: #f3ece1; border-radius: 5px; padding: 8px 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 6px 0; padding: 2px 10px; border-left: 3px solid var(--line); color: var(--muted); }
.md a { color: var(--accent); }
.md-hint { margin-right: auto; }
#detail textarea { width: 100%; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
#detail input[type=search] { width: 100%; margin-top: 8px; }
.item { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.item input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
#detail .item .item-name { flex: 1; border-color: transparent; background: transparent; min-width: 0; }
#detail .item .item-name:hover, #detail .item .item-name:focus { border-color: var(--line); background: #fff; }
.item.resolved .item-name { color: var(--muted); text-decoration: line-through; }
.rel { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.rel-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; max-height: 320px; overflow-y: auto; }
.result { display: flex; align-items: center; gap: 8px; border: 1px solid transparent; background: none; text-align: left; padding: 4px 6px; border-radius: 5px; cursor: pointer; }
.result:hover { border-color: var(--accent); background: #fff; }
.result-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 1100px) {
  #app.with-detail { grid-template-columns: minmax(0, 1fr) 360px; }
}
@media (max-width: 820px) {
  #app.with-detail { grid-template-columns: 1fr; }
  #detail { position: static; height: auto; border-left: 0; border-top: 1px solid var(--line); }
}

/* graph view */
#graph { background: var(--canvas); height: calc(100vh - 53px); overflow: auto; position: relative; cursor: grab; }
#graph.panning { cursor: grabbing; user-select: none; }
.g-node { cursor: default; }
.g-canvas { position: relative; }
.g-edges { position: absolute; left: 0; top: 0; pointer-events: none; }
.g-edge { fill: none; stroke: var(--edge); stroke-width: 1.4; }
.g-link { cursor: pointer; }
.g-hit { fill: none; stroke: transparent; stroke-width: 12; pointer-events: stroke; }
.g-link:hover .g-edge { stroke: var(--danger); stroke-width: 2.6; }
body.dragging-card .g-link { pointer-events: none; }
.g-edge-epic { stroke: #6b4fa3; stroke-width: 1.3; }
.g-node { position: absolute; }
.g-outcome {
  background: var(--card); border: 2px solid var(--accent); border-radius: 7px; padding: 8px 10px 7px;
  cursor: pointer; box-shadow: 0 1px 2px rgba(40, 25, 10, .15);
}
.g-outcome { user-select: none; }
.g-outcome.drop-ok { outline: 3px solid var(--accent); outline-offset: 3px; }
.g-ghost { position: fixed; z-index: 30; pointer-events: none; opacity: .75; box-shadow: 0 6px 18px rgba(40, 25, 10, .35); }
body.dragging-card, body.dragging-card .g-outcome { cursor: grabbing; }
.g-outcome:hover { box-shadow: 0 2px 8px rgba(40, 25, 10, .25); }
.g-outcome.selected { outline: 3px solid var(--ink); outline-offset: 2px; }
.g-outcome.done { border-color: var(--ok); background: #eef4ec; }
.g-title { font-weight: 700; font-size: 13.5px; line-height: 1.25; padding-right: 4px; display: flex; gap: 5px; align-items: baseline; }
.g-owner {
  position: absolute; top: -12px; right: 10px; max-width: calc(50% - 26px); background: var(--ink); color: #fff;
  font-size: 12px; padding: 2px 10px; border-radius: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.g-outcome:has(.g-owner) .g-title { margin-top: 6px; }
.g-check { color: var(--ok); font-weight: 800; }
.g-add {
  position: absolute; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; padding: 0; border-radius: 50%;
  border: 1.5px solid var(--accent); background: #fff; color: var(--accent); font-size: 15px; font-weight: 700; line-height: 16px;
  cursor: pointer; opacity: .45; z-index: 1;
}
.g-add-right { right: -11px; cursor: crosshair; touch-action: none; }
.g-link-drag { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 30; pointer-events: none; }
.g-link-drag path { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 4; }
body.dragging-link, body.dragging-link .g-outcome { cursor: crosshair; }
.g-add-left { left: -11px; }
.g-outcome:hover .g-add, .g-outcome.selected .g-add, .g-add:focus-visible { opacity: 1; }
.g-add:hover { background: var(--accent); color: #fff; }
.g-fold {
  position: absolute; left: -9px; top: calc(50% + 14px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  border: 1px solid var(--accent); background: #fff; color: var(--accent); font-size: 10px; font-weight: 700; line-height: 1;
  cursor: pointer;
}
.g-fold.folded { background: var(--accent); color: #fff; }
.g-fold:hover { border-color: var(--ink); }
.g-crit { position: relative; margin-top: 7px; }
.g-crit.folded { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.g-crit-fold {
  width: 16px; height: 16px; padding: 0; border: 1px solid #8c7f74; border-radius: 50%; background: #fff; color: var(--ink);
  font-size: 9px; line-height: 1; cursor: pointer; flex: none;
}
.g-crit:not(.folded) .g-crit-fold { position: absolute; left: -7px; top: -7px; z-index: 1; }
.g-crit-fold:hover { border-color: var(--accent); color: var(--accent); }
.g-criteria {
  list-style: none; margin: 0; padding: 6px 8px; border: 1px solid #8c7f74; border-radius: 10px;
  background: #ebe3d9; font-size: 12px; line-height: 1.3;
}
.g-criteria li { display: flex; gap: 6px; align-items: flex-start; padding: 1px 0; }
.g-criteria li.met span { color: var(--muted); }
.g-tick {
  flex: none; width: 13px; height: 13px; margin-top: 1px; border-radius: 50%; border: 1.5px solid var(--ink);
  background: #fff; padding: 0; font-size: 9px; line-height: 10px; color: #fff; cursor: pointer; text-align: center;
}
.g-criteria li.met .g-tick { background: var(--ok); border-color: var(--ok); }
.g-tick:hover { border-color: var(--accent); }
.g-criteria li.from-epic .g-tick { border-color: #6b4fa3; cursor: default; }
.g-criteria li.from-epic.met .g-tick { background: #6b4fa3; border-color: #6b4fa3; }
.item.from-epic { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.item.from-epic .epic-state { width: 18px; text-align: center; color: #6b4fa3; font-weight: 700; }
.item.from-epic .epic-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.g-foot { display: flex; align-items: center; gap: 8px; margin-top: 7px; font-size: 11.5px; color: var(--muted); }
.g-progress { flex: 1; display: flex; align-items: center; gap: 5px; min-width: 0; }
.g-progress .bar { flex: 1; height: 4px; background: #ddd2c4; border-radius: 2px; overflow: hidden; }
.g-progress .fill { display: block; height: 100%; background: var(--accent); }
.g-outcome.done .g-progress .fill { background: var(--ok); }
.g-progress .count { font-variant-numeric: tabular-nums; }
.g-none { flex: 1; font-style: italic; }
.g-epic-progress { margin-top: 6px; cursor: default; font-size: 11px; color: var(--muted); }
.g-epic-progress .bar { background: #ddd3ee; }
.g-epic-progress .fill { background: #6b4fa3; }
.g-pct { margin-left: auto; padding-left: 6px; color: var(--muted); font-variant-numeric: tabular-nums; }
.g-month { white-space: nowrap; }
.g-task {
  background: #f7f4fb; border: 1.5px dashed #8a76ad; border-radius: 6px; padding: 5px 8px; font-size: 12px;
}
.g-epic { cursor: pointer; }
.g-epic.selected { box-shadow: 0 0 0 3px rgba(107, 79, 163, .35); }
.g-epic { background: #f3eefa; border: 2px solid #6b4fa3; padding: 8px 10px 7px; font-size: 13px; box-shadow: 0 1px 2px rgba(40, 25, 10, .15); }
.g-epic .g-task-name { font-weight: 700; margin-top: 4px; }
.g-task.done { border-color: var(--ok); border-style: solid; background: #eef4ec; }
.g-task-head { display: flex; align-items: center; gap: 6px; }
.g-task-head .open { margin-left: auto; }
.g-task-name { margin-top: 2px; line-height: 1.25; overflow-wrap: anywhere; }
