:root {
  --bg: #0d0f12; --panel: #14171c; --panel2: #1b1f26; --line: #262b33; --text: #e6e8eb; --muted: #8b939e;
  --claude: #f08a3e; --claude-bg: rgba(240, 138, 62, .12); --codex: #3fb96a; --codex-bg: rgba(63, 185, 106, .12);
  --accent: #f08a3e; --danger: #f25f5c; --ok: #3fb96a; --warn: #e0b341;
  --user: #22324a; --code: #0a0c0f; --shadow: 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f6f7f9; --panel: #ffffff; --panel2: #f0f2f5; --line: #dfe3e8; --text: #1b1f24; --muted: #6a737d;
  --user: #dbe8fb; --code: #f3f4f6; --shadow: 0 8px 24px rgba(0, 0, 0, .12); color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, select, input, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #111; font-weight: 600; }
button.wide { width: 100%; padding: 11px; }
button.icon { background: transparent; border: none; font-size: 20px; padding: 4px 8px; }
button.danger { color: var(--danger); }
select {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 5px 8px; max-width: 150px;
}
input, textarea {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.muted { color: var(--muted); }
.msg { min-height: 20px; margin-top: 10px; color: var(--danger); font-size: 14px; }
.msg.ok { color: var(--ok); }
.brand { font-weight: 800; font-size: 22px; letter-spacing: .3px; }
.brand.big { font-size: 34px; }

/* вход */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 28px 22px; box-shadow: var(--shadow); text-align: center;
}
.totp { display: grid; gap: 8px; margin-top: 18px; text-align: left; }
.totp input { font-size: 22px; letter-spacing: 6px; text-align: center; }

/* каркас */
#app { display: flex; height: 100%; height: 100dvh; }
#side {
  width: 290px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex;
  flex-direction: column; padding: 14px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
}
.side-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.theme button { padding: 4px 9px; border-radius: 50%; }
.new-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.new { border-radius: 999px; font-weight: 600; padding: 9px; }
.new.claude { border-color: var(--claude); color: var(--claude); background: var(--claude-bg); }
.new.codex { border-color: var(--codex); color: var(--codex); background: var(--codex-bg); }
.search { margin: 10px 0 6px; width: 100%; padding: 7px 10px; }
#chatList { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.group { font-size: 12px; color: var(--muted); margin: 12px 6px 4px; text-transform: none; }
.chat {
  display: flex; align-items: center; gap: 8px; padding: 8px 9px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent;
}
.chat:hover { background: var(--panel2); }
.chat.active { background: var(--panel2); border-color: var(--line); }
.chat .name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.badge { font-size: 11px; border-radius: 999px; padding: 1px 7px; border: 1px solid; white-space: nowrap; }
.badge.claude { color: var(--claude); border-color: var(--claude); background: var(--claude-bg); }
.badge.codex { color: var(--codex); border-color: var(--codex); background: var(--codex-bg); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none; animation: pulse 1.2s infinite; }
.pin { font-size: 11px; color: var(--muted); }
details.arch summary { cursor: pointer; color: var(--muted); font-size: 13px; margin: 12px 6px 4px; }
.usage {
  border: 1px solid var(--line); border-radius: 12px; padding: 9px 10px; margin-top: 8px; font-size: 13px;
  background: var(--panel2);
}
.usage .row { display: flex; justify-content: space-between; gap: 8px; }
.usage .bar { height: 4px; background: var(--line); border-radius: 4px; margin: 3px 0 6px; overflow: hidden; }
.usage .bar i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.usage .bar i.mid { background: var(--warn); }
.usage .bar i.high { background: var(--danger); }
.usage .h { font-weight: 600; margin: 2px 0 2px; }
.usage .small { color: var(--muted); font-size: 11.5px; margin-bottom: 4px; }
.side-bottom { display: flex; gap: 8px; margin-top: 8px; }
.side-bottom button { flex: 1; font-size: 13px; padding: 6px; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line);
  background: var(--bg); position: relative; padding-top: calc(8px + env(safe-area-inset-top, 0px));
}
#btnMenu { display: none; }
.title-wrap { flex: 1; min-width: 0; }
.title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.sub { font-size: 12px; color: var(--muted); }
.controls { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.menu {
  position: absolute; right: 10px; top: 52px; z-index: 20; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); display: grid; padding: 6px; min-width: 170px;
}
.menu button { background: none; border: none; text-align: left; padding: 9px 10px; }
.menu button:hover { background: var(--panel2); }
.banner {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 14px; background: var(--claude-bg);
  border-bottom: 1px solid var(--line); font-size: 14px;
}

/* лента */
.msgs { flex: 1; overflow-y: auto; padding: 18px 16px 8px; }
.msgs > * { max-width: 860px; margin-left: auto; margin-right: auto; }
.empty { text-align: center; margin-top: 18vh; }
.u {
  background: var(--user); border-radius: 16px 16px 4px 16px; padding: 9px 13px; margin: 14px 0 10px auto;
  width: fit-content; max-width: min(86%, 700px); white-space: pre-wrap; overflow-wrap: anywhere;
}
.u .photos { font-size: 12px; color: var(--muted); margin-top: 4px; }
.u img { max-width: 160px; max-height: 160px; border-radius: 8px; display: block; margin-top: 6px; }
.a { margin: 8px 0; overflow-wrap: anywhere; }
.a.streaming { white-space: pre-wrap; }
.a p { margin: .45em 0; }
.a h2, .a h3, .a h4, .a h5 { margin: .8em 0 .35em; line-height: 1.3; }
.a h2 { font-size: 1.25em; } .a h3 { font-size: 1.12em; } .a h4, .a h5 { font-size: 1em; }
.a ul, .a ol { padding-left: 1.4em; margin: .4em 0; }
.a code { background: var(--code); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px; font-size: .92em; }
.a pre { position: relative; background: var(--code); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow-x: auto; }
.a pre code { background: none; border: none; padding: 0; font-family: Consolas, "SF Mono", monospace; font-size: 13px; white-space: pre; }
.a pre .copy { position: absolute; top: 6px; right: 6px; font-size: 12px; padding: 2px 8px; opacity: .75; }
.a blockquote { border-left: 3px solid var(--line); margin: .5em 0; padding-left: 12px; color: var(--muted); }
.a a { color: var(--accent); }
.a hr { border: none; border-top: 1px solid var(--line); }
.tbl { overflow-x: auto; margin: .5em 0; }
.a table { border-collapse: collapse; font-size: 14px; }
.a th, .a td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; vertical-align: top; }
.a th { background: var(--panel2); }
.tools {
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); padding: 6px 10px; margin: 8px 0; font-size: 13px;
}
.tool { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; cursor: pointer; }
.tool .st { width: 14px; flex: none; text-align: center; }
.tool .st.run { color: var(--warn); }
.tool .st.ok { color: var(--ok); }
.tool .st.err { color: var(--danger); }
.tool .sm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.tool .sm b { color: var(--text); font-weight: 600; }
.tool-prev { font-family: Consolas, monospace; font-size: 12px; color: var(--muted); white-space: pre-wrap; margin: 0 0 4px 22px; }
.appr {
  border: 1px solid var(--warn); border-radius: 12px; padding: 10px 12px; margin: 10px 0; background: var(--panel);
}
.appr .h { font-weight: 700; margin-bottom: 4px; }
.appr pre { background: var(--code); border-radius: 8px; padding: 8px; font-size: 12px; max-height: 220px; overflow: auto; white-space: pre-wrap; }
.appr .btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.appr.done { border-color: var(--line); opacity: .75; }
.appr .q { margin: 8px 0 4px; font-weight: 600; }
.appr .opts { display: flex; flex-wrap: wrap; gap: 6px; }
.appr .opts button.sel { border-color: var(--accent); background: var(--claude-bg); }
.note { text-align: center; color: var(--muted); font-size: 12.5px; margin: 8px auto; }
.err { color: var(--danger); font-size: 14px; margin: 8px auto; white-space: pre-wrap; }
.foot { color: var(--muted); font-size: 12.5px; display: flex; gap: 10px; align-items: center; margin: 4px auto 14px; }
.foot button { font-size: 12px; padding: 2px 9px; }

/* ввод */
#composer {
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: var(--bg);
}
.input-row {
  display: flex; gap: 2px; align-items: flex-end; max-width: 860px; margin: 0 auto; padding: 4px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 24px;
}
.input-row:focus-within { border-color: var(--accent); }
#input {
  flex: 1; min-width: 0; resize: none; max-height: 40vh; min-height: 40px; line-height: 1.4;
  border: none; background: transparent; padding: 9px 6px;
}
.cbtn, .send, .stop {
  width: 40px; height: 40px; flex: none; padding: 0; border: none; border-radius: 50%;
  display: grid; place-items: center; background: transparent; color: var(--muted);
}
.cbtn:hover { background: var(--line); color: var(--text); }
.input-row svg {
  width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.send { background: var(--accent); color: #111; }
.send:hover { filter: brightness(1.08); }
.send svg { stroke-width: 2.5; }
.stop { background: var(--danger); color: #fff; }
.stop svg { fill: currentColor; stroke: none; }
.mic.rec {
  background: var(--danger); color: #fff; transition: box-shadow .12s linear;
  box-shadow: 0 0 0 calc(2px + var(--lvl, 0) * 9px) rgba(242, 95, 92, .28);
}
.mic.wait { position: relative; color: var(--text); }
.mic.wait::after {
  content: ""; position: absolute; inset: 3px; border-radius: 50%; border: 2px solid var(--accent);
  border-right-color: transparent; animation: spin .8s linear infinite;
}
.status.rec { color: var(--danger); }
.thumbs { display: flex; gap: 8px; max-width: 860px; margin: 0 auto 6px; flex-wrap: wrap; }
.thumb { position: relative; }
.thumb img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.thumb button { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; padding: 0; border-radius: 50%; font-size: 12px; }
.status { max-width: 860px; margin: 4px auto 0; font-size: 12px; color: var(--muted); min-height: 16px; }
body.codex { --accent: var(--codex); }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; width: min(420px, 92vw);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.hint { font-size: 13px; margin: 0 0 8px; }
#dictList { max-height: 45vh; overflow-y: auto; }
.dict-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.dict-form input { flex: 1 1 120px; min-width: 0; padding: 7px 9px; }
.dev { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }

@keyframes pulse { 50% { opacity: .35; } }
@keyframes spin { to { transform: rotate(360deg); } }
/* надпись, пока скрипт не показал вход или приложение; подсказка проявляется через 6 с */
.booting { min-height: 100vh; display: grid; place-content: center; gap: 14px; padding: 24px; text-align: center;
  color: var(--muted); font-size: 17px; }
.booting small { max-width: 420px; font-size: 13px; visibility: hidden; animation: appear 0s 6s forwards; }
@keyframes appear { to { visibility: visible; } }

@media (max-width: 820px) {
  #side {
    position: fixed; z-index: 30; inset: 0 auto 0 0; width: 86vw; max-width: 330px; transform: translateX(-102%);
    transition: transform .2s ease; box-shadow: var(--shadow);
  }
  #app.open #side { transform: none; }
  #shade { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 25; }
  #btnMenu { display: block; }
  .controls select { max-width: 104px; font-size: 13px; padding: 4px 5px; }
  #selEffort { display: none; }
  .msgs { padding: 12px 12px 6px; }
}
