:root {
  --base-spacing: 24px;
  --equal-spacing: var(--base-spacing);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--it-font, 'OpenSansLight', Verdana, 'Geneva CY', sans-serif);
  font-weight: normal;
  font-size: var(--it-fs, 14px);
  line-height: var(--it-lh, 1.25);
  color: var(--it-ink, #111);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  background: var(--it-surface, #f7f5f2);
  overflow: hidden;
}

#chat-wrapper {
  display: flex;
  flex-direction: row;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  /* Кнопки ☰ и «Новый диалог» в один ряд — отступ списка сессий сразу под ними */
  --dev-chat-toolbar-top: var(--base-spacing);
  --dev-chat-toolbar-row-height: 40px;
  --dev-chat-toolbar-row-width: calc(40px + 8px + 40px);
  --session-sidebar-top-gap: calc(
    var(--dev-chat-toolbar-top) + var(--dev-chat-toolbar-row-height) + 4px
  );
  --chat-scrollbar-width: 8px;
  --chat-scrollbar-gutter: 10px;
  --chat-input-scrollbar-inset: calc(
    var(--chat-scrollbar-gutter) + var(--chat-scrollbar-width) / 2
  );
}

#top-buttons {
  position: absolute;
  top: var(--dev-chat-toolbar-top);
  left: var(--base-spacing);
  z-index: 10000;
}

#top-buttons .button-group {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

#chat-layout {
  display: flex;
  flex-direction: row;
  flex: 1 1 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  padding-left: 0;
  --sidebar-width: 300px;
  --chat-toolbar-inset: calc(var(--base-spacing) + var(--dev-chat-toolbar-row-width, 88px));
  --chat-content-left: calc(
    var(--sidebar-width) + var(--chat-toolbar-inset) + var(--base-spacing)
  );
}

#chat-layout:has(#session-sidebar.hidden),
#chat-layout.sidebar-collapsed {
  --sidebar-width: 0px;
  --chat-content-left: calc(var(--chat-toolbar-inset) + var(--base-spacing));
}

#session-sidebar {
  width: 300px;
  background: var(--it-surface, #f7f5f2) !important;
  border-right: none !important;
  padding: var(--session-sidebar-top-gap) 16px 16px var(--base-spacing);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100%;
  align-self: stretch;
  overflow: hidden;
}

#session-sidebar h3 {
  margin: 0;
  padding-top: 0;
  height: 40px; /* Высота как у кнопки */
  display: flex;
  align-items: center;
}

#session-list {
  list-style: none;
  margin: 0 0 12px;
  flex: 1;
  overflow-y: auto;
  padding-left: 0;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
  margin-top: 0;
}

#session-list::-webkit-scrollbar {
  width: 8px;
}

#session-list::-webkit-scrollbar-track {
  background: transparent;
}

#session-list::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

#session-list::-webkit-scrollbar-thumb:hover {
  background-color: rgba(0, 0, 0, 0.3);
}

#session-list li {
  padding: 12px 16px;
  background: #ffffff;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--it-ink, #0d0d0d);
}

#session-list li:first-child {
  margin-top: 0;
}

#session-list li:hover {
  background: var(--it-surface, #f7f5f2);
}

#session-list li.active {
  background: #e2e6f5;
  font-weight: 500;
}

#new-session {
  padding: 8px 12px;
  font-size: 14px;
  background: #f5f7fd;
  color: var(--it-ink, #0d0d0d);
  border: 1px solid #d0d8ef;
  border-radius: 6px;
  cursor: pointer;
  font-weight: normal;
  margin-top: 8px;
  transition: background 0.2s, color 0.2s;
}

#new-session:hover {
  background: #e2e6f5;
  color: #152050;
}

#chat-widget {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  min-width: 0;
  width: 100%;
  padding-left: var(--chat-toolbar-inset);
  box-sizing: border-box;
}

#chat-container {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  min-width: 0;
  max-width: none;
  margin: 0;
  position: relative;
  box-sizing: border-box;
}

#chat-inner {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

#messages {
  flex: 1 1 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
  padding: var(--base-spacing)
    calc(var(--base-spacing) + var(--chat-scrollbar-gutter)) 180px var(--base-spacing);
  margin: 0;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
  scrollbar-gutter: stable;
}

/* Стили для Webkit (Chrome, Safari, новые версии Edge) */
#messages::-webkit-scrollbar {
  width: 8px;
}

#messages::-webkit-scrollbar-track {
  background: transparent;
}

#messages::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

#messages::-webkit-scrollbar-thumb:hover {
  background-color: rgba(0, 0, 0, 0.3);
}

#messages::-webkit-scrollbar-button {
  display: none;
}

.message .content {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.message .content .table-wrapper {
  max-width: 100%;
  overflow-x: auto;
}

.message {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 98%;
  box-sizing: border-box;
  border-radius: 16px;
  padding: 16px 20px;
  font-size: var(--it-fs-text, 17px);
  line-height: var(--it-lh-text, 1.4);
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  background: #f0f4ff;
  animation: fadeInGrow 0.4s ease forwards;
}

.message.user {
  background: #e0f7e9;
  align-self: flex-end;
  width: fit-content;
  max-width: 98%;
  text-align: left;
}

.message.assistant {
  background: #eef1ff;
  align-self: flex-start;
  width: fit-content;
  max-width: 98%;
  text-align: left;
}

.message.assistant.wide-message {
  max-width: 100%;
  width: 100%;
  align-self: center;
  padding: 0;
  background: #f5f7fd;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  overflow: visible;
  border: 1px solid #d0d8ef;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.message.assistant.wide-message .content-container {
  padding: 0;
  margin: 0;
}

.message.assistant.wide-message iframe {
  display: block;
  width: 100%;
  min-height: 60vh;
  height: 700px;
  max-height: 90vh;
  border: none;
  margin: 0;
  flex-shrink: 0;
}

.text-block {
  display: flex;
  flex-direction: column;
}

.sender {
  font-weight: bold;
  margin-bottom: 4px;
}

.content {
  font-size: var(--it-fs-text, 17px);
  line-height: var(--it-lh-text, 1.4);
  color: var(--it-muted, #585858);
  padding: 0;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  max-width: 100%;
  box-sizing: border-box;
}

.content h3,
.content h2,
.content h1 {
  font-size: var(--it-fs-page, 18px);
  font-family: var(--it-font-display, 'Noto Sans Display Condensed', 'Segoe UI', sans-serif);
  font-weight: 600;
  margin: 24px 0 10px;
  color: var(--it-ink, #0d0d0d);
}

/* Стили для нумерованных списков */
.content ol {
  list-style: decimal;
  padding-left: 2em;
  margin: 0.5em 0 1em;
}

/* Стили для маркированных списков */
.content ul {
  list-style: disc;
  padding-left: 2em;
  margin: 0.5em 0 1em;
}

/* Стили для элементов списка */
.content li {
  margin: 0.5em 0;
  padding-left: 0.5em;
}

/* Стили для вложенных списков */
.content li > ul {
  margin: 0.5em 0;
  list-style-type: circle;
}

.content li > ul > li > ul {
  list-style-type: square;
}

/* Стили для вложенных нумерованных списков */
.content li > ol {
  margin: 0.5em 0;
  list-style-type: lower-alpha;
}

.content li > ol > li > ol {
  list-style-type: lower-roman;
}

/* Убираем отступ сверху у первого вложенного списка */
.content li > ul:first-child,
.content li > ol:first-child {
  margin-top: 0;
}

/* Убираем отступ снизу у последнего вложенного списка */
.content li > ul:last-child,
.content li > ol:last-child {
  margin-bottom: 0;
}

.content strong {
  font-weight: 600;
  color: #000;
}

.content em {
  font-style: normal;
  font-weight: 600;
  color: #2a3b7d;
}

.content p {
  margin: 10px 0;
}

/* Стили для таблиц в сообщениях */
.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
  background: white;
  table-layout: fixed;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.content table th,
.content table td {
  padding: 8px;
  border: 1px solid #ccc;
  vertical-align: top;
}

.content table th {
  font-weight: bold;
  background: #f5f7fd;
}

.content table tr td[style*="background"] {
  padding: 12px;
}

#input-area {
  position: fixed;
  bottom: 0;
  left: var(--chat-content-left);
  right: calc(var(--base-spacing) + var(--chat-input-scrollbar-inset));
  transform: none;
  z-index: 999;
  padding: 8px 2px;
  background: rgba(255,255,255,0.1);
  border-top: none;
  box-shadow: none !important;
  width: auto;
  max-width: none;
  max-height: none;
  overflow: visible;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

#input-area-inner {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: visible;
  padding: 2px;
}

#input-wrapper {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 0 0 1px #ccc;
  padding: 6px 14px;
  position: relative;
  min-height: 56px;
  box-sizing: border-box;
}

#user-input {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 8px 6px;
  border: none;
  outline: none;
  font-size: 14px;
  line-height: 20px;
  background: transparent;
  resize: none;
  height: 40px;
  min-height: 40px;
  max-height: calc(40vh - 80px);
  overflow-y: hidden;
  transition: height 0.15s;
  box-sizing: border-box;
  display: block;
  white-space: pre-wrap;
  word-wrap: break-word;
}

#user-input::placeholder {
  color: #888;
  opacity: 1;
}

#user-input:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

#top-buttons button {
  all: unset;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  font-size: 18px;
  font-weight: bold;
  background: #ffffff;
  border: 1px solid #d0d8ef;
  border-radius: 8px;
  cursor: pointer;
  color: var(--it-ink, #0d0d0d);
  box-shadow: none;
  transition: background 0.2s ease;
  overflow: visible;
  box-sizing: border-box;
}

#top-buttons button:hover {
  background: #f0f3fb;
}

#toggle-sessions-button {
  margin-bottom: 0;
}

#buttons {
  display: flex;
  flex-direction: row;
  gap: 5px;
  align-items: center;
  padding: 4px 0;
}

#buttons button,
#buttons label[role="button"] {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  background: transparent;
  box-shadow: none;
  transition: all 0.2s ease;
  color: var(--it-ink, #0d0d0d);
}

#buttons button:hover,
#buttons label[role="button"]:hover {
  background: #f0f3fb;
}

#buttons button:disabled,
#buttons label[role="button"].disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

#send-button {
  background: transparent !important;
  color: #000 !important;
  transform: none;
  border: none !important;
  position: relative;
  width: 48px !important;
  height: 48px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 !important;
}

#send-button:hover {
  background: #f0f3fb !important;
}

#send-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

#send-button:hover svg {
  opacity: 0.8;
}

#file-upload-button svg {
  width: 18px !important;
  height: 18px !important;
  stroke: currentColor;
}

.copy-button {
  position: absolute;
  right: -11px;
  bottom: -11px;
  width: 26px;
  height: 26px;
  background: #fff;
  border-radius: 50%;
  border: 1.5px solid #e0e4f1;
  box-shadow: 0 1px 8px 0 rgba(50,50,90,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.19s, background 0.13s, box-shadow 0.14s;
  z-index: 9;
  padding: 0;
}

.copy-button:hover {
  background: #eaf0fb;
  opacity: 1;
  box-shadow: 0 2px 12px 0 rgba(50,60,120,0.18);
}

.copy-button svg {
  width: 15px;
  height: 15px;
  color: #6c6c80;
  pointer-events: none;
}

.message:hover .copy-button {
  opacity: 0.75;
}

.iframe-button-block {
  margin: 8px 0;
}

.open-iframe-btn {
  display: inline-block;
  width: auto;
  min-width: 200px;
  padding: 8px 16px;
  font-size: 14px;
  background: #e2e6f5;
  border: 1px solid #b3bedf;
  border-radius: 8px;
  cursor: pointer;
  color: var(--it-ink, #0d0d0d);
  font-weight: 500;
  text-align: left;
  margin: 0;
  transition: background 0.2s, color 0.2s;
}

.open-iframe-btn:hover {
  background: #d5dbee;
}

.open-iframe-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* Специальные стили для кнопок в списках */
.content li .iframe-button-block {
  margin: 4px 0;
}

.content li .open-iframe-btn {
  width: 100%;
  display: block;
}

#file-list {
  display: flex;
  flex-direction: row;
  gap: 6px;
  align-items: center;
  margin: 0;
  min-height: 28px;
  max-width: 100%;
  flex-wrap: wrap;
  padding: 0 0 4px 4px;
  overflow-y: auto;
  max-height: 80px;
}

.uploaded-file {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #e2e6f5;
  border-radius: 7px;
  padding: 3px 10px 3px 8px;
  font-size: 13px;
  color: var(--it-ink, #0d0d0d);
  max-width: 180px;
  overflow: hidden;
}

.uploaded-file .file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 110px;
}

.remove-file-btn {
  background: none;
  border: none;
  color: #F44336;
  font-size: 15px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
  margin-left: 2px;
  transition: color 0.12s;
}

.remove-file-btn:hover {
  color: #b60000;
}

@keyframes rotate {
  100% {
    transform: rotate(360deg);
  }
}

@keyframes fadeInGrow {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 768px) {
  #chat-layout {
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    --chat-content-left: var(--base-spacing);
  }

  #session-sidebar {
    width: 100%;
    height: auto;
    max-height: min(42vh, 320px);
    flex-shrink: 0;
    flex-grow: 0;
    order: 1;
    overflow: hidden;
    border-right: none !important;
    border-bottom: 1px solid #d0d8ef;
    padding: var(--session-sidebar-top-gap) var(--base-spacing) 12px var(--base-spacing);
    z-index: 2;
  }

  #session-sidebar.hidden {
    display: none !important;
  }

  #session-list {
    max-height: min(36vh, 260px);
  }

  #chat-widget {
    border-radius: 0 !important;
    width: 100%;
    z-index: 1;
    flex: 1;
    min-height: 0;
    height: auto !important;
    order: 2;
    padding-left: 0;
    padding-top: var(--session-sidebar-top-gap);
  }

  #session-sidebar.hidden ~ #chat-widget {
    padding-left: 0;
  }

  #session-sidebar:not(.hidden) ~ #chat-widget,
  #chat-layout.sessions-panel-open #chat-widget {
    padding-top: 0;
  }

  #chat-inner {
    padding: 0 12px;
  }

  #messages {
    max-width: 100%;
    padding: var(--base-spacing) var(--base-spacing) 180px var(--base-spacing);
    margin: 0;
  }

  .message {
    max-width: 100% !important;
  }

  .message.user {
    margin-left: auto;
    margin-right: 0;
  }

  .message.assistant {
    margin-left: 0;
    margin-right: auto;
  }

  #input-area {
    left: var(--base-spacing);
    right: calc(var(--base-spacing) + var(--chat-input-scrollbar-inset));
    padding: 8px 0;
  }

  #user-input {
    font-size: 13px;
  }

  #buttons button {
    min-width: 36px !important;
    min-height: 36px !important;
  }

  #buttons svg {
    width: 20px !important;
    height: 20px !important;
  }

  #send-button {
    width: 36px !important;
    height: 36px !important;
  }

  #file-upload-button svg {
    width: 18px !important;
    height: 18px !important;
  }

  #chat-layout {
    padding-left: 0;
  }

  #chat-container {
    width: 100%;
    max-width: none;
  }
}

#session-sidebar.hidden {
  display: none !important;
}

/* Скрытый сайдбар на десктопе: контент справа от кнопок ☰ / «Новый диалог» */
@media (min-width: 769px) {
  #session-sidebar.hidden ~ #chat-widget {
    padding-left: var(--chat-toolbar-inset);
  }

  #session-sidebar.hidden + #chat-widget #messages {
    padding-left: var(--base-spacing);
  }

  #session-sidebar.hidden ~ #chat-widget #messages {
    max-width: 100%;
  }

  #session-sidebar.hidden ~ #chat-widget .message {
    max-width: 98%;
  }
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: #90959f;
    border-radius: 50%;
    animation: typing 1s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.4s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.6s;
}

@keyframes typing {
    0%, 100% {
        transform: translateY(0);
        opacity: 0.3;
    }
    50% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.message table {
    width: 100% !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    margin: 16px 0 !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
    background: #fff !important;
    border-radius: 8px !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
    border: 1px solid #e0e4f1 !important;
}

.message table tbody {
    display: table-row-group !important;
}

.message table tr {
    display: table-row !important;
}

.message table tr:first-child {
    background: #f5f7fd !important;
}

.message table tr:first-child th {
    color: var(--it-ink, #0d0d0d) !important;
    font-weight: 600 !important;
    padding: 12px 16px !important;
    text-align: left !important;
    border-bottom: 2px solid #e0e4f1 !important;
    white-space: normal !important;
    display: table-cell !important;
    background: #f5f7fd !important;
}

.message table td {
    padding: 12px 16px !important;
    border-bottom: 1px solid #e0e4f1 !important;
    color: #333 !important;
    vertical-align: top !important;
    display: table-cell !important;
    white-space: normal !important;
    word-wrap: break-word !important;
}

.message table tr:last-child td {
    border-bottom: none !important;
}

.message table tbody tr:not(:first-child):nth-child(even) {
    background: #f8faff !important;
}

.message table tbody tr:not(:first-child):hover {
    background: #f0f3fb !important;
}

.message table tr:first-child th:first-child,
.message table td:first-child {
    padding-left: 24px !important;
}

.message table tr:first-child th:last-child,
.message table td:last-child {
    padding-right: 24px !important;
}

/* Стили для мобильных устройств */
@media (max-width: 768px) {
    .message table {
        margin: 12px -12px !important;
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
    }

    .message table tr:first-child th,
    .message table td {
        padding: 10px 12px !important;
        font-size: 13px !important;
    }

    .message table tr:first-child th:first-child,
    .message table td:first-child {
        padding-left: 16px !important;
    }

    .message table tr:first-child th:last-child,
    .message table td:last-child {
        padding-right: 16px !important;
    }
}

/* Стили для двухколоночных таблиц */
.message .table-wrapper table.two-columns {
    table-layout: fixed !important;
}

.message .table-wrapper table.two-columns th,
.message .table-wrapper table.two-columns td {
    width: 50% !important;
}

@media (min-width: 1440px) {
  #messages {
    padding: var(--base-spacing)
      calc(var(--base-spacing) + var(--chat-scrollbar-gutter)) 180px var(--base-spacing);
  }

  .message {
    max-width: 98%;
  }

  .content {
    font-size: var(--it-fs-text, 17px);
    line-height: var(--it-lh-text, 1.4);
  }
}

@media (min-width: 2560px) {
  .message {
    font-size: var(--it-fs-text, 17px);
  }

  .content {
    font-size: var(--it-fs-text, 17px);
  }
}

/* Очень широкий экран: лента и поле ввода — центральная половина viewport */
@media (min-width: 1600px) {
  #chat-layout {
    --chat-viewport-column-left: 25vw;
    --chat-viewport-column-width: 50vw;
  }

  #chat-container {
    width: var(--chat-viewport-column-width);
    max-width: var(--chat-viewport-column-width);
    margin-left: max(
      0px,
      calc(
        var(--chat-viewport-column-left) - var(--sidebar-width) -
          var(--chat-toolbar-inset)
      )
    );
    margin-right: auto;
  }

  #input-area {
    left: var(--chat-viewport-column-left);
    right: auto;
    width: calc(var(--chat-viewport-column-width) - var(--chat-input-scrollbar-inset));
    max-width: calc(var(--chat-viewport-column-width) - var(--chat-input-scrollbar-inset));
  }
}

/* Дополнительные стили для ультраширких экранов */

#session-list::-webkit-scrollbar-button {
  display: none;
}

.content li .iframe-button-block {
  margin: 8px 0;
}

.content li .open-iframe-btn {
  width: auto;
  min-width: 200px;
  padding: 8px 16px;
  font-size: 14px;
  text-align: left;
}

/* Медиа-запросы для мобильных устройств - уменьшенные шрифты */
@media (max-width: 768px) {
    /* Основной размер шрифта для body */
    html, body {
        font-size: var(--it-fs, 14px);
    }
    
    /* Сайдбар и сессии */
    #session-list li {
        font-size: var(--it-fs, 14px);
        padding: 10px 14px; /* немного уменьшен отступ */
    }
    
    #new-session {
        font-size: var(--it-fs, 14px);
        padding: 6px 10px; /* уменьшен отступ */
    }
    
    /* Контент сообщений */
    .content {
        font-size: var(--it-fs-text, 17px);
        line-height: var(--it-lh-text, 1.4);
    }
    
    /* Заголовки в сообщениях */
    .content h3,
    .content h2,
    .content h1 {
        font-size: var(--it-fs-page, 18px);
        margin: 16px 0 8px; /* уменьшены отступы */
    }
    
    /* Таблицы в сообщениях */
    .content table {
        font-size: 12px; /* было 14px */
        margin: 12px 0; /* уменьшены отступы */
    }
    
    .content table th,
    .content table td {
        padding: 6px; /* было 8px */
        font-size: 12px;
    }
    
    /* Поле ввода */
    #user-input {
        font-size: 12px; /* было 14px */
        line-height: 18px; /* было 20px */
        padding: 6px 4px; /* уменьшен отступ */
        height: 36px; /* было 40px */
        min-height: 36px;
    }
    
    #user-input::placeholder {
        font-size: 12px;
    }
    
    /* Кнопки */
    .open-iframe-btn {
        font-size: 12px; /* было 14px */
        padding: 6px 12px; /* было 8px 16px */
        min-width: 150px; /* было 200px */
    }
    
    /* Отправка сообщений */
    .button-group button {
        font-size: 12px;
        padding: 6px 10px;
    }
    
    /* Адаптивность для сайдбара на мобильных */
    #session-sidebar {
        width: 100%;
        padding: var(--session-sidebar-top-gap) var(--base-spacing) 12px var(--base-spacing);
    }
    
    #session-sidebar h3 {
        font-size: 14px;
        height: 36px; /* было 40px */
    }
    
    /* Отступы для области сообщений */
    #messages {
        padding: 16px 0 140px 0; /* было 24px 0 180px 0 */
        gap: 12px; /* было 16px */
    }
    
    /* Область ввода */
    #input-area {
        padding: 6px 0; /* было 8px 0 */
        max-height: 35vh; /* было 40vh */
    }
    
    #input-wrapper {
        min-height: 48px; /* было 56px */
        padding: 4px 12px; /* было 6px 14px */
        border-radius: 20px; /* было 24px */
    }
}

/* Медиа-запросы для планшетов (769px - 1024px) - промежуточные размеры шрифтов */
@media (min-width: 769px) and (max-width: 1024px) {
    /* Основной размер шрифта */
    html, body {
        font-size: var(--it-fs, 14px);
    }
    
    /* Сайдбар и сессии */
    #session-list li {
        font-size: var(--it-fs, 14px);
        padding: 11px 15px;
    }
    
    #new-session {
        font-size: var(--it-fs, 14px);
        padding: 7px 11px;
    }
    
    /* Контент сообщений */
    .content {
        font-size: var(--it-fs-text, 17px);
        line-height: var(--it-lh-text, 1.4);
    }
    
    /* Заголовки */
    .content h3,
    .content h2,
    .content h1 {
        font-size: var(--it-fs-page, 18px);
        margin: 20px 0 9px;
    }
    
    /* Таблицы */
    .content table {
        font-size: 13px;
        margin: 14px 0;
    }
    
    .content table th,
    .content table td {
        padding: 7px;
        font-size: 13px;
    }
    
    /* Поле ввода */
    #user-input {
        font-size: 13px;
        line-height: 19px;
        padding: 7px 5px;
        height: 38px;
        min-height: 38px;
    }
    
    #user-input::placeholder {
        font-size: 13px;
    }
    
    /* Кнопки */
    .open-iframe-btn {
        font-size: 13px;
        padding: 7px 14px;
        min-width: 175px;
    }
    
    /* Сайдбар планшетный */
    #session-sidebar {
        width: 280px; /* промежуточная ширина */
        padding: 20px 14px 14px 20px;
    }
    
    #session-sidebar h3 {
        font-size: 15px;
        height: 38px;
    }
    
    /* Область сообщений */
    #messages {
        padding: 20px 0 160px 0;
        gap: 14px;
    }
    
    /* Область ввода */
    #input-area {
        padding: 7px 0;
        max-height: 38vh;
    }
    
    #input-wrapper {
        min-height: 52px;
        padding: 5px 13px;
        border-radius: 22px;
    }
}

/* Стили для группировки сессий по времени */
.session-group-header {
  font-size: 12px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 16px;
  margin-bottom: 8px;
  padding-left: 4px;
}

.session-group-header:first-child {
  margin-top: 0;
}

.session-group {
  display: flex;
  flex-direction: column;
}

.session-item {
  padding: 12px 16px !important;
  background: #ffffff !important;
  border-radius: 8px !important;
  cursor: pointer !important;
  transition: background 0.2s !important;
  font-size: 14px !important;
  margin-bottom: 8px !important;
  color: var(--it-ink, #0d0d0d) !important;
  list-style: none !important;
}

.session-item:hover {
  background: #f0f3fb !important;
}

.session-item.active {
  background: #e2e6f5 !important;
  font-weight: 500 !important;
}

/* Убираем лишние отступы для первого элемента в группе */
.session-group .session-item:first-child {
  margin-top: 0;
}

/* Адаптация для мобильных устройств */
@media (max-width: 768px) {
  .session-group-header {
    font-size: 11px;
    margin-top: 12px;
    margin-bottom: 6px;
  }
  
  .session-item {
    font-size: 12px !important;
    padding: 10px 14px !important;
  }
}

/* Адаптация для планшетов */
@media (min-width: 769px) and (max-width: 1024px) {
  .session-group-header {
    font-size: 11px;
    margin-top: 14px;
    margin-bottom: 7px;
  }
  
  .session-item {
    font-size: 13px !important;
    padding: 11px 15px !important;
  }
}

.message .table-wrapper table.two-columns th,
.message .table-wrapper table.two-columns td {
  width: 50%;
}

/* Дополнительные стили для обработки переполнения */
.content a {
  word-break: break-all;
  overflow-wrap: break-word;
}

.content code {
  word-break: break-all;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.content pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow-x: auto;
}

.content ul, .content ol {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.content li {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

#reset-button {
  line-height: 0;
  overflow: visible;
}

#reset-button svg {
  display: block;
  width: 18px;
  height: 18px;
  overflow: visible;
}

#chat-container > #site-footer {
  flex: 0 0 auto;
  padding: 12px 16px 16px;
  background: var(--it-surface, #f7f5f2);
}

#chat-container > #site-footer .site-footer-inner {
  grid-template-columns: 1fr;
  gap: 10px;
  max-width: none;
}