/* Макет Figma «Ластик — виджет на портале Ньютон», шаг 6 (769:2700); активные
 * состояния кнопок — шаг 2 (769:2498); добавлены только состояния, которых в макете нет.
 * Шрифты локальные (assets/fonts): стенд бывает офлайн, внешний CDN недопустим. */

@font-face {
  font-family: "PT Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/ptsans-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "PT Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/ptsans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}
@font-face {
  font-family: "PT Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/assets/fonts/ptsans-bold-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "PT Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/assets/fonts/ptsans-bold-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}

:root {
  --page-bg: #fafaf8;      /* фон страницы под шапкой и карточек */
  --surface: #ffffff;
  --line: #e6e6e3;         /* границы шапок и карточек */
  --line-input: #d8dee7;   /* граница поля ввода */
  --line-btn: #e1e4e8;     /* граница активной кнопки карточки */
  --line-btn-off: #edeff2; /* граница погашенной кнопки */
  --line-gray: #e3e5e8;    /* neutral/line gray — аватар в шапке портала */

  --ink: #1f2023;          /* текст реплик и заголовок */
  --ink-soft: #747f8b;     /* primary/gray — меню портала, подзаголовок */
  --muted: #8a93a1;        /* сноска композера, выбранная кнопка */
  --muted-2: #9aa1ac;      /* время реплик, плейсхолдер, погашенные кнопки */

  --bubble: #efefec;       /* пузырь сотрудника */
  --history-bg: #f4f7fb;   /* холодный фон панели истории (макет, шаг 3) */
  --chosen-bg: #f2f3f5;    /* нажатая кнопка карточки */

  /* Фирменный градиент: у знака два стопа, у кнопок четыре; угол один. */
  --brand-cool: #1a85b4;
  --brand-warm: #c55c36;
  --brand-badge: linear-gradient(109.89deg, #1a85b4 1.56%, #c55c36 76.56%);
  --brand-button: linear-gradient(109.89deg, #1a85b4 1.56%, #5e7288 28.13%, #8b6c76 51.56%, #c55c36 76.56%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "PT Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--page-bg);
}

.hidden { display: none !important; }

/* --- шапка портала Ньютон (статичная) -------------------------------------- */
.portal {
  height: 90px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.portal-inner {
  max-width: 1440px;
  height: 100%;
  margin: 0 auto;
  padding: 0 22px 0 30px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.portal-logo { width: 212px; height: 52px; flex-shrink: 0; }
.portal-menu {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 44px;
  font-size: 16px;
  line-height: 1.3;
  color: var(--ink-soft);
  text-transform: uppercase;
  white-space: nowrap;
}
.portal-icons { display: flex; align-items: center; gap: 20px; flex-shrink: 0; }
.portal-avatar {
  width: 48px;
  height: 48px;
  margin-right: 32px;
  border-radius: 50%;
  background: var(--line-gray);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.portal-avatar img { width: 17.4px; height: 18.44px; }
.portal-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.portal-icon-bell { width: 24px; height: 33.31px; }
.portal-icon-chat { width: 30px; height: 30px; }
.portal-bell { position: relative; }
.portal-badge {
  position: absolute;
  top: -4px;
  right: -1px;
  width: 24px;
  height: 24px;
  background: url("/assets/badge-ellipse.svg") center / contain no-repeat;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- страница Ластика ------------------------------------------------------- */
/* С2: две колонки в общей ширине содержимого — панель истории 280 и лента.
 * Урезанный вариант макета: содержимое 1055, поля по бокам. */
.page {
  height: calc(100vh - 91px);
  height: calc(100dvh - 91px); /* мобильные с динамической адресной строкой */
  background: var(--page-bg);
  display: flex;
  justify-content: center;
}
/* Рабочая область макета: обе колонки в одном контуре, поля по бокам страницы. */
.workspace {
  width: 1055px;
  max-width: 100%;
  height: 100%;
  display: flex;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.history {
  width: 280px;
  flex-shrink: 0;
  height: 100%;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--history-bg);
  border-right: 1px solid var(--line);
}
.history-empty {
  margin: 0;
  font-size: 13.5px;
  color: var(--muted-2);
}
/* «+ Новый диалог» — акцентная кнопка панели (макет): тёплая рамка, тёмный текст. */
.btn-new {
  height: 40px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1.5px solid var(--brand-warm);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn-new:hover { background: #fff7f3; }
.btn-new-plus { font-size: 18px; font-weight: 400; line-height: 1; color: var(--ink-soft); }

.history-search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-input);
  border-radius: 10px;
  background: var(--surface);
  flex-shrink: 0;
}
.history-search img { width: 16px; height: 16px; opacity: 0.6; }
.history-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
}
.history-search input::placeholder { color: var(--muted-2); }

/* Н7: список чатов занимает остаток панели и прокручивается сам. */
.dialogs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dialogs-group {
  margin: 8px 0 2px;
  font-size: 12px;
  color: var(--muted-2);
}
.dialogs-group:first-child { margin-top: 0; }
.dialog {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  font: inherit;
  cursor: pointer;
  flex-shrink: 0;
}
.dialog:hover { border-color: var(--line-input); }
.dialog.is-active { background: #e9ecf1; border-color: #e9ecf1; }
.dialog.is-active .dialog-title { font-weight: 700; }
.dialog-title {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dialog-date { font-size: 11.5px; color: var(--muted-2); white-space: nowrap; flex-shrink: 0; }
.dialogs-more { margin-top: 4px; flex-shrink: 0; }
.assistant {
  flex: 1; /* остаток ширины рабочей области после панели истории (С2) */
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.assistant-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.assistant-badge {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--brand-badge);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.assistant-badge img { width: 20px; height: 20px; }
.assistant-name { font-size: 17px; font-weight: 700; color: var(--ink); }
.assistant-sub { font-size: 11.5px; color: var(--ink-soft); }

.session { display: flex; flex-direction: column; align-items: stretch; gap: 8px; flex-shrink: 0; }
.session-user { font-size: 11.5px; color: var(--muted-2); white-space: nowrap; }
.session-user:empty { display: none; }
.btn-block { width: 100%; }
.history .btn-ghost { background: var(--surface); }

/* Первичная кнопка — градиент макета; на самой странице чата её нет, только вход. */
.btn-primary {
  height: 34px;
  padding: 0 14px;
  border: none;
  border-radius: 10px;
  background: var(--brand-button);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:disabled { opacity: .45; cursor: default; }
.btn-wide { width: 100%; height: 46px; font-size: 14.5px; }
.btn-ghost {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line-input);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn-ghost:hover { border-color: var(--brand-cool); color: var(--brand-cool); }

/* --- лента ------------------------------------------------------------------ */
.feed {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Реплика: контент и время под ним; подпись — только время (шаг 6). */
.msg { display: flex; flex-direction: column; gap: 6px; }
.msg-label { font-size: 11.5px; color: var(--muted-2); }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }

.msg.user { align-items: flex-end; }
.msg.user .msg-text {
  max-width: 520px;
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--bubble);
  color: var(--ink);
}

/* Ответ Ластика — без карточки, почти вровень с полями ленты. */
.msg.bot { align-items: flex-start; padding: 6px 2px; }
.msg.bot .msg-text { color: var(--ink); }

/* ДФ5: индикатор ожидания ответа — строка Ластика без подписи. */
.msg.typing { padding: 6px 2px; color: var(--muted); font-size: 15px; }

/* ДФ6/FR-036: системные сообщения фронта отличимы от сообщений Ластика. */
.msg.system {
  align-self: center;
  align-items: center;
  max-width: 560px;
  padding: 10px 16px;
  background: rgba(197, 92, 54, .05);
  border: 1px solid rgba(197, 92, 54, .24);
  border-radius: 12px;
  color: var(--brand-warm);
  font-size: 13px;
  text-align: center;
}
.msg.system button.retry {
  margin-top: 2px;
  height: 30px;
  padding: 0 14px;
  border: 1px solid rgba(197, 92, 54, .5);
  border-radius: 8px;
  background: transparent;
  color: var(--brand-warm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.msg.system button.retry:disabled { opacity: .5; cursor: default; }

/* Карточка (payload.form) — текст вопроса и кнопки к нему; шаги 2 и 6 макета. */
.card {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--page-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}
/* Вопрос над кнопками: тот же набор, что у обычной реплики. */
.card-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.card button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  overflow-wrap: anywhere;
  padding: 13px 20px;
  border: 1px solid var(--line-btn);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
}
/* Хвост варианта — у правого края, обычным начертанием: в макете «14 дней»
   стоит отдельным столбцом и не спорит с датами за внимание. */
.btn-main { min-width: 0; }
.btn-aside { margin-left: auto; padding-left: 12px; color: var(--muted-2); font-weight: 400; white-space: nowrap; }
.card button.is-chosen .btn-aside { color: var(--muted); }
.card button:disabled .btn-aside { color: inherit; }

/* Кнопка подтверждения — по центру и в фирменной рамке-градиенте (шаг 2 макета).
   Рамка рисуется подложкой: градиент в border-color браузеры не берут. */
.card button:only-of-type { justify-content: center; text-align: center; }
.card button.confirm {
  justify-content: center;
  text-align: center;
  border-color: transparent;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    var(--brand-button) border-box;
  border: 1.5px solid transparent;
}
.card button.confirm:hover:not(:disabled) {
  background:
    linear-gradient(var(--page-bg), var(--page-bg)) padding-box,
    var(--brand-button) border-box;
}
.card button.confirm:disabled {
  background: var(--surface);
  border: 1px solid var(--line-btn-off);
}
/* Выбор сотрудника из справочника: поле поиска и найденные — теми же кнопками. */
.picker { display: flex; flex-direction: column; gap: 8px; }
.picker-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--line-btn);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
}
.picker-input:focus { outline: none; border-color: var(--muted); }
.picker-results { display: flex; flex-direction: column; gap: 8px; }
.picker-results button { font-weight: 400; }
.picker-empty { padding: 4px 2px; color: var(--muted); font-size: 14px; }
.card button:hover:not(:disabled) { background: var(--page-bg); }
/* ДФ1/ДФ2: нажатая и вытесненные карточки остаются в ленте, но неактивны. */
.card button:disabled {
  border-color: var(--line-btn-off);
  color: var(--muted-2);
  opacity: .45;
  cursor: default;
}
/* Выбранный вариант: серая плашка с галочкой (шаг 6). */
.card button.is-chosen {
  opacity: 1;
  background: var(--chosen-bg);
  border-color: var(--chosen-bg);
  color: var(--muted);
}
.card button.is-chosen::before {
  content: "";
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  background: url("/assets/icon-check.svg") center / contain no-repeat;
}

/* --- композер --------------------------------------------------------------- */
.composer {
  flex-shrink: 0;
  padding: 14px 26px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.composer-field {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px 13px 16px;
  background: var(--surface);
  border: 1px solid var(--line-input);
  border-radius: 12px;
}
/* Фокуса в макете нет: подсвечиваем поле холодным концом фирменного градиента. */
.composer-field:focus-within {
  border-color: var(--brand-cool);
  box-shadow: 0 0 0 3px rgba(26, 133, 180, .12);
}
.composer input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
}
.composer input::placeholder { color: var(--muted-2); }
.composer-send {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: none;
  border-radius: 17px;
  background: var(--brand-button);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.composer-send img { width: 17px; height: 17px; }
.composer-send:disabled { opacity: .45; cursor: default; }

.composer-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
}
.composer-note { flex: 1; min-width: 0; }
.composer-counter { width: 130px; text-align: right; flex-shrink: 0; }
/* О5: лимит длины реплики держит app.js, здесь только цвет предупреждения. */
.composer-note.warn,
.composer-counter.warn { color: var(--brand-warm); }

/* --- узкие экраны ----------------------------------------------------------- */
@media (max-width: 1240px) {
  /* Меню портала — декорация: на узком экране уступает место логотипу и иконкам. */
  .portal-menu { display: none; }
  .portal-inner { justify-content: space-between; }
}
/* Панель истории на узком экране уступает ленте: две колонки в 700 не помещаются,
   а список чатов ведёт Ньютон — на стенде он всё равно пуст. Знак и «Новый
   диалог» возвращаются полосой над лентой, чтобы начать разговор было чем. */
@media (max-width: 900px) {
  .history {
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .workspace { flex-direction: column; }
  .history-empty { display: none; }
  .dialogs, .history-search { display: none; } /* узкий экран: список не помещается, остаётся «Новый диалог» */
  .session { flex-direction: row; margin-left: auto; }
  .btn-block { width: auto; }
}
@media (max-width: 700px) {
  .portal { height: 72px; }
  .portal-inner { padding: 0 16px; gap: 12px; }
  .portal-logo { width: 150px; height: 37px; }
  .portal-icons { gap: 12px; }
  .portal-avatar { margin-right: 8px; }
  .portal-icon, .portal-avatar { width: 36px; height: 36px; }
  .portal-icon-bell { width: 18px; height: 25px; }
  .portal-icon-chat { width: 22px; height: 22px; }
  .portal-avatar img { width: 13px; height: 13.8px; }
  .portal-badge { width: 18px; height: 18px; font-size: 11px; top: -3px; right: 0; }

  .page { height: calc(100vh - 73px); height: calc(100dvh - 73px); }
  .feed { padding: 16px; }
  .session-user { display: none; }
  .msg.user .msg-text { max-width: 86%; }
  .composer { padding: 12px 16px 16px; }
}

/* --- экран входа по логину и паролю (стенд с авторизацией) ------------------ */
.login {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(31, 32, 35, .45);
  backdrop-filter: blur(2px);
}
.login-card {
  width: min(420px, calc(100vw - 48px));
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 48px rgba(31, 32, 35, .18);
}
.login-title { font-size: 17px; font-weight: 700; }
.login-text { margin: 0; color: var(--ink-soft); font-size: 13px; }
/* Вкладки «Вход» / «Регистрация»: переключают одну и ту же пару полей. */
.login-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--chosen-bg);
  border-radius: 10px;
}
.login-tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.login-tab.is-active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(31, 32, 35, .08);
}
.login-hint { margin: 0; color: var(--muted); font-size: 11.5px; }
.login-card input {
  padding: 13px 16px;
  border: 1px solid var(--line-input);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.login-card input::placeholder { color: var(--muted-2); }
.login-card input:focus {
  outline: none;
  border-color: var(--brand-cool);
  box-shadow: 0 0 0 3px rgba(26, 133, 180, .12);
}
/* Ошибка входа; пустая — не занимает места. */
.login-error { color: var(--brand-warm); font-size: 13px; }
.login-error:empty { display: none; }
