/* ==========================================================================
   pzh-risk.ru — сквозной плавающий чат «🤖 Пожарный ИИ-Консультант».

   Токены виджета заданы здесь же, чтобы его можно было перенести на любую
   страницу без внешних зависимостей:
     светло: акцент #1e3a5f, карточка #f4f6f9, радиусы 12–16px;
     тёмно:  акцент #254b7a, поверхности темнее, тот же ритм.
   Тёмная тема включается классом .dark-theme на <html> (js/theme.js).

   Структура:
     .aic-root      — контейнер (pointer-events:none)
       .aic-fab     — плавающая кнопка
       .aic-panel   — окно: .aic-head / .aic-modes / .aic-body
         .aic-block--chat     — чат: .aic-log + .aic-foot
         .aic-block--feedback — форма замечания
   ========================================================================== */

.aic-root {
  /* акцент */
  --aic-accent: #1e3a5f;
  --aic-accent-2: #254b7a;
  --aic-accent-ink: #ffffff;
  --aic-accent-soft: rgba(30, 58, 95, .08);
  --aic-accent-soft-2: rgba(30, 58, 95, .14);
  /* поверхности */
  --aic-bg: #f4f6f9;
  --aic-card: #ffffff;
  --aic-card-2: #f4f6f9;
  --aic-line: #dde4ec;
  --aic-line-soft: #e9eef4;
  /* текст */
  --aic-text: #16222e;
  --aic-muted: #5a6b7c;
  --aic-danger: #b3261e;
  --aic-danger-bg: #fff6f5;
  --aic-danger-line: #ebd3d3;
  /* геометрия */
  --aic-r-lg: 16px;
  --aic-r-md: 12px;
  --aic-r-sm: 10px;
  --aic-shadow: 0 18px 44px rgba(16, 32, 56, .18), 0 2px 8px rgba(16, 32, 56, .06);
  --aic-shadow-sm: 0 6px 18px rgba(16, 32, 56, .12);
  /* позиционирование */
  --aic-bottom: 148px;
  --aic-vh: 100dvh;
  --aic-kb: 0px;
  position: fixed;
  inset: 0;
  z-index: 10020;
  pointer-events: none;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.4;
  color: var(--aic-text);
}

/* тёмная тема — свои значения поверх токенов сайта */
html.dark-theme .aic-root {
  --aic-accent: #254b7a;
  --aic-accent-2: #3a6796;
  --aic-accent-ink: #f2f6fb;
  --aic-accent-soft: rgba(120, 168, 220, .12);
  --aic-accent-soft-2: rgba(120, 168, 220, .2);
  --aic-bg: #141b24;
  --aic-card: #1b242f;
  --aic-card-2: #212c39;
  --aic-line: #2e3c4b;
  --aic-line-soft: #263240;
  --aic-text: #e6edf4;
  --aic-muted: #9db0c2;
  --aic-danger: #ff8a80;
  --aic-danger-bg: rgba(179, 38, 30, .16);
  --aic-danger-line: rgba(255, 138, 128, .35);
  --aic-shadow: 0 20px 48px rgba(0, 0, 0, .55), 0 2px 8px rgba(0, 0, 0, .4);
  --aic-shadow-sm: 0 6px 18px rgba(0, 0, 0, .4);
}

/* ---------------------------------------------------------------- кнопка */
.aic-fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--aic-bottom, 20px) + env(safe-area-inset-bottom, 0px));
  z-index: 10021;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  /* Правка 2026-12-04: широкая плавающая кнопка перекрывала кнопки страницы
     (напр. «Добавить сценарий» на riskspa). По умолчанию — круглая иконка 44px,
     подпись раскрывается при наведении. */
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 0;
  justify-content: center;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--aic-accent), var(--aic-accent-2));
  color: #fff;
  font: inherit;
  font-size: .86rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--aic-shadow-sm);
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.aic-fab:hover { transform: translateY(-2px); box-shadow: var(--aic-shadow); }
.aic-fab:active { transform: translateY(0); }
.aic-fab:focus-visible { outline: 3px solid #f0a202; outline-offset: 2px; }
.aic-fab__ic { width: 20px; height: 20px; fill: currentColor; flex: 0 0 auto; }
.aic-fab__t {
  white-space: nowrap;
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-width .18s ease, opacity .18s ease;
}
.aic-fab:hover,
.aic-fab:focus-visible {
  width: auto;
  height: auto;
  padding: 11px 16px 11px 12px;
}
.aic-fab:hover .aic-fab__t,
.aic-fab:focus-visible .aic-fab__t { max-width: 160px; opacity: 1; }

/* Правка 2026-12-04: если под плавающей кнопкой оказалась кнопка
   страницы — прячем её, чтобы пользователь мог нажать обе. */
.aic-root.aic-fab-overlap .aic-fab{
  opacity:0;
  pointer-events:none;
  transform:scale(.85);
}

/* пока открыто окно чата — плавающая кнопка не нужна */
body.aic-open .aic-fab { opacity: 0; pointer-events: none; transform: scale(.9); }
/* Плавающая кнопка не должна перекрывать открытые шторки и списки:
   при открытой мобильной шторке фильтров или выпадающем списке — прячем её. */
body.bs-sheet-lock .aic-fab,
body.csel-open .aic-fab,
body.aic-open .aic-fab { opacity: 0; pointer-events: none; transform: scale(.9); }

/* ------------------------------------------------------------- окно чата */
.aic-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 10022;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  width: 440px;
  height: 650px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow: hidden;
  border: 1px solid var(--aic-line);
  border-radius: var(--aic-r-lg);
  background: var(--aic-card);
  box-shadow: var(--aic-shadow);
  animation: aic-in .2s ease;
}
.aic-panel[hidden] { display: none; }
@keyframes aic-in {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to { opacity: 1; transform: none; }
}

/* шапка */
.aic-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 12px;
  background: linear-gradient(135deg, var(--aic-accent), var(--aic-accent-2));
  color: #fff;
  flex: 0 0 auto;
}
.aic-head__brand { display: flex; align-items: center; gap: 9px; flex: 1 1 auto; min-width: 0; }
.aic-head__logo { flex: 0 0 auto; display: block; width: 30px; height: 30px; }
.aic-head__logo svg { width: 30px; height: 30px; fill: #fff; display: block; }
.aic-head__titles { min-width: 0; }
.aic-head__t {
  font-size: .92rem;
  font-weight: 700;
  letter-spacing: .01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.aic-head__sub {
  font-size: .68rem;
  opacity: .78;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.aic-hbtn {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font: inherit;
  font-size: .95rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}
.aic-hbtn:hover { background: rgba(255, 255, 255, .3); }
.aic-hbtn:focus-visible { outline: 3px solid #f0a202; outline-offset: 2px; }
.aic-hbtn svg {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  fill: currentColor;
  stroke: currentColor;
}
.aic-hbtn--clear svg { fill: none; }

/* переключатель режимов */
.aic-modes {
  display: flex;
  gap: 6px;
  padding: 10px 12px 9px;
  border-bottom: 1px solid var(--aic-line);
  background: var(--aic-card);
  flex: 0 0 auto;
}
.aic-mode {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 8px;
  border: 1px solid var(--aic-line);
  border-radius: 10px;
  background: var(--aic-card-2);
  color: var(--aic-text);
  font: inherit;
  font-size: .78rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.aic-mode:hover { border-color: var(--aic-accent); }
.aic-mode.is-on {
  background: var(--aic-accent);
  border-color: var(--aic-accent);
  color: #fff;
}
.aic-mode:focus-visible { outline: 3px solid #f0a202; outline-offset: 2px; }

/* тело окна: два взаимоисключающих блока (чат / форма замечания) */
.aic-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.aic-block {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.aic-block[hidden] { display: none; }

/* ------------------------------------------------------------ лента чата */
.aic-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: var(--aic-bg);
}
.aic-msg { display: flex; }
.aic-msg--user { justify-content: flex-end; }
.aic-msg--ai, .aic-msg--sys, .aic-msg--err { justify-content: flex-start; }

/* сообщение пользователя */
.aic-bubble {
  max-width: 92%;
  padding: 8px 12px;
  border-radius: var(--aic-r-md);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.aic-msg--user .aic-bubble {
  background: var(--aic-accent);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
  max-width: 86%;
  white-space: pre-wrap;
}

/* приветственный блок */
.aic-welcome {
  background: var(--aic-card);
  border: 1px solid var(--aic-line);
  border-radius: var(--aic-r-lg);
  padding: 11px 13px;
  box-shadow: var(--aic-shadow-sm);
  flex: 1 1 auto;
  min-width: 0;
}
.aic-welcome__t { font-size: 13.5px; font-weight: 700; margin-bottom: 3px; }
.aic-welcome__s { font-size: 12px; line-height: 1.4; color: var(--aic-muted); }
.aic-welcome__chips { margin-top: 9px; }
.aic-welcome__chips-l {
  display: block;
  font-size: 10.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--aic-muted);
  margin-bottom: 6px;
}
.aic-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.aic-chip {
  padding: 6px 10px;
  border: 1px solid var(--aic-line);
  border-radius: 999px;
  background: var(--aic-card-2);
  color: var(--aic-text);
  font: inherit;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.aic-chip:hover {
  border-color: var(--aic-accent);
  background: var(--aic-accent-soft);
  color: var(--aic-accent);
}
html.dark-theme .aic-chip:hover { color: var(--aic-accent-2); }
.aic-chip:focus-visible { outline: 3px solid #f0a202; outline-offset: 2px; }

/* карточка ответа ИИ */
.aic-cardbox {
  position: relative;
  max-width: 96%;
  background: var(--aic-card);
  border: 1px solid var(--aic-line);
  border-radius: var(--aic-r-lg);
  /* справа место под кнопку копирования в углу карточки */
  padding: 11px 38px 11px 13px;
  box-shadow: var(--aic-shadow-sm);
}
.aic-cardbox__body { font-size: 13px; line-height: 1.5; }
.aic-cardbox .aic-p { margin: 0 0 6px; }
.aic-cardbox .aic-p:last-child { margin-bottom: 0; }
.aic-cardbox .aic-h { margin: 9px 0 5px; font-size: 13.5px; font-weight: 700; line-height: 1.3; }
.aic-cardbox .aic-h:first-child { margin-top: 0; }
.aic-cardbox .aic-list { margin: 0 0 6px; padding-left: 19px; }
.aic-cardbox .aic-list li { margin: 3px 0; }
.aic-cardbox .aic-quote {
  margin: 0 0 6px;
  padding: 2px 0 2px 9px;
  border-left: 3px solid var(--aic-accent);
  color: var(--aic-muted);
}
.aic-cardbox .aic-hr { margin: 9px 0; border: 0; border-top: 1px solid var(--aic-line); }
.aic-cardbox code {
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--aic-accent-soft);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* подсветка нормативов: код документа, форма, пункт, номер приказа */
.aic-nrm {
  padding: 0 3px;
  border-radius: 5px;
  background: var(--aic-accent-soft);
  color: var(--aic-accent);
  font-weight: 600;
  white-space: nowrap;
}
html.dark-theme .aic-nrm { color: var(--aic-accent-2); }
.aic-nrm--form { background: var(--aic-accent-soft-2); }
.aic-nrm--cl { font-weight: 500; }
.aic-nrm--order { background: transparent; color: inherit; text-decoration: underline dotted; }

/* кнопка «Скопировать ответ» — в углу карточки */
.aic-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--aic-line);
  border-radius: 8px;
  background: var(--aic-card-2);
  color: var(--aic-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s ease, color .15s ease, border-color .15s ease;
}
.aic-copy svg {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
}
.aic-copy:hover { color: var(--aic-accent); border-color: var(--aic-accent); }
.aic-copy:focus-visible { outline: 3px solid #f0a202; outline-offset: 2px; opacity: 1; }
.aic-cardbox:hover .aic-copy, .aic-copy.is-done, .aic-copy.is-fail { opacity: 1; }
.aic-copy.is-done { color: #1c7a44; border-color: #1c7a44; }
.aic-copy.is-fail { color: var(--aic-danger); border-color: var(--aic-danger-line); }

/* системные и ошибочные сообщения */
.aic-msg--sys .aic-bubble {
  background: var(--aic-card);
  border: 1px dashed var(--aic-line);
  color: var(--aic-muted);
  font-size: 12px;
  border-radius: var(--aic-r-md);
}
.aic-msg--err .aic-bubble {
  background: var(--aic-danger-bg);
  border: 1px solid var(--aic-danger-line);
  color: var(--aic-text);
}
.aic-msg--status .aic-bubble { color: var(--aic-muted); font-style: italic; }

/* состояние загрузки: скелетон */
.aic-cardbox--skel { max-width: 88%; }
.aic-skel__head { display: flex; align-items: center; gap: 7px; margin-bottom: 10px; }
.aic-skel__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--aic-accent);
  animation: aic-pulse 1.1s infinite ease-in-out;
}
.aic-skel__txt { font-size: 12px; color: var(--aic-muted); }
.aic-skel__line {
  height: 9px;
  margin-bottom: 7px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--aic-line-soft) 25%, var(--aic-card-2) 37%, var(--aic-line-soft) 63%);
  background-size: 400% 100%;
  animation: aic-shimmer 1.4s ease infinite;
}
.aic-skel__line--lg { width: 92%; height: 11px; }
.aic-skel__line--sm { width: 62%; margin-bottom: 0; }
@keyframes aic-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}
@keyframes aic-pulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

/* кнопка «Повторить» */
.aic-retry {
  display: inline-block;
  margin-top: 7px;
  padding: 5px 11px;
  border: 1px solid var(--aic-accent);
  border-radius: 9px;
  background: transparent;
  color: var(--aic-accent);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
html.dark-theme .aic-retry { color: var(--aic-accent-2); }
.aic-retry:hover { background: var(--aic-accent); color: #fff; }

/* текст ответа: формулы */
.aic-f { font-family: "Cambria Math", "Latin Modern Math", Georgia, serif; }
.aic-f--display { display: block; margin: 8px 0; text-align: center; font-size: 14px; }
.aic-frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .92em; }
.aic-frac__n { border-bottom: 1px solid currentColor; padding: 0 3px; }
.aic-frac__d { padding: 0 3px; }
.aic-sqrt { white-space: nowrap; }
.aic-sqrt__r { border-top: 1px solid currentColor; }

/* --------------------------------------------------------- капсула ввода */
.aic-foot {
  flex: 0 0 auto;
  padding: 9px 12px 10px;
  border-top: 1px solid var(--aic-line);
  background: var(--aic-card);
}
.aic-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  border: 1px solid var(--aic-line);
  border-radius: 18px;
  background: var(--aic-card-2);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.aic-input:focus-within {
  border-color: var(--aic-accent);
  background: var(--aic-card);
  box-shadow: 0 0 0 3px var(--aic-accent-soft);
}
.aic-ta {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 26px;
  max-height: 132px;
  padding: 5px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--aic-text);
  font: inherit;
  font-size: 13px;
  line-height: 1.45;
  resize: none;
  overflow-y: auto;
}
.aic-ta:focus { outline: none; }
.aic-ta::placeholder { color: var(--aic-muted); opacity: .85; }
.aic-send {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--aic-accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, transform .15s ease, opacity .15s ease;
}
.aic-send:hover { background: var(--aic-accent-2); }
.aic-send:active { transform: scale(.94); }
.aic-send:disabled { opacity: .55; cursor: default; }
.aic-send:focus-visible { outline: 3px solid #f0a202; outline-offset: 2px; }
.aic-send__ic { display: block; width: 17px; height: 17px; fill: currentColor; }
.aic-send__ic--spin { animation: aic-spin .9s linear infinite; }
@keyframes aic-spin { to { transform: rotate(360deg); } }
.aic-send__tip {
  display: none;
  font-size: 10px;
  color: var(--aic-muted);
  padding-right: 4px;
}
.aic-hint {
  margin-top: 6px;
  font-size: 10.5px;
  color: var(--aic-muted);
  text-align: right;
}

/* ------------------------------------------------ форма замечания (блок 2) */
.aic-form {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--aic-bg);
}
.aic-form__scroll {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 11px 12px 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.aic-form__foot {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 9px 12px 12px;
  border-top: 1px solid var(--aic-line);
  background: var(--aic-card);
}
.aic-form__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  flex: 0 0 auto;
}
.aic-form__cell { min-width: 0; }
.aic-form__lab {
  display: block;
  margin-bottom: 3px;
  font-size: 11.5px;
  color: var(--aic-muted);
}
.aic-form__in {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid var(--aic-line);
  border-radius: 10px;
  background: var(--aic-card);
  color: var(--aic-text);
  font: inherit;
  font-size: 12.5px;
}
.aic-form__in:focus-visible { outline: 3px solid #f0a202; outline-offset: 1px; }
.aic-ta--fb {
  width: 100%;
  box-sizing: border-box;
  min-height: 62px;
  max-height: 140px;
  flex: 0 0 auto;
  padding: 8px 10px;
  border: 1px solid var(--aic-line);
  border-radius: 12px;
  background: var(--aic-card);
  color: var(--aic-text);
  font: inherit;
  font-size: 12.5px;
  line-height: 1.45;
  resize: none;
  overflow-y: auto;
}
.aic-ta--fb:focus-visible { outline: 3px solid #f0a202; outline-offset: 1px; }
.aic-consent--fb { padding: 4px 0 0; }
/* --- e-mail для ответа + согласие на обработку ПД (152-ФЗ) --- */
.aic-form__in--mail { min-height: 40px; }
.aic-fb-consent {
  margin-top: 4px;
  padding: 9px 10px;
  border: 1px solid var(--aic-line);
  border-radius: 10px;
  background: var(--aic-card);
}
.aic-fb-consent[hidden] { display: none !important; }
.aic-fb-consent__lab {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--aic-text);
  cursor: pointer;
}
.aic-fb-consent__box {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  margin: 1px 0 0;
  accent-color: var(--aic-accent);
  cursor: pointer;
}
.aic-fb-consent__link { color: var(--aic-accent); text-decoration: underline; }
.aic-fb-consent__hint {
  margin-top: 7px;
  font-size: 11.5px;
  line-height: 1.4;
  color: #e2564a;
}
.aic-fb-consent__hint[hidden] { display: none !important; }
.aic-send--wide {
  width: 100%;
  height: auto;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 11px;
  font-size: .82rem;
  font-weight: 600;
}
/* кнопка во всю ширину и без переноса текста */
.aic-send--nowrap { white-space: nowrap; }

/* быстрые теги замечания */
.aic-fb-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}
.aic-fb-tag {
  appearance: none;
  border: 1px solid var(--aic-line);
  background: var(--aic-card);
  color: var(--aic-text);
  border-radius: 999px;
  padding: 5px 11px;
  font: inherit;
  font-size: 11.5px;
  line-height: 1.3;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.aic-fb-tag:hover { border-color: var(--aic-accent); }
.aic-fb-tag.is-on {
  background: var(--aic-accent);
  border-color: var(--aic-accent);
  color: #fff;
}
html.dark-theme .aic-fb-tag.is-on { color: #10151c; }
.aic-fb-tag:focus-visible { outline: 3px solid #f0a202; outline-offset: 1px; }

/* пояснение под формой: что прикрепляется автоматически */
.aic-fb-note {
  font-size: 10.5px;
  line-height: 1.35;
  color: var(--aic-muted);
  padding-bottom: 2px;
}

/* экран успешной отправки */
.aic-fb-done {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 16px 16px;
  text-align: center;
  background: var(--aic-bg);
}
.aic-fb-done__ic {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(22, 160, 90, .14);
  color: #16a05a;
}
.aic-fb-done__ic svg { width: 24px; height: 24px; fill: none; }
.aic-fb-done__t { font-size: 14px; font-weight: 700; color: var(--aic-text); }
.aic-fb-done__d { font-size: 12px; line-height: 1.4; color: var(--aic-muted); max-width: 30ch; }
.aic-fb-done .aic-send--wide { margin-top: 6px; }

/* скрытие по [hidden] не должно ломаться из-за display у .aic-form / .aic-fb-done */
.aic-form[hidden], .aic-fb-done[hidden] { display: none !important; }
.aic-fb-status { flex: 0 0 auto; }
.aic-fb-status:empty { display: none; }
.aic-fb-status .aic-msg { margin-top: 7px; }

/* согласие 152-ФЗ (только в форме замечания) */
.aic-consent { padding: 9px 12px 0; flex: 0 0 auto; }
.aic-consent__lab { display: flex; gap: 7px; align-items: flex-start; cursor: pointer; }
.aic-consent__box {
  flex: 0 0 auto;
  width: 15px; height: 15px;
  margin: 1px 0 0;
  accent-color: var(--aic-accent);
}
.aic-consent__txt { font-size: 11.5px; line-height: 1.35; color: var(--aic-muted); }
.aic-consent__link {
  display: inline-block;
  margin: 3px 0 0 22px;
  font-size: 11.5px;
  color: var(--aic-accent);
  text-decoration: underline;
}
html.dark-theme .aic-consent__link { color: var(--aic-accent-2); }
.aic-consent__err {
  margin: 6px 0 0 22px;
  font-size: 11.5px;
  color: var(--aic-danger);
}
.aic-consent__err[hidden] { display: none; }

/* пока открыт чат — блок контактов не мешает */
.contactdock { transition: opacity .18s ease, transform .18s ease; }
body.aic-open .contactdock { opacity: 0; pointer-events: none; transform: translateY(14px); }

/* ---------------------------------------------------------------- мобильные */
@media (max-width: 768px) {
  /* плавающая кнопка чата — строго в правый нижний угол, 44×44,
     с учётом шторки мобильного браузера */
  .aic-fab {
    right: 12px;
    bottom: calc(82px + env(safe-area-inset-bottom, 0px));
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
    gap: 0;
  }
  .aic-fab__ic { width: 22px; height: 22px; }
  .aic-fab__t { display: none; }

  /* почти вся ширина экрана, отступы 10px; высота — по dvh и без уезда
     за экран при открытой клавиатуре */
  .aic-panel {
    left: 10px;
    right: 10px;
    bottom: calc(10px + var(--aic-kb, 0px));
    width: auto;
    max-width: none;
    height: min(650px, calc(var(--aic-vh, 100dvh) - 20px));
    max-height: calc(var(--aic-vh, 100dvh) - 20px);
    border-radius: 18px;
  }
  .aic-head { padding: 9px 9px 9px 12px; }
  .aic-mode { font-size: .76rem; }
  .aic-form__grid { grid-template-columns: 1fr; }
  .aic-log { padding: 10px; }
  .aic-bubble { font-size: 13.5px; }
  .aic-cardbox { max-width: 100%; }
  .aic-copy { opacity: 1; }
  .aic-hint { display: none; }

  /* на страницах есть глобальное button{width:100%} (≤560px) — оно растягивает
     кнопки, поэтому ширину задаём явно */
  .aic-fab { width: 44px; height: 44px; }
  .aic-hbtn { width: 30px; }
  .aic-send { width: 34px; }
  .aic-send--wide { width: 100%; }
  .aic-retry { width: auto; }
  .aic-chip { width: auto; }
}

@media (max-width: 360px) {
  .aic-panel { left: 6px; right: 6px; height: min(650px, calc(var(--aic-vh, 100dvh) - 12px)); max-height: calc(var(--aic-vh, 100dvh) - 12px); }
  .aic-head__sub { display: none; }
}

/* очень низкие экраны (ландшафт телефона) — окно короче, лента остаётся */
@media (max-height: 480px) {
  .aic-panel { height: calc(var(--aic-vh, 100dvh) - 20px); max-height: calc(var(--aic-vh, 100dvh) - 20px); }
  .aic-head__sub { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .aic-panel { animation: none; }
  .aic-fab, .contactdock, .aic-copy { transition: none; }
  .aic-skel__line, .aic-skel__dot, .aic-send__ic--spin { animation: none; }
  .aic-log { scroll-behavior: auto; }
}

/* --------------------------------------------------- сброс глобальных кнопок
   style.css задаёт всем button{padding:11px 18px;min-height:44px;box-shadow:…}
   и на ширине ≤560px — button{width:100%}. Здесь возвращаем кнопкам виджета
   собственные размеры: иначе иконки в шапке схлопываются в ноль, а чипсы
   превращаются в широкие плашки. */
.aic-root button {
  min-height: 0;
  box-shadow: none;
  text-transform: none;
  letter-spacing: normal;
}
.aic-root .aic-fab { box-shadow: var(--aic-shadow-sm); }
.aic-root .aic-fab:hover { box-shadow: var(--aic-shadow); }
.aic-root .aic-mode { min-height: 38px; }
.aic-root .aic-send--wide { min-height: 44px; }
.aic-root .aic-chip { min-height: 0; }
.aic-root .aic-copy { width: 26px; height: 26px; min-width: 26px; }
@media (max-width: 768px) {
  .aic-root .aic-copy { width: 30px; height: 30px; min-width: 30px; }
  .aic-root .aic-mode { width: auto; }
  .aic-root .aic-chip { width: auto; }
  .aic-root .aic-retry { width: auto; }
  .aic-root .aic-hbtn { width: 30px; }
  .aic-root .aic-send { width: 34px; }
  /* широкие кнопки («Отправить замечание») остаются во всю ширину:
     иначе правило выше превращает их в круглые иконки */
  .aic-root .aic-send--wide {
    width: 100%;
    border-radius: 11px;
    padding: 10px 12px;
    font-size: .82rem;
    white-space: nowrap;
  }
}

/* --- вложения к замечанию: файл/буфер --- */
.aic-fb-attach { margin-top: 10px; }
.aic-fb-file {
  position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none;
}
.aic-fb-attachbtn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: 999px;
  border: 1px dashed var(--aic-line, #4b5a6b);
  background: transparent; color: var(--aic-text);
  font: inherit; font-size: 13px; cursor: pointer;
}
.aic-fb-attachbtn:hover { border-color: var(--aic-accent); color: var(--aic-accent); }
.aic-fb-attachbtn:focus-visible { outline: 3px solid #f0a202; outline-offset: 1px; }
.aic-fb-gal {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 9px;
}
.aic-fb-gal[hidden] { display: none !important; }
.aic-fb-thumb { position: relative; width: 78px; height: 78px; }
.aic-fb-thumbimg {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--aic-line, #4b5a6b);
  display: block;
}
.aic-fb-thumbx {
  position: absolute; top: -6px; right: -6px;
  width: 22px; height: 22px; border-radius: 50%;
  border: none; background: #d33; color: #fff;
  font-size: 12px; line-height: 1; cursor: pointer;
}
.aic-fb-hint { margin-top: 7px; font-size: 11.5px; line-height: 1.4; color: var(--aic-muted); }

/* ==========================================================================
   КАЛЬКУЛЯТОРНЫЙ РЕЖИМ (перенесён из виджета «ИИ-помощник: Расчёт пожарного риска»)
   ========================================================================== */
.aic-calc-stat {
  margin: 6px 12px 0;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--aic-soft, rgba(30, 58, 95, .06));
  color: var(--aic-dim, #5a6b80);
  font-size: 12px;
  line-height: 1.35;
}
.aic-calc-consent {
  margin: 8px 12px 0;
  padding: 8px 10px;
  border: 1px solid var(--aic-line, rgba(30, 58, 95, .14));
  border-radius: 10px;
  background: var(--aic-soft, rgba(30, 58, 95, .04));
  font-size: 12px;
  line-height: 1.4;
}
.aic-calc-consent__lab {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
}
.aic-calc-consent__box {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin: 1px 0 0;
  accent-color: #1e3a5f;
}
.aic-calc-consent__txt { color: var(--aic-dim, #5a6b80); }
.aic-calc-consent__link { color: #1e3a5f; text-decoration: underline; }
.aic-calc-consent__hint {
  margin-top: 6px;
  color: #a5372c;
  font-size: 12px;
}
.aic-chip--calc {
  border-color: #1e3a5f;
  font-weight: 600;
}
.aic-calc-box { margin-top: 6px; }
.aic-calc-sug {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 2px 0;
}
.aic-calc-sug__v { flex: 1 1 180px; }
.aic-calc-note { flex: 1 1 100%; color: #1e6b3a; font-size: 12px; }
.aic-calc-warn { color: #a5372c; font-size: 13px; margin: 2px 0; }
.aic-calc-row { margin-top: 8px; }
.aic-calc-flash {
  outline: 2px solid #1e6b3a !important;
  outline-offset: 1px;
}
html.dark-theme .aic-calc-stat,
html.dark-theme .aic-calc-consent {
  background: rgba(255, 255, 255, .05);
}

/* калькуляторные элементы: увеличенные touch-таргеты */
.aic-chip--calc {
  min-height: 40px;
  padding: 9px 14px;
  font-size: 12.5px;
}
.aic-calc-consent__box {
  width: 20px;
  height: 20px;
  margin: 0;
}

/* touch-таргеты общего виджета: не ниже 36px */
.aic-root .aic-chip { min-height: 40px; padding-top: 9px; padding-bottom: 9px; }
.aic-root .aic-clear,
.aic-root .aic-hbtn { min-height: 36px; min-width: 36px; }
