@layer legacy {
/* Shared UI surfaces; all colors follow the selected theme. */
html[data-theme] .sidebar { padding: 16px 12px 12px; }
.sidebar .brand { padding: 2px 8px 16px; gap: 12px; }
.sidebar .brand .logo { width: 32px; height: 32px; }
.sidebar .new-chat { min-height: 44px; font-size: 13px; font-weight: 600; }
html[data-theme] .sidebar .new-chat { background: var(--accent-soft); border-color: transparent; color: var(--text); }
html[data-theme] .sidebar .new-chat:hover { border-color: var(--accent); }
.sidebar .sidebar-tool { padding: 8px; gap: 12px; }
.sidebar .sidebar-tool-icon { background: transparent; }
.sidebar .section-label { padding-top: 24px; padding-bottom: 10px; font-size: 10px; font-weight: 600; }
html[data-theme] .sidebar .chat-row.active { background: var(--accent-soft); box-shadow: none; }
.sidebar .profile { padding: 10px 8px; }
.sidebar .profile-plan { display: none; }
html[data-theme] .overlay .modal { border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.overlay .modal-head { top: -24px; margin: -24px -24px 20px; padding: 18px 20px; gap: 16px; }
.overlay .modal-head h2 { font-size: 19px; font-weight: 650; }
.overlay .modal-head .close { flex: 0 0 40px; }
#settingsOverlay .modal { width: min(720px, 100%); }
.settings-tabs { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 4px; border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 24px; }
.settings-tabs button { display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; min-height: 42px; padding: 8px 6px; background: transparent; color: var(--muted); border: 0; border-radius: 6px; cursor: pointer; font: inherit; font-size: 13px; }
.settings-tabs svg { width: 17px; height: 17px; flex-shrink: 0; }
.settings-tabs button:hover { background: var(--soft); color: var(--text); }
.settings-tabs button[aria-selected=true] { color: var(--text); background: var(--accent-soft); font-weight: 600; }
.settings-tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.settings-panels { min-height: 300px; }
.settings-panels [hidden] { display: none; }
.settings-panels :is(.theme-section,.preset-section,.memory-section,.usage-settings) { margin-top: 0; padding-top: 0; border-top: 0; }
.settings-panels .field > :is(label,.preset-label) { font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.settings-panels .theme-grid { grid-template-columns: repeat(5,minmax(0,1fr)); gap: 10px; }
.settings-panels .theme-card { min-height: 84px; padding: 12px; }
.settings-panels .theme-swatch { width: 48px; height: 24px; border-radius: 6px; }
.settings-panels .preset-grid { grid-template-columns: 1fr; gap: 10px; }
.settings-panels .preset-card { min-height: 90px; padding: 16px; }
.settings-panels .preset-card-title { font-size: 14px; }
.settings-panels .preset-card-desc { font-size: 13px; line-height: 1.6; }
.settings-panels .memory-summary { font-size: 14px; line-height: 1.65; padding: 12px 0; }
html[data-theme] .modal .field .memory-toggle { color: var(--muted); }
html[data-theme] .settings-panels .memory-details { border-color: var(--line); }
.settings-panels .memory-row { font-size: 13px; gap: 16px; padding-block: 12px; }
.settings-panels .memory-row button { flex-shrink: 0; }
.memory-row > span { flex: 1; min-width: 0; }
.memory-actions { display: flex; gap: 6px; flex-shrink: 0; }
.memory-editor { display: flex; align-items: flex-start; gap: 12px; width: 100%; }
.memory-editor textarea { flex: 1; min-width: 0; min-height: 88px; resize: vertical; padding: 10px; font: inherit; line-height: 1.5; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); }
@media (max-width: 480px) { .memory-editor { flex-wrap: wrap; } .memory-editor textarea { flex-basis: 100%; } }
.settings-panels .memory-add { gap: 8px; }
.settings-panels .usage-settings { margin-top: 24px; }
.account-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
#settingsOverlay .modal-actions { position: sticky; bottom: -24px; display: flex; justify-content: flex-end; margin: 20px -24px -24px; padding: 16px 24px; }
#settingsOverlay #saveSettings { min-width: 120px; }
html[data-theme] :is(.api-platform-intro,.image-library-intro,.api-platform-section) { border-color: var(--line); }
.api-platform-intro { gap: 16px; padding-bottom: 24px; }
.api-platform-copy h3 { font-size: 18px; font-weight: 600; }
.api-platform-copy p,.image-library-copy p { font-size: 13px; line-height: 1.6; max-width: 520px; }
.api-platform-section { padding-block: 24px; }
.api-platform-section-head { margin-bottom: 14px; gap: 12px; }
.api-platform-section h3 { font-size: 14px; font-weight: 600; }
.api-code { font-size: 12px; line-height: 1.75; padding: 16px; }
.api-doc-endpoint { padding: 4px 0 10px; font-size: 12px; }
.api-key-create { gap: 10px; }
.api-key-empty { padding: 16px 0; font-size: 13px; }
.api-platform-status:empty { display: none; }
.image-library-modal .api-image-empty { min-height: 200px; display: grid; place-items: center; text-align: center; font-size: 14px; padding: 24px; border: 1px dashed var(--line2); border-radius: 8px; }
.image-library-intro { align-items: flex-start; gap: 16px; }
.api-image-gallery { gap: 14px; }
.api-image-item button { min-width: 40px; min-height: 40px; }
.model-menu .model-option { padding: 12px; gap: 12px; min-height: 68px; }
.model-menu .model-option-icon { width: 34px; height: 34px; flex-basis: 34px; }
.model-menu .model-option-title { font-size: 13px; }
.model-menu .model-option-desc { line-height: 1.5; }
.account-menu { padding: 8px; }
.account-menu-btn { min-height: 44px; }
.context button { min-height: 40px; }
.file-pill { max-width: 100%; }
.attach-preview { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; align-items: center; scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }
.attachment-photo { position: relative; flex: 0 0 88px; width: 88px; height: 88px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); overflow: hidden; }
.attachment-photo > img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attachment-remove { display: grid; place-items: center; flex: 0 0 32px; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.attachment-remove svg { width: 16px; height: 16px; }
.attachment-remove:hover { color: var(--text); background: var(--soft); }
.attachment-photo .attachment-remove { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,.75); color: white; }
.file-pill.attachment-file { flex: 0 0 210px; min-width: 0; max-width: 100%; height: 64px; gap: 10px; padding: 8px; }
.attachment-icon { width: 24px; height: 24px; flex: 0 0 24px; color: var(--accent); }
.attachment-info { display: grid; min-width: 0; flex: 1; gap: 4px; }
.attachment-info span { font-size: 12px; font-weight: 600; }
.attachment-info small { color: var(--muted); font-size: 11px; }
[data-preview-image] { cursor: zoom-in; }
[data-preview-image]:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.image-viewer { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #090b0eee; color: #f6f7f9; overscroll-behavior: contain; }
.image-viewer::backdrop { background: #090b0e; }
.image-viewer[open] { display: flex; flex-direction: column; }
.image-viewer-toolbar { display: flex; align-items: center; justify-content: space-between; flex: 0 0 auto; gap: 16px; padding: max(12px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) 12px max(16px,env(safe-area-inset-left)); font-size: 14px; }
.image-viewer-toolbar > div { display: flex; gap: 8px; }
.image-viewer-toolbar button { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid #ffffff38; border-radius: 8px; background: #ffffff0d; color: inherit; cursor: pointer; }
.image-viewer-toolbar button:hover { background: #ffffff20; }
.image-viewer-toolbar button:disabled { opacity: .4; cursor: default; }
.image-viewer-toolbar button:focus-visible { outline: 2px solid white; outline-offset: 3px; }
.image-viewer-toolbar svg { width: 21px; height: 21px; }
.image-viewer-stage { display: flex; align-items: center; justify-content: center; flex: 1; min-height: 0; padding: 8px max(16px,env(safe-area-inset-right)) max(20px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left)); }
.image-viewer-stage img { display: block; width: 100%; height: 100%; object-fit: contain; }
.image-viewer-stage [hidden] { display: none; }
.image-viewer-stage p { max-width: 420px; text-align: center; line-height: 1.6; color: #c5cbd3; }
@media(max-width:760px) {
  html[data-theme] .overlay .modal { padding: 18px; border-radius: 10px; }
  .overlay .modal-head { top: -18px; margin: -18px -18px 16px; padding: 12px 14px; }
  .settings-tabs { gap: 2px; margin-bottom: 20px; }
  .settings-tabs button { flex-direction: column; gap: 5px; font-size: 11px; min-height: 58px; }
  .settings-panels { min-height: 0; }
  .settings-panels .theme-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .settings-panels .theme-card { min-height: 72px; }
  #settingsOverlay .modal-actions { bottom: -18px; margin: 18px -18px -18px; padding: 12px 18px; }
  .account-actions .btn { flex: 1 1 140px; }
  .image-library-intro { flex-wrap: wrap; }
  .model-menu .model-option { min-height: 64px; }
}
@media(prefers-reduced-motion:no-preference) {
  .settings-tabs button { transition: color 150ms ease,background-color 150ms ease; }
}
.stream-notice {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}
.stream-notice p { margin: 0 0 8px; }

}
