:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-muted: #eef3f2;
  --ink: #15191d;
  --muted: #64717a;
  --line: #d9e0e3;
  --primary: #0b756f;
  --primary-strong: #075b56;
  --danger: #b43d2e;
  --warning: #a15c0a;
  --accent: #c8543b;
  --focus: rgba(11, 117, 111, 0.22);
  --shadow: 0 16px 50px rgba(21, 25, 29, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app,
.boot {
  min-height: 100vh;
}

.boot {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(320px, 1.1fr);
}

.auth-aside {
  padding: 48px;
  background: #17201f;
  color: #f6fbfa;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  margin-bottom: 18px;
}

.brand-logo {
  display: block;
  width: 120px;
  height: auto;
  aspect-ratio: 108 / 18;
  object-fit: contain;
  flex: 0 0 auto;
}

.auth-aside .brand-logo {
  width: 168px;
  filter: brightness(0) invert(1);
}

.auth-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  font-size: 13px;
  white-space: nowrap;
}

.auth-main {
  display: grid;
  place-items: center;
  padding: 32px;
}

.auth-card {
  width: min(100%, 520px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 30px;
}

.auth-card h2,
.panel-title h2,
.chat-title h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.auth-card .subtle,
.panel-title p,
.empty-state,
.field-help {
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 7px;
}

.field label,
.toggle-row {
  font-size: 13px;
  font-weight: 700;
  color: #293238;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.6;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--focus);
}

.field-help {
  min-height: 18px;
  font-size: 12px;
  line-height: 1.5;
}

.toggle-row {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  padding: 9px 14px;
  background: #e8eef0;
  color: #1d282d;
  font-weight: 800;
  text-decoration: none;
}

.button.primary {
  background: var(--primary);
  color: #fff;
}

.button.primary:hover {
  background: var(--primary-strong);
}

.button.ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.button.danger {
  background: #f8dfdb;
  color: var(--danger);
}

.mobile-history-toggle,
.mobile-history-close {
  display: none;
}

.flash {
  margin: 16px 0;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f6faf9;
  color: var(--primary-strong);
  line-height: 1.5;
}

.flash.error {
  background: #fff1ef;
  color: var(--danger);
  border-color: #f0c7c0;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(0, 1fr);
}

.sidebar {
  min-width: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  max-height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #ffffff;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.sidebar-head {
  display: flex;
  align-items: center;
}

.sidebar-head .brand-logo {
  width: 112px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button {
  min-height: 42px;
  text-align: left;
  border-radius: 8px;
  padding: 10px 12px;
  background: transparent;
  color: #2c363c;
  font-weight: 800;
}

.nav button.active,
.nav button:hover {
  background: var(--panel-muted);
  color: var(--primary-strong);
}

.account-box {
  margin-top: auto;
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.account-name {
  font-weight: 900;
  overflow-wrap: anywhere;
}

.account-meta {
  color: var(--muted);
  font-size: 13px;
}

.main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.topbar {
  min-height: 66px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
}

.topbar-title {
  min-width: 0;
}

.topbar-title strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-title span {
  color: var(--muted);
  font-size: 13px;
}

.content {
  min-height: 0;
  min-width: 0;
  width: 100%;
  overflow: auto;
  padding: 24px;
}

.shell-chat {
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

.content-chat {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.content-chat > .chat-page {
  flex: 1 1 auto;
}

.chat-page {
  height: 100%;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 14px;
}

.history-panel {
  min-height: 0;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-head .button {
  min-height: 34px;
  padding: 7px 10px;
}

.history-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px 34px;
  gap: 6px;
  border-radius: 8px;
}

.history-row > button:first-child {
  min-width: 0;
  text-align: left;
  border-radius: 8px;
  background: transparent;
  padding: 9px 10px;
  color: var(--ink);
}

.history-row.active > button:first-child,
.history-row > button:first-child:hover {
  background: var(--panel-muted);
}

.history-row span,
.history-row small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-row span {
  font-weight: 800;
}

.history-row small,
.history-empty {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.history-action,
.history-delete {
  width: 34px;
  height: 34px;
  align-self: center;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.history-action {
  font-size: 16px;
}

.history-action:hover {
  background: var(--panel-muted);
  color: var(--primary-strong);
}

.history-delete:hover {
  background: #fff1ef;
  color: var(--danger);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.chat-layout {
  height: 100%;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
}

.chat-header,
.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chat-header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.chat-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.model-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.model-switch select {
  min-height: 40px;
  width: min(260px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

.chat-title {
  min-width: 0;
}

.chat-title h2 {
  font-size: 20px;
  overflow-wrap: anywhere;
}

.badge-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.badge {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
  background: #ecf2f1;
  color: var(--primary-strong);
  max-width: 100%;
  overflow-wrap: anywhere;
}

.badge.warn {
  background: #fff3df;
  color: var(--warning);
}

.messages {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 420px;
  line-height: 1.7;
}

.message {
  max-width: min(860px, 92%);
  display: grid;
  gap: 7px;
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.message-role {
  font-size: 12px;
  color: var(--muted);
  font-weight: 900;
}

.message-body {
  border-radius: 8px;
  padding: 12px 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
}

.message.user .message-body {
  background: #0b756f;
  color: #fff;
  border-color: #0b756f;
}

.message.assistant .message-body {
  background: #fbfcfc;
}

.message-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 260px));
  gap: 10px;
  margin-top: 10px;
}

.message-images img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f8fafb;
}

.message.typing .message-body {
  color: var(--muted);
  font-weight: 800;
}

.typing-dots span {
  animation: typingPulse 1.2s infinite ease-in-out;
}

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

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

@keyframes typingPulse {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

.composer {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.composer textarea {
  width: 100%;
  min-height: 92px;
  max-height: 220px;
  resize: vertical;
  border: 0;
  outline: none;
  line-height: 1.7;
}

.attachment-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.attachment-button.disabled {
  pointer-events: none;
  opacity: 0.62;
}

.attachment-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
}

.attachment-preview {
  width: 112px;
  margin: 0;
  position: relative;
  display: grid;
  gap: 5px;
}

.attachment-preview img {
  width: 112px;
  height: 82px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.attachment-preview figcaption {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-preview button {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(21, 25, 29, 0.76);
  color: #fff;
  font-weight: 900;
}

.image-page {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.image-panel,
.gallery-panel {
  padding: 18px;
}

.image-form {
  display: grid;
  gap: 14px;
}

.image-form textarea {
  min-height: 132px;
}

.image-controls,
.image-upload-box {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)) auto;
  align-items: end;
  gap: 12px;
}

.image-controls .field {
  min-width: 0;
}

.image-upload-box {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.muted-box {
  opacity: 0.82;
}

.image-upload-strip {
  margin-top: 4px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}

.gallery-card {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.gallery-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: #f8fafb;
}

.gallery-card figcaption {
  display: grid;
  gap: 7px;
  padding: 10px;
}

.gallery-card figcaption span,
.gallery-card figcaption small {
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  flex-wrap: wrap;
}

.context-control {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
}

.context-control input[type="range"] {
  width: 130px;
  accent-color: var(--primary);
}

.context-control input[type="number"] {
  width: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 420px);
  gap: 18px;
  align-items: start;
  min-width: 0;
}

.admin-main-stack {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.panel {
  padding: 18px;
}

.panel-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-title p {
  margin: 6px 0 0;
  line-height: 1.5;
}

.table-wrap {
  min-width: 0;
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font-size: 12px;
  color: var(--muted);
  background: #f8fafb;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

.table-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.model-catalog-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) repeat(4, minmax(72px, auto));
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  min-width: 0;
}

.model-name-field,
.model-display-field {
  min-width: 220px;
}

.model-actions {
  grid-column: 1 / -1;
  margin-top: 0;
}

.model-table-wrap {
  margin-top: 8px;
}

.mini-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin: 2px 6px 2px 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-muted);
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 800;
}

.model-checklist {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.model-checklist.compact {
  max-height: 220px;
}

.model-check-row {
  min-height: 40px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(110px, auto);
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f9fbfb;
  color: #293238;
  font-weight: 700;
}

.model-check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.model-check-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.model-real-name {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.model-check-flags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mini-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.mini-check input {
  width: 15px;
  height: 15px;
}

.empty-inline {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  display: inline-block;
  background: var(--primary);
  margin-right: 7px;
}

.status-dot.off {
  background: #abb5bb;
}

.muted {
  color: var(--muted);
}

.nowrap {
  white-space: nowrap;
}

@media (max-width: 1180px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .chat-page {
    grid-template-columns: 1fr;
  }

  .history-panel {
    max-height: 280px;
  }

  .chat-layout {
    min-height: 0;
  }
}

@media (max-width: 980px) {
  .auth-page {
    grid-template-columns: 1fr;
  }

  .auth-aside {
    padding: 30px;
  }

  .shell {
    grid-template-columns: 1fr;
  }

  .shell-chat {
    height: 100dvh;
    min-height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    position: static;
    height: auto;
    max-height: none;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .account-box {
    margin-top: 0;
  }

  .model-catalog-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .model-name-field {
    grid-column: auto;
  }

  .model-display-field {
    grid-column: 1 / -1;
  }

  .chat-layout {
    height: 100%;
    min-height: 0;
  }

  .messages {
    min-height: 0;
  }
}

@media (max-width: 760px) {
  body {
    background: #f4f6f7;
  }

  .shell {
    display: block;
  }

  .shell.shell-chat {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
  }

  .sidebar-head {
    justify-content: flex-start;
  }

  .sidebar-head .brand-logo {
    width: 104px;
  }

  .nav {
    grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
    gap: 6px;
  }

  .nav button {
    min-height: 36px;
    padding: 8px 10px;
    text-align: center;
    font-size: 14px;
  }

  .account-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-top: 10px;
  }

  .shell-chat .account-box {
    display: none;
  }

  .account-box .button {
    width: auto;
    min-height: 34px;
    padding: 7px 10px;
    white-space: nowrap;
  }

  .account-meta {
    font-size: 12px;
  }

  .main {
    display: block;
    overflow: visible;
  }

  .shell-chat .main {
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    overflow: hidden;
  }

  .topbar {
    min-height: 48px;
    padding: 10px 12px;
    background: #fff;
  }

  .shell-chat .topbar {
    display: none;
  }

  .topbar-title strong {
    font-size: 16px;
  }

  .topbar-title span {
    display: none;
  }

  .topbar .button {
    width: auto;
    min-height: 34px;
    padding: 7px 10px;
  }

  .content {
    padding: 12px;
    overflow: visible;
  }

  .shell-chat .content {
    padding: 8px;
  }

  .content-chat {
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .flash {
    margin: 0 0 10px;
    padding: 10px;
    font-size: 14px;
  }

  .panel,
  .chat-header,
  .messages,
  .composer,
  .history-panel {
    border-radius: 8px;
  }

  .chat-page,
  .image-page,
  .admin-layout,
  .admin-main-stack {
    display: grid;
    gap: 10px;
  }

  .chat-page {
    height: 100%;
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
  }

  .shell-chat .history-panel {
    display: none;
  }

  .shell-chat .history-panel.mobile-open {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 90;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    max-height: min(70dvh, 520px);
    padding: 12px;
    box-shadow: 0 18px 50px rgba(21, 25, 29, 0.22);
  }

  .history-head {
    gap: 8px;
  }

  .history-head-actions {
    flex-direction: row;
  }

  .history-head .button {
    width: auto;
    min-height: 32px;
    padding: 6px 9px;
  }

  .mobile-history-toggle,
  .mobile-history-close {
    display: inline-flex;
  }

  .history-list {
    max-height: 146px;
  }

  .history-row {
    grid-template-columns: minmax(0, 1fr) 32px 32px;
  }

  .history-row > button:first-child {
    padding: 8px;
  }

  .history-action,
  .history-delete {
    width: 32px;
    height: 32px;
  }

  .chat-layout {
    height: 100%;
    min-height: 0;
    gap: 8px;
  }

  .chat-header {
    padding: 10px;
  }

  .chat-title h2 {
    font-size: 20px;
  }

  .badge-row {
    gap: 6px;
    margin-top: 7px;
  }

  .badge {
    min-height: 24px;
    padding: 3px 8px;
    font-size: 11px;
  }

  .shell-chat .badge-model-count,
  .shell-chat .badge-ready {
    display: none;
  }

  .chat-tools {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: end;
    gap: 8px;
  }

  .model-switch {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    width: 100%;
  }

  .shell-chat .model-switch span {
    display: none;
  }

  .model-switch select {
    width: 100%;
    max-width: none;
  }

  .chat-tools .button {
    width: auto;
    white-space: nowrap;
  }

  .messages {
    min-height: 0;
    padding: 12px;
    gap: 10px;
  }

  .message {
    max-width: 100%;
  }

  .message-body {
    padding: 10px;
    line-height: 1.65;
  }

  .message-images {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  }

  .composer {
    position: relative;
    bottom: auto;
    z-index: 20;
    padding: 10px;
    box-shadow: none;
  }

  .composer textarea {
    min-height: 68px;
    max-height: 120px;
  }

  .composer-foot {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(92px, auto);
    align-items: end;
    gap: 9px;
  }

  .context-control {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    width: 100%;
    gap: 8px;
  }

  .context-control input[type="number"],
  .context-control input[type="range"] {
    width: 100%;
  }

  .shell-chat .context-control input[type="number"] {
    display: none;
  }

  .composer-foot .button {
    width: 100%;
  }

  .attachment-box {
    align-items: stretch;
  }

  .attachment-button {
    width: 100%;
  }

  .attachment-preview {
    width: 92px;
  }

  .attachment-preview img {
    width: 92px;
    height: 70px;
  }

  .image-panel,
  .gallery-panel,
  .panel {
    padding: 12px;
  }

  .panel-title {
    margin-bottom: 12px;
  }

  .panel-title h2 {
    font-size: 20px;
  }

  .panel-title p {
    font-size: 13px;
  }

  .image-form textarea {
    min-height: 108px;
  }

  .image-controls,
  .image-upload-box {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .image-controls .button {
    width: 100%;
  }

  .image-upload-box .button {
    width: 100%;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .gallery-card figcaption {
    padding: 9px;
    gap: 5px;
  }

  .gallery-card figcaption strong {
    font-size: 13px;
    line-height: 1.35;
  }

  .gallery-card figcaption span,
  .gallery-card figcaption small {
    font-size: 12px;
  }

  .gallery-card .button {
    width: 100%;
    min-height: 34px;
    padding: 7px 10px;
  }

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    border-radius: 8px;
  }

  table {
    min-width: 560px;
  }

  th,
  td {
    padding: 9px;
    font-size: 13px;
  }

  .table-actions .button {
    width: auto;
    min-height: 34px;
    padding: 7px 10px;
  }

  .model-catalog-form {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .model-name-field,
  .model-display-field {
    min-width: 0;
    grid-column: auto;
  }

  .model-checklist {
    max-height: 220px;
    padding: 8px;
  }

  .model-check-row {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
  }

  .model-check-flags {
    grid-column: 2;
    justify-content: flex-start;
  }

  .actions .button,
  .model-actions .button {
    width: 100%;
  }

  .auth-page {
    display: block;
  }

  .auth-aside {
    padding: 18px;
    gap: 18px;
  }

  .auth-main {
    padding: 14px;
  }

  .auth-card {
    padding: 18px;
    box-shadow: none;
  }
}

@media (max-width: 640px) {
  .auth-main,
  .content {
    padding: 10px;
  }

  .auth-card,
  .panel {
    padding: 12px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .chat-header,
  .panel-title,
  .composer-foot {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
  }

  .chat-tools,
  .model-switch,
  .model-switch select,
  .context-control,
  .context-control input[type="range"],
  .context-control input[type="number"],
  .attachment-box,
  .attachment-button,
  .image-controls,
  .image-controls .field,
  .image-upload-box {
    width: 100%;
  }

  .image-controls,
  .image-upload-box {
    grid-template-columns: 1fr;
  }

  .model-catalog-form {
    grid-template-columns: 1fr;
  }

  .model-check-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .model-check-flags {
    grid-column: 2;
    justify-content: flex-start;
  }

  .history-head,
  .history-head-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .history-head-actions {
    align-items: center;
    flex-direction: row;
  }

  .button {
    width: auto;
  }

  table {
    min-width: 620px;
  }

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