/* Infinite CAD chrome: Divs & Spans' quiet bones. The part is the content. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#ececea, #161617);
  --dot: light-dark(#d2d2ce, #2a2a2c);
  --panel: light-dark(#ffffff, #222224);
  --panel-2: light-dark(#f6f6f4, #2b2b2e);
  --line: light-dark(#dcdcd8, #38383b);
  --text: light-dark(#1d1d1f, #ececee);
  --muted: light-dark(#76767a, #9a9aa0);
  --accent: light-dark(#4f46e5, #8b85ff);
  --accent-soft: light-dark(#4f46e51a, #8b85ff26);
  --danger: light-dark(#d93d42, #ff6b6b);
  --shadow: 0 1px 2px #0000000f, 0 8px 24px #0000001a;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --tree: 300px;
  /* room the phone dock takes at the bottom; 0 on desktop */
  --dock: 0px;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body { font: 13px/1.4 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
code, .id { font-family: var(--mono); font-size: 12px; }

/* ---------- 3D view ---------- */
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
body.stale #view { filter: saturate(0.35) opacity(0.7); }
/* measure: labels over the canvas, under the chrome; lines are drawn in the scene */
.dims { position: fixed; inset: 0; z-index: 5; pointer-events: none; overflow: hidden; }
.dim {
  position: absolute; left: 0; top: 0; font: 11px/1 var(--mono); padding: 3px 5px; border-radius: 5px; white-space: nowrap;
  color: light-dark(#0b7285, #66d9e8); background: color-mix(in srgb, var(--panel) 88%, transparent); border: 1px solid currentColor;
}
.tip {
  position: fixed; left: 0; top: 0; z-index: 20; pointer-events: none;
  font: 12px var(--mono); padding: 3px 7px; border-radius: 6px; background: var(--text); color: var(--bg); white-space: nowrap;
}

/* ---------- toolbar ---------- */
.bar { position: fixed; inset: 12px 12px auto 12px; z-index: 10; display: flex; align-items: center; gap: 6px; pointer-events: none; }
.bar > *, .bar .group { pointer-events: auto; flex: none; }
.bar > .group:first-child { flex: 0 1 auto; min-width: 0; }
.view-sheet { display: contents; }
.group {
  display: flex; align-items: center; gap: 2px; padding: 3px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.spacer { flex: 1; pointer-events: none; }
.brand { display: flex; align-items: center; gap: 8px; padding: 3px 10px 3px 8px; text-decoration: none; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.brand-mark { font-family: var(--mono); font-size: 22px; line-height: 1; color: var(--accent); }
.file-name { border: 0; background: transparent; padding: 4px 8px; border-radius: 6px; width: 18ch; min-width: 0; flex: 1 1 auto; }
.file-name:hover { background: var(--panel-2); }
.file-name:focus { outline: 2px solid var(--accent); background: var(--panel-2); }
.version { font: 12px var(--mono); color: var(--muted); white-space: nowrap; }
.status-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); margin: 0 6px; }
.status-dot.live { background: #22a06b; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  border: 0; border-radius: 7px; background: transparent; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--panel-2); }
.btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.btn.primary { background: var(--accent); color: white; }
.btn.danger { color: var(--danger); background: color-mix(in oklab, var(--danger) 12%, transparent); }
/* keycaps: every action shows its key */
.btn kbd, .sel-bar kbd, .toast kbd, .how kbd {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px;
  font: 600 11px/1 var(--font); color: var(--muted); background: var(--panel);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; white-space: nowrap;
}
.btn[aria-pressed="true"] kbd { color: inherit; border-color: currentColor; background: transparent; }
.btn.primary kbd { color: white; background: transparent; border-color: rgb(255 255 255 / 0.55); }
.toast kbd { background: transparent; color: inherit; border-color: currentColor; opacity: 0.75; }
.sep { width: 1px; height: 18px; background: var(--line); margin: 0 3px; }
.dropdown { position: relative; display: flex; }
.dropdown .caret { color: var(--muted); margin-left: -2px; }
.btn[aria-expanded="true"] { background: var(--panel-2); }
.menu {
  position: absolute; top: calc(100% + 7px); left: -3px; z-index: 20; min-width: 150px; padding: 4px;
  display: flex; flex-direction: column; gap: 1px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.menu-item {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 28px; padding: 0 6px 0 10px;
  border: 0; border-radius: 6px; background: transparent; cursor: pointer; text-align: left; white-space: nowrap;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--panel-2); outline: none; }
.menu-sep { height: 1px; margin: 3px 4px; background: var(--line); }
.menu.end { left: auto; right: -3px; }
.menu-item .fmt { display: inline-block; min-width: 4.5ch; font-weight: 600; }
.menu-item .note { color: var(--muted); }
.menu-item[aria-checked="true"] { color: var(--accent); }
.menu-item kbd {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px;
  font: 600 11px/1 var(--font); color: var(--muted); background: var(--panel);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
}

/* ---------- features panel: the part's tree, ids first ---------- */
.tree-panel {
  position: fixed; top: 60px; left: 12px; bottom: 12px; width: var(--tree); z-index: 5; display: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  overflow: auto; padding: 6px; overscroll-behavior: contain;
}
body.tree-open .tree-panel { display: block; }
.tree-head {
  position: sticky; top: -6px; z-index: 1; display: flex; align-items: center; justify-content: space-between;
  margin: -6px -6px 4px; padding: 6px 6px 6px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
  color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
}
.tree-head .btn { height: 26px; padding: 0 8px; font-size: 12px; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--text); }
.tree, .tree ol { list-style: none; margin: 0; padding: 0; }
.tree ol { padding-left: 12px; }
.tree .feat > ol { display: none; }
.tree .feat.open > ol { display: block; }
.row {
  display: flex; width: 100%; align-items: center; gap: 6px; border: 0; background: none;
  padding: 4px 8px; border-radius: 6px; cursor: pointer; text-align: left; min-height: 26px;
}
.row:hover, .row.hover { background: var(--panel-2); }
.row.on { background: var(--accent-soft); color: var(--accent); }
.row.in { color: var(--accent); }
.row.part { font-weight: 600; }
.row.part .id { font-weight: 600; }
.row.role, .row.inst { color: var(--muted); padding: 2px 8px; min-height: 22px; }
.row.role.on, .row.inst.on, .row.role.in, .row.inst.in { color: var(--accent); }
.row.absent .id { color: var(--muted); text-decoration: line-through; }
.row .op { margin-left: auto; color: var(--muted); font-size: 11px; white-space: nowrap; }
.row .caret { width: 22px; height: 22px; margin-left: -6px; flex: none; display: grid; place-items: center; border-radius: 5px; color: color-mix(in srgb, var(--text) 70%, transparent); transition: transform 0.12s, color 0.12s, background 0.12s; }
.row .caret:empty { pointer-events: none; }
.row .caret:not(:empty):hover { color: var(--text); background: var(--line); }
.feat.open > .row .caret { transform: rotate(90deg); color: var(--text); }
.tree .feat > ol { margin-left: 13px; padding-left: 6px; border-left: 1px solid var(--line); }
.row.err .id::after { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--danger); margin-left: 6px; vertical-align: middle; }

/* ---------- the agent holds the edit lock ---------- */
.working {
  position: fixed; top: 60px; left: 12px; right: 12px; margin-inline: auto; width: fit-content; z-index: 9;
  display: flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); white-space: nowrap;
}
.working b { font-weight: 600; }
.working .task { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.working .task:not(:empty)::before { content: "· "; }
.pulse { flex: none; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; transform: scale(0.7); } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }
/* centered over the canvas, not the window, when the tree panel is open */
body.tree-open .working, body.tree-open .sel-bar, body.tree-open .toast { left: calc(var(--tree) + 24px); }

/* ---------- build errors: keep the last good part, say why ---------- */
.errors {
  position: fixed; top: 60px; right: 12px; z-index: 9; width: min(380px, calc(100vw - 24px)); max-height: 50vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--danger); border-radius: 10px; box-shadow: var(--shadow); padding: 10px 14px;
}
body.working-on .errors { top: 104px; }
.errors h3 { margin: 0 0 2px; font-size: 13px; color: var(--danger); }
.errors p { margin: 0 0 8px; color: var(--muted); }
.errors ol { margin: 4px 0 0; padding-left: 18px; }
.errors li { margin: 4px 0; overflow-wrap: anywhere; }
.errors .id { border: 0; background: var(--panel-2); border-radius: 4px; padding: 0 4px; cursor: pointer; color: inherit; }
.errors .id:hover { color: var(--accent); }

/* ---------- selection bar ---------- */
.sel-bar {
  position: fixed; left: 12px; right: 12px; margin-inline: auto; width: fit-content; bottom: calc(var(--dock) + 16px); z-index: 8;
  display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.sel-bar.idle { padding: 7px 12px; color: var(--muted); }
.sel-bar .hint { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.sel-bar .hint b { color: var(--text); font-weight: 600; }
.sel-bar .chips { display: flex; gap: 4px; overflow-x: auto; min-width: 0; scrollbar-width: none; }
.chip { font: 12px var(--mono); padding: 3px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.chip.gone { background: var(--panel-2); color: var(--muted); text-decoration: line-through; }
.sel-bar .actions { display: flex; gap: 2px; flex: none; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 12px; right: 12px; margin-inline: auto; width: fit-content; bottom: calc(var(--dock) + 70px); transform: translateY(8px); z-index: 30;
  padding: 8px 14px; border-radius: 8px; background: var(--text); color: var(--bg); opacity: 0; transition: opacity 0.18s, transform 0.18s;
  pointer-events: none; max-width: 560px; text-align: center;
}
.toast.show { opacity: 1; transform: none; }
.toast code { font: 12px var(--mono); opacity: 0.8; overflow-wrap: anywhere; }

/* ---------- empty, trashed, connect ---------- */
.empty { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; padding: 16px; }
body.tree-open .empty { padding-left: calc(var(--tree) + 24px); }
.tree .none { padding: 8px; color: var(--muted); }
.empty-card { max-width: 460px; padding: 28px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); pointer-events: auto; }
.empty-card h2 { margin: 0 0 6px; font-size: 17px; letter-spacing: -0.01em; }
.empty-card p { margin: 0 0 14px; color: var(--muted); }
.empty-card .btn.primary { height: 32px; padding: 0 14px; }
.trashed { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.trashed .row { display: flex; gap: 8px; }
.trashed .row .btn { height: 32px; padding: 0 14px; border: 1px solid var(--line); }
.pop {
  position: fixed; top: 56px; right: 12px; z-index: 20; width: min(420px, calc(100vw - 24px)); padding: 16px;
  border-radius: 12px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.pop h3 { margin: 0 0 4px; font-size: 13px; }
.pop p { margin: 0 0 12px; color: var(--muted); }
.field { display: flex; gap: 6px; margin-bottom: 14px; }
.field input { flex: 1; min-width: 0; height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); font: 12px var(--mono); }
.field .btn { border: 1px solid var(--line); }
.prompt { font: 12px/1.5 var(--mono); padding: 10px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); white-space: pre-wrap; margin: 0; }

/* ---------- home ---------- */
.home {
  min-height: 100%; display: grid; place-items: center; padding: 48px 16px;
  background-image: radial-gradient(var(--dot) 1px, transparent 1px); background-size: 24px 24px;
}
.home-card { width: min(540px, 100%); padding: 32px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.home-card h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -0.02em; }
.home-card h1 span { font-family: var(--mono); font-weight: 400; font-size: 18px; color: var(--accent); margin-left: 6px; }
.home-card > p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.home-card .how { margin: 0 0 22px; padding-left: 18px; color: var(--muted); }
.home-card .how li { margin: 3px 0; }
.home-card .how code { color: var(--text); }
.home-card form { display: flex; gap: 8px; margin-bottom: 24px; }
.home-card form input { flex: 1; min-width: 0; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.home-card form .btn { height: 36px; padding: 0 16px; }
.home-card h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.recent { list-style: none; margin: 0 0 24px; padding: 0; }
.recent li { position: relative; }
.recent a { display: flex; justify-content: space-between; gap: 12px; padding: 8px 40px 8px 10px; margin: 0 -10px; border-radius: 8px; text-decoration: none; }
.recent a:hover { background: var(--panel-2); }
.recent time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.recent .forget {
  position: absolute; right: -6px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px;
  border: 0; border-radius: 6px; background: none; color: var(--muted); font-size: 16px; cursor: pointer; opacity: 0;
}
.recent li:hover .forget, .recent .forget:focus-visible { opacity: 1; }
.recent .forget:hover { background: var(--panel); color: var(--text); }
@media (pointer: coarse) { .recent .forget { opacity: 1; } }

/* ---------- the bar is full: secondary keycaps go first, then labels (tooltips still name every key) ---------- */
@media (max-width: 1379px) { .bar kbd.k2 { display: none !important; } }
@media (max-width: 1180px) { .hide-md { display: none !important; } }
@media (max-width: 1060px) { .bar kbd { display: none !important; } .bar .menu-item kbd { display: inline-grid !important; } }
@media (min-width: 821px) { .phone-only { display: none !important; } .bar > .group:first-child { width: var(--tree); } }

/* ---------- phones: identity on top, tools in a dock at the thumb, view settings in a sheet ---------- */
@media (max-width: 820px) {
  :root { --dock: calc(64px + env(safe-area-inset-bottom)); }
  .not-phone, .bar kbd, .sel-bar kbd, .tree-head kbd { display: none !important; }
  .bar { top: calc(8px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); right: calc(8px + env(safe-area-inset-right)); }
  .bar, .tools, .view-sheet, .sel-bar { touch-action: none; }
  .bar .btn { height: 36px; }
  .file-name { width: auto; }
  .tools { position: fixed; left: 50%; bottom: calc(10px + env(safe-area-inset-bottom)); translate: -50% 0; max-width: calc(100vw - 16px); }
  .tools .btn { height: 40px; padding: 0 11px; }
  .tools .btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); }
  .view-sheet {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
    position: fixed; left: 8px; right: 8px; bottom: calc(var(--dock) + 8px); max-width: 420px; margin: 0 auto; padding: 10px;
    border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
  }
  body:not(.view-open) .view-sheet { display: none; }
  .view-sheet .group { padding: 0; border: 0; box-shadow: none; background: none; flex-wrap: wrap; gap: 6px; }
  .view-sheet .views { flex: 1 1 100%; }
  .view-sheet .views .sep { display: none; }
  .view-sheet .views .btn { flex: 1; justify-content: center; background: var(--panel-2); }
  .view-sheet .views .dropdown { flex: 1; }
  .view-sheet .menu { top: auto; bottom: calc(100% + 8px); left: 0; }
  .view-sheet #exportWrap { position: static; } /* the menu spans the sheet, not the button */
  .view-sheet .menu.end { left: 0; right: 0; }
  .menu-item { height: 38px; }
  .bar .menu-item kbd { display: none !important; }
  .view-sheet .group:last-child { margin-left: auto; }
  .tree-panel { top: auto; left: 8px; right: 8px; width: auto; max-width: 420px; margin: 0 auto; bottom: calc(var(--dock) + 8px); max-height: 42dvh; border-radius: 14px; }
  .row { min-height: 34px; }
  .row.role, .row.inst { min-height: 32px; }
  body.tree-open .sel-bar, body.tree-open .working, body.tree-open .toast { left: 12px; }
  body.tree-open .sel-bar { bottom: calc(var(--dock) + 42dvh + 16px); }
  body.view-open .sel-bar { display: none; }
  .sel-bar { bottom: calc(var(--dock) + 8px); max-width: calc(100vw - 24px); }
  .sel-bar .btn { height: 38px; padding: 0 10px; }
  .sel-bar .btn[aria-pressed="true"] { color: var(--accent); }
  .working { top: calc(60px + env(safe-area-inset-top)); }
  .errors { top: auto; bottom: calc(var(--dock) + 64px); left: 8px; right: 8px; width: auto; max-height: 30dvh; }
  .pop { top: calc(56px + env(safe-area-inset-top)); left: 8px; right: 8px; width: auto; max-height: calc(100dvh - var(--dock) - 72px); overflow: auto; touch-action: pan-y; }
  .toast { bottom: calc(var(--dock) + 64px); }
}
@media (max-width: 430px) {
  nav.tools .btn { padding: 0 8px; }
  .tools .sep { margin: 0 1px; }
}

/* ===== comments ===== */
.btn .badge {
  min-width: 17px; height: 17px; padding: 0 5px; border-radius: 99px;
  background: var(--accent); color: white; font: 600 11px/17px var(--font); text-align: center;
}
/* pins: DOM buttons over the canvas, under the chrome; the bottom-left corner sits on the anchor */
.pins { position: fixed; inset: 0; z-index: 6; pointer-events: none; overflow: hidden; }
.pin {
  position: absolute; left: 0; top: -28px;
  display: flex; align-items: center; gap: 2px;
  padding: 2px; border: 0; border-radius: 15px 15px 15px 3px;
  background: var(--panel); box-shadow: 0 1px 3px #0003, 0 4px 14px #0002;
  pointer-events: auto; cursor: pointer; transform-origin: 0 100%;
}
.pin:hover, .pin.active { box-shadow: 0 0 0 2px var(--accent), 0 4px 14px #0003; z-index: 1; }
.pin i { font: 600 11px var(--font); font-style: normal; color: var(--muted); padding: 0 6px 0 2px; }
.pin.resolved { opacity: 0.7; }
.pin.resolved .av { filter: grayscale(0.6); }
.pin.behind { opacity: 0.4; }
.pin.behind:hover, .pin.behind.active { opacity: 0.85; }
.av {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--c, var(--muted)); color: white; font: 600 10px/1 var(--font); letter-spacing: 0.02em;
}
.av.agent { font-size: 12px; }

/* the thread: beside its pin on desktop, a bottom sheet on phones */
.thread-pop {
  position: fixed; left: 0; top: 0; z-index: 25;
  width: 340px; max-height: min(520px, calc(100dvh - 80px));
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 32px rgb(0 0 0 / 0.25);
}
.thread-pop .head { display: flex; align-items: center; gap: 2px; padding: 6px 6px 6px 10px; border-bottom: 1px solid var(--line); }
.thread-pop .head .where { flex: 1; min-width: 0; display: flex; align-items: center; overflow: hidden; white-space: nowrap; font-weight: 600; }
.thread-pop .head .btn { height: 26px; padding: 0 7px; gap: 4px; }
.thread-pop .head [data-act="status"] { color: var(--accent); }
.thread-pop .head .where .chip { min-width: 6ch; }
.thread-pop .nav { display: flex; align-items: center; gap: 2px; white-space: nowrap; margin: -2px 0 -2px -6px; }
.thread-pop .nav .btn { height: 22px; padding: 0 6px; font-size: 15px; color: var(--text); }
.thread-pop .nav .of { margin-right: 4px; }
.thread-pop kbd {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px;
  font: 600 11px/1 var(--font); color: var(--muted); background: var(--panel);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; white-space: nowrap;
}
.thread-pop .btn.primary kbd { color: white; background: transparent; border-color: rgb(255 255 255 / 0.55); }
.thread-pop button.chip { border: 0; cursor: pointer; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.thread-pop button.chip:hover { box-shadow: inset 0 0 0 1px currentColor; }
.thread-pop .sub { display: flex; flex-direction: column; gap: 2px; padding: 6px 12px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.thread-pop .sub code { font: 11px var(--mono); color: var(--text); }
.thread-pop .link { border: 0; background: none; padding: 0; color: var(--accent); font-size: 12px; cursor: pointer; text-align: left; }
.thread-pop .link:hover { text-decoration: underline; }
.thread-pop .items { list-style: none; margin: 0; padding: 4px 0; overflow: auto; touch-action: pan-y; overscroll-behavior: contain; }
.thread-pop .items:empty { display: none; }
.thread-pop .items li { display: flex; gap: 10px; padding: 8px 12px; }
.thread-pop .items .body { min-width: 0; flex: 1; }
.thread-pop .meta { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.thread-pop time { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; }
.thread-pop .items p { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.thread-pop .items .note { color: var(--muted); font-size: 12px; }
.thread-pop .tag { font-size: 11px; color: var(--accent); background: var(--accent-soft); padding: 0 5px; border-radius: 4px; }
.thread-pop .own { display: none; gap: 6px; }
.thread-pop li:hover .own, .thread-pop li:focus-within .own { display: inline-flex; }
.thread-pop .own button, .thread-pop .as button { border: 0; background: none; padding: 0; color: var(--muted); font-size: 12px; cursor: pointer; }
.thread-pop .own button:hover, .thread-pop .as button:hover { color: var(--accent); }
.thread-pop .as button[data-act="rename"] { font-weight: 600; }
.thread-pop form { padding: 8px; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.thread-pop .items:empty + form, .thread-pop .sub[hidden] + .items:empty + form { border-top: 0; }
.thread-pop textarea {
  width: 100%; resize: none; min-height: 40px; max-height: 160px; field-sizing: content;
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font: inherit; color: inherit;
}
.thread-pop textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.thread-pop .foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.thread-pop .as { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-pop .rename { width: 16ch; height: 22px; padding: 0 6px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel-2); font-size: 12px; }
.thread-pop.resolved .head .where { opacity: 0.7; }

/* Features panel: open-comment badges per row (a collapsed feature sums what's inside it), "+" on hover */
.row .cside { margin-left: auto; display: flex; align-items: center; gap: 4px; flex: none; }
.row .op ~ .cside { margin-left: 0; }
.cbadge { display: flex; }
.cbadge:empty { display: none; }
.cbadge i {
  font: 600 10.5px/16px var(--font); font-style: normal; min-width: 16px; height: 16px; padding: 0 5px; border-radius: 8px 8px 8px 2px;
  background: var(--accent-soft); color: var(--accent); text-align: center; cursor: pointer;
}
.cbadge i:hover { background: var(--accent); color: white; }
.feat.open > .row .cbadge .sum, .feat:not(.open) > .row .cbadge .own { display: none; }
.cadd {
  width: 18px; height: 18px; display: grid; place-items: center; border-radius: 5px;
  color: var(--muted); font: 500 15px/1 var(--font); visibility: hidden; cursor: pointer;
}
.cadd:hover { background: var(--line); color: var(--text); }
.row:hover .cadd { visibility: visible; }
.tree > .cwhole { margin-bottom: 4px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.tree > .cwhole .row { color: var(--muted); }
.tree > .cwhole .row .id { font-family: var(--font); font-size: 13px; }
body.commenting .tree > .cwhole .row { color: var(--text); }

@media (max-width: 820px) {
  .tools .btn .badge { margin-left: -2px; }
  .thread-pop {
    left: 8px; right: 8px; top: auto; bottom: calc(var(--dock) + 8px); width: auto; max-width: 420px; margin: 0 auto;
    transform: none !important; max-height: calc(100dvh - var(--dock) - 80px); border-radius: 14px;
  }
  .thread-pop .head .btn { height: 34px; padding: 0 9px; }
  .thread-pop textarea { font-size: 16px; }
  body.thread-open .sel-bar { display: none; }
}
@media (max-width: 820px), (pointer: coarse) {
  .cadd { display: none; }
  .cbadge i { min-width: 20px; height: 20px; line-height: 20px; font-size: 11.5px; }
  .thread-pop .own { display: inline-flex; gap: 10px; }
  .thread-pop .own button { padding: 2px 0; }
}
@media (pointer: coarse) {
  .thread-pop kbd { display: none !important; }
}
/* ===== /comments ===== */

/* ===== history, compare, notes ===== */
/* right side panel: History and Notes share the slot; the model centers in what's left (--right-inset) */
.side-panel {
  position: fixed; top: 60px; right: 12px; bottom: 12px; z-index: 7; width: 340px; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden;
}
.side-panel > header { display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 14px; border-bottom: 1px solid var(--line); }
.side-panel > header h2 { flex: 1; min-width: 0; margin: 0; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.side-panel > header .hint { color: var(--muted); font-size: 11px; white-space: nowrap; display: flex; align-items: center; gap: 3px; }
.side-panel kbd, .pin-banner kbd, .cmp-bar kbd {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px;
  font: 600 11px/1 var(--font); color: var(--muted); background: var(--panel);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; white-space: nowrap;
}
.side-panel .muted { color: var(--muted); }
body.side-open .sel-bar, body.side-open .working, body.side-open .toast, body.side-open .pin-banner, body.side-open .cmp-bar { right: calc(var(--right-inset) + 12px); }
body.side-open .errors { right: calc(var(--right-inset) + 12px); }
body.tree-open .pin-banner, body.tree-open .cmp-bar { left: calc(var(--tree) + 24px); }
#notesBtn { position: relative; }
#notesBtn.has::after { content: ""; position: absolute; top: 4px; right: 4px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.version[role="button"] { cursor: pointer; padding: 3px 6px; border-radius: 6px; }
.version[role="button"]:hover { background: var(--panel-2); color: var(--text); }
.version[role="button"]:focus-visible { outline: 2px solid var(--accent); }
body.pinned .version { color: var(--accent); }

/* history: versions newest first; the focused one opens to its per-property diff */
.versions { list-style: none; margin: 0; padding: 4px; flex: 1; overflow: auto; overscroll-behavior: contain; outline: none; }
.versions .pad { padding: 10px; }
.ver { padding: 7px 10px 8px; border-radius: 7px; cursor: pointer; border: 1px solid transparent; }
.ver + .ver { margin-top: 1px; }
.ver:hover { background: var(--panel-2); }
.ver.focus { background: var(--panel-2); border-color: var(--line); cursor: default; }
.ver.on { box-shadow: inset 3px 0 0 var(--accent); }
.ver-head { display: flex; gap: 8px; align-items: baseline; }
.ver .vn { font: 600 12px var(--mono); flex: none; }
.ver.on .vn { color: var(--accent); }
.ver .sum { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ver.focus .sum { white-space: normal; overflow-wrap: anywhere; }
.ver-meta { margin-top: 2px; color: var(--muted); font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.ver-meta .agent { color: var(--accent); }
.ver .tag { font-size: 11px; padding: 0 5px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.ver .tag.latest { color: #22a06b; border-color: color-mix(in srgb, #22a06b 40%, transparent); }
.ver .tag.viewing { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.ver-ids { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 5px; }
.vchip { font: 11px var(--mono); padding: 1px 5px; border-radius: 4px; background: var(--panel-2); color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ver.focus .vchip { background: var(--panel); }
.vchip.added, .cmp-chip.added { color: light-dark(#17855a, #4cd391); }
.vchip.changed, .cmp-chip.changed { color: light-dark(#b45309, #fbbf24); }
.vchip.removed, .cmp-chip.removed { color: var(--danger); text-decoration: line-through; }
.ver-diff { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); }
.ver-diff p { margin: 4px 0; font-size: 12px; }
.diff { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.diff li { padding: 2px 0; overflow-wrap: anywhere; }
.diff code { font: 12px var(--mono); }
.diff .sign { display: inline-block; width: 1ch; font: 600 12px var(--mono); }
.diff .d-add .sign { color: light-dark(#17855a, #4cd391); }
.diff .d-rm .sign, .diff .d-rm > code { color: var(--danger); }
.diff .from { color: var(--muted); text-decoration: line-through; font-family: var(--mono); }
.diff .to { font: 600 12px var(--mono); }
.diff s { color: var(--muted); }
.side-panel .id { border: 0; background: var(--panel); border-radius: 4px; padding: 0 4px; cursor: pointer; color: inherit; }
.side-panel .id:hover { color: var(--accent); }
.ver-acts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.ver-acts .btn { height: 26px; padding: 0 8px; border: 1px solid var(--line); background: var(--panel); font-size: 12px; }
.ver-acts .btn:hover { background: var(--panel-2); }
.history-panel .more { padding: 6px 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.history-panel .more:empty { display: none; }
.history-panel .more .btn { height: 26px; border: 1px solid var(--line); }

/* viewing a past version */
.pin-banner {
  position: fixed; top: 60px; left: 12px; right: 12px; margin-inline: auto; width: fit-content; max-width: calc(100vw - 24px); z-index: 9;
  display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 14px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--accent); box-shadow: var(--shadow); white-space: nowrap;
}
.pin-banner b { color: var(--accent); }
.pin-banner .btn { height: 28px; border-radius: 999px; }
.pin-banner .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.pin-banner .btn.danger kbd { color: inherit; border-color: currentColor; background: transparent; }
body.working-on .pin-banner { top: 104px; }
body.comparing .pin-banner { display: none; }

/* compare: two halves, one camera; the bar replaces the selection bar */
body.comparing .sel-bar { display: none; }
.cmp-labels { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
.cmp-label { position: absolute; font: 600 12px var(--mono); padding: 3px 8px; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); white-space: nowrap; }
.cmp-labels .divider { position: absolute; background: var(--line); }
.cmp-bar {
  position: fixed; left: 12px; right: 12px; margin-inline: auto; width: fit-content; max-width: calc(100vw - 24px); bottom: calc(var(--dock) + 16px); z-index: 8;
  display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); white-space: nowrap;
}
.cmp-pair { display: flex; align-items: center; gap: 2px; flex: none; }
.cmp-pair b { font: 600 12px var(--mono); padding: 0 2px; }
.cmp-pair .latest { font: 400 11px var(--font); color: var(--muted); }
.cmp-pair .arrow { color: var(--muted); margin: 0 4px; }
.cmp-pair kbd { margin-left: 2px; }
.cmp-bar .btn.step { width: 26px; padding: 0; justify-content: center; font-size: 15px; }
.cmp-bar .btn:disabled { opacity: 0.35; cursor: default; background: none; }
.cmp-sum { display: flex; align-items: center; gap: 10px; color: var(--muted); flex: none; }
.cmp-sum .lg::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.cmp-sum .lg.added::before { background: #22a06b; }
.cmp-sum .lg.changed::before { background: #f59e0b; }
.cmp-sum .lg.removed::before { background: #e5484d; }
.cmp-sum .err { color: var(--danger); }
.cmp-chips { display: flex; gap: 3px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.cmp-chip { font: 11px var(--mono); padding: 2px 6px; border: 0; border-radius: 5px; background: var(--panel-2); cursor: pointer; white-space: nowrap; }
.cmp-chip:hover { outline: 1px solid currentColor; }
.cmp-chips .more { color: var(--muted); font-size: 11px; align-self: center; }
.cmp-bar .actions { display: flex; gap: 2px; flex: none; }

/* notes (ported from Divs & Spans) */
.notes-panel .md { flex: 1; overflow: auto; padding: 4px 16px 16px; touch-action: pan-y; overscroll-behavior: contain; font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere; }
.notes-panel .md .notes-empty { color: var(--muted); }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 18px 0 6px; line-height: 1.3; }
.md h1 { font-size: 18px; } .md h2 { font-size: 15px; } .md h3, .md h4, .md h5, .md h6 { font-size: 13.5px; }
.md h4, .md h5, .md h6 { color: var(--muted); }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 8px 0; }
.md ul, .md ol { padding-left: 20px; }
.md li.task { list-style: none; margin-left: -20px; }
.md li.task input { margin: 0 4px 0 0; vertical-align: -1px; }
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md a.ref { border-bottom: 1px dashed currentColor; }
.md a.ref:hover { text-decoration: none; background: var(--accent-soft); }
.md code { font: 0.92em var(--mono); background: var(--panel-2); padding: 1px 4px; border-radius: 4px; }
.md pre { background: var(--panel-2); padding: 8px 10px; border-radius: 8px; overflow: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md table { border-collapse: collapse; display: block; overflow: auto; font-size: 12.5px; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--panel-2); }
.notes-panel form { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 8px; gap: 8px; }
.notes-panel textarea {
  flex: 1; width: 100%; resize: none; padding: 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2); font: 12.5px/1.55 var(--mono); color: inherit; tab-size: 2;
}
.notes-panel textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.notes-panel .row { display: flex; align-items: center; gap: 6px; }
.notes-panel .hint { flex: 1; min-width: 0; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notes-panel .banner { padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); font-size: 12.5px; }
.notes-panel .banner .btn { height: 24px; padding: 0 8px; margin-top: 4px; border: 1px solid var(--line); background: var(--panel); }
.notes-panel .by { padding: 6px 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notes-panel .by:empty { display: none; }
.notes-panel .row .btn:not(.primary) { border: 1px solid var(--line); }

@media (max-width: 1060px) {
  .cmp-chips { display: none; }
}
@media (max-width: 820px) {
  .side-panel { top: auto; left: 8px; right: 8px; bottom: calc(var(--dock) + 8px); width: auto; max-width: 420px; margin: 0 auto; height: 50dvh; border-radius: 14px; }
  .side-panel > header .hint, .cmp-bar kbd, .pin-banner kbd { display: none; }
  .side-panel .btn { height: 36px; }
  .notes-panel textarea { font-size: 16px; }
  .ver { padding: 10px 10px; }
  .ver-acts .btn { height: 36px; padding: 0 12px; }
  body.side-open .sel-bar { bottom: calc(var(--dock) + 50dvh + 16px); }
  body.side-open .toast { bottom: calc(var(--dock) + 50dvh + 64px); }
  body.side-open .sel-bar, body.side-open .working, body.side-open .toast, body.side-open .pin-banner, body.side-open .cmp-bar { right: 12px; }
  body.tree-open .pin-banner, body.tree-open .cmp-bar { left: 12px; }
  .pin-banner { top: calc(60px + env(safe-area-inset-top)); padding-left: 12px; gap: 4px; }
  .pin-banner .btn { height: 34px; padding: 0 10px; }
  body.working-on .pin-banner { top: calc(104px + env(safe-area-inset-top)); }
  .cmp-bar { left: 8px; right: 8px; bottom: calc(var(--dock) + 8px); flex-wrap: wrap; justify-content: center; gap: 4px 10px; padding: 6px; border-radius: 14px; touch-action: none; }
  .cmp-bar .btn { height: 36px; }
  .cmp-bar .btn.step { width: 36px; }
  .cmp-sum { font-size: 12px; gap: 8px; }
  body.comparing .toast { bottom: calc(var(--dock) + 110px); }
}
@media (pointer: coarse) {
  .side-panel kbd, .pin-banner kbd, .cmp-bar kbd { display: none !important; }
}
/* ===== /history, compare, notes ===== */
