/* The AI setup screen: the family tree and the list. Panels, tiles, counts, rows and the round arrow are app.css's; this file adds the tree, its lines and marks, and the list's whole-row layout. The tree's own sizes are the --tree-* below. */

/* Each kind's gradient pair for the tile inside it. */
.tree-kind { display: grid; flex: none; }
.tree-kind-behavior { --tone-a: #6366f1; --tone-b: #312e81; }
.tree-kind-skill { --tone-a: #34d399; --tone-b: #059669; }
.tree-kind-template { --tone-a: #fcd34d; --tone-b: #f59e0b; }

/* The colour of each shared item, the wash set first. */
.tree-tint-0 { --tint: #6366f1; --tint-wash: #eef2ff; }
.tree-tint-1 { --tint: #0ea5e9; --tint-wash: #e0f2fe; }
.tree-tint-2 { --tint: #f59e0b; --tint-wash: #fef3c7; }
.tree-tint-3 { --tint: #10b981; --tint-wash: #d1fae5; }
.tree-tint-4 { --tint: #8b5cf6; --tint-wash: #ede9fe; }
.tree-tint-5 { --tint: #f43f5e; --tint-wash: #ffe4e6; }
.tree-tint-6 { --tint: #14b8a6; --tint-wash: #ccfbf1; }
.tree-tint-7 { --tint: #f97316; --tint-wash: #ffedd5; }

/* Marks: the shared dot, the main prompt's orb, the wait for approval. */
.tree-marks { display: inline-flex; flex: none; align-items: center; gap: 6px; }
.tree-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--tint); box-shadow: 0 0 0 3px var(--tint-wash); }
.tree-named { display: grid; flex: none; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-deep); }
.tree-named .icon { width: 12px; height: 12px; stroke-width: 2.2; }
.tree-wait { display: grid; place-items: center; color: var(--warn); }
.tree-wait .icon { width: 15px; height: 15px; stroke-width: 2; }

/* The legend in the panel's head. */
.tree-legend { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px 18px; color: var(--ink-2); font-size: 0.8125rem; font-weight: 600; }
.tree-key { display: inline-flex; align-items: center; gap: 8px; }
.tree-key-dots { display: inline-flex; gap: 3px; }
.tree-key-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--tint); }

/*
  The tree's lines. Each agent sits in a slot; the slot's ::before draws the piece of rail above it and the stub down to its card, from the card before it or, for the first of a row, from the spine in the left gutter. A row's first slot draws the spine down to the next rail with ::after. The trunk drops from the main prompt to the first rail. Columns come from the tree's own width through container queries, so the first of each row is known without measuring.
*/
.pnl-body:has(> .tree-body) { padding: 0; }
.tree-body {
  --tree-gut: 28px;
  --tree-gap: 14px;
  --tree-row: 44px;
  --tree-stub: 22px;
  --tree-drop: 30px;
  --tree-w: 2px;
  --tree-ink: #c5cce0;
  --tree-arm: calc(var(--tree-gut) / -2 - var(--tree-w) / 2);
  --tree-link: calc(-50% - var(--tree-gap) - var(--tree-w) / 2);
  --tree-none: calc(50% - var(--tree-w) / 2);
  --tint: var(--accent);
  --tint-wash: var(--accent-soft);
  container: tree / inline-size;
  padding: 28px var(--tree-gut) 30px;
  border-radius: 0 0 17px 17px;
  background: var(--canvas) radial-gradient(circle, #e3e7f1 1px, transparent 1.4px) 0 0 / 22px 22px;
}
.tree-top { --tree-cols: 1; position: relative; display: flex; justify-content: center; padding-bottom: var(--tree-drop); }
.tree-top::after { content: ""; position: absolute; bottom: 0; left: calc(50% - var(--tree-w) / 2); width: var(--tree-w); height: calc(var(--tree-drop) + 12px); background: var(--tree-ink); }
/* The first rail from the first card's centre to the trunk, so the trunk meets it even when the first row is short. */
.tree-body:has(.tree-slot) .tree-top::before { content: ""; position: absolute; bottom: calc(-1 * var(--tree-w)); left: calc((100% - (var(--tree-cols) - 1) * var(--tree-gap)) / var(--tree-cols) / 2 - var(--tree-w) / 2); right: calc(50% - var(--tree-w) / 2); height: var(--tree-w); background: var(--tree-ink); }
.tree-agents { --tree-cols: 1; display: grid; grid-template-columns: repeat(var(--tree-cols), minmax(0, 1fr)); gap: var(--tree-row) var(--tree-gap); margin: 0; padding: var(--tree-stub) 0 0; list-style: none; }
.tree-slot { --tree-from: var(--tree-arm); position: relative; display: flex; min-width: 0; }
.tree-slot::before { content: ""; position: absolute; top: calc(-1 * var(--tree-stub)); left: var(--tree-from); right: calc(50% - var(--tree-w) / 2); height: calc(var(--tree-stub) + 12px); border-top: var(--tree-w) solid var(--tree-ink); border-right: var(--tree-w) solid var(--tree-ink); }
.tree-slot::after { content: ""; position: absolute; top: calc(-1 * var(--tree-stub)); bottom: calc(var(--tree-stub) - var(--tree-row)); left: var(--tree-arm); display: none; width: var(--tree-w); background: var(--tree-ink); }
/* The first card has an arm to the spine only when the spine goes on below it. */
.tree-slot:first-child { --tree-from: var(--tree-none); }
.has-loose .tree-slot:first-child { --tree-from: var(--tree-arm); }
.tree-top::before, .tree-top::after, .tree-slot::before, .tree-slot::after, .tree-loose::before { pointer-events: none; }

@container tree (width < 440px) {
  .tree-slot:not(:last-child)::after, .has-loose .tree-slot::after { display: block; }
  .tree-slot:first-child:not(:last-child) { --tree-from: var(--tree-arm); }
}
@container tree (440px <= width < 660px) {
  .tree-top, .tree-agents { --tree-cols: 2; }
  .tree-slot:not(:nth-child(2n+1)) { --tree-from: var(--tree-link); }
  .tree-slot:nth-child(2n+1):nth-last-child(n+3)::after, .has-loose .tree-slot:nth-child(2n+1)::after { display: block; }
  .tree-slot:first-child:nth-last-child(n+3) { --tree-from: var(--tree-arm); }
}
@container tree (660px <= width < 880px) {
  .tree-top, .tree-agents { --tree-cols: 3; }
  .tree-slot:not(:nth-child(3n+1)) { --tree-from: var(--tree-link); }
  .tree-slot:nth-child(3n+1):nth-last-child(n+4)::after, .has-loose .tree-slot:nth-child(3n+1)::after { display: block; }
  .tree-slot:first-child:nth-last-child(n+4) { --tree-from: var(--tree-arm); }
}
@container tree (880px <= width < 1080px) {
  .tree-top, .tree-agents { --tree-cols: 4; }
  .tree-slot:not(:nth-child(4n+1)) { --tree-from: var(--tree-link); }
  .tree-slot:nth-child(4n+1):nth-last-child(n+5)::after, .has-loose .tree-slot:nth-child(4n+1)::after { display: block; }
  .tree-slot:first-child:nth-last-child(n+5) { --tree-from: var(--tree-arm); }
}
@container tree (width >= 1080px) {
  .tree-top, .tree-agents { --tree-cols: 5; }
  .tree-slot:not(:nth-child(5n+1)) { --tree-from: var(--tree-link); }
  .tree-slot:nth-child(5n+1):nth-last-child(n+6)::after, .has-loose .tree-slot:nth-child(5n+1)::after { display: block; }
  .tree-slot:first-child:nth-last-child(n+6) { --tree-from: var(--tree-arm); }
}

/* The main prompt: one premium card, centred, the trunk under it. */
.tree-main { position: relative; z-index: 1; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; width: min(500px, 100%); padding: 16px 16px 16px 18px; border: 1px solid #dfe3f3; border-radius: var(--r-panel); background: var(--surface) var(--wash); box-shadow: var(--sh-panel); color: var(--ink); font: inherit; text-align: left; cursor: pointer; transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.tree-main:hover { border-color: #c7d2fe; box-shadow: var(--glow-hover); transform: translateY(-2px); }
.tree-main:active { transform: scale(0.99); }
.tree-main .fr-tile { width: 44px; height: 44px; border-radius: 12px; }
.tree-main .fr-tile .icon { width: 22px; height: 22px; }
.tree-main-text { display: grid; gap: 3px; min-width: 0; }
.tree-main-text b { display: flex; align-items: center; gap: 8px; font-size: 1.0625rem; font-weight: 700; letter-spacing: -0.01em; }
.tree-main-line { color: var(--ink-2); font-size: 0.875rem; font-weight: 500; line-height: 1.4; }
.tree-main-facts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 3px; color: var(--ink-2); font-size: 0.8125rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.tree-size { display: inline-flex; align-items: center; gap: 8px; }
.tree-meter { width: 64px; height: 6px; overflow: hidden; border-radius: var(--r-pill); background: #e4e8f4; }
.tree-meter i { display: block; width: var(--fill, 0%); height: 100%; border-radius: inherit; background: var(--grad); }
.tree-open { display: inline-flex; align-items: center; gap: 4px; height: 34px; padding: 0 12px 0 16px; border-radius: var(--r-pill); background: var(--grad-pill); box-shadow: var(--glow-btn); color: #fff; font-size: 0.875rem; font-weight: 600; white-space: nowrap; }
.tree-open .icon { width: 15px; height: 15px; stroke-width: 2.2; }
.tree-main.is-missing { grid-template-columns: auto minmax(0, 1fr); border-style: dashed; cursor: default; }
.tree-main.is-missing:hover { border-color: #dfe3f3; box-shadow: var(--sh-panel); transform: none; }

/* An agent: a wall card filling its slot. It lifts while the pointer is anywhere in the slot, which never moves, so it cannot flicker. */
.tree-agent { position: relative; z-index: 1; display: flex; flex: 1; flex-direction: column; gap: 12px; min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: var(--r-panel); background: linear-gradient(135deg, color-mix(in srgb, #eef2ff 85%, #fff), #fff 50%); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 12px 28px -18px rgba(15, 23, 42, 0.28); transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.tree-slot:hover > .tree-agent { border-color: #c7d2fe; box-shadow: var(--glow-hover); transform: translateY(-2px); }
.tree-agent-head { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px 11px; margin: -4px; padding: 4px; border: 0; border-radius: 12px; background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer; transition: background var(--dur-fast) var(--ease); }
.tree-agent-head:hover { background: rgba(255, 255, 255, 0.75); }
.tree-agent-head .fr-tile { width: 36px; height: 36px; }
.tree-agent-head .fr-tile .icon { width: 19px; height: 19px; }
.tree-agent-title { display: grid; align-content: center; gap: 1px; min-width: 0; }
.tree-agent-title b { display: flex; align-items: center; gap: 7px; min-width: 0; font-size: 0.9375rem; font-weight: 650; line-height: 1.3; }
.tree-agent-title small { color: var(--ink-2); font-size: 0.75rem; font-weight: 600; }
.tree-agent-line { display: -webkit-box; grid-column: 1 / -1; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; color: var(--ink-2); font-size: 0.8125rem; font-weight: 500; line-height: 1.45; overflow-wrap: normal; }
.tree-none { margin: 0; padding: 10px 12px; border-radius: var(--r-card); background: var(--well); color: var(--ink-2); font-size: 0.8125rem; font-weight: 500; }

/* Skills: rows in a well. A lit shared item rings in the colour the tree body names while it is lit. */
.tree-well { display: grid; gap: 2px; margin: 0; padding: 4px; border-radius: var(--r-card); background: var(--well); box-shadow: inset 0 0 0 1px rgba(226, 232, 240, 0.7); list-style: none; }
.tree-skill, .tree-more { display: flex; align-items: center; gap: 7px; width: 100%; min-height: 32px; padding: 5px 7px; border: 0; border-radius: var(--r-ctl); background: none; color: var(--ink); font: 550 0.8125rem/1.3 var(--font); text-align: left; cursor: pointer; transition: background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
.tree-skill > .icon { width: 15px; height: 15px; color: #64748b; }
.tree-skill-name { flex: 1; min-width: 0; overflow-wrap: normal; }
.tree-skill:hover, .tree-more:hover { background: var(--surface); box-shadow: var(--sh-sm); }
.tree-more { color: var(--accent); font-weight: 600; }
.tree-more .icon { width: 15px; height: 15px; stroke-width: 2; }
.tree-skill.is-lit, .tree-more.is-lit, .tree-tpl.is-lit { background: var(--tint-wash); box-shadow: inset 0 0 0 2px var(--tint); }

/* Templates: amber tags under the skills, a different kind of thing at a glance. */
.tree-tpls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: auto; }
.tree-tpls-label { flex-basis: 100%; color: var(--ink-2); font-size: 0.75rem; font-weight: 600; }
.tree-tpl { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 3px 9px 3px 7px; border: 1px solid #fde68a; border-radius: var(--r-ctl); background: #fffbeb; color: #92400e; font: 600 0.8125rem/1.3 var(--font); cursor: pointer; transition: background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
.tree-tpl > .icon { width: 15px; height: 15px; color: #d97706; }
.tree-tpl:hover { background: #fef3c7; box-shadow: var(--sh-sm); }

/* What no agent lists: its panel hung from the spine by its tile, the skills in columns. */
.tree-loose { --tree-loose-x: calc(1px + 0.9rem + 15px); position: relative; z-index: 1; margin-top: var(--tree-row); }
.tree-loose::before { content: ""; position: absolute; top: calc(-1 * var(--tree-stub)); left: var(--tree-arm); right: calc(100% - var(--tree-loose-x) - var(--tree-w) / 2); height: var(--tree-stub); border-top: var(--tree-w) solid var(--tree-ink); border-right: var(--tree-w) solid var(--tree-ink); }
.tree-family:not(:has(.tree-slot)) .tree-loose { margin-top: 0; }
.tree-family:not(:has(.tree-slot)) .tree-loose::before { display: none; }
.tree-loose .pnl-body { display: grid; gap: 12px; padding-top: 0.9rem; }
.tree-loose .tree-well { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.tree-loose .tree-tpls-label { flex-basis: auto; margin-right: 4px; }

/* The list: every row one target that lifts (app.css's nav-row), its button stretched over the whole row and 2px under it, so the lift never takes the row from under the pointer. */
.ailist-find { flex: 1 1 220px; }
.card-head .ailist-find { width: auto; max-width: 320px; }
.ailist-pick { width: auto; padding-block: 0.4rem; font-size: 0.875rem; cursor: pointer; }
.ailist-group + .ailist-group { margin-top: 18px; }
.ailist-head { display: flex; align-items: center; gap: 10px; margin: 6px 0 8px; padding: 0 6px; color: var(--ink); font-size: 0.95rem; font-weight: 700; }
.ailist-head .fr-tile { width: 26px; height: 26px; border-radius: var(--r-ctl); }
.ailist-head .fr-tile .icon { width: 14px; height: 14px; }
.ailist-rows { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.ailist-rows > .ailist-row { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 4px 14px; min-height: 60px; padding: 10px 12px; border: 1px solid transparent; border-radius: var(--r-card); }
.ailist-rows > .ailist-row:hover { border-color: #c7d2fe; }
.ailist-row .row-lead .fr-tile { width: 36px; height: 36px; }
.ailist-row .row-lead .fr-tile .icon { width: 18px; height: 18px; }
.ailist-rows .ailist-row .row-main { position: static; cursor: pointer; }
.ailist-rows .ailist-row .row-main::after { content: ""; position: absolute; inset: -1px -1px -3px; border-radius: inherit; }
.ailist-rows .ailist-row .row-main:focus-visible { box-shadow: none; }
.ailist-rows > .ailist-row:has(.row-main:focus-visible) { border-color: var(--accent); box-shadow: var(--focus); }
.ailist-row .row-title { font-size: 0.9375rem; }
.ailist-row .row-line { display: block; font-size: 0.875rem; font-weight: 500; line-height: 1.45; }
.ailist-row .row-meta { flex-wrap: nowrap; gap: 10px; max-width: 340px; font-weight: 600; text-align: right; }

/* The popup's rows: who uses an item and what it uses, each a row to go on to. */
.ailist-links { display: grid; gap: 8px; }
.ailist-links h3 { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--ink); font-size: 0.875rem; font-weight: 700; }
.ailist-links .ailist-rows > .ailist-row { min-height: 54px; padding: 8px 10px; background: var(--well); }
.ailist-none { margin: 0; padding: 10px 12px; border-radius: var(--r-card); background: var(--well); color: var(--ink-2); font-size: 0.875rem; font-weight: 500; }
.ailist-text { padding-top: 16px; border-top: 1px solid var(--line-soft); }

@media (max-width: 760px) {
  .tree-body { --tree-gut: 22px; padding-top: 20px; }
  .tree-main { grid-template-columns: auto minmax(0, 1fr); gap: 12px; padding: 14px; }
  .tree-main .tree-open { grid-column: 1 / -1; justify-content: center; }
  .card-head .ailist-find { max-width: none; }
  .ailist-pick { flex: 1 1 auto; }
  .ailist-rows > .ailist-row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .ailist-rows > .ailist-row > .row-meta { grid-column: 2 / -1; grid-row: 2; justify-content: flex-start; max-width: none; padding-left: 0; text-align: left; }
  .ailist-row .row-tools { grid-column: 3; grid-row: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .tree-main:hover, .tree-slot:hover > .tree-agent { transform: none; }
}
