:root {
  color-scheme: dark;
  --bg: #171717;
  --panel: #212121;
  --panel-2: #2a2a2a;
  --panel-3: #303030;
  --text: #f4f4f4;
  --muted: #a8a8a8;
  --muted-2: #777;
  --border: rgba(255, 255, 255, 0.11);
  --border-strong: rgba(255, 255, 255, 0.18);
  --accent: #10a37f;
  --accent-2: #0d8f70;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --sidebar-width: 292px;
  --composer-width: 980px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  min-height: 100vh;
  background: #111;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 14px;
  overflow: hidden;
  transition: width 0.2s ease, flex-basis 0.2s ease, padding 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}


.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(3px);
}

.sidebar-backdrop[hidden] {
  display: none !important;
}

body.sidebar-open {
  overflow: hidden;
}

body.sidebar-collapsed .sidebar {
  width: 0;
  flex-basis: 0;
  padding-left: 0;
  padding-right: 0;
  border-right: 0;
  overflow: hidden;
  visibility: hidden;
}

body.sidebar-collapsed .sidebar > * {
  opacity: 0;
  pointer-events: none;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 8px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: #f4f4f4;
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18), 0 8px 22px rgba(0,0,0,0.22);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.brand-title {
  font-weight: 700;
  line-height: 1.2;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.primary-sidebar-btn,
.ghost-sidebar-btn,
.sidebar-footer-btn {
  width: 100%;
  border-radius: 12px;
  padding: 11px 12px;
  color: var(--text);
  text-align: left;
  background: var(--panel-2);
}

.primary-sidebar-btn {
  background: #f4f4f4;
  color: #111;
  font-weight: 700;
}

.ghost-sidebar-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 9px 10px;
  margin-bottom: 8px;
}

.primary-sidebar-btn:hover,
.sidebar-footer-btn:hover,
.ghost-sidebar-btn:hover,
.conversation-item:hover,
.preset-item:hover {
  filter: brightness(1.08);
}

.sidebar-section {
  min-height: 0;
}

.sidebar-section.grow {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px 6px;
}

.section-heading-row h2 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.icon-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 8px;
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
}

.icon-btn:hover {
  background: var(--panel-2);
  color: var(--text);
}

.icon-btn.danger,
.sidebar-footer-btn.danger {
  color: #ff9a9a;
}

.sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: auto;
  padding-right: 2px;
}

.sidebar-list.empty-list-note:empty::after,
.empty-list-note:not(:has(*))::after {
  content: attr(data-empty);
}

.conversation-item,
.preset-item {
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 9px 8px 9px 10px;
  min-height: 44px;
}

.conversation-item.active,
.preset-item.active {
  background: var(--panel-2);
}

.item-main {
  min-width: 0;
}

.item-title {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-subtitle {
  color: var(--muted-2);
  font-size: 12px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.conversation-item:hover .item-actions,
.preset-item:hover .item-actions {
  opacity: 1;
}

.mini-icon {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.mini-icon:hover {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text);
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-footer-btn {
  background: transparent;
  border: 1px solid var(--border);
}

.main-panel {
  flex: 1;
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  background: var(--panel);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.topbar {
  height: 72px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.mobile-menu-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
  align-items: center;
}

.status-pill,
.mini-pill {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.ok {
  color: #a7f3d0;
  border-color: rgba(16, 163, 127, 0.45);
}

.status-pill.warn {
  color: #fde68a;
  border-color: rgba(245, 158, 11, 0.45);
}

.topbar-btn,
.primary-btn,
.secondary-btn {
  border-radius: 10px;
  padding: 9px 13px;
  color: var(--text);
  background: var(--panel-2);
}

.primary-btn {
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.primary-btn:hover {
  background: var(--accent-2);
}

.secondary-btn {
  border: 1px solid var(--border);
}

.chat-scroll {
  min-height: 0;
  overflow-y: auto;
  display: block;
  padding: 34px 24px 20px;
}

.empty-state {
  margin: 0 auto;
  width: min(720px, 100%);
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  color: var(--muted);
}

.empty-state.hidden {
  display: none;
}

.empty-orb {
  width: 78px;
  height: 78px;
  margin: 0 auto 22px;
  border-radius: 22px;
  background: #f4f4f4;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.empty-orb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.empty-state h2 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 28px;
}

.empty-state p {
  margin: 0 auto 22px;
  line-height: 1.6;
}

.empty-suggestions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.suggestion {
  max-width: 210px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 14px;
  padding: 12px;
  text-align: left;
  line-height: 1.45;
}

.message-list {
  width: min(100%, 920px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.message-list:empty {
  display: none;
}

.message {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 14px;
}

.message.user {
  grid-template-columns: minmax(0, 1fr) 38px;
}

.message.user .avatar {
  grid-column: 2;
}

.message.user .message-content {
  grid-column: 1;
  justify-self: end;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  background: #3b3b3b;
  font-weight: 800;
  font-size: 13px;
}

.message.user .avatar {
  background: #5b46f6;
}

.message.assistant .avatar {
  background: var(--accent);
}

.message.error .avatar {
  background: var(--danger);
}

.message-content {
  max-width: 100%;
  border-radius: 18px;
  padding: 14px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  line-height: 1.65;
  white-space: pre-wrap;
}

.message.user .message-content {
  background: #303030;
  max-width: min(760px, 100%);
}

.message.assistant .message-content {
  background: transparent;
  border-color: transparent;
  padding: 0;
}

.message.error .message-content {
  border-color: rgba(239, 68, 68, 0.35);
  color: #fecaca;
}

.message-meta {
  color: var(--muted-2);
  font-size: 12px;
  margin-top: 10px;
  white-space: normal;
}

.request-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  white-space: normal;
}

.summary-chip {
  color: var(--muted);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.image-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
}

.image-card img {
  display: block;
  width: 100%;
  background: #0f0f0f;
  object-fit: contain;
}

.image-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  color: var(--muted);
  font-size: 12px;
}

.download-link {
  color: var(--text);
  text-decoration: none;
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 5px 8px;
}

.attachment-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.attachment-preview {
  width: 86px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #111;
}

.attachment-preview img {
  width: 100%;
  height: 64px;
  object-fit: cover;
  display: block;
}

.attachment-preview span {
  display: block;
  padding: 4px 6px;
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.loading-dots::after {
  content: "";
  display: inline-block;
  width: 1.5em;
  text-align: left;
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75%, 100% { content: "..."; }
}

.composer-shell {
  padding: 12px 24px 20px;
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(33,33,33,0.88), var(--panel));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.validation-panel,
.attachment-strip,
.composer-card,
.param-rail {
  width: min(100%, var(--composer-width));
}

.validation-panel {
  border-radius: 14px;
  border: 1px solid rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.08);
  color: #fde68a;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
}

.validation-panel.error {
  border-color: rgba(239, 68, 68, 0.42);
  background: rgba(239, 68, 68, 0.08);
  color: #fecaca;
}

.hidden {
  display: none !important;
}

.attachment-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0;
}

.attachment-chip {
  display: grid;
  grid-template-columns: 42px minmax(110px, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--panel-2);
  padding: 6px;
  min-width: 240px;
}

.attachment-chip img {
  width: 42px;
  height: 42px;
  border-radius: 9px;
  object-fit: cover;
}

.attachment-chip-title {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip-subtitle {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}

.remove-attachment {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
}

.remove-attachment:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

.composer-card {
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
  padding: 12px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.composer-card > * {
  min-width: 0;
}

#promptInput {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  min-height: 48px;
  max-height: 180px;
  line-height: 1.55;
  padding: 5px 4px;
}

#promptInput::placeholder {
  color: var(--muted-2);
}

.composer-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  min-width: 0;
  width: 100%;
}

.round-action,
.send-btn {
  border-radius: 999px;
  height: 38px;
  padding: 0 13px;
  background: var(--panel-3);
  color: var(--text);
}

.send-btn {
  min-width: 70px;
  background: white;
  color: #111;
  font-weight: 800;
}

.param-rail {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scroll-snap-type: x proximity;
  scroll-padding-inline: 2px 20px;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  min-width: 0;
  padding: 2px 20px 8px 2px;
}

.param-rail::after {
  content: "";
  flex: 0 0 1px;
}

.param-card {
  flex: 0 0 220px;
  min-height: 94px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.045);
  padding: 12px;
  scroll-snap-align: start;
}

.param-card.compact {
  flex-basis: 170px;
}

.param-card.model-card {
  flex-basis: 170px;
}

.param-card.wide {
  flex-basis: 360px;
}

.param-card label,
.form-field span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
  font-weight: 750;
  margin-bottom: 8px;
}

.param-card input,
.param-card select,
.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #171717;
  color: var(--text);
  outline: 0;
  padding: 9px 10px;
}

.param-card select,
.form-field select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 34px;
  background-color: #171717;
  background-image: url("data:image/svg+xml,%3Csvg width='14' height='14' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.5 7.5 10 12l4.5-4.5' fill='none' stroke='%23a8a8a8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
}

.param-card input:disabled,
.param-card select:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.param-card input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

.param-card-head,
.custom-size-row,
.size-builder,
.switch-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.param-card-head {
  justify-content: space-between;
  align-items: center;
  min-height: 18px;
  margin-bottom: 8px;
}

.param-card-head label {
  margin: 0;
  line-height: 1.25;
}

.mini-btn {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: transparent;
  font-size: 12px;
}

.mini-btn:hover {
  color: var(--text);
  background: var(--panel-3);
}

.size-builder {
  display: grid;
  grid-template-columns: minmax(118px, 1fr) minmax(96px, 0.85fr);
  gap: 8px;
}

.custom-size-row {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
}

.checkbox-row,
.switch-row {
  display: flex;
  gap: 9px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}

.switch-row input[type="checkbox"],
.checkbox-row input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 42px;
  height: 24px;
  flex: 0 0 42px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: #0f0f0f;
  padding: 0;
  position: relative;
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease;
}

.switch-row input[type="checkbox"]::after,
.checkbox-row input[type="checkbox"]::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  top: 2px;
  left: 2px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.16s ease, background-color 0.16s ease;
}

.switch-row input[type="checkbox"]:checked,
.checkbox-row input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.switch-row input[type="checkbox"]:checked::after,
.checkbox-row input[type="checkbox"]:checked::after {
  transform: translateX(18px);
  background: #fff;
}

.switch-row input[type="checkbox"]:focus-visible,
.checkbox-row input[type="checkbox"]:focus-visible {
  outline: 2px solid rgba(16, 163, 127, 0.72);
  outline-offset: 2px;
}

.modal-dialog {
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  background: transparent;
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
}

.modal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(8px);
}

.modal-card {
  background: var(--panel);
  padding: 22px;
  overflow: auto;
  max-height: calc(100dvh - 32px);
}

.preset-card {
  width: min(920px, calc(100vw - 24px));
}

#presetDialog {
  width: min(920px, calc(100vw - 24px));
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-header p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.dialog-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 22px;
}

.form-field {
  display: block;
  margin-bottom: 14px;
}

.form-field small {
  color: var(--muted-2);
  display: block;
  margin-top: 6px;
  line-height: 1.45;
}

.form-field textarea {
  resize: vertical;
  min-height: 84px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid.two-cols {
  grid-template-columns: 1.2fr 0.8fr;
}

.form-grid.three-cols {
  grid-template-columns: repeat(3, 1fr);
}

.security-note {
  border-radius: 14px;
  border: 1px solid rgba(245, 158, 11, 0.32);
  background: rgba(245, 158, 11, 0.08);
  color: #fcd34d;
  padding: 10px 12px;
  line-height: 1.5;
  margin: 14px 0;
  font-size: 13px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.toast-host {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  width: min(360px, calc(100vw - 36px));
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: #111;
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  line-height: 1.5;
  animation: toastIn 0.18s ease-out;
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.45);
}

.toast.success {
  border-color: rgba(16, 163, 127, 0.45);
}

@keyframes toastIn {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}


@media (max-width: 1280px) {
  .composer-card {
    grid-template-columns: 1fr;
  }

  .composer-actions {
    justify-content: flex-end;
  }

  .param-card.wide {
    flex-basis: min(380px, 76vw);
  }
}

@media (max-width: 900px), (orientation: portrait) {
  body.sidebar-collapsed .sidebar {
    width: min(86vw, var(--sidebar-width));
    flex-basis: min(86vw, var(--sidebar-width));
    padding: 14px;
    border-right: 1px solid var(--border);
    visibility: visible;
  }

  body.sidebar-collapsed .sidebar > * {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(86vw, var(--sidebar-width));
    flex-basis: min(86vw, var(--sidebar-width));
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 24px 0 70px rgba(0, 0, 0, 0.5);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mobile-menu-btn {
    display: grid;
    place-items: center;
  }

  .main-panel {
    width: 100vw;
  }

  .topbar {
    padding: 0 14px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .status-pill {
    display: none;
  }

  .chat-scroll {
    padding: 24px 14px 16px;
  }

  .composer-shell {
    padding: 10px 12px 14px;
  }

  .composer-card {
    grid-template-columns: 1fr;
    border-radius: 20px;
  }

  .composer-actions {
    justify-content: space-between;
  }

  .param-card.wide {
    flex-basis: 80vw;
  }

  .size-builder {
    grid-template-columns: 1fr 1fr;
  }

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

  .message.user .avatar {
    grid-column: 1;
  }

  .message.user .message-content {
    grid-column: 2;
    justify-self: stretch;
  }

  .avatar {
    width: 32px;
    height: 32px;
  }

  .form-grid.two-cols,
  .form-grid.three-cols {
    grid-template-columns: 1fr;
  }
}

/* ===== v6 overrides ===== */
:root {
  color-scheme: dark light;
  --sidebar-bg: #111111;
  --panel-user: #303030;
  --surface-contrast: #111111;
  --icon-surface: #f4f4f4;
  --icon-ink: #111111;
  --success-text: #a7f3d0;
  --warning-text: #fde68a;
  --danger-soft-text: #fecaca;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light dark;
    --bg: #f3f5f8;
    --panel: #ffffff;
    --panel-2: #f5f7fa;
    --panel-3: #eef2f6;
    --text: #151515;
    --muted: #667085;
    --muted-2: #8a8f98;
    --border: rgba(15, 23, 42, 0.10);
    --border-strong: rgba(15, 23, 42, 0.16);
    --shadow: 0 18px 56px rgba(15, 23, 42, 0.14);
    --sidebar-bg: #f8fafc;
    --panel-user: #eef2f7;
    --surface-contrast: #ffffff;
    --icon-surface: #ffffff;
    --icon-ink: #111111;
    --success-text: #0f766e;
    --warning-text: #92400e;
    --danger-soft-text: #b91c1c;
  }
}

body {
  background: var(--bg);
}

.sidebar {
  background: var(--sidebar-bg);
}

.brand-mark,
.empty-orb,
.primary-sidebar-btn {
  background: var(--icon-surface);
  color: var(--icon-ink);
}

.message.user .message-content {
  background: var(--panel-user);
}

.image-card img,
.attachment-preview,
.toast {
  background: var(--surface-contrast);
}

.status-pill.ok {
  color: var(--success-text);
}

.status-pill.warn,
.validation-panel,
.security-note {
  color: var(--warning-text);
}

.message.error .message-content,
.validation-panel.error {
  color: var(--danger-soft-text);
}

.topbar-btn {
  border-radius: 14px;
}

.message-list {
  gap: 14px;
}

.message {
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
}

.message.user {
  grid-template-columns: minmax(0, 1fr) 34px;
}

.avatar {
  width: 34px;
  height: 34px;
  font-size: 12px;
}

.message-content {
  border-radius: 16px;
  padding: 10px 12px;
  line-height: 1.55;
  white-space: normal;
}

.message-meta {
  font-size: 11.5px;
  margin-top: 0;
}

.request-summary {
  gap: 5px;
  margin-top: 8px;
}

.attachment-preview-grid {
  gap: 6px;
  margin-top: 8px;
}

.param-card > label,
.param-card-head > label,
.form-field > span {
  display: block;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: 0.01em;
  margin: 0 0 8px;
}

.param-card-head {
  align-items: baseline;
  min-height: auto;
}

.message-main-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-body-block + .message-body-block {
  margin-top: 8px;
}

.message-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.message-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.copy-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.copy-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.raw-output {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.raw-output summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
  user-select: none;
}

.raw-output summary::-webkit-details-marker {
  display: none;
}

.raw-output pre {
  margin: 0;
  padding: 0 10px 10px;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  max-height: 360px;
  overflow: auto;
}

.pending-chip {
  color: var(--warning-text);
}

.settings-tools {
  margin: 14px 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel-2);
}

.settings-tools h3 {
  margin: 0;
  font-size: 15px;
}

.settings-tools p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.utility-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.secondary-btn.danger {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}

@media (prefers-color-scheme: light) {
  .copy-btn,
  .raw-output,
  .summary-chip,
  .status-pill,
  .mini-pill {
    background: rgba(15, 23, 42, 0.03);
  }

  .composer-shell {
    background: linear-gradient(180deg, rgba(255,255,255,0.9), var(--panel));
  }

  .message.assistant .message-content {
    background: transparent;
  }
}

/* ===== v7 emergency fixes: no external script + light controls ===== */
@media (prefers-color-scheme: light) {
  .param-card input,
  .param-card select,
  .form-field input,
  .form-field select,
  .form-field textarea,
  .composer-card textarea {
    background-color: #ffffff;
    color: var(--text);
    border-color: var(--border);
  }

  .param-card select,
  .form-field select {
    background-color: #ffffff;
  }

  .param-card input::placeholder,
  .form-field input::placeholder,
  .form-field textarea::placeholder,
  .composer-card textarea::placeholder {
    color: var(--muted-2);
  }

  .send-btn {
    background: #111111;
    color: #ffffff;
  }

  .primary-btn {
    color: #ffffff;
  }
}

/* ===== v8 robust light-mode form controls ===== */
@media (prefers-color-scheme: light) {
  .param-card input,
  .param-card select,
  .form-field input,
  .form-field select,
  .form-field textarea,
  .composer-card textarea {
    background-color: #ffffff !important;
    color: var(--text) !important;
    -webkit-text-fill-color: var(--text);
  }

  .param-card select,
  .form-field select {
    background-image: url("data:image/svg+xml,%3Csvg width='14' height='14' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.5 7.5 10 12l4.5-4.5' fill='none' stroke='%23667085' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 11px center !important;
  }

  .param-card input:disabled,
  .param-card select:disabled {
    color: var(--muted) !important;
    -webkit-text-fill-color: var(--muted);
    background-color: #f3f4f6 !important;
  }
}
