/* Bold Friday Space — оболочка: тёмная, спокойная, системные шрифты. Холст главный, оболочка не спорит с ним. */
:root {
  --bg: #0f1115;
  --surface: #16191f;
  --surface-2: #1d2129;
  --surface-3: #252a34;
  --line: rgb(255 255 255 / 8%);
  --line-2: rgb(255 255 255 / 15%);
  --ink: #eceef1;
  --mut: #a2a9b4;
  --dim: #858d9a;
  --accent: #ffd23f;
  --accent-ink: #1a1400;
  --ok: #5fd38d;
  --no: #8b93a1;
  --danger: #ff7b6e;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --top: 48px;
  --panel: 380px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 400 14px/20px var(--sans); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font: 500 11px/16px var(--mono); letter-spacing: .6px; text-transform: uppercase; }
kbd { font: 500 11px/16px var(--mono); padding: 0 5px; border-radius: 4px; background: rgb(255 255 255 / 10%); color: var(--mut); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ── Кнопки ─────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; color: var(--ink); font: 500 13px/32px var(--sans); white-space: nowrap; text-decoration: none; }
.btn:hover { background: rgb(255 255 255 / 8%); }
.btn.solid { background: var(--surface-3); }
.btn.solid:hover { background: #2e3440; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #ffdc66; }
.btn[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .5; cursor: default; }
.btn kbd { background: rgb(0 0 0 / 0%); padding: 0; color: inherit; opacity: .7; }
.btn .count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font: 600 11px/20px var(--mono); text-align: center; }
.btn .count.zero { background: rgb(255 255 255 / 10%); color: var(--mut); }

/* ── Шапка ──────────────────────────────────────────────────────────────── */
.top { position: sticky; top: 0; z-index: 30; height: var(--top); display: flex; align-items: center; gap: 8px; padding: 0 12px 0 16px; background: var(--bg); box-shadow: 0 1px 0 var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; font: 600 14px/20px var(--sans); letter-spacing: -.1px; text-decoration: none; white-space: nowrap; }
.brand::before { content: ''; width: 12px; height: 12px; background: var(--accent); border-radius: 3px 3px 3px 0; }
.top .grow { flex: 1; min-width: 0; }
.who { display: inline-flex; align-items: center; gap: 8px; color: var(--mut); white-space: nowrap; }
.who b { color: var(--ink); font-weight: 500; }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; font: 500 10px/18px var(--mono); letter-spacing: .6px; text-transform: uppercase; background: rgb(255 255 255 / 10%); color: var(--mut); white-space: nowrap; }

/* ── Вход ───────────────────────────────────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(360px, 100%); display: grid; gap: 16px; }
.login h1 { margin: 0 0 8px; font: 600 22px/28px var(--sans); letter-spacing: -.3px; }
.login .brand { margin-bottom: 28px; }
.field { display: grid; gap: 6px; }
.field label { color: var(--mut); font-size: 13px; }
.input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface); outline: 0; }
.input:focus { border-color: var(--accent); }
.input[aria-invalid='true'] { border-color: var(--danger); }
.error { min-height: 20px; margin: 0; color: var(--danger); font-size: 13px; }
.login .btn.primary { height: 40px; justify-content: center; font-size: 14px; }
.login .note { margin: 4px 0 0; color: var(--dim); font-size: 13px; }

/* ── Список ─────────────────────────────────────────────────────────────── */
.wrap { max-width: 1120px; margin: 0 auto; padding: 28px 24px 80px; }
.search { position: relative; margin-bottom: 28px; }
.search input { width: 100%; height: 52px; padding: 0 16px 0 46px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface); outline: 0; font-size: 17px; }
.search input:focus { border-color: var(--accent); }
.search input::-webkit-search-cancel-button { filter: invert(1) opacity(.5); }
.search::before { content: ''; position: absolute; left: 17px; top: 17px; width: 13px; height: 13px; border: 2px solid var(--dim); border-radius: 50%; pointer-events: none; }
.search::after { content: ''; position: absolute; left: 30px; top: 31px; width: 7px; height: 2px; background: var(--dim); transform: rotate(45deg); transform-origin: 0 50%; pointer-events: none; }
.search .keys { position: absolute; right: 14px; top: 16px; display: flex; gap: 6px; color: var(--dim); font-size: 12px; pointer-events: none; }
.search input:not(:placeholder-shown) ~ .keys { display: none; }

.group { margin-bottom: 36px; }
.group > h2 { display: flex; align-items: baseline; gap: 10px; margin: 0 0 12px; font: 600 13px/20px var(--sans); color: var(--mut); }
.group > h2 span { color: var(--dim); font: 500 11px/20px var(--mono); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.card { display: flex; flex-direction: column; gap: 8px; min-height: 148px; padding: 16px 18px; border-radius: 10px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); text-decoration: none; }
.card:hover, .card.is-active { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-2); }
.card.is-active { box-shadow: inset 0 0 0 2px var(--accent); }
.card h3 { margin: 0; font: 600 16px/22px var(--sans); letter-spacing: -.2px; }
.card p { margin: 0; color: var(--mut); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { margin-top: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; color: var(--dim); font-size: 12px; }
.card .meta > span { white-space: nowrap; }
.card .meta .open { margin-left: auto; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 11px; font: 500 12px/22px var(--sans); white-space: nowrap; }
.pill.hot { background: var(--accent); color: var(--accent-ink); }
.pill.calm { background: rgb(255 255 255 / 7%); color: var(--mut); }

/* Результаты поиска: три вида читаются по метке слева и по форме строки. */
.hits h2 { margin: 24px 0 8px; font: 600 13px/20px var(--sans); color: var(--mut); display: flex; gap: 8px; align-items: baseline; }
.hits h2:first-child { margin-top: 0; }
.hits h2 span { color: var(--dim); font: 500 11px/20px var(--mono); }
.hit { display: grid; grid-template-columns: 76px 1fr auto; gap: 4px 14px; align-items: baseline; padding: 11px 14px; border-radius: 8px; text-decoration: none; }
.hit + .hit { box-shadow: 0 -1px 0 var(--line); }
.hit:hover, .hit.is-active { background: var(--surface-2); box-shadow: none; }
.hit.is-active { box-shadow: inset 2px 0 0 var(--accent); }
.hit .kind { grid-row: span 2; font: 500 10px/20px var(--mono); letter-spacing: .8px; text-transform: uppercase; color: var(--dim); }
.hit .t { font-weight: 500; min-width: 0; }
.hit .s { grid-column: 2 / 4; color: var(--dim); font-size: 12px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hit.canvas .kind { color: var(--accent); }
.hit.canvas .t { font-size: 16px; }
.hit.screen .kind::before { content: '▢ '; }
.hit.comment .kind::before { content: '“ '; }
.hit.comment .t { font-weight: 400; color: var(--ink); padding-left: 10px; box-shadow: inset 2px 0 0 var(--line-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
mark { background: rgb(255 210 63 / 25%); color: inherit; border-radius: 2px; }

.state { padding: 48px 0; color: var(--mut); text-align: center; }
.state b { display: block; margin-bottom: 6px; color: var(--ink); font: 600 16px/22px var(--sans); }
.state .btn { margin-top: 14px; }
.state.error b { color: var(--danger); }
.skel { height: 148px; border-radius: 10px; background: linear-gradient(90deg, var(--surface) 0 40%, var(--surface-2) 50%, var(--surface) 60% 100%) 0 0 / 300% 100%; animation: skel 1.2s linear infinite; }
@keyframes skel { to { background-position: -150% 0; } }

/* ── Просмотр ───────────────────────────────────────────────────────────── */
.viewer { height: 100vh; overflow: hidden; display: grid; grid-template-rows: var(--top) 1fr; grid-template-columns: minmax(0, 1fr); }
.viewer .top { position: static; }
.crumb { display: flex; align-items: baseline; gap: 8px; min-width: 0; white-space: nowrap; }
.crumb .project { color: var(--dim); flex: none; max-width: 30%; overflow: hidden; text-overflow: ellipsis; }
.crumb h1 { margin: 0; font: 600 14px/20px var(--sans); overflow: hidden; text-overflow: ellipsis; }
.back { color: var(--mut); }
.sep { width: 1px; height: 20px; background: var(--line-2); flex: none; }
.body { display: flex; min-height: 0; }
.stage { position: relative; flex: 1; min-width: 0; background: #0b0d10; }
.stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
.stage.commenting { box-shadow: inset 0 0 0 2px var(--accent); }
.stage .veil { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); pointer-events: none; }

.hint { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 5; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 14px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 500; white-space: nowrap; box-shadow: 0 8px 24px rgb(0 0 0 / 40%); }
.hint kbd { background: rgb(0 0 0 / 12%); color: inherit; }
.hint.err { background: var(--danger); color: #1b0400; }

/* Окно ввода комментария — рядом с местом щелчка. */
.composer { position: absolute; z-index: 6; width: 320px; border-radius: 10px; background: var(--surface-2); box-shadow: 0 0 0 1px var(--line-2), 0 16px 48px rgb(0 0 0 / 55%); overflow: hidden; }
.composer header { padding: 10px 12px 8px; display: grid; gap: 2px; }
.composer header b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer header span { color: var(--dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer textarea, .reply textarea { display: block; width: 100%; min-height: 84px; padding: 10px 12px; border: 0; outline: 0; resize: vertical; background: var(--bg); box-shadow: inset 0 1px 0 var(--line), inset 0 -1px 0 var(--line); }
.composer textarea:focus, .reply textarea:focus { box-shadow: inset 0 0 0 1px var(--accent); }
.composer footer { display: flex; align-items: center; gap: 8px; padding: 8px; }
.composer .error { flex: 1; min-height: 0; font-size: 12px; line-height: 16px; }

/* Панель комментариев сдвигает холст, а не перекрывает его. */
.panel { width: var(--panel); flex: none; display: flex; flex-direction: column; min-height: 0; background: var(--surface); box-shadow: -1px 0 0 var(--line); }
.panel > header { padding: 12px; display: grid; gap: 10px; box-shadow: 0 1px 0 var(--line); }
.panel > header h2 { margin: 0; font: 600 14px/20px var(--sans); display: flex; justify-content: space-between; align-items: center; }
.seg { display: flex; padding: 2px; border-radius: 8px; background: var(--bg); }
.seg button { flex: 1; height: 28px; padding: 0 6px; border: 0; border-radius: 6px; background: none; color: var(--mut); font: 500 12px/28px var(--sans); white-space: nowrap; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed='true'] { background: var(--surface-3); color: var(--ink); }
.seg button small { font: 500 11px/28px var(--mono); color: var(--dim); margin-left: 3px; }
.seg button[aria-pressed='true'] small { color: var(--mut); }
.list { flex: 1; overflow: auto; overscroll-behavior: contain; }
.list .state { padding: 32px 20px; font-size: 13px; }

.c { position: relative; box-shadow: 0 1px 0 var(--line); }
.c > .head { display: grid; grid-template-columns: 24px 1fr; gap: 2px 10px; width: 100%; padding: 12px 14px 12px 12px; border: 0; background: none; text-align: left; }
.c > .head:hover { background: rgb(255 255 255 / 3%); }
.c.is-open > .head, .c.is-active > .head { background: var(--surface-2); }
.c.is-active { box-shadow: inset 2px 0 0 var(--accent), 0 1px 0 var(--line); }
.num { grid-row: span 3; width: 24px; height: 24px; border-radius: 12px 12px 12px 3px; background: var(--accent); color: var(--accent-ink); font: 600 11px/24px var(--mono); text-align: center; }
.c.resolved .num { background: var(--ok); color: #03200f; }
.c.wontfix .num { background: var(--no); color: #111; }
.c .where { color: var(--mut); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c .by { display: flex; gap: 8px; align-items: baseline; color: var(--dim); font-size: 12px; }
.c .by b { color: var(--ink); font-weight: 500; }
.c .txt { grid-column: 2; margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.c.is-open .txt { display: block; }
.c .foot { grid-column: 2; display: flex; gap: 10px; margin-top: 6px; color: var(--dim); font-size: 12px; }
.st { font: 500 10px/18px var(--mono); letter-spacing: .6px; text-transform: uppercase; }
.st.resolved { color: var(--ok); }
.st.wontfix { color: var(--no); }
.c.resolved .txt, .c.wontfix .txt { color: var(--mut); }

.thread { padding: 0 14px 14px 46px; background: var(--surface-2); display: grid; gap: 12px; }
.thread .target { margin: 0; padding: 6px 10px; border-radius: 6px; background: rgb(255 255 255 / 5%); color: var(--mut); font-size: 12px; overflow-wrap: anywhere; }
.replies { display: grid; gap: 10px; }
.replies .r { padding-left: 10px; box-shadow: inset 2px 0 0 var(--line-2); }
.replies .r p { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.reply { border-radius: 8px; overflow: hidden; background: var(--bg); }
.reply textarea { min-height: 64px; box-shadow: none; }
.reply footer { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 6px; }
.reply .error { flex: 1; min-height: 0; font-size: 12px; line-height: 16px; }
.status-row { display: grid; gap: 6px; }
.status-row .seg button[aria-pressed='true'][data-status='open'] { background: var(--accent); color: var(--accent-ink); }
.status-row .seg button[aria-pressed='true'][data-status='resolved'] { background: var(--ok); color: #03200f; }
.status-row .seg button[aria-pressed='true'][data-status='wontfix'] { background: var(--no); color: #111; }
.status-row .by { color: var(--dim); font-size: 12px; }
.tools { display: flex; gap: 4px; justify-content: flex-end; }
.tools .btn { height: 26px; padding: 0 8px; font-size: 12px; color: var(--mut); }
.tools .btn.danger { color: var(--danger); }
.guest-note { margin: 0; padding: 10px 12px; border-radius: 8px; background: rgb(255 255 255 / 4%); color: var(--mut); font-size: 13px; }

/* Версия холста и метки локального режима — в строке названия. */
.crumb .ver { flex: none; align-self: center; height: 24px; padding: 0 8px; border-radius: 5px; background: rgb(255 255 255 / 7%); color: var(--mut); font: 600 12px/24px var(--mono); }
.crumb .ver:hover, .crumb .ver[aria-expanded='true'] { background: var(--surface-3); color: var(--ink); }
#local, #stale { flex: none; text-transform: none; letter-spacing: 0; font: 500 12px/20px var(--sans); padding: 0 8px; }
.top:has(#stale:not([hidden])) .agent-ref .what { display: none; }
.tag.warn { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* История версий: выпадает под кнопкой, только чтение. */
.history { position: fixed; z-index: 40; top: calc(var(--top) + 4px); width: min(432px, calc(100vw - 16px)); max-height: calc(100vh - var(--top) - 16px); overflow: auto; overscroll-behavior: contain; border-radius: 10px; background: var(--surface-2); box-shadow: 0 0 0 1px var(--line-2), 0 16px 48px rgb(0 0 0 / 55%); outline: 0; }
.history h2 { margin: 0; padding: 12px 14px 8px; font: 600 13px/20px var(--sans); color: var(--mut); }
.history ol { margin: 0; padding: 0 0 6px; list-style: none; }
.history ol > li { padding: 10px 14px; box-shadow: 0 -1px 0 var(--line); }
.history ol > li.cur { box-shadow: 0 -1px 0 var(--line), inset 2px 0 0 var(--accent); }
.history .vh { display: flex; align-items: baseline; gap: 8px; }
.history .vh b { font: 700 13px/20px var(--mono); }
.history .vh .by { font-weight: 500; }
.history .vh time { color: var(--dim); font-size: 12px; }
.history .vh .tag { margin-left: auto; }
.history .vh .tag + .tag { margin-left: 0; }
.history p { margin: 4px 0 0; overflow-wrap: anywhere; }
.history .state { padding: 20px 14px; font-size: 13px; }
.history details { margin-top: 6px; }
.history summary, .history .nums { display: inline-block; font: 500 12px/20px var(--mono); color: var(--dim); cursor: pointer; }
.history .nums { cursor: default; margin-top: 6px; }
.history summary::marker { color: var(--dim); }
.history ul { margin: 6px 0 0; padding: 8px 10px; max-height: 220px; overflow: auto; list-style: none; border-radius: 6px; background: var(--bg); font: 400 12px/18px var(--mono); }
.history .add { color: var(--ok); }
.history .chg { color: var(--accent); }
.history .del { color: var(--danger); }

/* Строка для агента: видна до копирования. В шапке — то, что копирует L. */
.agent-ref { flex: 0 1 auto; display: flex; align-items: center; gap: 8px; min-width: 0; height: 32px; padding: 0 2px 0 10px; border-radius: 6px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.agent-ref .what { flex: 0 1 auto; max-width: 180px; color: var(--dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-ref code { flex: 0 1 auto; min-width: 0; font: 500 12px/18px var(--mono); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; user-select: all; }
.agent-ref .btn { flex: none; height: 28px; padding: 0 10px; font-size: 12px; background: var(--surface-3); }
/* В нити и в окне комментария строка целиком, кнопка переносится под неё, если не помещается. */
.ref { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px 8px; padding: 6px 6px 6px 10px; border-radius: 6px; background: var(--bg); }
.ref code { flex: 1 1 auto; font: 500 12px/18px var(--mono); color: var(--ink); overflow-wrap: anywhere; user-select: all; }
.ref .btn { flex: none; height: 26px; padding: 0 8px; font-size: 12px; background: var(--surface-3); }
.composer .ref { margin-top: 8px; }

@media (max-width: 1360px) { .agent-ref .what { display: none; } }
@media (max-width: 760px) {
  :root { --panel: 300px; }
  .crumb .project, .who b, .btn .label { display: none; }
  .agent-ref, #local, #stale { display: none; }
}
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }
