/* Страница гостя — как чат Nomad Code на телефоне: палитра «Виноград и персик» (Theme.kt),
   светлая и тёмная, сначала под телефон, на большом экране — колонка до 780px. */
:root {
  --accent: #6a3d9a; --on-accent: #fff; --accent-soft: #f1eaf8; --on-accent-soft: #52297d;
  --attention: #7a3a0c; --attention-soft: #fcdfc8; --attention-fill: #e8823f;
  --ok: #1e5e4c; --ok-soft: #ddf2eb; --ok-fill: #3fa88b;
  --danger: #c0262d;
  --ground: #f2eef7; --card: #fff; --chip: #ece6f3; --text: #231b2e; --muted: #4c4458; --faint: #8a8096;
  --line: #e3dcec; --code: #f6f3fa;
  --shadow: 0 1px 2px rgba(35, 27, 46, .06), 0 4px 16px rgba(35, 27, 46, .06);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #c9b2e6; --on-accent: #2a1640; --accent-soft: #3a2a4e; --on-accent-soft: #e6daf4;
    --attention: #ffb27a; --attention-soft: #45291a; --attention-fill: #ffb27a;
    --ok: #7fd3b8; --ok-soft: #173a31; --ok-fill: #3fa88b;
    --danger: #ff8f8a;
    --ground: #1d1724; --card: #28202f; --chip: #342a3d; --text: #f3ecf7; --muted: #b4a9c0; --faint: #8c8098;
    --line: #3a3045; --code: #17121d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --accent: #c9b2e6; --on-accent: #2a1640; --accent-soft: #3a2a4e; --on-accent-soft: #e6daf4;
  --attention: #ffb27a; --attention-soft: #45291a; --attention-fill: #ffb27a;
  --ok: #7fd3b8; --ok-soft: #173a31; --ok-fill: #3fa88b;
  --danger: #ff8f8a;
  --ground: #1d1724; --card: #28202f; --chip: #342a3d; --text: #f3ecf7; --muted: #b4a9c0; --faint: #8c8098;
  --line: #3a3045; --code: #17121d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ground); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column; overflow: hidden;
}
button { font: inherit; color: inherit; }
svg { display: block; }
.col { width: 100%; max-width: 780px; margin: 0 auto; padding: 0 16px; }

/* --- шапка --- */
header { background: var(--card); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); flex: none; }
.bar { max-width: 780px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.mark { width: 36px; height: 36px; border-radius: 11px; flex: none; }
.head { min-width: 0; flex: 1; }
.title { font-weight: 700; font-size: 17px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub:empty { display: none; }

/* --- переписка --- */
main { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: auto; }
main .col { padding-top: 12px; padding-bottom: 16px; }
.warn {
  display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 14px;
  background: var(--attention-soft); color: var(--attention); border-radius: 14px; padding: 10px 12px;
  font-size: 13.5px; line-height: 1.4; font-weight: 500;
}
.warn svg { width: 18px; height: 18px; flex: none; fill: currentColor; margin-top: 1px; }
.warn:has(#warn:empty) { display: none; }
#log { display: flex; flex-direction: column; gap: 10px; }

.msg { overflow-wrap: anywhere; }
.bubble { padding: 10px 14px; border-radius: 18px; max-width: min(88%, 620px); }
.msg.user { align-self: flex-end; display: flex; flex-direction: column; align-items: flex-end; max-width: 100%; }
.msg.user .bubble { background: var(--accent); color: var(--on-accent); white-space: pre-wrap; border-bottom-right-radius: 6px; }
.msg.user.pending .bubble { opacity: .55; }
.msg .note { font-size: 11.5px; color: var(--faint); margin: 3px 6px 0; }
.msg.assistant { align-self: flex-start; max-width: 100%; }
.msg.assistant .bubble { background: var(--card); box-shadow: var(--shadow); border-bottom-left-radius: 6px; max-width: min(94%, 680px); }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; white-space: pre-wrap; }
.md h4 { margin: 10px 0 4px; font-size: 15.5px; }
.md ul, .md ol { margin: 4px 0 8px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md a { color: var(--accent); }
.md code { font-family: var(--mono); font-size: .88em; background: var(--code); border-radius: 5px; padding: 1px 5px; }
.md pre {
  background: var(--code); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 6px 0 8px;
  overflow-x: auto; white-space: pre; font: 12.5px/1.45 var(--mono);
}
.md pre code { background: none; padding: 0; font-size: inherit; }

/* действия агента подряд — одной строкой, раскрываются */
.tools { align-self: stretch; }
.tools > button {
  display: inline-flex; align-items: center; gap: 7px; max-width: 100%; padding: 4px 6px; margin-left: -6px;
  border: 0; background: none; color: var(--muted); font-size: 13.5px; cursor: pointer; border-radius: 8px;
}
.tools > button:hover { background: var(--chip); }
.tools > button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tools > button svg { width: 15px; height: 15px; flex: none; }
.tools .chev { transition: transform .15s; }
.tools.open .chev { transform: rotate(180deg); }
.tools .list { display: none; margin-top: 4px; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.tools.open .list { display: block; }
.tool { display: flex; gap: 8px; align-items: baseline; padding: 8px 12px; font-size: 13px; border-top: 1px solid var(--line); min-width: 0; }
.tool:first-child { border-top: 0; }
.tool b { font-weight: 600; flex: none; }
.tool code { font: 12px/1.4 var(--mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

.thinking { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; padding: 2px 4px; }
.dots { display: flex; gap: 5px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: dot 1.2s infinite ease-in-out; opacity: .3; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes dot { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: .7; } }

.notice { align-self: center; background: var(--chip); color: var(--muted); font-size: 13px; padding: 6px 12px; border-radius: 999px; }

/* --- вопрос и разрешение: последним сообщением, как на телефоне --- */
#ask:empty { display: none; }
#ask { margin-top: 12px; }
.card { background: var(--card); border: 1.5px solid var(--accent); border-radius: 18px; padding: 14px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 4px; font-size: 13px; font-weight: 600; color: var(--accent); text-transform: none; }
.card .q { margin: 2px 0 10px; font-weight: 700; font-size: 16px; line-height: 1.35; }
.card .q + .opts { margin-bottom: 4px; }
.card .opts + .q { margin-top: 14px; }
.card p { margin: 0 0 12px; color: var(--muted); }
.opts { display: flex; flex-direction: column; gap: 8px; }
.opt {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  border: 1px solid var(--line); background: var(--ground); border-radius: 14px; padding: 10px 12px; cursor: pointer;
}
.opt:hover { border-color: var(--accent); }
.opt .num {
  width: 26px; height: 26px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--chip); color: var(--text); font-size: 13px; font-weight: 700;
}
.opt.on { border-color: var(--accent); background: var(--accent-soft); }
.opt.on .num { background: var(--accent); color: var(--on-accent); }
.opt .t { min-width: 0; }
.opt .t b { display: block; font-weight: 600; }
.opt .t small { display: block; color: var(--muted); font-size: 13px; line-height: 1.35; margin-top: 1px; }
.req {
  background: var(--code); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; margin: 6px 0 2px;
  font: 12.5px/1.45 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 40vh; overflow-y: auto;
}
.row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn {
  flex: 1 1 140px; border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 600; cursor: pointer;
  background: var(--chip); color: var(--text); text-align: center;
}
.btn.main { background: var(--accent); color: var(--on-accent); }
.btn:active, .round:active, .opt:active { transform: scale(.98); }

/* --- поле ответа --- */
footer { flex: none; background: var(--card); border-top: 1px solid var(--line); padding: 6px 0 calc(10px + env(safe-area-inset-bottom)); }
.status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; min-height: 18px; margin-bottom: 4px; padding-left: 6px; }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.status[data-kind="ok"] .dot { background: var(--ok-fill); }
.status[data-kind="direct"] .dot { background: var(--ok-fill); box-shadow: 0 0 0 3px var(--ok-soft); }
.status[data-kind="busy"] .dot { background: var(--accent); }
.status[data-kind="wait"] .dot { background: var(--attention-fill); }
form { display: flex; gap: 8px; align-items: flex-end; }
textarea {
  flex: 1; min-width: 0; resize: none; border: 1px solid var(--line); border-radius: 22px; padding: 11px 16px;
  font: inherit; line-height: 1.4; background: var(--ground); color: var(--text); max-height: 38vh; outline: none;
}
textarea:focus { border-color: var(--accent); }
textarea::placeholder { color: var(--faint); }
.round {
  width: 46px; height: 46px; border-radius: 50%; border: 0; flex: none; display: grid; place-items: center; cursor: pointer;
  background: var(--accent); color: var(--on-accent);
}
.round svg { width: 22px; height: 22px; }
.round:disabled { opacity: .35; cursor: default; }
.round.stop { background: var(--chip); color: var(--text); }
.round[hidden], .down[hidden] { display: none; }

.down {
  position: fixed; right: max(16px, calc(50% - 390px + 16px)); bottom: calc(110px + env(safe-area-inset-bottom));
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--text);
  box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer;
}
.down svg { width: 20px; height: 20px; }

/* --- открыть в приложении и «доступ закрыт» --- */
.hero { text-align: center; padding: 28px 18px 18px; border-color: var(--line); }
.hero img { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 14px; display: block; }
.hero h2 { margin: 0 0 6px; font-size: 20px; }
.hero p { margin: 0 auto 16px; max-width: 420px; }
.hero .row { flex-direction: column; }
.hero .btn { flex: none; }
.gone { flex: 1; display: grid; place-items: center; padding: 24px 16px; overflow-y: auto; }
.gone .card { max-width: 420px; width: 100%; }
.status:has(#status:empty) .dot { display: none; }
body.gated footer { display: none; }
