:root {
  --bg: #ffffff; --sidebar: #f9f9f9; --text: #0d0d0d; --muted: #8f8f8f;
  --border: #e6e6e6; --hover: #ececec; --accent: #0d0d0d; --accent-text: #fff;
  --user: #f4f4f4; --shadow: 0 2px 14px rgba(0,0,0,.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
          "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg);
       font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
button { font-family: inherit; }
a { color: inherit; text-decoration: none; }

.logo { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px;
        background: var(--accent); color: #fff; border-radius: 8px; font-size: 11px; font-weight: 700;
        letter-spacing: .3px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center;
              background: radial-gradient(1100px 460px at 50% -8%, #f2f3f5, #fff); padding: 20px; }
.login-card { background: #fff; border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow);
              width: 360px; padding: 34px 30px; display: flex; flex-direction: column; align-items: center;
              gap: 6px; animation: pop .35s cubic-bezier(.2,.8,.2,1); }
.login-logo { width: 46px; height: 46px; background: var(--accent); color: #fff; border-radius: 13px;
              display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px;
              margin-bottom: 8px; }
.login-card h1 { font-size: 20px; margin: 0; font-weight: 600; }
.login-card .sub { margin: 0 0 14px; color: var(--muted); font-size: 13px; text-align: center; }
.login-form { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.login-form input { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; font-size: 14px;
                    transition: border-color .15s, box-shadow .15s; }
.login-form input:focus { outline: none; border-color: #b5b5b5; box-shadow: 0 0 0 3px rgba(0,0,0,.04); }
.login-form button { margin-top: 4px; padding: 12px; border: none; border-radius: 12px; background: var(--accent);
                     color: #fff; font-size: 15px; font-weight: 500; cursor: pointer;
                     transition: opacity .15s, transform .05s; }
.login-form button:hover { opacity: .88; }
.login-form button:active { transform: scale(.99); }
.login-form .remember { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #555; }
.login-form .remember input { width: auto; padding: 0; margin: 0; }
.error { background: #fdeaea; color: #c0392b; padding: 9px 12px; border-radius: 10px; font-size: 13px; }

/* ---------- профиль (анкета + согласие на ПДн), переиспользует .login-* ---------- */
.login-card.profile-card { max-width: 460px; }
.login-form select { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px;
  font-size: 14px; background: #fff; width: 100%; }
.login-form select:focus { outline: none; border-color: #b5b5b5; box-shadow: 0 0 0 3px rgba(0,0,0,.04); }
.login-form label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: #555; text-align: left; }
.login-form label.consent { display: flex; align-items: flex-start; gap: 9px; font-size: 12.5px;
  color: #444; text-align: left; line-height: 1.5; }
.login-form label.consent input { width: auto; margin-top: 3px; flex-shrink: 0; }
.consent-note { font-size: 11.5px; color: var(--muted); line-height: 1.5; text-align: left; margin: 2px 0 4px; }

/* ---------- app shell ---------- */
.app { display: flex; height: 100vh; }
.sidebar { width: 264px; flex-shrink: 0; background: var(--sidebar); border-right: 1px solid var(--border);
           display: flex; flex-direction: column; padding: 12px 10px; }
.side-top { display: flex; align-items: center; gap: 9px; padding: 8px 8px 12px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15px; cursor: pointer; }
.brand:hover { opacity: .8; }
.brand-text { font-weight: 600; font-size: 15px; }
.side-collapse { margin-left: auto; flex-shrink: 0; width: 30px; height: 30px; border: none; background: none;
                 cursor: pointer; color: var(--muted); border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.side-collapse svg { width: 20px; height: 20px; }
.side-collapse:hover { background: var(--hover); color: var(--text); }
.side-expand { display: none; position: relative; width: 30px; height: 30px; border: none; background: none;
               cursor: pointer; padding: 0; align-items: center; justify-content: center; }
.side-expand .expand-ic { position: absolute; width: 20px; height: 20px; color: var(--text); opacity: 0; transition: opacity .12s; }
.side-expand:hover .logo { opacity: 0; }
.side-expand:hover .expand-ic { opacity: 1; }
.new-chat { display: flex; align-items: center; gap: 9px; width: 100%; padding: 10px 12px; margin-bottom: 6px;
            background: #fff; border: 1px solid var(--border); border-radius: 12px; font-size: 14px;
            cursor: pointer; color: var(--text); transition: background .15s; }
.new-chat:hover { background: var(--hover); }
.new-chat svg { width: 16px; height: 16px; opacity: .8; }
.history { flex: 1; overflow-y: auto; margin: 6px 0; display: flex; flex-direction: column; gap: 2px; }
.history-item { display: flex; align-items: center; gap: 4px; padding: 9px 8px 9px 12px; border-radius: 10px;
                font-size: 14px; cursor: pointer; color: var(--text); transition: background .15s; }
.history-item:hover { background: var(--hover); }
.history-item.active { background: var(--hover); font-weight: 500; }
.hi-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hi-del, .hi-export { opacity: 0; flex-shrink: 0; border: none; background: none; color: var(--muted);
          cursor: pointer; line-height: 1; padding: 0 4px; border-radius: 6px;
          transition: opacity .12s, background .12s; }
.hi-del { font-size: 17px; }
.hi-export { font-size: 18px; font-weight: 700; }
.history-item:hover .hi-del, .history-item:hover .hi-export { opacity: 1; }
.hi-del:hover, .hi-export:hover { background: #dcdcdc; color: #333; }

/* выпадающее меню экспорта у «⋮» */
.dropdown { position: fixed; z-index: 50; background: #fff; border: 1px solid var(--border); border-radius: 10px;
            box-shadow: 0 6px 24px rgba(0,0,0,.14); padding: 4px; min-width: 170px; animation: pop .12s ease; }
.dd-item { display: block; width: 100%; text-align: left; padding: 8px 12px; border: none; background: none;
           font-size: 14px; color: var(--text); cursor: pointer; border-radius: 7px; }
.dd-item:hover { background: var(--hover); }
.dd-head { padding: 6px 12px 3px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.dd-item.danger { color: #c0392b; }
.dd-item.danger:hover { background: #fdecea; }
.dd-head-back { display: flex; align-items: center; gap: 6px; padding: 4px 8px 6px 4px; }
.dd-back { border: none; background: none; cursor: pointer; color: var(--muted); padding: 3px 6px; border-radius: 6px;
           display: flex; align-items: center; }
.dd-back:hover { background: var(--hover); color: var(--text); }
.dd-head-back span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; font-size: 14px;
            cursor: pointer; color: var(--text); background: none; border: none; text-align: left; width: 100%;
            transition: background .15s; }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--hover); font-weight: 500; }
.nav-item svg { width: 17px; height: 17px; opacity: .7; flex-shrink: 0; }
/* «Справка» с подменю. Раскрывается по наведению И по фокусу/классу open — на тач-экране и с
   клавиатуры hover недоступен, а пункты меню должны быть достижимы всегда. */
.nav-group { position: relative; }
.nav-caret { margin-left: auto; opacity: .55; transition: transform .15s; }
.nav-group:hover .nav-caret, .nav-group.open .nav-caret { transform: translateX(2px); }
/* Раскрывается ВВЕРХ: «Справка» — последний пункт меню и стоит у нижнего края сайдбара,
   вниз подменю уходило за пределы экрана. */
.nav-menu { display: none; position: absolute; left: calc(100% - 6px); bottom: 0; z-index: 40; min-width: 232px;
            background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 6px;
            box-shadow: var(--shadow); }
.nav-group:hover .nav-menu, .nav-group:focus-within .nav-menu, .nav-group.open .nav-menu { display: block; }
/* Пункты — и ссылки, и кнопка запуска тура: сбрасываем браузерные стили кнопки, иначе она выглядит
   выделенной среди ссылок сама по себе, без наведения. */
.nav-menu-item { display: block; width: 100%; padding: 8px 10px; border: none; background: none;
                 border-radius: 8px; font: inherit; font-size: 13.5px; color: var(--text); text-align: left;
                 white-space: nowrap; cursor: pointer; transition: background .15s; }
.nav-menu-item:hover, .nav-menu-item:focus-visible { background: var(--hover); }
/* в свёрнутом сайдбаре подменю выезжает от иконки и не должно перекрывать саму полосу */
.app.collapsed .nav-menu { left: calc(100% + 4px); }

/* Инструменты под ответом: копировать и поделиться. Подпись — по hover/фокусу, без JS-тултипов. */
.msg-tools { display: flex; gap: 4px; margin-top: 6px; }
.tool-btn { position: relative; display: inline-flex; align-items: center; justify-content: center;
            width: 30px; height: 30px; border: none; border-radius: 8px; background: none; cursor: pointer;
            color: var(--muted); transition: background .15s, color .15s; }
.tool-btn:hover { background: var(--hover); color: var(--text); }
.tool-btn.ok { color: #16794c; }
.tool-btn::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%;
                   transform: translateX(-50%); padding: 5px 9px; border-radius: 7px; font-size: 12px;
                   line-height: 1.3; white-space: nowrap; background: var(--accent); color: var(--accent-text);
                   opacity: 0; pointer-events: none; transition: opacity .12s; }
.tool-btn:hover::after, .tool-btn:focus-visible::after, .tool-btn.ok::after { opacity: 1; }

.side-bottom { margin-top: auto; border-top: 1px solid var(--border); padding-top: 10px;
               display: flex; align-items: center; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; flex-shrink: 0;
          display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; }
.uname { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout { font-size: 13px; color: var(--muted); padding: 6px 9px; border-radius: 8px;
          transition: background .15s, color .15s; }
.logout:hover { background: var(--hover); color: var(--text); }

/* поиск по чатам */
.search-box { padding: 4px 2px 8px; }
.search-box input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px;
                    font-size: 14px; font-family: inherit; }
.search-box input:focus { outline: none; border-color: #b5b5b5; }

/* свёрнутый сайдбар (компактный вид) */
.app.collapsed .sidebar { width: 64px; }
.app.collapsed .nc-text, .app.collapsed .brand, .app.collapsed .side-collapse,
.app.collapsed .history, .app.collapsed .search-box { display: none; }
.app.collapsed .side-expand { display: flex; }
.app.collapsed .new-chat, .app.collapsed .nav-item, .app.collapsed .side-top { justify-content: center; }
.app.collapsed .user-chip { justify-content: center; }

/* ---------- main / chat ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header { height: 54px; display: flex; align-items: center; padding: 0 22px; border-bottom: 1px solid var(--border); }
.chat-title { font-weight: 600; font-size: 15px; }
.chat-scroll { flex: 1; overflow-y: auto; }
.chat-col { max-width: 760px; margin: 0 auto; padding: 26px 20px 8px; }
.hero { text-align: center; padding: 0 10px 26px; animation: fadeInUp .4s ease; }
.hero h1 { font-size: 27px; font-weight: 600; margin: 0 0 10px; }
.hero p { color: var(--muted); font-size: 14px; max-width: 470px; margin: 0 auto; line-height: 1.55; }
.messages { display: flex; flex-direction: column; gap: 18px; padding-bottom: 10px; }

.msg { display: flex; flex-direction: column; animation: fadeInUp .28s ease; }
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: stretch; }
.bubble { font-size: 15px; line-height: 1.6; word-wrap: break-word; }
.msg.user .bubble { max-width: 78%; background: var(--user); padding: 11px 15px; border-radius: 18px; white-space: pre-wrap; }
.msg.assistant .bubble { max-width: 100%; }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul { margin: 8px 0; padding-left: 20px; }
.bubble li { margin: 4px 0; }
.bubble strong { font-weight: 600; }
.bubble p.sec { margin-top: 14px; }
.bubble p.sec:first-child { margin-top: 0; }
/* T17: таблицы в ответе — с горизонтальным скроллом (не ломают вёрстку на узком экране) */
.bubble .tbl-wrap { overflow-x: auto; margin: 10px 0; -webkit-overflow-scrolling: touch; }
.bubble table { border-collapse: collapse; width: 100%; font-size: 14px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
.bubble thead th { background: var(--sidebar); font-weight: 600; white-space: nowrap; }
.bubble tbody tr:nth-child(even) { background: var(--user); }
/* U6: строки за порогом свёрнутой таблицы. Класс ставит JS — число видимых строк живёт ТОЛЬКО
   там (TBL_VISIBLE_ROWS), иначе порог разъехался бы между стилями и логикой. */
.bubble .row-hidden { display: none; }
.tbl-more { margin: -4px 0 12px; padding: 5px 11px; font: inherit; font-size: 13px; color: var(--muted);
            background: none; border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
            transition: background .15s; }
.tbl-more:hover { background: var(--hover); color: var(--text); }
.tbl-more:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
.sources { margin-top: 10px; font-size: 13px; }
.sources summary { cursor: pointer; color: var(--muted); list-style: none; display: inline-flex; align-items: center;
                   gap: 6px; padding: 5px 11px; border: 1px solid var(--border); border-radius: 999px; transition: background .15s; }
.sources summary::-webkit-details-marker { display: none; }
.sources summary:hover { background: var(--hover); }
.sources[open] summary { margin-bottom: 8px; }
.src-item { display: block; padding: 6px 2px; border-top: 1px solid var(--border); color: #2563eb;
            text-decoration: none; transition: color .15s; }
.src-item:first-of-type { border-top: none; }
.src-item:hover { color: #1d4ed8; text-decoration: underline; }

.typing { display: inline-flex; gap: 5px; padding: 6px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: #c4c4c4; animation: blink 1.3s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }

.composer-area { padding: 10px 20px 16px; display: flex; flex-direction: column; }
.composer-disclaimer { width: 100%; max-width: 50vw; margin: 10px auto 0; text-align: center; color: var(--muted);
                       font-size: 12px; line-height: 1.5; }
.composer-disclaimer a { color: var(--muted); text-decoration: underline; }
.composer-disclaimer a:hover { color: var(--text); }
/* Метка релиза. Отдельной строкой и слабее основного текста: это служебная справка «что сейчас
   на сервере», а не часть согласия с условиями — смешивать их в один абзац значило бы разбавлять
   юридическую оговорку технической. */
.composer-version { display: block; margin-top: 4px; opacity: .65; font-size: 11px;
                    letter-spacing: .01em; }
/* Пометка релиза на остальных страницах (чат печатает свою внутри дисклеймера). Служебная
   справка «что сейчас на сервере»: в углу, слабо, и НЕ перехватывает клики — иначе она накрыла бы
   собой то, что под ней, на узких экранах. */
.release-marker { position: fixed; right: 10px; bottom: 8px; z-index: 5; pointer-events: none;
                  color: var(--muted); opacity: .55; font-size: 11px; letter-spacing: .01em; }
/* Короткая оговорка над полем ввода — только когда диалог начат: на пустом экране ту же роль
   играет hero-блок, и две надписи подряд превращаются в шум. */
.composer-notice { display: none; width: 100%; max-width: 50vw; margin: 0 auto 8px; text-align: center;
                   color: var(--muted); font-size: 12px; line-height: 1.4; }
.main:not(.empty) .composer-notice { display: block; }

/* пустой экран: скролл прячем, приветствие + инпут + дисклеймер по центру; после ввода композер уходит вниз */
.main.empty .chat-scroll { display: none; }
.main.empty .composer-area { flex: 1; justify-content: center; }
.main:not(.empty) .hero { display: none; }
.composer { width: 100%; max-width: 50vw; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
            background: #fff; border: 1px solid var(--border); border-radius: 24px; padding: 8px 8px 8px 20px;
            box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: #c9c9c9; box-shadow: 0 4px 22px rgba(0,0,0,.09); }
.composer textarea { flex: 1; border: none; resize: none; font-size: 15px; font-family: inherit; line-height: 1.5;
                     overflow-y: hidden; padding: 8px 0; background: transparent; }
.composer textarea:focus { outline: none; }
.send-btn { flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--accent);
            color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer;
            transition: opacity .15s, transform .08s; }
.send-btn:hover { opacity: .85; }
.send-btn:active { transform: scale(.92); }
.send-btn:disabled { background: #d0d0d0; cursor: default; }
.composer-hint { max-width: 760px; margin: 8px auto 0; text-align: center; color: var(--muted); font-size: 12px; }

/* ---------- обратная связь на ответ (звёзды + исправление + коммент к диалогу) ---------- */
.fb-bar { margin-top: 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.fb-rate { display: inline-flex; align-items: center; gap: 8px; }
.fb-cap { font-size: 13px; }
.fb-stars { display: inline-flex; gap: 2px; }
.fb-star { border: none; background: none; cursor: pointer; padding: 0 1px; font-size: 18px; line-height: 1;
           color: #d4d4d4; transition: color .1s, transform .05s; }
.fb-star:hover { transform: scale(1.12); }
.fb-star.on { color: #f5b301; }
.fb-actions { display: inline-flex; gap: 12px; }
.fb-link { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 13px; padding: 0;
           text-decoration: underline; text-underline-offset: 2px; transition: color .12s; }
.fb-link:hover { color: var(--text); }
.fb-link.primary { color: var(--text); font-weight: 500; }
.fb-panel { flex-basis: 100%; display: flex; flex-direction: column; gap: 6px; margin-top: 2px; }
.fb-ta { width: 100%; max-width: 520px; padding: 8px 11px; border: 1px solid var(--border); border-radius: 10px;
         font-size: 14px; font-family: inherit; resize: vertical; }
.fb-ta:focus { outline: none; border-color: #b5b5b5; }
.fb-save { align-self: flex-start; padding: 7px 14px; border: none; border-radius: 9px; background: var(--accent);
           color: #fff; font-size: 13px; cursor: pointer; transition: opacity .15s; }
.fb-save:hover { opacity: .88; }
.fb-flash { color: #15803d; font-size: 12px; }
.answer-flag { display: flex; align-items: flex-start; gap: 8px; margin-top: 10px; padding: 9px 12px;
               background: #fef3c7; color: #92400e; border-radius: 10px; font-size: 13px; line-height: 1.5; }
.answer-flag svg { flex-shrink: 0; margin-top: 1px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center;
         justify-content: center; z-index: 20; padding: 20px; animation: fade .2s ease; }
.modal-card { background: #fff; border-radius: 18px; padding: 26px; width: 440px; max-width: 100%;
              display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
              animation: pop .3s cubic-bezier(.2,.8,.2,1); }
.modal-card h2 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: #555; }
.modal-card select, .modal-card textarea { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
              font-size: 14px; font-family: inherit; transition: border-color .15s; }
.modal-card select:focus, .modal-card textarea:focus { outline: none; border-color: #b5b5b5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.modal-actions button { padding: 10px 18px; border-radius: 10px; border: none; background: var(--accent);
              color: #fff; font-size: 14px; cursor: pointer; transition: opacity .15s; }
.modal-actions button:hover { opacity: .88; }
.btn-secondary { background: #efefef !important; color: #333 !important; }
.thanks { color: #15803d; font-size: 14px; text-align: center; }
.modal-card .field-row { display: flex; gap: 10px; }
.modal-card .field-row label { flex: 1; }
.modal-card input[type="date"] { padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px;
                                 font-size: 14px; font-family: inherit; }
.modal-card label.checkbox { flex-direction: row; align-items: center; gap: 8px; }
.modal-card label.checkbox input { width: auto; }

/* ---------- admin ---------- */
.admin-header { height: 54px; display: flex; align-items: center; gap: 14px; padding: 0 22px;
                border-bottom: 1px solid var(--border); }
.admin-header .spacer { flex: 1; }
.admin-header .muted { color: var(--muted); font-size: 13px; }
.admin-header .link { font-size: 14px; color: #2563eb; }
.admin-header .link:hover { text-decoration: underline; }
.admin { max-width: 900px; margin: 0 auto; padding: 24px 20px; }
.totals { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px;
          margin-bottom: 16px; font-size: 14px; }
.totals .muted { display: block; margin-top: 3px; font-size: 12px; }
.thread-meta { color: var(--muted); font-size: 12px; font-weight: 400; }
.tok { color: #6b7280; font-size: 11px; margin-left: 8px; }
.user-block { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px;
              margin-bottom: 16px; animation: fadeInUp .3s ease; }
.user-block h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
.user-block h2 .role { font-size: 11px; color: #fff; background: #6b7280; padding: 2px 8px; border-radius: 999px;
              vertical-align: middle; margin-left: 4px; }
.user-block h2 .count { font-size: 13px; color: var(--muted); font-weight: 400; }
.fb-list { background: #f0f9f4; border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }
.fb-list h3 { font-size: 11px; margin: 0 0 6px; color: #15803d; text-transform: uppercase; letter-spacing: .5px; }
.fb { font-size: 13px; padding: 5px 0; border-top: 1px solid #dcefe3; }
.fb:first-of-type { border-top: none; }
.thread { margin: 6px 0; }
.thread summary { cursor: pointer; font-size: 13px; color: #2563eb; padding: 5px 0; }
.log-msg { font-size: 13px; padding: 8px 12px; margin: 5px 0; border-radius: 10px; background: #f7f8fa; line-height: 1.55; }
.log-msg.user { background: #eef2ff; }
.log-msg .content { white-space: pre-wrap; }
.flag { display: inline-block; margin-left: 8px; font-size: 11px; color: #b45309; background: #fef3c7;
        padding: 1px 7px; border-radius: 6px; }
.ts { color: #bbb; font-size: 11px; margin-left: 8px; }
.empty { color: #aaa; font-size: 13px; }

/* ---------- dashboard ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tab { padding: 10px 16px; border: none; background: none; font-size: 14px; color: var(--muted); cursor: pointer;
       border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.tab-panel { animation: fadeInUp .25s ease; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.kpi-val { font-size: 24px; font-weight: 700; }
.kpi-label { font-size: 13px; margin-top: 2px; }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 3px; }
/* тренд-чипы на плитках (к прошлому периоду): зелёный=хорошо, красный=плохо, серый=нейтр./новое */
.kpi-tr { margin-top: 6px; }
.trend { font-size: 11px; font-weight: 600; white-space: nowrap; }
.trend.tr-good { color: #1e874b; }
.trend.tr-bad { color: #c0392b; }
.trend.tr-flat, .trend.tr-new { color: var(--muted); }
.trend-note { font-size: 11px; color: var(--muted); margin: -10px 2px 16px; }
/* приёмка ≥70%: зелёный = порог пройден, красный = ниже */
.pass { color: #1e874b; }
.fail { color: #c0392b; }

/* ---- панель фильтров (единый срез для всех вкладок) ---- */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; padding: 12px 14px;
  background: #fff; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 16px; }
.f-field { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); }
.f-field span { text-transform: uppercase; letter-spacing: .4px; }
.f-field input, .f-field select { padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; font-family: inherit; background: #fff; color: var(--text); }
.f-field input:focus, .f-field select:focus { outline: none; border-color: #b5b5b5; }
.f-apply { padding: 8px 16px; border: none; border-radius: 9px; background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 500; cursor: pointer; }
.f-apply:hover { opacity: .88; }
.f-reset { font-size: 13px; color: #2563eb; align-self: center; }
.f-reset:hover { text-decoration: underline; }
.f-right { margin-left: auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.f-stamp { font-size: 11px; color: var(--muted); }
.f-export { font-size: 12px; color: var(--muted); }
.f-export a { color: #2563eb; margin-left: 4px; }
.f-export a:hover { text-decoration: underline; }

/* ---- здоровье системы (оперативный статус инфраструктуры) ---- */
.health .hstat { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; }
.health .hstat.sub { padding-left: 15px; font-size: 12.5px; }
.health .hstat b { font-weight: 600; }
.health .hmeta { margin-left: auto; font-size: 11px; color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: #cbd5e1; }
.dot.ok { background: #1e874b; }
.dot.bad { background: #c0392b; }

/* ---- лента последних вопросов ---- */
.feed { display: flex; flex-direction: column; }
.feed-row { display: flex; align-items: baseline; gap: 12px; padding: 7px 0; border-top: 1px solid var(--border); }
.feed-row:first-child { border-top: none; }
.feed-q { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-meta { flex-shrink: 0; font-size: 11px; color: var(--muted); }

/* ---- вкладка «Плохие ответы» (триаж ≤2★) ---- */
.bad-intro { font-size: 13px; color: var(--muted); background: #fff; border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 16px; margin-bottom: 14px; line-height: 1.6; }
.bad-card { background: #fff; border: 1px solid var(--border); border-left: 4px solid #c0392b;
  border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.bad-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 12px; }
.bad-card .stars { color: #fff; background: #c0392b; padding: 1px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.bad-who { font-weight: 600; font-size: 13px; }
.bad-link { margin-left: auto; color: #2563eb; cursor: pointer; }
.bad-link:hover { text-decoration: underline; }
.bad-q { font-size: 14px; margin: 4px 0; line-height: 1.5; }
.lbl { display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); margin-right: 8px; vertical-align: 1px; }
.bad-a { margin: 6px 0; font-size: 13px; }
.bad-a > summary { cursor: pointer; color: var(--muted); list-style: none; }
.bad-a > summary::-webkit-details-marker { display: none; }
.bad-a-full { white-space: pre-wrap; margin-top: 8px; padding: 10px 12px; background: #f7f8fa;
  border-radius: 8px; line-height: 1.55; }
.bad-c { font-size: 13px; color: #555; margin-top: 6px; }
.bad-fix { font-size: 13px; color: #15803d; margin-top: 4px; }

/* смысловые цвета баров (оценки/регионы): хорошо/средне/плохо/нет данных */
.bar-fill.good { background: #1e874b; }
.bar-fill.mid { background: #eab308; }
.bar-fill.bad { background: #c0392b; }
.bar-fill.na { background: #cbd5e1; }

/* приёмка по регионам */
.region-row .wide-label { width: 190px; }
.region-meta { font-size: 11px; color: var(--muted); flex-shrink: 0; margin-left: 8px; white-space: nowrap; }

/* группирующие заголовки + вторичные KPI (объём/затраты — под гейтом) */
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
  margin: 22px 2px 10px; font-weight: 600; }
.kpis.secondary { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); margin-bottom: 6px; }
.kpis.secondary .kpi-val { font-size: 20px; }

/* бейдж-счётчик на вкладке «Плохие ответы» */
.tab-badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 999px;
  background: #e5e7eb; color: #555; font-size: 11px; font-weight: 600; text-align: center; vertical-align: 1px; }
.tab-badge.warn { background: #fdecec; color: #c0392b; }
.ul-region { font-size: 11px; color: #2563eb; background: #eef2ff; padding: 1px 7px; border-radius: 999px; font-weight: 500; }

.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.card.wide { grid-column: 1 / -1; }
.card h3 { font-size: 12px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }

.bar-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-size: 13px; }
.bar-label { width: 92px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 16px; background: #f1f2f4; border-radius: 5px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 5px; min-width: 2px; transition: width .4s ease; }
.bar-fill.cost { background: #2563eb; }
.bar-val { width: 56px; text-align: right; flex-shrink: 0; color: var(--muted); }

.daychart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; }
.daybar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.daybar-fill { width: 100%; max-width: 34px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; transition: height .4s ease; }
.daybar em { font-size: 10px; color: var(--muted); margin-top: 5px; font-style: normal; }

.fb-stat { font-size: 14px; padding: 5px 0; }
.corr { font-size: 13px; padding: 8px 0; border-top: 1px solid var(--border); }
.corr:first-of-type { border-top: none; }
.corr-head { font-weight: 600; display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.corr-ans { color: var(--muted); margin-bottom: 3px; }
.corr-fix { color: #15803d; }

.user-log { background: #fff; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 12px; }
.user-log > summary { display: flex; align-items: center; gap: 12px; padding: 14px 18px; cursor: pointer; list-style: none; }
.user-log > summary::-webkit-details-marker { display: none; }
.user-log > summary::before { content: "▸"; color: var(--muted); flex-shrink: 0; transition: transform .15s; }
.user-log[open] > summary::before { transform: rotate(90deg); }
.ul-name { font-weight: 600; font-size: 15px; }
.ul-meta { font-size: 12px; color: var(--muted); margin-left: auto; text-align: right; }
.ul-body { padding: 0 18px 16px; }

@media (max-width: 720px) {
  .charts { grid-template-columns: 1fr; }
  .region-row .wide-label { width: 120px; }
  .feed-row { flex-direction: column; gap: 2px; }
  .feed-q { white-space: normal; }
}

/* ---------- keyframes ---------- */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes blink { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

/* ---------- mobile (сайдбар → off-canvas «шторка») ---------- */
.menu-btn { display: none; }        /* гамбургер — только на мобиле */
.drawer-backdrop { display: none; }

@media (max-width: 760px) {
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px;
    margin: 0 8px 0 -6px; border: none; background: none; color: var(--text); cursor: pointer; border-radius: 9px; flex-shrink: 0; }
  .menu-btn:hover { background: var(--hover); }
  .menu-btn svg { width: 22px; height: 22px; }

  /* сайдбар выезжает слева; перекрываем и «свёрнутый» десктопный вид */
  .sidebar, .app.collapsed .sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
    width: 82vw; max-width: 320px; transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 2px 0 22px rgba(0,0,0,.16); }
  .sidebar.open { transform: none; }
  .side-collapse, .side-expand { display: none; }
  .app.collapsed .nc-text, .app.collapsed .brand, .app.collapsed .history { display: revert; }

  .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.42);
    opacity: 0; pointer-events: none; transition: opacity .25s ease; }
  .drawer-backdrop.open { opacity: 1; pointer-events: auto; }

  .chat-col, .composer, .composer-hint, .composer-disclaimer { max-width: 100%; }
  .composer-area { padding: 10px 12px 14px; }
  .hero { padding-top: 24px; }
  .hero h1 { font-size: 22px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .admin, .admin-header { padding-left: 12px; padding-right: 12px; }
}

/* ---------- T16: навигация по вопросам внутри чата (кнопка в композере, слева от «Отправить») ---------- */
.jump-btn { flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border);
            background: var(--bg); color: var(--muted); cursor: pointer; display: flex; align-items: center;
            justify-content: center; transition: background .15s, color .15s; }
.jump-btn:hover { background: var(--hover); color: var(--text); }
.jump-btn svg { width: 18px; height: 18px; }
.jump-menu { position: fixed; z-index: 51; background: #fff; border: 1px solid var(--border); border-radius: 12px;
             box-shadow: var(--shadow); min-width: 240px; max-width: 360px; max-height: 60vh; overflow-y: auto; padding: 6px; }
.jump-head { padding: 6px 10px 8px; font-size: 12px; color: var(--muted); font-weight: 600; }
.jump-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border: none; background: none;
             cursor: pointer; font-size: 13px; color: var(--text); border-radius: 8px;
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.jump-item:hover { background: var(--hover); }
.msg.q-flash .bubble { animation: qflash 1.2s ease; }
@keyframes qflash { 0%, 100% { background: var(--user); } 30% { background: #ffe9a8; } }

/* ---------- правовые и справочные страницы (Условия, Политика, Справочный центр) ---------- */
.doc-wrap { max-width: 860px; margin: 0 auto; padding: 0 20px 60px; }
.doc-head { display: flex; align-items: center; gap: 16px; padding: 16px 0; margin-bottom: 8px;
            border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 5; }
.doc-logo { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
            background: var(--accent); color: #fff; border-radius: 9px; font-size: 12px; font-weight: 700;
            flex-shrink: 0; }
.doc-nav { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13.5px; }
.doc-nav a { color: var(--muted); padding: 4px 0; border-bottom: 2px solid transparent; }
.doc-nav a:hover { color: var(--text); }
.doc-nav a.on { color: var(--text); border-bottom-color: var(--accent); }
.doc-back { margin-left: auto; font-size: 13.5px; color: var(--muted); white-space: nowrap; }
.doc-back:hover { color: var(--text); }

.doc-body h1 { font-size: 27px; margin: 26px 0 6px; }
.doc-body h2 { font-size: 17px; margin: 30px 0 10px; }
.doc-body p, .doc-body li { font-size: 15px; line-height: 1.65; }
.doc-body ul { padding-left: 20px; }
.doc-body li { margin: 5px 0; }
.doc-body a { color: #2563eb; text-decoration: underline; }
.doc-lead { color: var(--text); background: var(--sidebar); border: 1px solid var(--border);
            border-radius: 12px; padding: 14px 16px; margin: 14px 0 4px; }
.doc-meta { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.doc-note { color: var(--muted); font-size: 13.5px; border-top: 1px solid var(--border);
            margin-top: 28px; padding-top: 14px; }

.doc-table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 14px; display: block;
             overflow-x: auto; }
.doc-table th, .doc-table td { border: 1px solid var(--border); padding: 8px 11px; text-align: left;
                               vertical-align: top; }
.doc-table thead th { background: var(--sidebar); font-weight: 600; }

/* FAQ: раскрывающиеся вопросы — без JS, на details/summary */
.faq { border: 1px solid var(--border); border-radius: 12px; padding: 2px 14px; margin: 8px 0;
       background: var(--bg); }
.faq summary { cursor: pointer; padding: 12px 0; font-weight: 500; list-style: none; display: flex;
               align-items: center; gap: 10px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::before { content: "+"; color: var(--muted); font-size: 17px; line-height: 1; width: 14px;
                       flex-shrink: 0; }
.faq[open] summary::before { content: "–"; }
.faq[open] summary { border-bottom: 1px solid var(--border); }
.faq p { margin: 12px 0; }

.doc-foot { display: flex; flex-wrap: wrap; gap: 10px 16px; justify-content: space-between;
            border-top: 1px solid var(--border); margin-top: 34px; padding-top: 14px;
            color: var(--muted); font-size: 13px; }
.doc-foot a { color: var(--muted); text-decoration: underline; }
.doc-foot a:hover { color: var(--text); }

@media (max-width: 720px) {
  .doc-head { flex-wrap: wrap; gap: 10px; }
  .doc-nav { order: 3; width: 100%; }
  .doc-body h1 { font-size: 22px; }
}

/* ссылки на правовые страницы под формой входа */
.login-legal { margin: 14px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); text-align: center; }
.login-legal a { color: var(--muted); text-decoration: underline; }
.login-legal a:hover { color: var(--text); }

/* ---------- онбординг-тур: подсветка области + карточка по центру ---------- */
.tour { position: fixed; inset: 0; z-index: 90; }
body.tour-on { overflow: hidden; }

/* Затемнение — тень самого «окна»: подсветка и фон это один элемент, поэтому переход между
   шагами анимируется одним transition и слои не расходятся. */
.tour-spot { position: fixed; border-radius: 12px; pointer-events: none;
             box-shadow: 0 0 0 9999px rgba(13, 13, 13, .62), 0 0 0 2px rgba(255, 255, 255, .9);
             transition: top .42s cubic-bezier(.22,.8,.24,1), left .42s cubic-bezier(.22,.8,.24,1),
                         width .42s cubic-bezier(.22,.8,.24,1), height .42s cubic-bezier(.22,.8,.24,1); }

/* Карточка не центрируется вслепую: `top` ей задаёт JS, выбирая свободную сторону от подсветки —
   иначе на шаге про поле ввода (оно внизу экрана) карточка накрывает ровно то, что подсвечивает. */
.tour-card { position: fixed; left: 50%; top: 50%; transform: translateX(-50%);
             width: min(430px, calc(100vw - 40px)); background: var(--bg); border-radius: 18px;
             box-shadow: 0 18px 50px rgba(0,0,0,.28); padding: 26px 26px 20px; text-align: center;
             transition: top .42s cubic-bezier(.22,.8,.24,1); }
.tour-card.swap { animation: tourIn .34s cubic-bezier(.22,.8,.24,1); }
@keyframes tourIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); }
                    to   { opacity: 1; transform: translateX(-50%) translateY(0); } }
.tour-step-no { font-size: 11.5px; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); }
.tour-card h2 { font-size: 19px; margin: 8px 0 8px; }
.tour-card p { font-size: 14px; line-height: 1.6; color: #444; margin: 0; }
.tour-skip { position: absolute; top: 12px; right: 14px; border: none; background: none; cursor: pointer;
             color: var(--muted); font-size: 12.5px; padding: 4px 6px; border-radius: 7px; }
.tour-skip:hover { background: var(--hover); color: var(--text); }
.tour-dots { display: flex; justify-content: center; gap: 6px; margin: 18px 0 14px; }
.tour-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); cursor: pointer;
            transition: background .2s, transform .2s; }
.tour-dot.on { background: var(--accent); transform: scale(1.25); }
.tour-nav { display: flex; gap: 10px; justify-content: center; }
.tour-nav button { padding: 10px 20px; border: none; border-radius: 11px; background: var(--accent);
                   color: var(--accent-text); font-size: 14px; cursor: pointer; transition: opacity .15s; }
.tour-nav button:hover { opacity: .88; }
.tour-nav .btn-secondary { background: var(--sidebar); color: var(--text); border: 1px solid var(--border); }

/* Уважаем системную настройку «меньше движения»: подсветка перескакивает сразу, без анимации. */
@media (prefers-reduced-motion: reduce) {
  .tour-spot { transition: none; }
  .tour-card.swap { animation: none; }
}

/* Блокировка отправки: в вопросе нашлись данные, которые нельзя отдавать во внешнюю модель. */
.input-block { display: flex; align-items: flex-start; gap: 9px; width: 100%; max-width: 50vw;
               margin: 0 auto 10px; padding: 11px 14px; border-radius: 12px; font-size: 13px;
               line-height: 1.5; background: #fdf0ec; border: 1px solid #f0c6b8; color: #8a3b1e;
               animation: fadeInUp .2s ease; }
.input-block svg { flex-shrink: 0; margin-top: 1px; }
@media (max-width: 900px) { .input-block { max-width: 100%; } }
/* Мягкое предупреждение: отправка возможна, решение за человеком — отсюда другой тон и кнопка. */
.input-block.soft { background: #fdf6e3; border-color: #ecd9a0; color: #7a5c12; align-items: center; }
.input-block-go { margin-left: auto; flex-shrink: 0; padding: 6px 12px; border: 1px solid #ecd9a0;
                  border-radius: 9px; background: #fff; color: #7a5c12; font-size: 12.5px;
                  cursor: pointer; white-space: nowrap; transition: background .15s; }
.input-block-go:hover { background: #fbf0d6; }
