:root {
  color-scheme: light;
  --bg: #f6f3ed;
  --paper: #fffdf9;
  --ink: #1e2329;
  --muted: #6b7280;
  --line: #ddd6cc;
  --accent: #1d6f8f;
  --accent-strong: #0f4d64;
  --warn: #b64b3b;
  --soft: #e8f3f6;
  --shadow: 0 18px 45px rgba(54, 45, 35, 0.12);
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
}

.server-mode-banner {
  padding: 10px 16px;
  background: #fff4cf;
  border-bottom: 1px solid #e2c56a;
  color: #644f07;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

button,
input,
select,
textarea {
  font: inherit;
  min-width: 0;
}

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

.file-action {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  width: auto;
  flex: 0 0 auto;
  margin: 0;
  padding: 0 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 400;
}

.file-action input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.hidden-file-input {
  display: none;
}

button:hover {
  border-color: #9bb9c3;
}

.nav-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  text-decoration: none;
}

.nav-button:hover {
  border-color: #9bb9c3;
}

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

.primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.danger {
  color: var(--warn);
}

.big {
  min-height: 46px;
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #f1ece4;
  padding: 24px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #23313d;
  color: #fff;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 19px;
}

h3 {
  font-size: 16px;
}

p,
small {
  color: var(--muted);
  line-height: 1.55;
}

.panel,
.controls,
.result-area,
.agent-chat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.panel-heading,
.result-toolbar,
.topbar,
.button-row,
.topbar-actions,
.assist-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-actions,
.assist-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.topbar-account {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.topbar-account small {
  color: var(--muted);
  font-weight: 700;
}

.compact-row {
  margin-top: 12px;
  justify-content: flex-start;
}

.generate-actions {
  align-items: center;
}

.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

label {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  font-size: 13px;
  font-weight: 700;
  color: #39414a;
}

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

textarea {
  min-height: 105px;
  resize: vertical;
  line-height: 1.45;
}

#profileNote {
  min-height: 64px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 111, 143, 0.14);
}

.two-col,
.param-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.size-note {
  grid-column: 1 / -1;
  margin: -4px 0 0;
  font-size: 11px;
  line-height: 1.25;
  color: var(--muted);
  white-space: nowrap;
}

.site-footer {
  padding: 18px 16px 24px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--accent-strong);
}

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

.prompt-sites {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.prompt-sites a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--accent-strong);
  font-size: 13px;
  text-decoration: none;
}

.prompt-library {
  margin-top: 10px;
}

.prompt-samples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.prompt-samples button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.workspace {
  padding: 24px;
  overflow: auto;
}

.topbar {
  margin-bottom: 22px;
}

.creator {
  display: grid;
  grid-template-columns: minmax(420px, 560px) minmax(360px, 1fr);
  gap: 22px;
  align-items: start;
}

.controls,
.result-area {
  padding: 20px;
}

.account-panel {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfb;
}

.account-login,
.account-models {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: end;
  margin-top: 12px;
}

@media (max-width: 680px) {
  .account-login,
  .account-models {
    grid-template-columns: 1fr;
  }

  .profile-shell {
    padding: 12px;
  }

  .profile-grid,
  .profile-main-grid {
    grid-template-columns: 1fr;
  }

  .profile-daily-bars {
    grid-template-columns: repeat(7, minmax(26px, 1fr));
    row-gap: 14px;
  }

  .profile-bar-head,
  .profile-list-item {
    align-items: flex-start;
    flex-direction: column;
  }

  .profile-attachment-main {
    width: 100%;
  }
}

@media (min-width: 681px) and (max-width: 1180px) {
  .profile-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .profile-settings {
    grid-column: 1 / -1;
  }

  .profile-main-grid {
    grid-template-columns: 1fr;
  }
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

.login-shell {
  width: min(440px, calc(100vw - 32px));
}

.login-card {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.profile-shell {
  min-height: 100vh;
  padding: 24px;
}

.profile-topbar {
  margin-bottom: 18px;
}

.profile-grid,
.profile-main-grid {
  display: grid;
  gap: 14px;
}

.profile-grid {
  grid-template-columns: minmax(260px, 1.5fr) repeat(4, minmax(150px, 1fr));
  margin-bottom: 14px;
}

.profile-main-grid {
  grid-template-columns: minmax(0, 1.4fr) minmax(340px, 0.8fr);
  margin-bottom: 14px;
}

.profile-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.profile-settings label {
  margin-top: 12px;
}

.profile-stat-card {
  display: flex;
  min-height: 150px;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

.profile-stat-card span,
.profile-stat-card small,
.profile-card small,
.form-hint,
.empty-note {
  color: var(--muted);
}

.profile-stat-card strong {
  font-size: 28px;
  color: var(--ink);
}

#profileRoleBadge {
  padding: 5px 10px;
  border-radius: 999px;
  background: #e6f3ee;
  color: #267451;
  font-size: 12px;
  font-weight: 700;
}

.profile-bars {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.profile-bar-row {
  display: grid;
  gap: 7px;
}

.profile-bar-head,
.profile-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.profile-bar-head strong,
.profile-list-item strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-bar-head span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
}

.profile-bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eeee;
}

.profile-bar-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: hsl(calc(185 + var(--bar-index) * 28), 70%, 42%);
}

.profile-daily-bars {
  display: grid;
  min-height: 190px;
  grid-template-columns: repeat(14, minmax(26px, 1fr));
  align-items: end;
  gap: 8px;
  padding-top: 18px;
}

.profile-day {
  display: grid;
  align-items: end;
  gap: 8px;
  text-align: center;
}

.profile-day i {
  display: block;
  width: 100%;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, #16b4d8, #f1c40f);
}

.profile-day span {
  color: var(--muted);
  font-size: 12px;
}

.profile-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.profile-list-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.profile-list-item:last-child {
  border-bottom: 0;
}

.profile-list-item div {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.profile-list-item .cost {
  color: #c0392b;
  font-weight: 700;
}

.profile-list-item .income {
  color: #267451;
  font-weight: 700;
}

.profile-attachment-item {
  align-items: center;
}

.profile-attachment-main {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.attachment-thumb,
.attachment-file-icon {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f8f8;
}

.attachment-thumb {
  display: block;
  padding: 0;
  cursor: zoom-in;
}

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

.attachment-file-icon {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.login-actions {
  margin-top: 18px;
}

.login-links {
  margin-top: 16px;
  font-size: 13px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f0e8;
}

.segmented button {
  border: 0;
  background: transparent;
  min-height: 36px;
}

.segmented button.active {
  background: #fff;
  box-shadow: 0 2px 8px rgba(46, 39, 31, 0.1);
  color: var(--accent-strong);
  font-weight: 800;
}

.file-drop {
  display: grid;
  gap: 12px;
  padding: 14px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  border: 1px dashed #adc4cc;
  border-radius: 8px;
  background: var(--soft);
}

.file-drop label {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  margin-top: 0;
}

.file-drop input,
.file-drop select {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.file-drop input[type="file"] {
  inline-size: 100%;
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.upload-actions button {
  flex: 0 1 auto;
  max-width: 100%;
}

.upload-actions small,
#fileHint {
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.uploaded-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
}

.uploaded-image-item {
  display: grid;
  gap: 6px;
}

.uploaded-image-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  cursor: zoom-in;
}

.uploaded-image-item small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

details {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

summary {
  cursor: pointer;
  font-weight: 800;
}

.advanced {
  margin-top: 8px;
}

.preview-box {
  display: grid;
  min-height: 420px;
  align-content: start;
  gap: 12px;
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  overflow: auto;
}

.assist-actions {
  margin-top: 14px;
}

.agent-chat {
  margin-top: 16px;
  padding: 16px;
  box-shadow: none;
}

.agent-chat-list {
  display: grid;
  gap: 10px;
  max-height: 260px;
  margin-top: 12px;
  overflow: auto;
}

.agent-message {
  max-width: 92%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.agent-message.user {
  justify-self: end;
  background: #e8f3f6;
  border-color: #b8d1da;
}

.agent-message.assistant {
  justify-self: start;
}

.agent-message strong {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  color: var(--muted);
}

.log-panel {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #252a30;
  color: #f7f2e9;
}

.log-panel h3 {
  color: #fff;
}

.log-panel pre {
  max-height: 260px;
  margin-top: 12px;
  overflow: auto;
  color: #f7f2e9;
}

.settings-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  border: 0;
  border-radius: 10px;
  padding: 0;
  background: transparent;
}

.settings-dialog.fallback-open,
.image-viewer.fallback-open {
  position: fixed;
  inset: 14px;
  z-index: 20;
  display: block;
  margin: auto;
}

.settings-dialog::backdrop {
  background: rgba(28, 28, 28, 0.42);
}

.settings-content {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.settings-content textarea {
  min-height: 130px;
}

.image-result {
  display: grid;
  gap: 8px;
}

.image-result-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.preview-box img,
.history-item img {
  cursor: zoom-in;
}

.preview-box img {
  width: 100%;
  max-height: 540px;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
}

.image-viewer {
  width: min(1180px, calc(100vw - 24px));
  height: min(860px, calc(100vh - 24px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  background: transparent;
}

.image-viewer::backdrop {
  background: rgba(13, 17, 20, 0.72);
}

.image-viewer-content {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: #101418;
  color: #fff;
}

.image-viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.image-viewer-toolbar p {
  color: #c8d0d8;
}

.image-viewer-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 14px;
  overflow: auto;
}

.image-viewer-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.55;
}

#statusBadge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: #ede7dd;
  color: #5b5045;
  font-size: 12px;
  font-weight: 800;
}

#statusBadge.busy {
  background: #fff4cf;
}

#statusBadge.ok {
  background: #dff2df;
  color: #23602f;
}

#statusBadge.error {
  background: #fde4df;
  color: #a33628;
}

.history-wrap {
  margin-top: 18px;
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: 280px;
  overflow: auto;
  margin-top: 12px;
}

.history-item {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.history-item img {
  width: 74px;
  height: 74px;
  object-fit: cover;
  border-radius: 6px;
  background: #f4f1ec;
}

.history-item strong {
  display: block;
  margin-bottom: 5px;
}

.history-item p {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.memory-shell {
  height: 100vh;
  padding: 24px;
  overflow: hidden;
}

.memory-topbar {
  margin-bottom: 18px;
}

.memory-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(380px, 1fr) minmax(260px, 340px);
  gap: 16px;
  align-items: stretch;
  height: calc(100vh - 128px);
  min-height: 0;
}

.memory-side,
.memory-main,
.memory-panel {
  min-width: 0;
  min-height: 0;
  padding: 16px;
  box-shadow: none;
}

.memory-side,
.memory-panel {
  overflow: auto;
}

.memory-main {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 12px;
}

.memory-meta {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfb;
  color: var(--muted);
  font-size: 13px;
}

.memory-meta strong {
  color: var(--ink);
  font-size: 15px;
}

.memory-meta span,
.memory-meta p {
  overflow-wrap: anywhere;
}

.memory-heading-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.memory-heading-actions button {
  min-height: 34px;
  padding: 0 10px;
  white-space: nowrap;
}

.memory-action-row {
  justify-content: flex-start;
  gap: 8px;
  flex-wrap: nowrap;
  margin-top: 12px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.memory-action-row button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 9px;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
}

.memory-list-heading {
  margin-top: 18px;
}

.memory-conversation-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  max-height: calc(100vh - 350px);
  overflow: auto;
}

.memory-conversation {
  display: grid;
  height: auto;
  min-height: 72px;
  justify-items: stretch;
  gap: 4px;
  padding: 10px;
  text-align: left;
}

.memory-conversation.active {
  border-color: var(--accent);
  background: var(--soft);
}

.memory-conversation strong,
.memory-conversation span,
.memory-conversation small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-conversation span,
.memory-conversation small,
.memory-empty {
  color: var(--muted);
  font-size: 12px;
}

.memory-messages {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  overflow-y: auto;
}

.memory-message {
  display: grid;
  gap: 6px;
  max-width: 88%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  line-height: 1.55;
}

.memory-message.user {
  justify-self: end;
  border-color: #b8d1da;
  background: #e8f3f6;
}

.memory-message.assistant {
  justify-self: start;
}

.memory-message strong,
.memory-message small {
  color: var(--muted);
  font-size: 12px;
}

.memory-input-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.memory-attachments {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfb;
}

.memory-attachment-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.memory-attachment-actions div {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.memory-attachment-actions button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
  white-space: nowrap;
}

.memory-temp-attachment-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.memory-temp-attachment-option input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.memory-attachment-list {
  display: grid;
  gap: 8px;
}

.memory-attachment-list > span {
  color: var(--muted);
  font-size: 13px;
}

.memory-attachment-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.memory-attachment-item strong,
.memory-attachment-item small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-attachment-item small {
  color: var(--muted);
}

.memory-attachment-item button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.memory-input-bar textarea {
  min-height: 78px;
  max-height: 180px;
}

#memoryCostBadge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: #ede7dd;
  color: #5b5045;
  font-size: 12px;
  font-weight: 800;
}

#memoryText {
  max-height: calc(100vh - 260px);
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  overflow: auto;
}

.memory-help p {
  margin-top: 8px;
  font-size: 13px;
}

.memory-skills-dialog {
  width: min(820px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  border: 0;
  border-radius: 10px;
  padding: 0;
  background: transparent;
}

.memory-skills-dialog::backdrop {
  background: rgba(28, 28, 28, 0.42);
}

.memory-skills-dialog.fallback-open {
  position: fixed;
  inset: 14px;
  z-index: 30;
  display: block;
  margin: auto;
}

.memory-skills-content {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 28px);
  padding: 18px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.memory-skills-body {
  display: grid;
  gap: 16px;
}

.memory-skill-group {
  display: grid;
  gap: 10px;
}

.memory-skill-group h4 {
  margin: 0;
}

.memory-skill-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfb;
}

.memory-skill-card div {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.memory-skill-card span,
.memory-skill-card small,
.memory-skill-card p {
  color: var(--muted);
}

.memory-skill-card p {
  margin: 0;
  line-height: 1.55;
}

.memory-skill-card small {
  overflow-wrap: anywhere;
}

.memory-presets {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.memory-presets button {
  min-height: 34px;
  padding: 0 8px;
  font-size: 13px;
}

@media (max-width: 1080px) {
  .app-shell,
  .creator {
    grid-template-columns: 1fr;
  }

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

  .memory-conversation-list,
  #memoryText {
    max-height: none;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 680px) {
  .workspace,
  .sidebar {
    padding: 14px;
  }

  .controls,
  .result-area,
  .panel,
  .file-drop {
    min-width: 0;
  }

  .file-drop {
    padding: 12px;
  }

  .workspace {
    padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  }

  .memory-shell {
    min-height: 100dvh;
    padding: 14px;
    overflow: auto;
  }

  .memory-layout {
    display: grid;
    height: auto;
    gap: 14px;
    min-height: auto;
  }

  .memory-topbar {
    margin-bottom: 14px;
  }

  .memory-side,
  .memory-main,
  .memory-panel {
    padding: 14px;
  }

  .memory-main {
    order: 1;
  }

  .memory-side {
    order: 2;
  }

  .memory-panel {
    order: 3;
  }

  .memory-main {
    min-height: calc(100dvh - 122px);
  }

  .memory-messages {
    min-height: calc(100dvh - 340px);
    padding: 12px;
  }

  .memory-message {
    max-width: 96%;
  }

  .memory-input-bar {
    position: sticky;
    bottom: 0;
    z-index: 10;
    grid-template-columns: minmax(0, 1fr) 72px;
    margin: 0 -14px -14px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--line);
    background: rgba(255, 253, 249, 0.96);
    backdrop-filter: blur(10px);
  }

  .memory-input-bar textarea {
    min-height: 54px;
    max-height: 120px;
  }

  .memory-attachment-actions {
    display: grid;
    align-items: stretch;
  }

  .memory-attachment-actions div {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .memory-input-bar button {
    width: 72px;
    min-height: 54px;
  }

  .nav-button {
    width: 100%;
  }

  .memory-action-row {
    display: grid;
    grid-template-columns: 0.8fr 1.4fr 0.8fr;
    overflow-x: visible;
  }

  .memory-action-row button {
    width: 100%;
    min-height: 40px;
    padding: 0 8px;
    font-size: 13px;
  }

  .memory-conversation-list {
    max-height: 260px;
  }

  .memory-conversation {
    min-height: 62px;
  }

  .memory-presets {
    grid-template-columns: 1fr;
  }

  .memory-heading-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .memory-skills-dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .memory-skills-content {
    min-height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .memory-skill-card div {
    display: grid;
  }

  .creator {
    gap: 14px;
  }

  .controls,
  .result-area {
    padding: 14px;
    box-shadow: none;
  }

  .topbar,
  .topbar-actions,
  .topbar-account {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .topbar-account small {
    text-align: right;
  }

  .topbar {
    margin-bottom: 14px;
  }

  .topbar h2 {
    font-size: 18px;
  }

  .topbar p {
    font-size: 13px;
  }

  .account-panel {
    position: sticky;
    top: 0;
    z-index: 8;
    margin: -14px -14px 14px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    background: rgba(248, 251, 251, 0.96);
    backdrop-filter: blur(10px);
  }

  .account-panel .panel-heading {
    align-items: flex-start;
  }

  .account-models {
    grid-template-columns: 1fr;
  }

  .account-models label {
    margin-top: 0;
  }

  #logoutBtn {
    width: 100%;
  }

  .segmented {
    margin: 0 -2px 12px;
  }

  .segmented button {
    min-height: 42px;
    padding: 6px 4px;
    line-height: 1.2;
    white-space: normal;
  }

  #prompt {
    min-height: 150px;
  }

  .prompt-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .prompt-toolbar button,
  .prompt-samples button,
  .prompt-sites a {
    width: 100%;
  }

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

  .prompt-samples button {
    min-height: 40px;
    height: auto;
    padding: 8px;
    white-space: normal;
  }

  .prompt-sites {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .prompt-sites span {
    grid-column: 1 / -1;
  }

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

  .file-action,
  .upload-actions button {
    width: 100%;
  }

  .file-drop input[type="file"]::file-selector-button {
    min-height: 38px;
    margin-right: 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--ink);
  }

  .upload-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .upload-actions small {
    grid-column: 1 / -1;
  }

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

  .generate-actions {
    position: sticky;
    right: -14px;
    bottom: 0;
    left: -14px;
    z-index: 12;
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin: 16px -14px -14px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--line);
    background: rgba(255, 253, 249, 0.96);
    backdrop-filter: blur(10px);
  }

  .generate-actions button {
    width: 100%;
    min-height: 46px;
  }

  .preview-box {
    min-height: 260px;
    max-height: none;
    padding: 12px;
  }

  .preview-box img {
    max-height: 440px;
  }

  .result-toolbar,
  .assist-actions,
  .agent-chat .button-row,
  .image-result-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .assist-actions button,
  .agent-chat .button-row button,
  .image-result-actions button {
    width: 100%;
  }

  .agent-chat {
    padding: 12px;
  }

  .agent-chat-list {
    max-height: 220px;
  }

  .history-list {
    max-height: none;
  }

  .history-item {
    grid-template-columns: 64px 1fr;
  }

  .history-item img {
    width: 64px;
    height: 64px;
  }

  .settings-dialog,
  .image-viewer {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .settings-content {
    min-height: 100dvh;
    max-height: 100dvh;
    overflow: auto;
    border-radius: 0;
    padding: 16px;
  }

  .image-viewer-content {
    border-radius: 0;
  }

  .image-viewer-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .image-viewer-toolbar .topbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
  }

  .image-viewer-stage {
    padding: 8px;
  }

  .log-panel pre {
    max-height: 220px;
  }

  .profile-shell {
    padding: 12px;
  }

  .profile-grid,
  .profile-main-grid {
    grid-template-columns: 1fr;
  }

  .profile-daily-bars {
    grid-template-columns: repeat(7, minmax(26px, 1fr));
    row-gap: 14px;
  }

  .profile-bar-head,
  .profile-list-item {
    align-items: flex-start;
    flex-direction: column;
  }

  .profile-attachment-main {
    width: 100%;
  }

  .memory-heading-actions {
    max-width: 100%;
    min-width: 0;
  }

  .memory-panel > .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .memory-heading-actions button {
    flex: 1 1 120px;
    min-width: 0;
  }

  body.memory-page {
    height: 100dvh;
    overflow: hidden;
  }

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

  .memory-page .memory-topbar {
    display: flex;
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
    gap: 8px;
    margin: 0;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 253, 249, 0.98);
  }

  .memory-page .memory-topbar h2 {
    font-size: 16px;
  }

  .memory-page .memory-topbar p {
    display: none;
  }

  .memory-page .memory-topbar .topbar-account {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
  }

  .memory-page .memory-topbar .topbar-account small {
    display: none;
  }

  .memory-page .memory-topbar .topbar-actions {
    display: flex;
    align-items: center;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 6px;
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .memory-page .memory-topbar .topbar-actions::-webkit-scrollbar {
    display: none;
  }

  .memory-page .memory-topbar .nav-button,
  .memory-page .memory-topbar button {
    flex: 0 0 auto;
    width: auto;
    min-height: 34px;
    padding: 0 9px;
    white-space: nowrap;
  }

  .memory-page .memory-layout {
    height: 100%;
    min-height: 0;
    padding: 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .memory-page .memory-main {
    height: calc(100dvh - 82px);
    min-height: 0;
    padding: 12px 12px calc(98px + env(safe-area-inset-bottom, 0px));
    border-radius: 0;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .memory-page .memory-main > .panel-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .memory-page .memory-main > .panel-heading #memoryCostBadge {
    align-self: flex-start;
  }

  .memory-page .memory-messages {
    min-height: 0;
    height: auto;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .memory-page .memory-attachments {
    margin-bottom: 6px;
  }

  .memory-page .memory-input-bar {
    position: fixed;
    right: 0;
    bottom: var(--memory-input-bottom, 0px);
    left: 0;
    z-index: 50;
    grid-template-columns: minmax(0, 1fr) 72px;
    margin: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--line);
    background: rgba(255, 253, 249, 0.98);
    box-shadow: 0 -10px 24px rgba(21, 30, 36, 0.08);
    backdrop-filter: blur(12px);
  }

  .memory-page .memory-input-bar textarea {
    min-height: 48px;
    max-height: 132px;
    border-radius: 18px;
    resize: none;
  }

  .memory-page .memory-input-bar button {
    width: 72px;
    min-height: 48px;
    border-radius: 18px;
  }
}

@media (max-width: 390px) {
  .two-col,
  .prompt-toolbar,
  .prompt-samples,
  .prompt-sites,
  .param-grid,
  .upload-actions,
  .generate-actions {
    grid-template-columns: 1fr;
  }

  .memory-shell {
    padding: 10px;
  }

  .memory-side,
  .memory-main,
  .memory-panel {
    padding: 12px;
  }

  .memory-action-row {
    grid-template-columns: 1fr;
  }

  .memory-input-bar {
    grid-template-columns: minmax(0, 1fr) 64px;
    margin-right: -12px;
    margin-bottom: -12px;
    margin-left: -12px;
    padding-right: 12px;
    padding-left: 12px;
  }

  .memory-input-bar button {
    width: 64px;
  }

  .memory-page .memory-input-bar {
    right: 0;
    left: 0;
    grid-template-columns: minmax(0, 1fr) 64px;
    margin: 0;
    padding-right: 10px;
    padding-left: 10px;
  }

  .memory-page .memory-input-bar button {
    width: 64px;
  }

  .image-viewer-toolbar .topbar-actions {
    grid-template-columns: 1fr;
  }
}
