:root {
  color-scheme: light;
  --app-height: 100vh;
  --bg: #fffdfb;
  --bg-green: #f4faef;
  --panel: rgba(255, 255, 255, 0.88);
  --line: #e8dedb;
  --line-soft: #f0e9e6;
  --text: #2c2826;
  --muted: #7f7470;
  --soft: #f0f8ea;
  --accent: #4d9a38;
  --accent-strong: #3f812e;
  --accent-soft: #e8f5df;
  --user: #4d9a38;
  --assistant: #ffffff;
  --danger: #b3261e;
  --shadow: 0 18px 44px rgba(67, 49, 53, 0.12);
  --shadow-soft: 0 8px 22px rgba(72, 53, 57, 0.08);
  --font-ui: 16px;
  --font-ui-small: 14px;
  --font-meta: 12px;
  --font-title: 19px;
  --font-brand: 18px;
  --font-chat: 18px;
  --font-chat-small: 15px;
  --font-dialog-title: 23px;
  --font-login-title: 32px;
  --icon-size: 40px;
  --icon-font: 24px;
  --control-height: 50px;
  --button-height: 50px;
}

@supports (height: 100dvh) {
  :root {
    --app-height: 100dvh;
  }
}

html {
  height: 100%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: var(--app-height);
  font-family: "Avenir Next", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(145deg, #fffdfb 0%, #fffaf8 48%, var(--bg-green) 100%);
  color: var(--text);
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: var(--app-height);
}

.app[data-font-size="small"] {
  --font-ui: 14px;
  --font-ui-small: 12px;
  --font-meta: 11px;
  --font-title: 16px;
  --font-brand: 15px;
  --font-chat: 15px;
  --font-chat-small: 13px;
  --font-dialog-title: 20px;
  --font-login-title: 28px;
  --icon-size: 34px;
  --icon-font: 21px;
  --control-height: 44px;
  --button-height: 44px;
}

.app[data-font-size="large"] {
  --font-ui: 18px;
  --font-ui-small: 15px;
  --font-meta: 13px;
  --font-title: 21px;
  --font-brand: 20px;
  --font-chat: 20px;
  --font-chat-small: 17px;
  --font-dialog-title: 26px;
  --font-login-title: 36px;
  --icon-size: 44px;
  --icon-font: 26px;
  --control-height: 54px;
  --button-height: 54px;
}

.special-only {
  display: none;
}

.is-special .special-only {
  display: grid;
}

.login {
  display: none;
  min-height: var(--app-height);
  place-items: center;
  padding: 24px;
}

.is-locked .login {
  display: grid;
}

.is-locked .shell,
.is-locked .template-dialog {
  display: none;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 30px;
  backdrop-filter: blur(18px);
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: var(--font-login-title);
  line-height: 1.2;
}

.login-panel p {
  margin: 0 0 20px;
  color: var(--muted);
}

#loginForm {
  display: grid;
  gap: 12px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88, 166, 63, 0.18);
}

input {
  height: var(--control-height);
  padding: 0 12px;
  font-size: var(--font-ui);
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 680;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

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

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: default;
  opacity: 0.62;
}

#loginForm button {
  height: var(--button-height);
  font-size: var(--font-ui);
}

.error {
  min-height: 20px;
  margin-top: 12px;
  color: var(--danger);
  font-size: var(--font-ui);
}

.shell {
  position: relative;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  height: var(--app-height);
  min-height: 0;
  transition: grid-template-columns 160ms ease;
}

.shell.sidebar-collapsed {
  grid-template-columns: 64px minmax(0, 1fr);
}

.sidebar {
  z-index: 3;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--line);
  background: rgba(255, 249, 247, 0.78);
  backdrop-filter: blur(18px);
}

.sidebar-backdrop {
  display: none;
}

.mobile-menu-button {
  display: none;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 68px;
  padding: 14px 15px;
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  min-width: 0;
  flex: 1;
}

.app-title {
  font-size: var(--font-brand);
  font-weight: 780;
  letter-spacing: 0;
}

.app-subtitle,
.chat-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: var(--font-ui-small);
}

.icon-button {
  width: var(--icon-size);
  height: var(--icon-size);
  display: grid;
  place-items: center;
  padding: 0;
  font-size: var(--icon-font);
  line-height: 1;
  box-shadow: none;
}

.sidebar-toggle {
  flex: 0 0 36px;
  background: rgba(255, 255, 255, 0.56);
  color: var(--muted);
  border: 1px solid var(--line);
}

.sidebar-toggle:hover {
  background: #fff;
  color: var(--accent);
}

.shell.sidebar-collapsed .sidebar-head {
  flex-direction: column;
  justify-content: flex-start;
  gap: 8px;
  padding: 12px 8px;
}

.shell.sidebar-collapsed .brand,
.shell.sidebar-collapsed .conversation-list,
.shell.sidebar-collapsed .sidebar-foot {
  display: none;
}

.conversation-list {
  flex: 1;
  overflow: auto;
  padding: 10px 9px 14px;
}

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: var(--font-ui-small);
}

.sidebar-foot span {
  min-width: 0;
  overflow: hidden;
  padding: 6px 9px;
  border: 1px solid rgba(77, 154, 56, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.66);
  color: var(--accent-strong);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-foot button {
  margin-left: auto;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
  color: var(--muted);
  font-size: var(--font-ui-small);
  font-weight: 650;
}

.sidebar-foot button:hover {
  background: #fff;
  color: var(--danger);
}

.conversation-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px 28px;
  gap: 6px;
  align-items: center;
  margin: 0 0 6px;
  padding: 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.conversation-item:hover,
.conversation-item.is-active {
  background: rgba(255, 255, 255, 0.72);
  border-color: var(--line-soft);
  box-shadow: var(--shadow-soft);
}

.conversation-open {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 5px 6px;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.conversation-open:hover {
  background: transparent;
}

.conversation-title-edit,
.conversation-delete {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: calc(var(--font-ui) + 4px);
  line-height: 1;
}

.conversation-title-edit {
  font-size: var(--font-ui);
}

.conversation-title-edit:hover {
  background: var(--soft);
  color: var(--accent);
}

.conversation-delete:hover {
  background: var(--soft);
  color: var(--danger);
}

.conversation-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--font-ui);
}

.conversation-item small {
  overflow: hidden;
  color: var(--muted);
  font-size: var(--font-ui-small);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat {
  display: grid;
  grid-template-rows: 68px minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(255, 253, 251, 0.94), rgba(255, 251, 248, 0.74) 54%, rgba(245, 250, 241, 0.58));
}

.chat-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 0 28px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255, 253, 251, 0.76);
  backdrop-filter: blur(18px);
}

.chat-head > div:first-child {
  min-width: 0;
  flex: 1;
  padding-right: 10px;
}

.chat-title {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--font-title);
  font-weight: 780;
}

.chat-actions {
  position: static;
  transform: none;
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  padding: 4px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow-soft);
}

.view-switch {
  position: static;
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  padding: 4px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow-soft);
}

.view-switch button {
  height: 34px;
  min-width: 58px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: var(--font-ui);
  font-weight: 800;
}

.view-switch button:hover,
.view-switch button.is-active {
  background: var(--accent);
  color: #fff;
}

.new-chat-button,
.model-button,
.font-size-button {
  flex: 0 0 34px;
  background: transparent;
  color: var(--accent-strong);
  border: 0;
}

.model-button {
  display: none;
  width: 64px;
  font-size: var(--font-ui-small);
  font-weight: 800;
  white-space: nowrap;
}

.is-special .model-button {
  display: inline-grid;
}

.font-size-button {
  width: 36px;
  font-size: var(--font-ui-small);
  font-weight: 800;
}

.new-chat-button:hover,
.model-button:hover,
.font-size-button:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 26px 28px;
}

.message-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  margin-bottom: 17px;
}

.message-row.user {
  align-items: flex-end;
}

.message-row.assistant {
  align-items: flex-start;
}

.bubble {
  min-width: 0;
  max-width: min(760px, 78%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: var(--font-chat);
  line-height: 1.68;
  overflow-wrap: anywhere;
  box-shadow: 0 4px 16px rgba(70, 53, 57, 0.04);
}

.user .bubble {
  border-color: transparent;
  background: var(--user);
  color: #fff;
  box-shadow: 0 8px 20px rgba(77, 154, 56, 0.18);
}

.assistant .bubble {
  background: rgba(255, 255, 255, 0.9);
}

.assistant .bubble.is-loading {
  min-width: 128px;
  min-height: 46px;
  display: flex;
  align-items: center;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: var(--font-chat-small);
  line-height: 1;
}

.typing-indicator i {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  opacity: 0.38;
  animation: typing-pulse 1s ease-in-out infinite;
}

.typing-indicator i:nth-child(2) {
  animation-delay: 120ms;
}

.typing-indicator i:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes typing-pulse {
  0%,
  70%,
  100% {
    transform: translateY(0);
    opacity: 0.32;
  }

  35% {
    transform: translateY(-3px);
    opacity: 0.82;
  }
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
  color: var(--muted);
  font-size: var(--font-meta);
  opacity: 0.82;
}

.message-meta button {
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: var(--font-meta);
  font-weight: 440;
}

.message-meta button:hover {
  background: transparent;
  color: var(--accent);
}

.message-meta .message-delete:hover {
  color: var(--danger);
}

.bubble > :first-child {
  margin-top: 0;
}

.bubble > :last-child {
  margin-bottom: 0;
}

.bubble pre {
  max-width: 100%;
  overflow: auto;
  border-radius: 8px;
  padding: 12px;
  background: #f7f3f4;
}

.bubble code {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
}

.bubble th,
.bubble td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px;
  gap: 10px;
  padding: 14px 28px calc(18px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line-soft);
  background: rgba(255, 253, 251, 0.78);
  backdrop-filter: blur(18px);
}

.composer textarea {
  min-height: var(--control-height);
  max-height: 168px;
  resize: none;
  padding: 11px 13px;
  font-size: var(--font-chat);
  line-height: 1.5;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.composer button {
  height: var(--button-height);
  font-size: var(--font-ui);
  align-self: end;
  box-shadow: 0 8px 18px rgba(77, 154, 56, 0.2);
}

.image-page {
  display: none;
  min-height: 0;
  overflow: auto;
  padding: 22px 28px calc(24px + env(safe-area-inset-bottom, 0px));
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(250, 252, 248, 0.68)),
    var(--surface);
}

.chat.is-image-mode {
  grid-template-rows: 68px minmax(0, 1fr);
}

.chat.is-image-mode .messages,
.chat.is-image-mode .composer {
  display: none;
}

.chat.is-image-mode .image-page {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.image-editor,
.image-result {
  min-width: 0;
  border: 1px solid rgba(24, 33, 28, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-soft);
}

.image-editor {
  align-self: start;
  display: grid;
  gap: 12px;
  padding: 16px;
}

.image-mode-note {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid rgba(77, 154, 56, 0.14);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(244, 250, 239, 0.92), rgba(255, 250, 250, 0.92));
}

.image-mode-note strong {
  font-size: var(--font-ui);
  font-weight: 850;
}

.image-mode-note span {
  color: var(--accent-strong);
  font-size: var(--font-ui-small);
  font-weight: 700;
  text-align: right;
}

.image-drop {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 13px;
  border: 1px dashed rgba(77, 154, 56, 0.28);
  border-radius: 8px;
  background: rgba(249, 252, 246, 0.76);
  cursor: pointer;
  transition:
    border-color 0.18s ease,
    background 0.18s ease;
}

.image-drop:hover {
  border-color: rgba(77, 154, 56, 0.58);
  background: rgba(239, 249, 231, 0.9);
}

.image-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.image-drop-icon {
  width: 42px;
  height: 42px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  font-weight: 500;
  line-height: 1;
}

.image-drop strong {
  display: block;
  font-size: var(--font-ui);
  font-weight: 850;
}

.image-drop span,
.image-status {
  color: var(--muted);
  font-size: var(--font-ui-small);
}

.image-preview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-height: 74px;
}

.image-preview-grid.is-empty {
  grid-template-columns: 1fr;
}

.image-preview-empty {
  display: grid;
  place-items: center;
  min-height: 74px;
  border: 1px solid rgba(24, 33, 28, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
  font-size: var(--font-ui-small);
}

.image-preview-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(24, 33, 28, 0.08);
  border-radius: 8px;
  background: #fff;
}

.image-preview-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.image-preview-card span {
  display: block;
  overflow: hidden;
  padding: 6px 7px;
  color: var(--muted);
  font-size: var(--font-ui-small);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-preview-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: 1px solid rgba(24, 33, 28, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  box-shadow: 0 6px 14px rgba(24, 33, 28, 0.12);
}

.image-editor textarea {
  min-height: 150px;
  resize: vertical;
  padding: 12px 13px;
  font-size: var(--font-chat);
  line-height: 1.55;
}

.image-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 9px;
  align-items: center;
}

.image-controls select,
.image-controls button {
  height: var(--button-height);
  border-radius: 8px;
  font-size: var(--font-ui);
}

.image-controls select {
  min-width: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

.image-controls button {
  grid-column: 1 / -1;
  padding: 0 16px;
  font-weight: 850;
}

.image-result-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.image-history {
  min-width: 0;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(24, 33, 28, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: var(--shadow-soft);
}

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

.image-history-head strong {
  font-size: var(--font-ui);
}

.image-history-head span,
.image-history-empty {
  color: var(--muted);
  font-size: var(--font-ui-small);
}

.image-task-history {
  min-width: 0;
  display: flex;
  gap: 8px;
  overflow: auto;
  padding-bottom: 2px;
}

.image-history-item {
  min-width: 190px;
  max-width: 260px;
  display: grid;
  gap: 7px;
  padding: 8px;
  border: 1px solid rgba(24, 33, 28, 0.08);
  border-radius: 8px;
  background: rgba(255, 253, 251, 0.78);
  color: var(--text);
  text-align: left;
}

.image-history-item.is-active,
.image-history-item:hover {
  border-color: rgba(77, 154, 56, 0.38);
  background: rgba(244, 250, 239, 0.9);
}

.image-history-open {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.image-history-open span {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.image-history-open strong,
.image-history-open small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-history-open strong {
  font-size: var(--font-ui-small);
}

.image-history-open small {
  color: var(--muted);
  font-size: var(--font-meta);
}

.image-history-open em {
  flex: 0 0 auto;
  font-size: var(--font-meta);
  font-style: normal;
  color: var(--accent-strong);
  font-weight: 800;
}

.image-history-actions {
  display: flex;
  gap: 6px;
}

.image-history-actions button {
  height: 28px;
  flex: 1;
  border: 1px solid rgba(24, 33, 28, 0.08);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  font-size: var(--font-meta);
  font-weight: 800;
}

.image-history-actions button:hover {
  border-color: rgba(77, 154, 56, 0.28);
  color: var(--accent-strong);
}

.image-history-delete:hover {
  border-color: rgba(190, 68, 75, 0.24);
  color: #a3373e;
}

.image-result {
  min-height: 420px;
  display: grid;
  padding: 16px;
  background:
    linear-gradient(45deg, rgba(77, 154, 56, 0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(77, 154, 56, 0.035) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(77, 154, 56, 0.035) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(77, 154, 56, 0.035) 75%),
    rgba(255, 255, 255, 0.86);
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.image-result > .empty {
  align-self: center;
  justify-self: center;
  max-width: 360px;
  color: var(--muted);
  text-align: center;
}

.image-task {
  width: 100%;
  min-height: 100%;
  display: grid;
  align-content: start;
  gap: 14px;
}

.image-task-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.image-task-head strong {
  font-size: var(--font-title);
}

.image-task-head span,
.image-task-code {
  color: var(--muted);
  font-size: var(--font-ui-small);
}

.image-task-code {
  overflow-wrap: anywhere;
  padding: 10px 11px;
  border-radius: 8px;
  background: rgba(244, 250, 239, 0.72);
}

.image-task-loading {
  min-height: 280px;
  display: grid;
  place-items: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}

.image-task-loading span {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(77, 154, 56, 0.16);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.9s linear infinite;
}

.image-task-error {
  padding: 12px;
  border: 1px solid rgba(190, 68, 75, 0.24);
  border-radius: 8px;
  background: rgba(255, 241, 241, 0.78);
  color: #a3373e;
  font-size: var(--font-ui);
  line-height: 1.55;
}

.image-output {
  width: 100%;
  display: grid;
  gap: 12px;
  justify-items: center;
}

.image-output img {
  max-width: 100%;
  max-height: min(70vh, 760px);
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  object-fit: contain;
}

.image-download {
  height: var(--button-height);
  display: inline-grid;
  place-items: center;
  padding: 0 16px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: var(--font-ui);
  font-weight: 700;
  text-decoration: none;
}

.template-dialog,
.edit-dialog {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(20, 27, 23, 0.32);
  z-index: 20;
}

.template-dialog.is-open,
.edit-dialog.is-open {
  display: grid;
}

.template-panel,
.edit-panel,
.title-panel {
  width: min(680px, 100%);
  max-height: calc(var(--app-height) - 40px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
  backdrop-filter: blur(18px);
}

.edit-panel {
  width: min(760px, calc(100vw - 32px));
  display: grid;
  gap: 14px;
}

.title-panel {
  width: min(460px, calc(100vw - 32px));
  display: grid;
  gap: 14px;
}

.template-panel h2,
.edit-panel h2 {
  margin: 0 0 14px;
  font-size: var(--font-dialog-title);
}

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

.edit-head h2 {
  margin: 0;
}

.edit-close {
  width: var(--icon-size);
  height: var(--icon-size);
  display: grid;
  place-items: center;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: calc(var(--icon-font) + 1px);
}

.edit-close:hover {
  background: var(--soft);
  color: var(--text);
}

.edit-panel textarea {
  min-height: min(48vh, 420px);
  max-height: 58vh;
  resize: vertical;
  padding: 13px 14px;
  line-height: 1.6;
  font-size: var(--font-chat);
}

.title-panel input {
  height: var(--control-height);
}

.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.edit-actions button {
  min-width: 78px;
  height: var(--button-height);
  font-size: var(--font-ui);
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.secondary-button:hover {
  background: var(--soft);
}

.template-options {
  display: grid;
  gap: 12px;
}

.template-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.template-head h2 {
  margin: 0;
}

.depth-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, 68px);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(245, 250, 241, 0.75);
}

.depth-toggle button {
  height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: var(--font-ui);
  font-weight: 700;
}

.depth-toggle button.is-active,
.depth-toggle button:hover {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 5px 14px rgba(77, 154, 56, 0.18);
}

.template-card {
  display: grid;
  align-items: center;
  gap: 4px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.template-card.special-only {
  display: none;
}

.is-special .template-card.special-only {
  display: grid;
}

.template-card:hover {
  border-color: var(--accent);
  background: var(--soft);
}

.template-card span {
  display: block;
  font-weight: 750;
  font-size: var(--font-title);
}

.template-card small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.5;
}

.empty {
  margin: 0 auto;
  max-width: 520px;
  padding-top: 18vh;
  color: var(--muted);
  text-align: center;
}

.empty strong {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: var(--font-dialog-title);
}

@media (max-width: 760px) {
  :root {
    --mobile-menu-size: 38px;
  }

  .shell {
    display: block;
    height: var(--app-height);
  }

  .shell.sidebar-collapsed {
    grid-template-columns: none;
    grid-template-rows: none;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(84vw, 318px);
    min-height: var(--app-height);
    border-right: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: var(--shadow);
    transform: translateX(0);
    transition: transform 190ms ease;
    z-index: 8;
  }

  .shell.sidebar-collapsed .sidebar {
    min-height: var(--app-height);
    transform: translateX(-100%);
    box-shadow: none;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 7;
    display: block;
    padding: 0;
    border-radius: 0;
    background: rgba(30, 35, 31, 0.26);
  }

  .sidebar-backdrop:hover {
    background: rgba(30, 35, 31, 0.26);
  }

  .shell.sidebar-collapsed .sidebar-backdrop {
    display: none;
  }

  .sidebar-head {
    min-height: 58px;
    padding: 11px 12px;
  }

  .shell.sidebar-collapsed .sidebar-head {
    display: block;
    min-height: 0;
    padding: 0;
  }

  .shell.sidebar-collapsed .conversation-list {
    display: none;
  }

  .shell.sidebar-collapsed .brand {
    display: none;
  }

  .mobile-menu-button {
    position: fixed;
    top: 11px;
    left: 11px;
    z-index: 12;
    width: var(--mobile-menu-size);
    height: var(--mobile-menu-size);
    display: none;
    place-items: center;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.82);
    color: var(--accent-strong);
    border: 1px solid rgba(77, 154, 56, 0.22);
    box-shadow: 0 8px 24px rgba(67, 49, 53, 0.12);
    font-size: var(--icon-font);
    line-height: 1;
    backdrop-filter: blur(14px);
  }

  .shell.sidebar-collapsed .mobile-menu-button {
    display: grid;
  }

  .mobile-menu-button:hover {
    background: #fff;
  }

  .app-title {
    font-size: var(--font-brand);
  }

  .app-subtitle {
    font-size: var(--font-ui-small);
  }

  .conversation-list {
    display: block;
    flex: 1;
    overflow: auto;
    padding: 10px;
  }

  .conversation-item {
    width: 100%;
    margin: 0 0 6px;
    padding: 10px 11px;
  }

  .conversation-item strong {
    font-size: var(--font-ui);
  }

  .conversation-item small {
    display: none;
  }

  .chat-head {
    min-height: 60px;
    padding: 0 12px;
  }

  .chat-head > div:first-child {
    display: none;
  }

  .chat {
    height: var(--app-height);
    width: 100vw;
    grid-template-rows: 60px minmax(0, 1fr) auto;
    min-height: 0;
  }

  .shell.sidebar-collapsed .chat {
    width: 100vw;
    margin-left: 0;
  }

  .chat-title {
    max-width: 100%;
    font-size: var(--font-title);
  }

  .shell.sidebar-collapsed .chat-head {
    padding-left: 60px;
    padding-right: 12px;
  }

  .chat-actions {
    gap: 3px;
    padding: 3px;
  }

  .view-switch {
    gap: 3px;
    padding: 3px;
    margin-left: auto;
  }

  .view-switch button {
    min-width: 48px;
    height: 36px;
    padding: 0 10px;
    font-size: var(--font-ui-small);
  }

  .new-chat-button,
  .model-button,
  .font-size-button {
    flex-basis: 36px;
    width: max(36px, var(--icon-size));
    height: max(36px, var(--icon-size));
    font-size: var(--icon-font);
  }

  .model-button {
    width: 58px;
    font-size: var(--font-ui-small);
  }

  .font-size-button {
    width: 36px;
    font-size: var(--font-ui-small);
  }

  .chat-meta {
    font-size: var(--font-ui-small);
  }

  .messages {
    padding: 16px 13px 12px;
  }

  .bubble {
    max-width: 91%;
    padding: 10px 12px;
    line-height: 1.62;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 64px;
    gap: 8px;
    padding: 10px 13px calc(13px + env(safe-area-inset-bottom, 0px));
  }

  .composer textarea {
    min-height: 40px;
    max-height: 120px;
    padding: 9px 11px;
  }

  .composer button {
    height: max(40px, var(--button-height));
  }

  .chat.is-image-mode {
    grid-template-rows: 60px minmax(0, 1fr);
  }

  .chat.is-image-mode .image-page {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 13px 10px calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .image-editor {
    padding: 13px;
  }

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

  .image-controls button {
    grid-column: 1 / -1;
  }

  .image-result {
    min-height: 320px;
  }

  .image-result-panel {
    gap: 10px;
  }

  .image-history {
    padding: 10px;
  }

  .image-history-item {
    min-width: 168px;
  }

  .template-dialog,
  .edit-dialog {
    align-items: end;
    padding: 12px;
  }

  .template-panel,
  .edit-panel,
  .title-panel {
    padding: 18px;
  }

  .template-panel h2 {
    font-size: var(--font-dialog-title);
  }

  .template-head {
    margin-bottom: 12px;
    gap: 10px;
  }

  .depth-toggle {
    grid-template-columns: repeat(2, 58px);
  }

  .depth-toggle button {
    height: 34px;
    padding: 0 8px;
    font-size: var(--font-ui);
  }

  .template-card span {
    font-size: var(--font-title);
  }

  .template-card small {
    font-size: var(--font-ui);
  }

  .template-card {
    gap: 10px;
    padding: 13px;
  }

  .edit-panel {
    width: 100%;
  }

  .edit-panel textarea {
    min-height: 42vh;
    max-height: 58vh;
  }
}

@media (max-width: 420px) {
  .login-panel {
    padding: 22px;
  }

  .sidebar {
    width: min(84vw, 302px);
  }

  .shell.sidebar-collapsed .sidebar {
    min-height: var(--app-height);
  }

  .conversation-item {
    width: 100%;
  }

  .messages {
    padding: 13px 10px 10px;
  }

  .bubble {
    max-width: 93%;
  }
}
