/* ====================================================================
   Чат КИТ: адаптив — на планшете и телефоне всё крупнее и под палец.
   Подключается последним. Ступени: планшет ≤ 1100px, телефон ≤ 760px.
   Цели касания — не меньше 44px; поля ввода — 16px (иначе iOS увеличивает страницу).
   ==================================================================== */

/* Свёрнутый список диалогов — только на телефоне; на компьютере заголовок не кликается. */
.side-head .side-arrow { display: none; }

@media (max-width: 1100px) {
  body { font-size: 16px; }
  main, main.main-chat { padding-left: 16px; padding-right: 16px; }
  .topbar-inner { height: 64px; padding: 0 16px; gap: 16px; }
  .brand { font-size: 17px; }
  .nav-links { overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; min-width: 0; margin-left: 0; }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-links a { font-size: 15.5px; padding: 11px 14px; white-space: nowrap; }
  .topbar-user { font-size: 15px; gap: 10px; }
  .topbar-user .logout-btn, .theme-btn { width: 44px; height: 44px; flex: 0 0 44px; }
  .topbar-user .logout-btn svg, .theme-btn svg { width: 21px; height: 21px; }

  .btn { font-size: 15.5px; min-height: 44px; padding: 10px 18px; }
  .field input[type="text"], .field input[type="password"], .field .select,
  .field.row-field textarea, .table-filter input[type="search"] { font-size: 16px; padding: 11px 13px; }
  .field.row-field > label { min-width: 170px; font-size: 15px; }
  table { font-size: 15px; }
  thead th { font-size: 12.5px; }
  section h2 { font-size: 17px; }

  /* чат */
  .chat-layout { grid-template-columns: 300px 1fr; }
  .dialogs-layout { grid-template-columns: 340px 1fr; }
  .bubble { font-size: 16.5px; line-height: 1.6; padding: 12px 16px; max-width: 92%; }
  .bubble.md code { font-size: 14.5px; }
  .msg-meta { font-size: 13px; }
  .chat-ctx { font-size: 13.5px; height: 24px; line-height: 24px; }
  .chat-usage { font-size: 13.5px; }
  .dlg-link { padding: 10px; }
  .dlg-title { font-size: 15.5px; }
  .dlg-date { font-size: 12.5px; }
  .dlg-btn { flex-basis: 40px; width: 40px; height: 40px; font-size: 19px; }
  .composer textarea { font-size: 16.5px; min-height: 80px; height: 80px; }
  .think-toggle { font-size: 15px; }
  .think-toggle input { width: 20px; height: 20px; }
  .model-pick { font-size: 15px; }
  .model-pick select { font-size: 16px; padding: 8px 10px; }
  .composer-err { font-size: 14px; }
  .send-slot, .send-slot .btn { min-width: 140px; }

  /* поиск и списки */
  .filter-mode-toggle, .filter-label, .filter-count { font-size: 14.5px; }
  .filter-mode-toggle { padding: 8px 12px; }
  .tag { font-size: 13px; }
  .modal-head h3 { font-size: 17px; }
  .modal .field.row-field > label { min-width: 150px; }
  dl.kv { font-size: 15px; }
}

@media (max-width: 760px) {
  body { font-size: 16.5px; }
  /* шапка в две строки: логотип и кнопки сверху, меню — второй строкой с прокруткой */
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 8px 12px 6px; gap: 6px 10px; }
  .brand .app-version { display: none; }
  .nav-links { order: 3; flex: 1 0 100%; }
  .topbar-user .user-name { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-user + .theme-btn { margin-left: 0; }
  main, main.main-chat { padding: 10px 10px 16px; }
  header.page-header { margin-bottom: 14px; }
  section, section.card { padding: 14px 12px; }
  section.card > h2, section.card .modal-section > .modal-section-head { padding-left: 4ch; }

  /* чат — одна колонка; список диалогов сворачивается под заголовок */
  .chat-layout, .dialogs-layout { grid-template-columns: 1fr; height: auto; min-height: 0; gap: 10px; }
  .chat-side { max-height: none; }
  .side-head { cursor: pointer; user-select: none; display: flex; align-items: center; }
  .side-head .side-arrow { display: inline; margin-left: auto; padding-right: 4px; transition: transform .15s; }
  .chat-side:not(.open) > :not(.side-head) { display: none; }
  .chat-side:not(.open) > .side-head { margin-bottom: 0; border-bottom: none; padding-bottom: 0; }
  .chat-side.open .side-arrow { transform: rotate(180deg); }
  .chat-side.open .dlg-list, .chat-side.open .dlg-table-wrap { max-height: 50vh; }
  .chat-main { height: calc(100dvh - 120px); min-height: 420px; }
  .chat-head { flex-wrap: wrap; gap: 2px 10px; }
  .chat-head #chat-title { flex-basis: 100%; }
  .chat-ctx { white-space: normal; height: auto; min-height: 24px; line-height: 1.4; padding: 3px 8px; }
  .bubble { max-width: 96%; }
  .composer-bar { flex-wrap: wrap; gap: 8px; }
  .composer-err { order: 3; flex-basis: 100%; }
  .send-slot { margin-left: auto; }

  /* списки, формы, окна */
  .list-toolbar .table-filter { min-width: 0; flex-basis: 100%; }
  .table-filter input[type="search"] { max-width: none; }
  .list-table { display: block; overflow-x: auto; white-space: nowrap; }
  .field.row-field { flex-wrap: wrap; gap: 6px 12px; }
  .field.row-field > label, .modal .field.row-field > label { min-width: 0; flex-basis: 100%; }
  .settings-form .field.row-field input[type="text"] { flex: 0 0 140px; }
  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal, .modal-wide, .modal-xwide { width: 100%; max-height: 100dvh; border-radius: 0; }
  .log-pair { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 1fr; gap: 0 0; }
  dl.kv dd { margin-bottom: 6px; }
  .login-box { margin-top: 16px; }
}
