:root {
  --bg: #12131c; --bg-2: #171925; --card: #212436; --card-2: #282b40;
  --line: rgba(255,255,255,.07); --line-2: rgba(255,255,255,.12);
  --text: #eeedf6; --muted: #8f92ad; --dim: #63667f;
  --claude: #e07a52; --codex: #19b38a; --cowork: #a58bff;
  --working: #4fd18b; --waiting: #ffcf3f; --idle: #7f95c4; --bad: #ff6b6b;
  --accent: #ffb547; --accent-2: #ff8a5c;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bot: env(safe-area-inset-bottom, 0px);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
button { border: 0; cursor: pointer; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #23170a; font-weight: 700; border-radius: 12px; padding: 10px 14px; }
button.ghost { background: var(--card); color: var(--text); border: 1px solid var(--line-2); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* сопряжение */
#pairView { align-items: center; justify-content: center; padding: 24px; background: radial-gradient(ellipse at 50% 20%, #2a2440 0%, var(--bg) 65%); }
.pair-wrap { width: 100%; max-width: 380px; text-align: center; }
.pair-logo { width: 84px; height: 84px; border-radius: 22px; box-shadow: 0 14px 40px rgba(0,0,0,.5); }
.pair-wrap h1 { margin: 14px 0 6px; font-size: 26px; }
.pair-wrap p { line-height: 1.5; font-size: 13.5px; }
#codeIn { width: 100%; text-align: center; font-size: 34px; letter-spacing: 8px; font-weight: 800; background: var(--card); border: 1px solid var(--line-2); border-radius: 16px; padding: 14px; margin: 14px 0; outline: none; }
#codeIn:focus { border-color: var(--accent); }
button.big { width: 100%; padding: 14px; font-size: 16px; border-radius: 14px; }
.adv { margin-top: 16px; color: var(--muted); font-size: 12.5px; text-align: left; }
.adv input { width: 100%; margin-top: 8px; background: var(--card); border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 10px; outline: none; }
.err { color: var(--bad); margin-top: 12px; font-size: 13px; min-height: 18px; }

/* верх */
.top { padding: calc(var(--safe-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); background: rgba(18,19,28,.95); }
.top-title { font-weight: 800; font-size: 19px; flex: 1; }
.top-right { display: flex; align-items: center; gap: 8px; }
.conn { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); background: var(--card); padding: 5px 9px; border-radius: 20px; border: 1px solid var(--line); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.conn.ok i { background: var(--working); box-shadow: 0 0 6px var(--working); animation: blink 2s infinite; }
.conn.bad i { background: var(--bad); }
.lim { font-size: 11px; color: var(--muted); display: flex; gap: 5px; }
.lm { display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px 2px 2px; border-radius: 7px; background: rgba(255,255,255,.04); border: 1px solid var(--line); }
.lm i { width: 16px; height: 16px; border-radius: 5px; display: grid; place-items: center; background-repeat: no-repeat; background-position: center; background-size: 12px; }
.lm.claude i { background-color: #d9734c; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M10 2.5l1.6 4.9 4.9-1.6-3.3 3.9 3.3 3.9-4.9-1.6L10 17l-1.6-4.9-4.9 1.6 3.3-3.9-3.3-3.9 4.9 1.6z' fill='%23fff'/%3E%3C/svg%3E"); }
.lm.codex i { background-color: #1aa880; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 6l4 4-4 4' stroke='%23fff' stroke-width='2.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M10.5 14.5H15' stroke='%23fff' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E"); }
.lm b { color: var(--text); font-weight: 700; }
.lm.warm b { color: #ffa94d; } .lm.hot b { color: #ff6b6b; }
@keyframes blink { 50% { opacity: .4; } }

.pages { flex: 1; position: relative; overflow: hidden; }
.page { position: absolute; inset: 0; overflow-y: auto; padding: 14px 14px 90px; -webkit-overflow-scrolling: touch; }

/* нижние вкладки */
.tabs { position: absolute; left: 0; right: 0; bottom: 0; display: flex; padding: 6px 6px calc(var(--safe-bot) + 6px); background: rgba(23,25,37,.97); border-top: 1px solid var(--line-2); backdrop-filter: blur(12px); }
.tabs button { flex: 1; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; padding: 6px 0; position: relative; }
.tabs button span { font-size: 20px; filter: grayscale(.8); opacity: .7; }
.tabs button.on { color: var(--text); }
.tabs button.on span { filter: none; opacity: 1; }
.tb-badge { position: absolute; top: 2px; left: 55%; background: var(--waiting); color: #2a2200; font-size: 10px; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }

/* блоки */
.h { font-weight: 800; font-size: 15px; margin: 16px 2px 8px; display: flex; align-items: center; gap: 6px; }
.h:first-child { margin-top: 2px; }
.h .n { color: var(--muted); font-weight: 600; font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 11.5px; }
.stat.w b { color: var(--waiting); } .stat.g b { color: var(--working); } .stat.r b { color: var(--bad); }
.list { display: flex; flex-direction: column; gap: 8px; }
.empty { color: var(--dim); font-size: 13px; padding: 10px 4px; }

.card { display: flex; gap: 10px; align-items: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 11px; position: relative; overflow: hidden; }
.card:active { background: var(--card-2); }
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--idle); }
.card.working::before, .card.thinking::before { background: var(--working); }
.card.waiting { border-color: rgba(255,207,63,.45); } .card.waiting::before { background: var(--waiting); }
.card.alert { border-color: rgba(255,107,107,.5); } .card.alert::before { background: var(--bad); }
.card.pulse { animation: pulse .7s ease-out; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,181,71,.7); } 100% { box-shadow: 0 0 0 10px rgba(255,181,71,0); } }
.av { width: 44px; height: 44px; flex: 0 0 44px; border-radius: 13px; background-color: var(--card-2); background-repeat: no-repeat; background-size: 118% auto; background-position: 50% 0%; border: 2px solid var(--line-2); }
.av.claude { border-color: rgba(224,122,82,.7); } .av.codex { border-color: rgba(25,179,138,.7); } .av.cowork { border-color: rgba(165,139,255,.7); }
.c-body { flex: 1; min-width: 0; }
.c-top { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.c-top b { font-weight: 800; }
.c-top .role { color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src { margin-left: auto; font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 5px; background: rgba(255,255,255,.06); color: var(--muted); white-space: nowrap; }
.src.claude { color: var(--claude); background: rgba(224,122,82,.14); } .src.codex { color: var(--codex); background: rgba(25,179,138,.14); } .src.cowork { color: var(--cowork); background: rgba(139,108,240,.16); }
.c-proj { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.c-cat { display: inline-block; font-size: 9.5px; font-weight: 800; letter-spacing: .7px; text-transform: uppercase; color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); border-radius: 5px; padding: 1px 6px; margin-top: 5px; }
.c-act { font-size: 13.5px; font-weight: 600; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.c-title { font-size: 12px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-reply { font-size: 12.5px; color: #d6dcff; margin-top: 6px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.c-alert { font-size: 12px; font-weight: 700; margin-top: 5px; padding: 3px 7px; border-radius: 7px; display: inline-block; }
.c-alert.permission { background: var(--waiting); color: #2a2200; } .c-alert.stuck, .c-alert.error { background: #d94848; color: #fff; } .c-alert.slow { background: #ffa94d; color: #2a1700; }
.c-time { position: absolute; right: 10px; bottom: 8px; font-size: 10.5px; color: var(--dim); }

.proj { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.proj:active { background: var(--card-2); }
.proj.inactive { opacity: .55; }
.proj-top { display: flex; align-items: center; gap: 8px; }
.proj-top b { font-size: 15px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj-top span { color: var(--dim); font-size: 11.5px; }
.proj-bot { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.heads { display: flex; flex: 1; }
.head { width: 26px; height: 26px; border-radius: 50%; margin-right: -7px; border: 2px solid var(--card); background-color: var(--card-2); background-size: 118% auto; background-position: 50% 0%; background-repeat: no-repeat; }
.pstate { font-size: 12px; color: var(--muted); }
.pstate .w { color: var(--waiting); font-weight: 700; } .pstate .g { color: var(--working); font-weight: 700; } .pstate .r { color: var(--bad); font-weight: 700; }
.toggle-inactive { width: 100%; margin-top: 12px; }

/* проект */
.proj-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.proj-head b { display: block; font-size: 17px; }
.proj-head span { font-size: 11.5px; }
.back { background: var(--card); color: var(--text); width: 38px; height: 38px; padding: 0; font-size: 24px; line-height: 1; border-radius: 12px; border: 1px solid var(--line-2); flex: 0 0 38px; }
#officeBox { height: min(76vw, 46vh); min-height: 230px; border-radius: 18px; overflow: hidden; margin-bottom: 12px; background: radial-gradient(ellipse at 50% 40%, #222540 0%, #14151f 75%); border: 1px solid var(--line); position: relative; }
#officeBox canvas { display: block; }

/* эфир */
.feed li { list-style: none; display: flex; gap: 9px; padding: 9px 2px; border-bottom: 1px dashed var(--line); font-size: 13px; }
.feed { margin: 0; padding: 0; }
.f-ic { width: 28px; height: 28px; flex: 0 0 28px; border-radius: 9px; display: grid; place-items: center; background: color-mix(in srgb, var(--c, #8f92ad) 18%, transparent); border: 1px solid color-mix(in srgb, var(--c, #8f92ad) 45%, transparent); }
.f-b { min-width: 0; flex: 1; line-height: 1.35; }
.f-b b { font-weight: 800; } .f-b .role, .f-b .pj { color: var(--dim); font-size: 11.5px; }
.f-t { color: var(--dim); font-size: 11px; white-space: nowrap; }
.feed li.fresh { animation: fin .8s ease-out; }
@keyframes fin { from { background: rgba(255,181,71,.22); } }
.f-wait .f-x { color: #ffe7a0; } .f-error .f-x { color: #ff9a9a; } .f-start .f-x { color: #ffd9a8; } .f-permission .f-x { color: var(--waiting); font-weight: 700; }

/* контент */
.gal { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.g { background: var(--card); border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.g .img { aspect-ratio: 1; background: repeating-conic-gradient(#262a3f 0% 25%, #1f2234 0% 50%) 50% / 14px 14px; display: grid; place-items: center; }
.g img { max-width: 100%; max-height: 100%; object-fit: contain; }
.g .cap { font-size: 10.5px; padding: 4px 6px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#imgView { position: fixed; inset: 0; background: rgba(0,0,0,.92); display: grid; place-items: center; z-index: 50; }
#imgView img { max-width: 96vw; max-height: 86vh; }

/* агент */
.sheet { background: var(--bg); z-index: 20; animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.ag-head { padding: calc(var(--safe-top) + 10px) 12px 10px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.ag-av { width: 46px; height: 46px; border-radius: 14px; background-size: 118% auto; background-position: 50% 0%; background-repeat: no-repeat; background-color: var(--card-2); border: 2px solid var(--line-2); flex: 0 0 46px; }
.ag-who { flex: 1; min-width: 0; }
.ag-who b { display: block; font-size: 16px; }
.ag-who span { font-size: 12px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 11px; font-weight: 800; padding: 4px 9px; border-radius: 20px; background: var(--card); color: var(--idle); white-space: nowrap; }
.pill.working, .pill.thinking { color: var(--working); } .pill.waiting { background: var(--waiting); color: #2a2200; }
.ag-now { margin: 10px 12px 0; padding: 10px 12px; border-radius: 14px; background: linear-gradient(135deg, rgba(79,209,139,.12), rgba(79,209,139,.03)); border: 1px solid rgba(79,209,139,.25); font-weight: 600; font-size: 13.5px; }
.ag-now.waiting { background: linear-gradient(135deg, rgba(255,207,63,.16), rgba(255,207,63,.03)); border-color: rgba(255,207,63,.35); }
.ag-now.idle, .ag-now.done { background: var(--card); border-color: var(--line); }
.ag-now .cat { display: block; font-size: 10px; letter-spacing: .8px; text-transform: uppercase; font-weight: 800; margin-bottom: 3px; }
.ag-now .al { display: block; margin-top: 6px; font-size: 12.5px; }
.seg { display: flex; margin: 10px 12px 0; background: var(--card); border-radius: 12px; padding: 3px; gap: 2px; border: 1px solid var(--line); }
.seg button { flex: 1; background: transparent; color: var(--muted); padding: 7px 0; border-radius: 9px; font-weight: 600; }
.seg button.on { background: var(--card-2); color: var(--text); }
.ag-body { flex: 1; overflow-y: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
.chat { display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 86%; padding: 9px 12px; border-radius: 16px; line-height: 1.45; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; user-select: text; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, #6b4ed8, #8b6cf0); color: #fff; border-bottom-right-radius: 5px; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line-2); border-bottom-left-radius: 5px; }
.msg.pending { opacity: .7; }
.msg .t { display: block; font-size: 10px; opacity: .6; margin-top: 4px; text-align: right; }
.tools { align-self: flex-start; max-width: 92%; font-size: 12px; color: var(--muted); background: rgba(255,255,255,.03); border: 1px dashed var(--line-2); border-radius: 12px; padding: 6px 10px; }
.tools div { padding: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools .err { color: #ff9a9a; margin: 0; }
.typing { align-self: flex-start; color: var(--muted); font-size: 12.5px; padding: 4px 8px; }
.typing i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); margin-right: 3px; animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
.composer { padding: 8px 10px calc(var(--safe-bot) + 8px); border-top: 1px solid var(--line-2); background: var(--bg-2); }
.composer.note { color: var(--muted); font-size: 12.5px; text-align: center; line-height: 1.45; }
.comp-opts { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.comp-opts label { display: flex; align-items: center; gap: 6px; }
.stop { background: #d94848; color: #fff; padding: 5px 12px; font-size: 12px; border-radius: 9px; }
.comp-row { display: flex; gap: 8px; align-items: flex-end; }
#msgIn, #pjIn { flex: 1; resize: none; max-height: 120px; background: var(--card); border: 1px solid var(--line-2); border-radius: 14px; padding: 10px 12px; outline: none; }
#msgIn:focus, #pjIn:focus { border-color: var(--accent); }
#sendBtn, #pjSend { width: 46px; height: 44px; padding: 0; font-size: 18px; border-radius: 14px; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.info-grid div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.info-grid span { display: block; color: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: 1px; font-weight: 700; }
.info-grid b { display: block; margin-top: 2px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.block { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin-top: 10px; font-size: 13px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.block .lbl { display: block; color: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: 1px; font-weight: 700; margin-bottom: 4px; }
.lrow { display: flex; gap: 8px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.lrow .i { width: 22px; text-align: center; } .lrow .x { flex: 1; } .lrow .tm { color: var(--dim); font-size: 11px; }

.toast { position: fixed; left: 12px; right: 12px; top: calc(var(--safe-top) + 62px); background: rgba(36,32,18,.96); border: 1px solid rgba(255,207,63,.5); border-radius: 14px; padding: 11px 14px; z-index: 60; font-size: 13px; box-shadow: 0 14px 40px rgba(0,0,0,.5); }
.toast b { display: block; color: #ffe7a0; }

/* проект: зум, полоса агентов, чат с Claude */
#officeBox .zoom { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
#officeBox .zoom button { width: 34px; height: 34px; border-radius: 10px; background: rgba(23,25,37,.85); border: 1px solid var(--line-2); color: var(--text); font-size: 17px; font-weight: 700; padding: 0; backdrop-filter: blur(6px); }
.strip { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -14px; padding-left: 14px; padding-right: 14px; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; display: flex; align-items: center; gap: 7px; padding: 5px 10px 5px 5px; border-radius: 14px; background: var(--card); border: 1px solid var(--line-2); font-size: 12px; max-width: 200px; }
.chip .hd { width: 28px; height: 28px; border-radius: 9px; background-size: cover; background-position: center top; background-color: #2a2c40; flex: 0 0 28px; position: relative; }
.chip .hd::after { content: ''; position: absolute; right: -2px; bottom: -2px; width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--card); background: var(--idle); }
.chip.working .hd::after, .chip.thinking .hd::after { background: var(--working); }
.chip.waiting .hd::after { background: var(--waiting); }
.chip.alert { border-color: rgba(255,90,90,.6); }
.chip b { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip span { display: block; color: var(--muted); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.chip.target { border-color: var(--claude); box-shadow: 0 0 0 1px var(--claude) inset; }
.pj-chat-head { display: flex; align-items: center; gap: 9px; padding: 10px 0 8px; border-top: 1px solid var(--line); }
.cl-ic { width: 30px; height: 30px; border-radius: 9px; flex: 0 0 30px; background: #d9734c url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M10 2.5l1.6 4.9 4.9-1.6-3.3 3.9 3.3 3.9-4.9-1.6L10 17l-1.6-4.9-4.9 1.6 3.3-3.9-3.3-3.9 4.9 1.6z' fill='%23fff'/%3E%3C/svg%3E") center / 18px no-repeat; box-shadow: 0 0 10px rgba(217,115,76,.35); }
.pj-ct { flex: 1; min-width: 0; }
.pj-ct b { display: block; font-size: 14px; }
.pj-ct span { display: block; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
button.sm { padding: 6px 10px; font-size: 11.5px; border-radius: 10px; width: auto; }
#pjChat { padding-bottom: 6px; min-height: 80px; }
#mainView.in-project .tabs { display: none; }
#mainView.in-project #pg-project { padding-bottom: 14px; }
.pj-comp { position: relative; z-index: 3; }
.chat .hint { color: var(--muted); font-size: 12.5px; line-height: 1.5; text-align: center; padding: 14px 10px; border: 1px dashed var(--line-2); border-radius: 14px; }
