:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f2f3f7;
  --muted: #6b7280;
  --text: #111318;
  --border: #e7e8ef;
  --shadow: 0 8px 24px rgba(17, 19, 24, 0.08);

  --radius: 16px;

  --sidebar-w: 280px;
  --sidebar-w-collapsed: 72px;

  --btn-bg: #ffffff;
  --btn-bg-hover: #f2f3f7;
  --btn-border: #e7e8ef;
  --input-bg: #ffffff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden; /* важно: прокрутка только внутри .chat */
}

/* --- Layout --- */
.app-layout {
  display: flex;
  height: 100vh; /* вместо min-height */
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 200ms ease, transform 200ms ease;

  /* фиксируем слева как у Алисы */
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand__logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex: 0 0 34px;
}

.brand__meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand__title {
  font-weight: 800;
  letter-spacing: .2px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand__subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 10px;
  cursor: pointer;
  line-height: 1;
}
.icon-btn:hover { background: var(--btn-bg-hover); }

.nav {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav__item {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 12px;
  padding: 10px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
}
.nav__item:hover { background: var(--surface-2); }

.nav__icon {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 30px;
}

.nav__text {
  font-size: 14px;
}

.sidebar__bottom {
  margin-top: auto;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.muted { color: var(--muted); font-size: 12px; }

/* Collapsed sidebar (desktop) */
.sidebar.is-collapsed { width: var(--sidebar-w-collapsed); }
.sidebar.is-collapsed .brand__meta,
.sidebar.is-collapsed .nav__text,
.sidebar.is-collapsed .muted { display: none; }
.sidebar.is-collapsed .sidebar__top { justify-content: center; }
.sidebar.is-collapsed .icon-btn .icon {
  display: inline-block;
  transform: rotate(180deg);
}

/* --- Overlay (mobile) --- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 19, 24, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}
.overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
  z-index: 40;
}

/* --- Main area --- */
.main {
  flex: 1;
  height: 100vh;
  overflow: hidden;     /* важно */
  display: flex;
  flex-direction: column;
  padding: 18px;
}

/* Mobile topbar (shown on mobile) */
.topbar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  flex: 0 0 auto;
}

.topbar__title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar__titleMain { font-weight: 800; font-size: 14px; }
.topbar__titleSub { color: var(--muted); font-size: 12px; }
.topbar__spacer { flex: 1; }

.chat-shell {
  width: min(980px, 100%);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;

  /* ключевой flex-контейнер */
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Старый header больше не нужен (дублируется с sidebar/topbar) */
.chat-shell > .header { display: none; }

/* --- Chat --- */
.chat {
  flex: 1;
  min-height: 0; /* критично для скролла внутри flex */
  overflow: auto;
  padding: 12px 16px 16px;
  background: var(--surface);
}

/* Message bubbles */
.bubble {
  max-width: 86%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  margin: 10px 0;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 2px 10px rgba(17, 19, 24, 0.04);
}

.row { display: flex; }
.row.bot { justify-content: flex-start; }
.row.user { justify-content: flex-end; }

.bubble.user {
  background: #eef4ff;
  border-color: #d9e6ff;
}

/* Buttons under bubble */
.buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.btn {
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
}
.btn:hover { background: var(--btn-bg-hover); }

/* Images: keep aspect ratio (no stretching) */
.image {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  object-fit: contain;
}

/* wrapper for image + download icon */
.image-wrap { position: relative; display: block; }
.download-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
}
.download-btn:hover { background: var(--surface-2); }

.caption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

/* Composer (фикс снизу) */
.composer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  flex: 0 0 auto;
}

.composer input[type="text"] {
  flex: 1;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}
.composer input[type="text"]::placeholder { color: #9aa3b2; }

.composer button {
  height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
}
.composer button:hover { background: var(--btn-bg-hover); }

.upload input { display: none; }
.upload span {
  display: inline-flex;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  cursor: pointer;
}
.upload span:hover { background: var(--btn-bg-hover); }

/* System text */
.sys {
  color: var(--muted);
  font-size: 13px;
  margin: 6px 0;
}

/* --- Mobile adaptation --- */
@media (max-width: 768px) {
  .main { padding: 10px; }
  .topbar { display: flex; }

  /* off-canvas sidebar */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-102%);
    z-index: 50;
    box-shadow: var(--shadow);
  }
  .sidebar.is-open { transform: translateX(0); }

  .bubble { max-width: 92%; }
}

/* === Alice-like center column === */

/* центральная колонка без "карточки" */
.chat-shell {
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
  width: min(920px, 100%);
}

/* сделаем чат визуально "страницей" */
.chat {
  background: transparent;
  padding: 24px 18px 120px; /* снизу запас под composer */
}

/* убираем тяжелые пузырьки, делаем лёгкие */
.bubble {
  max-width: 100%;
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
  padding: 0;
  margin: 14px 0;
  font-size: 16px;
  line-height: 1.5;
}

/* для пользователя — легкая плашка справа (как у Алисы инпут/ответ) */
.row.user .bubble {
  background: #eef4ff;
  border: 1px solid #d9e6ff;
  border-radius: 16px;
  padding: 12px 14px;
  max-width: 70%;
}

/* для бота — просто текст, но если хочешь легкую плашку, раскомментируй:
.row.bot .bubble {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  max-width: 78%;
}
*/

.row.bot { justify-content: flex-start; }
.row.user { justify-content: flex-end; }

/* кнопки — более "алисячьи": светлые, широкие, аккуратные */
.buttons { margin-top: 12px; gap: 10px; }
.btn {
  border-radius: 16px;
  padding: 12px 14px;
  background: #ffffff;
  border: 1px solid var(--border);
}
.btn:hover { background: var(--surface-2); }

/* изображения: встраиваем аккуратно, но без рамки "карточки" вокруг bubble */
.image {
  border-radius: 16px;
  border: 1px solid var(--border);
}

/* composer как у Алисы: плавающий блок внизу */
.composer {
  position: sticky;
  bottom: 0;
  margin: 16px 18px 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #f2f3f7;
  box-shadow: 0 10px 30px rgba(17, 19, 24, 0.08);
  padding: 12px;
  gap: 12px;
}

/* поле ввода — без рамки, на светлом фоне */
.composer input[type="text"] {
  border: none;
  background: #ffffff;
  border-radius: 14px;
  height: 46px;
}

/* кнопки снизу — как отдельные элементы */
.upload span {
  border: none;
  background: #ffffff;
  border-radius: 14px;
  height: 46px;
  width: 46px;
}

.composer button {
  border: none;
  background: #ffffff;
  border-radius: 14px;
  height: 46px;
  padding: 0 16px;
}
.composer button:hover { background: #eef0f5; }

/* системные строки — чуть тише */
.sys { margin: 10px 0; }

/* mobile: больше воздуха, composer прижат */
@media (max-width: 768px) {
  .chat { padding: 18px 12px 120px; }
  .composer { margin: 12px; }
  .row.user .bubble { max-width: 88%; }
}