/* ИИ-помощник (v7, шаг A2): панель справа вместо окна поверх листа — макет M5 в гамме эскиза G.
   Цвета — переменные app.css и shell.css (--panel --line --text --muted --sel --sel-weak --input --hover; --primary — тёмно-синяя
   главная кнопка G, пока её нет — акцент). Свои — только жёлтое «Уточнения» и зелёное «Что сделано» (светлая и тёмная тема). */
:root { --aip-warn-bg: #fff7df; --aip-warn-line: #f3d27a; --aip-warn-ink: #5c3d00; --aip-warn-head: #8a5300; --aip-ok: #15803d; --aip-bad-bg: #fdecec; --aip-bad-ink: #b42318; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --aip-warn-bg: rgba(250, 204, 21, .1); --aip-warn-line: rgba(250, 204, 21, .36); --aip-warn-ink: #f3e3b5; --aip-warn-head: #fcd34d;
    --aip-ok: #4ade80; --aip-bad-bg: rgba(248, 113, 113, .12); --aip-bad-ink: #fca5a5; }
}
:root[data-theme="dark"] { --aip-warn-bg: rgba(250, 204, 21, .1); --aip-warn-line: rgba(250, 204, 21, .36); --aip-warn-ink: #f3e3b5; --aip-warn-head: #fcd34d;
  --aip-ok: #4ade80; --aip-bad-bg: rgba(248, 113, 113, .12); --aip-bad-ink: #fca5a5; }

/* — место: вместо колонки «Свойства» (размеры с неё берёт aiPlace), лист сужается на разницу — */
.aip { position: fixed; z-index: 14; top: var(--aip-top, 12px); bottom: var(--aip-bottom, 12px); right: var(--aip-right, 12px); width: var(--aip-w, 400px);
  display: flex; flex-direction: column; overflow: hidden; background: var(--panel); color: var(--text); border-radius: 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .07); font: 15px/1.45 Inter, system-ui, sans-serif; outline: none;
  animation: aip-in .22s cubic-bezier(.3, .7, .4, 1); }
.aip[hidden], .aip [hidden], .aip-scrim[hidden] { display: none !important; }
body.ai-open #right { visibility: hidden; }
body.ai-open #editor { margin-right: var(--aip-extra, 0px); }
/* панель — при листе: на страницах других разделов (Законы, Оформления…) прячется и возвращается вместе с листом */
body[data-section]:not([data-section="docs"]) :is(.aip, .aip-scrim) { display: none !important; }
.aip-scrim { display: none; }
.aip-grab { display: none; }
@keyframes aip-in { from { opacity: 0; transform: translateX(16px); } }

/* — шапка, режимы, подсказки — */
.aip-head { display: flex; align-items: center; gap: 10px; padding: 18px 14px 12px 20px; }
.aip-head h2 { flex: 1; min-width: 0; margin: 0; display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.aip-spark { display: inline-grid; place-items: center; color: var(--sel); flex: none; }
.aip-spark svg { width: 24px; height: 24px; }
.aip-x { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 12px; color: var(--muted); }
.aip-x:hover { background: var(--hover); color: var(--text); }
.aip-x svg { width: 20px; height: 20px; }
/* «Шире» — только когда есть место (aiPlace: .can-wide) */
.aip-wide { width: 40px; height: 40px; flex: none; display: none; place-items: center; border-radius: 12px; color: var(--muted); }
.aip-wide:hover { background: var(--hover); color: var(--text); }
.aip-wide svg { width: 20px; height: 20px; }
.aip-wide:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
.aip.can-wide .aip-wide { display: grid; }
.aip-wide[aria-pressed="true"] { color: var(--sel); background: var(--sel-weak); }
.aip-modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 0 16px; padding: 4px; border-radius: 14px; background: var(--input); }
.aip-modes button { min-width: 0; height: 40px; padding: 0 4px; display: flex; align-items: center; justify-content: center; gap: 6px; border-radius: 10px;
  color: var(--muted); font-size: 14px; font-weight: 600; transition: background .15s, color .15s; }
.aip-modes button svg { width: 18px; height: 18px; flex: none; }
.aip.narrow .aip-modes button svg { display: none; }
.aip-modes button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aip-modes button:hover { color: var(--text); }
.aip-modes button[aria-pressed="true"] { background: var(--sel); color: #fff; box-shadow: 0 1px 2px rgba(16, 24, 40, .14); }
.aip-modes button:focus-visible, .aip-tips button:focus-visible, .aip-x:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
/* подсказки над полем — когда в переписке уже есть ответы (пока пусто — «Что написать» в самой переписке) */
.aip-tips { display: none; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.aip-tips::-webkit-scrollbar { display: none; }
.aip.has-items .aip-tips { display: flex; }
.aip-tips button { flex: none; height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--text);
  font-size: 13px; font-weight: 500; white-space: nowrap; transition: border-color .15s, background .15s; }
.aip-tips button:hover { border-color: var(--sel); background: var(--sel-weak); }

/* — переписка — */
.aip-feed { position: relative; flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 18px; padding: 14px 16px 18px; }
/* «Что написать» — по режиму: что делает режим, примеры просьб целиком, чему можно верить */
.aip-hello { display: grid; gap: 12px; padding: 16px; border-radius: 16px; background: var(--input); font-size: 14px; line-height: 1.5; }
.aip-g-h { display: flex; align-items: flex-start; gap: 12px; }
.aip-g-ic { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 12px; background: var(--sel-weak); color: var(--sel); }
.aip-g-ic svg { width: 22px; height: 22px; }
.aip-g-h b { display: block; font-size: 17px; font-weight: 700; line-height: 1.3; }
.aip-g-h p { margin: 2px 0 0; color: var(--muted); }
.aip-ex { display: grid; gap: 6px; }
.aip-ex button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 9px 12px 9px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text); text-align: left; font-size: 14px; line-height: 1.4; transition: border-color .15s, background .15s; }
.aip-ex button:hover { border-color: var(--sel); background: var(--sel-weak); }
.aip-ex button:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
.aip-ex span { flex: 1; min-width: 0; }
.aip-ex small { display: block; font-size: 12px; font-weight: 600; color: var(--sel); letter-spacing: .01em; }
.aip-ex svg { width: 16px; height: 16px; flex: none; color: var(--muted); }
.aip-trust { margin: 0; padding-left: 18px; color: var(--muted); display: grid; gap: 3px; font-size: 13px; }
.aip-it { display: flex; flex-direction: column; gap: 10px; }
.aip-me { display: flex; justify-content: flex-end; align-items: flex-start; gap: 10px; }
.aip-me > div { min-width: 0; max-width: 84%; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.aip-me p { margin: 0; padding: 10px 14px; border-radius: 16px 16px 6px 16px; background: var(--sel-weak); color: var(--text); font-size: 14px;
  white-space: pre-wrap; overflow-wrap: anywhere; }
.aip-me small { font-size: 12px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aip-ava { order: 0; width: 32px; height: 32px; flex: none; margin-top: 2px; border-radius: 50%; overflow: hidden; display: grid; place-items: center;
  background: var(--input); color: var(--muted); }
.aip-ava img { width: 100%; height: 100%; object-fit: cover; }
.aip-ava i svg { width: 20px; height: 20px; display: block; }
.aip-card { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.aip-card h3 { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 700; line-height: 1.3; }
.aip-card h3 .aip-spark svg { width: 20px; height: 20px; }
.aip-card h4 { margin: 0 0 8px; font-size: 14px; font-weight: 700; }
/* сводка ответа: сколько уточнений и замечаний */
.aip-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -4px; }
.aip-chip { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px; border-radius: 999px; background: var(--input); color: var(--muted);
  font-size: 13px; font-weight: 600; }
.aip-chip svg { width: 16px; height: 16px; }
.aip-chip.warn { background: var(--aip-warn-bg); color: var(--aip-warn-head); box-shadow: inset 0 0 0 1px var(--aip-warn-line); }
.aip-chip.ok { background: color-mix(in srgb, var(--aip-ok) 12%, transparent); color: var(--aip-ok); }
/* «Что сделано» — ответ и список изменений */
.aip-done { padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--aip-ok) 7%, var(--panel)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--aip-ok) 22%, transparent); }
.aip-done h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 4px; }
.aip-done h4 svg { width: 20px; height: 20px; flex: none; }
.aip-done h4 b { color: var(--aip-ok); font-size: 14px; font-weight: 700; }
.aip-done p { margin: 0; font-size: 14px; color: var(--text); }
.aip-ch { margin: 8px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; font-size: 14px; }
.aip-ch li { position: relative; padding-left: 18px; }
.aip-ch li::before { content: ""; position: absolute; left: 4px; top: .55em; width: 6px; height: 6px; border-radius: 50%; background: var(--aip-ok); }
/* «Уточнения» — заметно: где документ или просьба расходятся с правилами и законами, и что поправить */
.aip-clar { padding: 12px 14px; border: 1px solid var(--aip-warn-line); border-radius: 12px; background: var(--aip-warn-bg); color: var(--aip-warn-ink); }
.aip-clar h4 { display: flex; align-items: center; gap: 8px; color: var(--aip-warn-head); }
.aip-clar h4 svg { width: 20px; height: 20px; flex: none; }
.aip-clar ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.aip-clar li { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 10px; align-items: start; }
.aip-num { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--aip-warn-line); color: var(--aip-warn-ink);
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.aip-clar li p { margin: 0; font-size: 14px; }
.aip-clar li p + p { margin-top: 4px; }
.aip-clar li p b { font-weight: 700; color: var(--aip-warn-head); }
.aip-cl-f { padding: 6px 10px; border-radius: 8px; background: color-mix(in srgb, var(--panel) 55%, transparent); }
.aip-cite { display: inline-flex; align-items: center; gap: 4px; margin-top: 3px; font-size: 13px; font-weight: 600; color: var(--aip-warn-head); text-decoration: none; }
a.aip-cite:hover { text-decoration: underline; }
.aip-cite svg { width: 13px; height: 13px; flex: none; }
.aip-rem { padding: 12px 14px; border-radius: 12px; background: var(--input); }
.aip-rem h4 { color: var(--muted); font-weight: 600; }
.aip .ai-remarks { margin: 0; padding-left: 18px; color: var(--text); font-size: 14px; display: grid; gap: 4px; }
.aip .ai-src { display: grid; gap: 8px; margin: 0; padding: 0; }
.aip-src, .aip .ai-src a.aip-src { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  color: var(--text); text-decoration: none; transition: border-color .15s, background .15s; }
a.aip-src:hover { border-color: var(--sel); background: var(--sel-weak); }
a.aip-src:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
.aip-src-ic { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 10px; background: var(--sel-weak); color: var(--sel); }
.aip-src-ic svg { width: 22px; height: 22px; }
.aip-src-t { flex: 1; min-width: 0; }
.aip-src-t b { display: block; font-size: 14px; font-weight: 600; line-height: 1.3; }
.aip-src-t small { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); line-height: 1.35; }
.aip-src em { flex: none; display: inline-flex; align-items: center; gap: 4px; font-style: normal; font-size: 13px; font-weight: 600; color: var(--sel); white-space: nowrap; }
.aip-src em svg { width: 13px; height: 13px; }
/* текст документа — свёрнут, раскрывается по нажатию */
.aip-draft { border: 1px solid var(--line); border-radius: 12px; }
.aip-draft summary { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; cursor: pointer; font-size: 14px; font-weight: 600; list-style: none; border-radius: 12px; }
.aip-draft summary::-webkit-details-marker { display: none; }
.aip-draft summary::after { content: ""; width: 8px; height: 8px; margin-left: auto; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg) translateY(-2px); transition: transform .15s; }
.aip-draft[open] summary::after { transform: rotate(-135deg) translateY(-2px); }
.aip-draft summary:hover { background: var(--hover); }
.aip-draft summary:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
.aip .ai-res { border: 0; border-top: 1px solid var(--line); border-radius: 0; padding: 12px 14px 14px; max-height: none; font: 14px/1.5 Tinos, 'Times New Roman', serif; color: var(--text); }
.aip .ai-res h4 { margin: 2px 0 6px; font-size: 15px; }
.aip .ai-res .ai-kind { font: 700 12px/1.4 Inter, sans-serif; letter-spacing: .12em; color: var(--sel); }
.aip .ai-res p { margin: 0 0 6px; }
.aip .ai-res ol { margin: 6px 0; padding-left: 20px; }
.aip .var { background: rgba(255, 205, 41, .38); border-radius: 3px; padding: 0 2px; }
/* кнопки ответа: главная — тёмно-синяя G, вторая — светлая капсула с синим текстом */
.aip-acts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.aip-acts.one { grid-template-columns: 1fr; }
.aip-b { min-width: 0; min-height: 44px; padding: 6px 12px; display: flex; align-items: center; justify-content: center; gap: 8px; border-radius: 12px;
  font-size: 14px; font-weight: 600; line-height: 1.2; text-align: center; transition: filter .15s, background .15s; }
.aip-b svg { width: 18px; height: 18px; flex: none; }
.aip-b.pri { background: var(--primary, var(--sel)); color: #fff; }
.aip-b.pri:hover { filter: brightness(1.12); }
.aip-b.sec { background: var(--sel-weak); color: var(--sel); }
.aip-b.sec:hover { filter: brightness(.97); }
.aip-b:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
.aip-note { margin: -4px 0 0; font-size: 13px; color: var(--muted); }
.aip-applied { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--aip-ok); }
.aip-applied svg { width: 20px; height: 20px; flex: none; }
.aip-applied + .aip-acts .aip-b { min-height: 40px; }
.aip-report { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 4px 6px; margin: -4px 0 0 4px; border-radius: 8px;
  color: var(--muted); font-size: 13px; font-weight: 500; }
.aip-report svg { width: 15px; height: 15px; }
.aip-report:hover:not(:disabled) { color: var(--text); background: var(--hover); }
.aip-report:disabled { cursor: default; color: var(--aip-ok); opacity: 1; }
.aip-report:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
.aip-wait { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.aip .ai-load { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.aip .ai-load i { width: 18px; height: 18px; flex: none; border-radius: 50%; border: 2px solid var(--sel); border-right-color: transparent; animation: spin 1s linear infinite; }
.aip-stop { flex: none; height: 34px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--text); }
.aip-stop:hover { background: var(--hover); }
.aip-bad { background: var(--aip-bad-bg); border-color: transparent; color: var(--aip-bad-ink); }
.aip-bad p { margin: 0; font-size: 14px; }
.aip-bad .aip-b { justify-self: start; }

/* — низ: какой документ, поле, остаток на сегодня — */
.aip-foot { display: grid; gap: 8px; padding: 12px 16px 14px; border-top: 1px solid var(--line); }
.aip-ctx { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; color: var(--muted); }
.aip-ctx svg { width: 18px; height: 18px; flex: none; }
.aip-ctx span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aip-ctx b { color: var(--text); font-weight: 600; }
.aip-ctx.none { color: var(--aip-warn-head); }
/* большое поле: от двух строк, растёт до ~10 (aiGrow), под ним — подсказка про Enter и кнопка */
.aip-form { display: flex; flex-direction: column; gap: 2px; padding: 8px 8px 8px 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--input);
  transition: border-color .15s, box-shadow .15s; }
.aip-form:focus-within { border-color: var(--sel); box-shadow: 0 0 0 3px var(--sel-weak); background: var(--panel); }
.aip-form textarea { width: 100%; min-height: 54px; max-height: 248px; padding: 4px 6px 4px 0; border: 0; outline: none; resize: none; background: transparent;
  color: var(--text); font: 16px/1.5 Inter, system-ui, sans-serif; }
.aip-fbar { display: flex; align-items: center; gap: 8px; }
.aip-hint { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aip-len { font-size: 12px; color: var(--aip-warn-head); font-variant-numeric: tabular-nums; }
.aip-len:empty { display: none; }
.aip-form textarea::placeholder { color: var(--muted); opacity: .85; }
.aip-send { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 11px; background: var(--sel); color: #fff; transition: filter .15s; }
.aip-send:hover { filter: brightness(1.08); }
.aip-send:disabled { opacity: .45; cursor: default; filter: none; }
.aip-send svg { width: 20px; height: 20px; }
.aip-send:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
.aip-flash { margin: 0; padding: 8px 12px; border-radius: 10px; background: var(--aip-warn-bg); color: var(--aip-warn-ink); font-size: 13px; }
.aip-meta { margin: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 14px; font-size: 13px; color: var(--muted); }
.aip-meta .ai-quota:empty, .aip-meta .ai-kb:empty { display: none; }
/* «База обновлена N мин назад» (api/laws/meta); старше 3 часов — жёлтой меткой */
.aip-meta .ai-kb.stale { padding: 0 8px; border-radius: 999px; background: var(--aip-warn-bg); box-shadow: inset 0 0 0 1px var(--aip-warn-line); color: var(--aip-warn-head); font-weight: 600; }
.aip .ai-quota.low { color: var(--aip-warn-head); font-weight: 600; }
/* гость: одна кнопка «Войти через Discord», код — мелкой ссылкой */
.aip-gate { display: grid; justify-items: center; gap: 10px; padding: 6px 4px 2px; text-align: center; }
.aip-gate-ic { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 16px; background: #5865f2; color: #fff; }
.aip-gate-ic svg { width: 32px; height: 32px; }
.aip-gate > b { font-size: 18px; font-weight: 700; }
.aip-gate > p { margin: 0; max-width: 34ch; font-size: 14px; color: var(--muted); }
.aip-gate .dc-btn { height: 46px; border-radius: 12px; font-size: 15px; }
.aip-codelink { padding: 4px 8px; border-radius: 8px; font-size: 13px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.aip-codelink:hover { color: var(--text); }
.aip-codef { width: 100%; display: flex; gap: 8px; }
.aip-codef .r-in { height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 15px; }
.aip-codef .btn { height: 42px; padding: 0 14px; border-radius: 10px; font-size: 14px; }
.aip-gate-err { margin: 0; font-size: 13px; color: var(--aip-bad-ink); }
.aip-off { margin: 0; padding: 12px 14px; border-radius: 12px; background: var(--input); font-size: 14px; color: var(--muted); }
/* v16: код не принят (выключен, истёк) — ключ на жёлтом, причина, «Сменить код» / «Убрать код» */
.aip-gate-ic.key { background: var(--aip-warn-bg); box-shadow: inset 0 0 0 1px var(--aip-warn-line); }
.aip-gate-acts, .lwc-gate-acts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.aip-gate-acts .btn, .lwc-gate-acts .btn { height: 42px; padding: 0 16px; border-radius: 10px; font-size: 14px; }

/* — v16: строка доступа гостя под полем ИИ (документы, «Законы», мастер на телефоне): код или гостевой доступ, остаток, кнопки — */
.ai-acc { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; min-width: 0; padding: 8px 8px 8px 12px; border-radius: 12px; background: var(--input);
  color: var(--text); font: 14px/1.4 Inter, system-ui, sans-serif; text-align: left; }
.ai-acc-ic { display: grid; place-items: center; flex: none; align-self: flex-start; margin-top: 1px; }
.ai-acc-ic svg { width: 20px; height: 20px; }
.ai-acc-t { flex: 1 1 200px; min-width: 0; color: var(--muted); }
.ai-acc-t b { color: var(--text); font-weight: 600; overflow-wrap: anywhere; }
.ai-acc-t small { display: block; margin-top: 1px; font-size: 13px; color: var(--muted); }
.ai-acc-b { display: flex; flex-wrap: wrap; gap: 2px; margin-left: auto; }
.ai-acc .ai-acc-b button { padding: 5px 8px; border-radius: 8px; color: var(--sel); font: 600 13px/1.3 Inter, system-ui, sans-serif; white-space: nowrap; }
.ai-acc .ai-acc-b button:hover { background: var(--sel-weak); }
.ai-acc .ai-acc-b button[data-acc="forget"] { color: var(--muted); }
.ai-acc .ai-acc-b button[data-acc="forget"]:hover { background: var(--hover); color: var(--text); }
.ai-acc button:focus-visible { outline: 2px solid var(--sel); outline-offset: 1px; }
/* три запроса и меньше — жёлтым, как «Осталось сегодня» вошедшего */
.ai-acc.low { background: var(--aip-warn-bg); box-shadow: inset 0 0 0 1px var(--aip-warn-line); }
.ai-acc.low .ai-acc-t { color: var(--aip-warn-ink); }
/* форма «Сменить код» / «Ввести код» на месте строки */
.ai-acc-f { display: grid; gap: 6px; padding: 8px; }
.ai-codef { display: flex; gap: 6px; min-width: 0; }
.ai-codef .r-in { flex: 1; min-width: 0; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text);
  font: 15px Inter, system-ui, sans-serif; letter-spacing: .02em; }
.ai-codef .r-in:focus { border-color: var(--sel); box-shadow: 0 0 0 3px var(--sel-weak); outline: none; }
.ai-codef .btn { height: 40px; padding: 0 14px; border-radius: 10px; font-size: 14px; flex: none; }
.ai-codef .btn[type="submit"] { background: var(--sel); border-color: var(--sel); color: #fff; }
.ai-acc-err { margin: 0 4px; font-size: 13px; color: var(--aip-bad-ink); }
.aip-acc[hidden], .lwc-acc[hidden] { display: none !important; }

/* — после «Применить к листу»: изменённое ИИ на листе мягко подсвечено несколько секунд (в PNG — нет) — */
@keyframes ai-hl { 0%, 55% { background-color: rgba(37, 99, 235, .14); box-shadow: 0 0 0 4px rgba(37, 99, 235, .14); }
  100% { background-color: rgba(37, 99, 235, 0); box-shadow: 0 0 0 4px rgba(37, 99, 235, 0); } }
#ed-pages .doc .ai-hl { animation: ai-hl 5s ease-out forwards; border-radius: 3px; }
.doc.exporting .ai-hl { animation: none !important; background: none !important; box-shadow: none !important; }
/* широкая панель — просторнее */
.aip.wide .aip-feed { padding: 16px 22px 22px; }
.aip.wide .aip-foot { padding: 12px 22px 14px; }
.aip.wide .aip-modes { margin: 0 22px; }
.aip.wide .aip-head { padding-left: 24px; }

/* — окно «Что не так?» — */
.aip-fb-modal .modal { width: min(520px, 100%); border-radius: 16px; }
.aip-fb-modal .m-h { padding: 16px 20px; font-size: 18px; font-weight: 700; border-bottom: 0; }
.aip-fb-modal .m-b { padding: 0 20px 12px; }
.aip-fb-modal .m-f { padding: 12px 20px 16px; border-top: 0; }
.aip-fb-modal .m-f .btn { height: 40px; padding: 0 18px; border-radius: 10px; font-size: 14px; }
.aip-fb-modal .m-f .btn.primary { background: var(--primary, var(--sel)); border-color: var(--primary, var(--sel)); }
.aip-fb { gap: 12px; }
.aip-fb-lead { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.45; }
.aip-fb textarea.r-in { width: 100%; min-height: 120px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); font-size: 15px; line-height: 1.45; }
.aip-fb textarea.r-in:focus { border-color: var(--sel); box-shadow: 0 0 0 3px var(--sel-weak); }
.aip-fb .chk.aip-fb-att { flex-direction: row; justify-content: flex-start; gap: 10px; font-size: 14px; color: var(--text); }
.aip-fb-msg { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--aip-bad-bg); color: var(--aip-bad-ink); font-size: 14px; }
.aip-fb-ok { display: grid; justify-items: center; gap: 8px; padding: 18px 8px 6px; text-align: center; }
.aip-fb-ok svg { width: 44px; height: 44px; }
.aip-fb-ok b { font-size: 18px; }
.aip-fb-ok p { margin: 0; font-size: 14px; color: var(--muted); }

/* — телефон: шторка снизу поверх листа — */
@media (max-width: 899px) {
  .aip { z-index: 52; top: auto; left: 0; right: 0; bottom: 0; width: auto; height: min(88vh, 760px); height: min(88dvh, 760px);
    border-radius: 22px 22px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); animation-name: aip-up; }
  .aip-scrim { display: block; position: fixed; inset: 0; z-index: 51; background: rgba(15, 18, 24, .42); }
  .aip-grab { display: block; flex: none; width: 40px; height: 5px; margin: 8px auto 0; border-radius: 3px; background: var(--line); }
  .aip-head { padding: 10px 10px 10px 18px; }
  .aip-head h2 { font-size: 20px; }
  .aip-x { width: 44px; height: 44px; }
  .aip-modes button { height: 44px; }
  .aip-tips button { height: 40px; }
  .aip-hint { display: none; }
  .aip-fbar { justify-content: flex-end; }
  .aip-form textarea { font-size: 16px; }  /* iPhone не увеличивает страницу при вводе */
  .aip-send { width: 44px; height: 44px; }
  .aip-codef .r-in { font-size: 16px; }
  .ai-codef .r-in { height: 44px; font-size: 16px; }  /* iPhone не приближает страницу при вводе */
  .ai-codef .btn { height: 44px; }
  .ai-acc .ai-acc-b button { min-height: 40px; }
  .aip-gate-acts .btn, .lwc-gate-acts .btn { height: 44px; }
  .aip-fb textarea.r-in { font-size: 16px; }
  .aip-report { min-height: 44px; }
  body.ai-open #editor { margin-right: 0; }
  body.ai-open #right { visibility: visible; }
  @keyframes aip-up { from { transform: translateY(40px); opacity: 0; } }
}
@media (prefers-reduced-motion: reduce) { .aip { animation: none; } .aip .ai-load i { animation-duration: 2.4s; } }

/* — v14: карточка ожидания ответа ИИ (документы и «Законы»): этапы по ходу, секунды, совет, «Отменить» — */
.aip-live { padding: 14px 16px 14px; }
.aiw { display: grid; gap: 12px; }
.aiw-top { display: flex; align-items: center; gap: 12px; min-width: 0; }
.aiw-orb { position: relative; flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: var(--sel-weak); }
.aiw-orb::before { content: ""; position: absolute; inset: -3px; border-radius: 16px; padding: 2px;
  background: conic-gradient(from var(--aiw-a, 0deg), transparent 0 55%, var(--sel) 80%, transparent 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; animation: aiw-turn 1.6s linear infinite; }
.aiw-orb svg { width: 26px; height: 26px; animation: aiw-breathe 2.4s ease-in-out infinite; }
@property --aiw-a { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
@keyframes aiw-turn { to { --aiw-a: 360deg; } }
@keyframes aiw-breathe { 50% { transform: scale(1.08); } }
.aiw-tt { display: grid; gap: 1px; min-width: 0; flex: 1; }
.aiw-h { font-size: 16px; font-weight: 700; color: var(--text); }
.aiw-tt small { font-size: 13px; color: var(--muted); }
.aiw-sec { font-variant-numeric: tabular-nums; }
.aiw-stop { flex: none; min-height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); font-size: 14px; font-weight: 600; color: var(--text); background: var(--panel); }
.aiw-stop:hover { background: var(--hover); }
.aiw-stop:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
.aiw-steps { list-style: none; margin: 0; padding: 0 0 0 4px; display: grid; gap: 9px; }
.aiw-steps li { display: grid; grid-template-columns: 22px 1fr; column-gap: 10px; row-gap: 6px; align-items: center; font-size: 14px; color: var(--text); animation: aiw-in .25s ease-out; }
.aiw-steps li > svg, .aiw-steps li > .aiw-dot { justify-self: center; width: 18px; height: 18px; }
.aiw-steps li.wait { color: var(--muted); }
.aiw-steps li.wait > svg { opacity: .45; filter: grayscale(1); }
.aiw-steps li.run > span { font-weight: 600; }
.aiw-dot { position: relative; display: block; border-radius: 50%; }
.aiw-dot::before, .aiw-dot::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--sel); }
.aiw-dot::after { inset: 0; background: none; border: 2px solid var(--sel); opacity: .5; animation: aiw-ping 1.2s ease-out infinite; }
@keyframes aiw-ping { 0% { transform: scale(.6); opacity: .8; } 100% { transform: scale(1.35); opacity: 0; } }
@keyframes aiw-in { from { opacity: 0; transform: translateY(4px); } }
.aiw-chips { grid-column: 2; display: flex; flex-wrap: wrap; gap: 6px; }
.aiw-chips span { padding: 3px 9px; border-radius: 999px; background: var(--input); font-size: 12.5px; font-weight: 600; color: var(--text); }
.aiw-chips .more { color: var(--muted); }
.aiw-doc { grid-column: 2; font-style: normal; font-size: 13.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aiw-tip { margin: 0; display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 12px; background: var(--input); font-size: 13.5px; color: var(--muted); }
.aiw-tip svg { flex: none; width: 16px; height: 16px; }
.aiw.writing .aiw-steps { display: none; }   /* ответ уже печатается — этапы прячутся, шапка остаётся */
@media (prefers-reduced-motion: reduce) { .aiw-orb::before, .aiw-orb svg, .aiw-dot::after, .aiw-steps li { animation: none; } }
