/* Пульт — визуальный язык iOS: системный шрифт, сгруппированные списки, пузыри сообщений, шторки. */
:root {
  --bg: #181818;
  --card: #1f1f1f;
  --chat-bg: #1f1f1f;
  --fill: rgba(255, 255, 255, .06);
  --fill-2: rgba(255, 255, 255, .1);
  --hover: #2a2d2e;
  --selected: #37373d;
  --text: #cccccc;
  --text-strong: #e7e7e7;
  --text-2: #9d9d9d;
  --text-3: #6e6e6e;
  --sep: #2b2b2b;
  --accent: #d97757;
  --accent-soft: rgba(217, 119, 87, .16);
  --on-accent: #ffffff;
  --bubble: #2b2b2b;
  --on-bubble: #e7e7e7;
  --badge: #4d4d4d;
  --green: #4ec36a;
  --orange: #e2a33b;
  --red: #f14c4c;
  --blue: #3794ff;
  --code-bg: #2a2a2a;
  --bar: #181818;
  --chat-bar: #1f1f1f;
  --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--bg); }
body { font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; color: var(--text); -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; letter-spacing: -.01em; }
#app { height: var(--app-h, 100dvh); display: flex; flex-direction: column; overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--accent); }
.boot { margin: auto; color: var(--text-3); font-weight: 600; }
.hidden { display: none !important; }
svg { display: block; }

/* ---------- шапка ---------- */
.top {
  flex: none; position: relative; z-index: 2; display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 4px) 8px 6px; background: var(--bar);
  -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 .5px 0 transparent; transition: box-shadow .2s;
}
.top.scrolled { box-shadow: 0 .5px 0 var(--sep); }
.top .title-btn { flex: 1; min-width: 0; text-align: center; padding: 2px 0; }
.top h1 { margin: 0; font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .sub { display: block; font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.icon-btn { min-width: 40px; height: 40px; border-radius: 20px; display: inline-flex; align-items: center; justify-content: center; color: var(--accent); }
.icon-btn > span, .icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { background: var(--fill); }
.top > span { display: flex; }

.top.large { display: block; padding: calc(env(safe-area-inset-top) + 2px) 16px 8px; }
.nav-row { display: flex; justify-content: space-between; margin: 0 -8px; }
.top .large-title { margin: 2px 0 10px; font-size: 34px; line-height: 1.1; font-weight: 700; letter-spacing: -.025em; }
.toolbar { display: grid; gap: 10px; }
.search-wrap { position: relative; display: block; }
.search-wrap > span { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-2); pointer-events: none; }
.search { width: 100%; height: 38px; border-radius: 10px; border: 0; background: var(--fill); padding: 0 12px 0 34px; font-size: 17px; outline: none; -webkit-appearance: none; }
.search::placeholder { color: var(--text-2); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--fill); border-radius: 9px; padding: 2px; }
.seg button { height: 30px; border-radius: 7px; font-size: 14px; font-weight: 500; color: var(--text); transition: background .15s; }
.seg button.on { background: var(--card); font-weight: 600; box-shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 1px 1px rgba(0, 0, 0, .04); }

/* ---------- список (панель сессий как в VS Code) ---------- */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.top.panel { display: block; padding: calc(env(safe-area-inset-top) + 8px) 10px 6px; background: var(--bg); }
.panel-row { display: flex; align-items: center; gap: 6px; }
.tabs { flex: 1; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: #252526; border-radius: 10px; padding: 3px; }
.tabs button { height: 34px; border-radius: 8px; font-size: 15px; color: var(--text-2); }
.tabs button.on { background: #181818; color: var(--text-strong); box-shadow: 0 1px 2px rgba(0, 0, 0, .4); }
.panel-tools { display: flex; align-items: center; gap: 4px; margin-top: 8px; }
.tool-btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border-radius: 8px; color: var(--text-2); font-size: 15px; }
.tool-btn > span:first-child { width: 17px; height: 17px; }
.tool-btn svg { width: 17px; height: 17px; }
.tool-btn:active, .tool-btn.on { background: var(--fill-2); color: var(--text-strong); }
.tool-btn.on > span:first-child { color: var(--orange); }
.search-row { margin-top: 6px; }
.search { width: 100%; height: 36px; border-radius: 8px; border: 1px solid #3c3c3c; background: #313131; padding: 0 10px; font-size: 16px; color: var(--text-strong); outline: none; -webkit-appearance: none; }
.search:focus { border-color: var(--blue); }
.search::placeholder { color: var(--text-3); }
.list { list-style: none; margin: 0; padding: 2px 6px calc(env(safe-area-inset-bottom) + 24px); }
.list > li { margin: 0; }
.rows-list { list-style: none; margin: 0; padding: 0; }
.group-head { display: flex; align-items: center; gap: 6px; width: 100%; height: 40px; padding: 0 8px 0 4px; border-radius: 8px; text-align: left; }
.group-head:active { background: var(--hover); }
.group-head .chev { width: 18px; height: 18px; color: var(--text-2); transition: transform .15s; flex: none; }
.group-head .chev svg { width: 18px; height: 18px; }
.group-head .chev.open { transform: rotate(90deg); }
.group-head .gname { flex: 1; min-width: 0; font-size: 16px; font-weight: 600; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { flex: none; min-width: 24px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--badge); color: var(--text-strong); font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.chat-row { display: flex; align-items: center; gap: 8px; width: 100%; height: 44px; padding: 0 10px 0 12px; border-radius: 8px; text-align: left; color: var(--text-strong); }
.group .chat-row { padding-left: 12px; }
.chat-row:active { background: var(--selected); }
.chat-row .t { flex: 1; min-width: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row .time { flex: none; font-size: 14px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.chat-row.ready .t { color: #ffffff; font-weight: 600; }
.sdot { flex: none; width: 9px; height: 9px; border-radius: 50%; }
.sdot.ready { background: var(--green); box-shadow: 0 0 6px rgba(78, 195, 106, .6); }
.sdot.running { background: var(--blue); animation: pulse 1.2s ease-in-out infinite; }
.sdot.waiting { background: var(--orange); }
.sdot.error { background: var(--red); }
.chip { flex: none; display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--fill); color: var(--text-2); white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.active .dot { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.empty { padding: 60px 24px; text-align: center; color: var(--text-2); }
.deep-btn { display: block; margin: 6px 12px 2px; font-size: 15px; color: var(--blue); }

/* ---------- чат ---------- */
.chat-wrap { flex: 1; position: relative; min-height: 0; display: flex; flex-direction: column; background: var(--chat-bg); }
.banner { flex: none; padding: 10px 16px; font-size: 14px; line-height: 1.35; background: color-mix(in srgb, var(--orange) 14%, var(--chat-bg)); }
.banner.err { background: color-mix(in srgb, var(--red) 12%, var(--chat-bg)); }
.banner .row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.msgs { padding: 14px 14px 10px; display: flex; flex-direction: column; gap: 12px; }
.more { align-self: center; font-size: 15px; color: var(--accent); padding: 6px 14px; border-radius: 999px; background: var(--fill); }
.msg { max-width: 100%; overflow-wrap: anywhere; }
.msg.user { align-self: stretch; background: var(--bubble); color: var(--on-bubble); padding: 9px 13px; border-radius: 10px; border: 1px solid #3a3a3a; white-space: pre-wrap; font-size: 16.5px; line-height: 1.38; }
.msg.assistant { align-self: stretch; font-size: 16px; line-height: 1.55; padding: 0 2px; color: var(--text-strong); }
.msg.assistant.live { white-space: pre-wrap; }
.msg.assistant.live::after { content: ""; display: inline-block; width: 8px; height: 8px; margin-left: 4px; border-radius: 50%; background: var(--accent); vertical-align: middle; animation: pulse 1s infinite; }
.msg.system { align-self: center; font-size: 13px; color: var(--text-2); text-align: center; padding: 2px 10px; }
.msg.system.err { color: var(--red); }
.msg .trunc { font-size: 12px; opacity: .7; margin-top: 4px; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md pre, .md table, .md blockquote { margin: 0 0 .65em; }
.md h1, .md h2, .md h3, .md h4 { font-size: 1.06em; font-weight: 650; margin: 1em 0 .35em; letter-spacing: -.015em; }
.md ul, .md ol { padding-left: 1.25em; }
.md li + li { margin-top: .2em; }
.md code { font-family: var(--mono); font-size: .84em; background: var(--code-bg); padding: .12em .38em; border-radius: 6px; }
.md pre { background: var(--code-bg); padding: 11px 13px; border-radius: 12px; overflow-x: auto; font-size: 13px; line-height: 1.45; }
.md pre code { background: none; padding: 0; font-size: inherit; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.md th, .md td { border: .5px solid var(--sep); padding: 6px 9px; text-align: left; }
.md th { background: var(--fill); font-weight: 600; }
.md blockquote { border-left: 3px solid var(--fill-2); padding-left: 11px; color: var(--text-2); }
.md img { max-width: 100%; border-radius: 10px; }
.md hr { border: 0; height: .5px; background: var(--sep); margin: 1em 0; }

/* группа шагов: одна строка «N действий», раскрывается по нажатию */
.acts { align-self: stretch; }
.acts > summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 12px; background: var(--fill); color: var(--text-2); font-size: 14px; cursor: pointer; user-select: none; }
.acts > summary::-webkit-details-marker { display: none; }
.acts > summary > span:first-child { width: 15px; height: 15px; flex: none; }
.acts > summary svg { width: 15px; height: 15px; }
.acts .acts-t { flex: none; font-weight: 600; color: var(--text); }
.acts .acts-s { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12.5px; }
.acts.has-err > summary .acts-t { color: var(--red); }
.acts[open] > summary { border-radius: 12px 12px 0 0; }
.acts-body { background: var(--fill); border-radius: 0 0 12px 12px; padding: 2px 8px 8px; display: grid; gap: 6px; }
.tool { background: var(--card); border-radius: 10px; font-size: 14px; }
.tool summary { list-style: none; display: flex; gap: 8px; align-items: baseline; padding: 8px 10px; cursor: pointer; }
.tool summary::-webkit-details-marker { display: none; }
.tool .name { flex: none; font-weight: 600; color: var(--accent); }
.tool .sum { flex: 1; min-width: 0; color: var(--text-2); font-family: var(--mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool .st { flex: none; font-size: 12px; color: var(--text-3); }
.tool .st.err { color: var(--red); }
.tool .st.ok { color: var(--green); }
.tool pre, .think pre, pre.plain { margin: 0; padding: 8px 10px 10px; font: 12.5px/1.45 var(--mono); white-space: pre-wrap; word-break: break-word; color: var(--text); border-top: .5px solid var(--sep); max-height: 45vh; overflow: auto; }
.think { background: var(--card); border-radius: 10px; font-size: 14px; color: var(--text-2); }
.think summary { cursor: pointer; padding: 8px 10px; list-style: none; font-style: italic; }
.think summary::-webkit-details-marker { display: none; }

/* ---------- подтверждения ---------- */
.perm { margin: 0 0 8px; padding: 14px; border-radius: 18px; background: var(--card); box-shadow: var(--shadow); border: .5px solid var(--sep); }
.perm h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.perm h3::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--orange); flex: none; }
.perm .what { font: 13px/1.45 var(--mono); background: var(--code-bg); padding: 9px 11px; border-radius: 10px; white-space: pre-wrap; word-break: break-word; max-height: 26vh; overflow: auto; }
.perm .why { font-size: 13px; color: var(--text-2); margin-top: 6px; }
.perm .btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.perm .btns .wide { grid-column: 1 / -1; }
.perm details { margin-top: 8px; font-size: 13px; color: var(--text-2); }
.perm details summary { cursor: pointer; }
.perm .q { margin: 10px 0 6px; font-weight: 600; font-size: 15px; }
.perm .opts { display: grid; gap: 6px; }
.perm .opt { text-align: left; padding: 10px 12px; border-radius: 12px; background: var(--fill); font-size: 15px; transition: background .1s; }
.perm .opt small { display: block; color: var(--text-2); font-size: 13px; margin-top: 2px; }
.perm .opt.on { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.perm .plan { max-height: 38vh; overflow: auto; padding: 10px 12px; background: var(--code-bg); border-radius: 10px; font-size: 15px; }

.btn { height: 46px; padding: 0 18px; border-radius: 14px; font-weight: 600; font-size: 16px; background: var(--fill); color: var(--text); transition: transform .1s, opacity .1s; }
.btn:active { transform: scale(.97); opacity: .85; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.danger { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn:disabled { opacity: .4; }
.btn.small { height: 34px; font-size: 14px; padding: 0 14px; border-radius: 17px; }

/* ---------- статус и поле ввода ---------- */
.dock { flex: none; position: relative; z-index: 2; background: var(--chat-bar); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%); box-shadow: 0 -.5px 0 var(--sep); padding: 6px 10px calc(env(safe-area-inset-bottom) + 6px); }
.kb .dock { padding-bottom: 6px; }
.status { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-2); min-height: 24px; padding: 0 6px 6px; }
.status .txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status .dot { width: 6px; height: 6px; }
.status.active { color: var(--blue); }
.status.waiting { color: var(--orange); }
.status.error { color: var(--red); }
.status.done { color: var(--green); }
.status:not(.active):not(.waiting):not(.error):not(.done) .dot { background: var(--text-3); }
.status .mode { flex: none; font-size: 12px; color: var(--text-2); padding: 3px 9px; border-radius: 999px; background: var(--fill); }
.composer { display: flex; align-items: flex-end; gap: 6px; background: var(--chat-bg); border: .5px solid var(--sep); border-radius: 22px; padding: 3px 3px 3px 14px; }
.composer textarea { flex: 1; min-height: 36px; max-height: 38vh; resize: none; border: 0; background: transparent; padding: 7px 0; font-size: 17px; line-height: 1.32; outline: none; }
.composer textarea::placeholder { color: var(--text-3); }
.send { flex: none; width: 34px; height: 34px; margin: 1px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center; transition: transform .1s, opacity .15s; }
.send > span, .send svg { width: 18px; height: 18px; }
.send:active { transform: scale(.9); }
.send:disabled { opacity: .3; }
.send.stop { background: var(--text); color: var(--chat-bg); }
.send.stop svg { width: 14px; height: 14px; }
.jump { position: absolute; right: 14px; bottom: 10px; width: 38px; height: 38px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); color: var(--text-2); display: flex; align-items: center; justify-content: center; }
.jump > span, .jump svg { width: 20px; height: 20px; }

/* ---------- страницы и формы ---------- */
.page { padding: 24px 20px calc(env(safe-area-inset-bottom) + 28px); display: grid; gap: 14px; align-content: start; max-width: 520px; margin: 0 auto; width: 100%; }
.page h2 { margin: 18px 0 0; font-size: 34px; font-weight: 700; letter-spacing: -.025em; }
.page p { margin: 0; color: var(--text-2); font-size: 16px; line-height: 1.45; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--text-2); text-transform: uppercase; letter-spacing: .02em; padding-left: 4px; }
.input, .select, .area { width: 100%; border-radius: 12px; border: 0; background: var(--card); padding: 12px 14px; font-size: 17px; outline: none; }
.area { min-height: 120px; resize: vertical; }
.input:focus, .area:focus, .select:focus { box-shadow: inset 0 0 0 1.5px var(--accent); }
.code-input { font: 600 26px/1 var(--mono); letter-spacing: .14em; text-align: center; text-transform: uppercase; padding: 16px; }
.note { font-size: 14px; line-height: 1.4; color: var(--text-2); background: var(--card); border-radius: 12px; padding: 12px 14px; }
.note.warn { color: var(--text); background: color-mix(in srgb, var(--orange) 14%, var(--card)); }
.card { background: var(--card); border-radius: 12px; overflow: hidden; }
.rows > * { position: relative; display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 12px 16px; background: var(--card); }
.rows > button:active { background: var(--fill-2); }
.rows > * + *::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: .5px; background: var(--sep); }
.rows > * > span:first-child:not(.grow) { width: 22px; height: 22px; color: var(--accent); flex: none; }
.rows .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .meta { font-size: 13px; color: var(--text-2); white-space: nowrap; }
.crumbs { font: 12.5px var(--mono); color: var(--text-2); word-break: break-all; padding: 6px 20px 10px; }
.viewer { flex: 1; min-height: 0; overflow: auto; background: var(--chat-bg); }
.viewer pre.plain { border: 0; max-height: none; padding: 14px 16px; }
.viewer .md { padding: 16px 18px; font-size: 16.5px; line-height: 1.5; }
.viewer img { display: block; max-width: 100%; margin: 12px auto; }
.viewer iframe { width: 100%; height: 100%; border: 0; background: #fff; }

/* ---------- шторки (iOS action sheet) ---------- */
#layer:empty { display: none; }
.overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; background: rgba(0, 0, 0, .32); animation: fade .2s ease; }
.sheet { width: 100%; max-width: 520px; max-height: 88%; overflow-y: auto; display: grid; gap: 10px; padding: 18px 16px calc(env(safe-area-inset-bottom) + 14px); background: var(--bg); border-radius: 22px 22px 0 0; animation: up .32s cubic-bezier(.2, .9, .25, 1); }
.sheet h3 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.015em; }
.sheet p { margin: 0; color: var(--text-2); font-size: 15px; line-height: 1.4; }
.sheet .acts { display: grid; gap: 8px; }
.sheet .acts .btn { width: 100%; }
.sheet.action { background: transparent; padding: 0 8px calc(env(safe-area-inset-bottom) + 8px); gap: 8px; }
.menu-card { background: var(--card); border-radius: 14px; overflow: hidden; }
.menu-title { padding: 12px 16px; font-size: 13px; color: var(--text-2); text-align: center; border-bottom: .5px solid var(--sep); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 54px; padding: 0 18px; text-align: left; font-size: 17px; color: var(--text); background: var(--card); }
.menu-item + .menu-item::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: .5px; background: var(--sep); }
.menu-item:active { background: var(--fill-2); }
.menu-item.danger { color: var(--red); }
.menu-item .val { font-size: 15px; color: var(--text-2); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }
.menu-cancel { height: 56px; border-radius: 14px; background: var(--card); color: var(--accent); font-size: 17px; font-weight: 600; }
.menu-cancel:active { background: var(--fill-2); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }

#toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 56px); transform: translate(-50%, -6px); max-width: calc(100% - 40px); padding: 10px 16px; border-radius: 14px; font-size: 14px; font-weight: 500; z-index: 20; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; background: var(--card); color: var(--text); box-shadow: var(--shadow); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: rot .8s linear infinite; display: inline-block; vertical-align: -3px; }
@keyframes rot { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (prefers-reduced-transparency: reduce) { .top, .dock { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--bg); } }
/* широкий экран (Mac): содержимое по центру читаемой ширины */
@media (min-width: 760px) {
  .msgs, .list, .page { max-width: 760px; margin-left: auto; margin-right: auto; width: 100%; }
  .dock > * { max-width: 760px; margin-left: auto; margin-right: auto; }
  .top.large > * { max-width: 728px; margin-left: auto; margin-right: auto; }
}
