:root {
  --bg: #f4efe7;
  --bg-deep: #e7ddcf;
  --panel: rgba(255, 251, 245, 0.82);
  --panel-strong: rgba(249, 242, 231, 0.94);
  --line: rgba(54, 40, 26, 0.16);
  --ink: #1f1a16;
  --muted: #6c5c4e;
  --accent: #a24b2a;
  --accent-soft: rgba(162, 75, 42, 0.12);
  --shadow: 0 18px 60px rgba(45, 29, 16, 0.12);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --font-display: "Iowan Old Style", "Palatino Linotype", "Noto Serif SC", serif;
  --font-body: "Microsoft YaHei UI", "PingFang SC", "Segoe UI", sans-serif;
  --shell-max-width: 1680px;
  --sidebar-width: clamp(272px, 19vw, 318px);
  --panel-padding: clamp(12px, 0.95vw, 16px);
  --card-padding: clamp(10px, 0.8vw, 14px);
  --input-height: 40px;
  --composer-textarea-min-height: clamp(94px, 12dvh, 128px);
  --app-shell-padding: clamp(8px, 0.82vw, 12px);
  --app-shell-gap: clamp(8px, 0.82vw, 12px);
  --panel-frame-height: calc(100dvh - (var(--app-shell-padding) * 2));
  --thread-max-height-desktop: clamp(360px, 93dvh, 100dvh);
  --thread-max-height-tablet: clamp(320px, 52dvh, 680px);
  --thread-max-height-mobile: clamp(260px, 48dvh, 520px);
  --control-panel-max-height-tablet: clamp(320px, 48dvh, 680px);
  --control-panel-max-height-mobile: clamp(280px, 42dvh, 520px);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100dvh;
  min-height: 100%;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(193, 126, 76, 0.16), transparent 28%),
    radial-gradient(circle at top right, rgba(128, 95, 52, 0.12), transparent 22%),
    linear-gradient(180deg, #f7f3ed 0%, var(--bg) 54%, var(--bg-deep) 100%);
  font-family: var(--font-body);
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: 0.24;
  background-image:
    linear-gradient(rgba(79, 59, 39, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79, 59, 39, 0.03) 1px, transparent 1px);
  background-size: 22px 22px;
  mask-image: radial-gradient(circle at center, black 52%, transparent 95%);
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, var(--sidebar-width)) minmax(0, 1fr);
  gap: var(--app-shell-gap);
  width: min(var(--shell-max-width), calc(100vw - (var(--app-shell-padding) * 2)));
  min-height: 100dvh;
  margin: 0 auto;
  padding: var(--app-shell-padding);
  align-items: stretch;
}

.sidebar,
.main-panel,
.settings-panel {
  backdrop-filter: blur(20px) saturate(120%);
  background:
    linear-gradient(180deg, rgba(255, 252, 247, 0.88) 0%, rgba(247, 239, 229, 0.76) 100%);
  border: 1px solid rgba(255, 255, 255, 0.52);
  box-shadow:
    0 24px 64px rgba(45, 29, 16, 0.11),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.sidebar {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: var(--panel-padding);
  border-radius: var(--radius-xl);
  min-height: var(--panel-frame-height);
  max-height: var(--panel-frame-height);
  overflow: hidden;
}

.brand-block {
  display: grid;
  gap: 6px;
  align-content: start;
}

.brand-block h1,
.thread-head h2,
.settings-panel h2 {
  margin: 2px 0 6px;
  font-family: var(--font-display);
  font-size: clamp(1.54rem, 2.52vw, 2.08rem);
  line-height: 0.94;
  letter-spacing: -0.03em;
}

.brand-copy,
.meta-note,
.composer-tip,
.message-caption,
.status-label,
.composer-reference-tip,
.reference-meta span {
  color: var(--muted);
}

.brand-copy {
  margin: 0;
  max-width: 34ch;
  font-size: 0.82rem;
  line-height: 1.52;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.2em;
}

.brand-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.github-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(76, 55, 35, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  text-decoration: none;
  transition:
    transform 140ms ease,
    background 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.github-link:hover {
  transform: translateY(-1px);
  border-color: rgba(76, 55, 35, 0.2);
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 10px 24px rgba(45, 29, 16, 0.08);
}

.github-link:focus-visible {
  outline: none;
  border-color: rgba(162, 75, 42, 0.44);
  box-shadow: 0 0 0 5px rgba(162, 75, 42, 0.08);
}

.github-link svg {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  fill: currentColor;
}

.control-card {
  padding: var(--card-padding);
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 253, 249, 0.86) 0%, rgba(249, 241, 230, 0.72) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.36);
}

.control-card-scrollable {
  min-height: 0;
  height: 100%;
  max-height: none;
  padding-right: 2px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.control-card-scrollable.is-reverse-mode {
  border-color: rgba(162, 75, 42, 0.18);
  box-shadow: inset 0 0 0 1px rgba(162, 75, 42, 0.05);
}

.control-card.compact {
  margin-top: auto;
}

.card-head,
.composer-actions,
.thread-head,
.message-meta,
.settings-actions,
.image-toolbar,
.composer-reference-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-head h2,
.control-card h2 {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 700;
  font-family: var(--font-body);
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.field > span {
  font-size: 0.78rem;
  font-weight: 600;
}

.field.is-mode-muted {
  opacity: 0.5;
}

.field.is-mode-muted .meta-note {
  color: rgba(108, 92, 78, 0.78);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid rgba(76, 55, 35, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.66);
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.checkbox-row span {
  font-size: 0.8rem;
  font-weight: 500;
}

input,
textarea,
select {
  width: 100%;
  min-height: var(--input-height);
  border: 1px solid rgba(76, 55, 35, 0.18);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(251, 247, 241, 0.8) 100%);
  color: var(--ink);
  padding: 9px 12px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.42);
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease,
    transform 140ms ease,
    background 140ms ease;
}

.control-select {
  appearance: none;
  padding-right: 44px;
  background-image:
    linear-gradient(45deg, transparent 50%, rgba(76, 55, 35, 0.72) 50%),
    linear-gradient(135deg, rgba(76, 55, 35, 0.72) 50%, transparent 50%);
  background-position:
    calc(100% - 20px) calc(50% - 3px),
    calc(100% - 14px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(162, 75, 42, 0.44);
  box-shadow: 0 0 0 5px rgba(162, 75, 42, 0.08);
}

textarea {
  min-height: var(--composer-textarea-min-height);
  line-height: 1.54;
  resize: vertical;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(66px, 1fr));
  gap: 5px;
}

.segment,
.ghost-button,
.secondary-button,
.primary-button,
.reference-preview,
.reference-remove {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 7px 10px;
  min-height: 32px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition:
    transform 140ms ease,
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease;
}

.segment {
  color: var(--muted);
  border-color: rgba(76, 55, 35, 0.12);
  background: rgba(255, 255, 255, 0.55);
}

.segment.is-active {
  color: #fff9f1;
  background: linear-gradient(135deg, #202224 0%, #7b3f27 100%);
  box-shadow: 0 10px 30px rgba(79, 42, 18, 0.18);
}

.ghost-button,
.secondary-button,
.reference-remove {
  color: var(--ink);
  border-color: rgba(76, 55, 35, 0.12);
  background: rgba(255, 255, 255, 0.52);
}

.primary-button {
  color: #fff9f1;
  background: linear-gradient(135deg, #1f2328 0%, #a24b2a 100%);
  box-shadow: 0 12px 30px rgba(95, 45, 21, 0.22);
}

.segment:hover,
.ghost-button:hover,
.secondary-button:hover,
.primary-button:hover,
.reference-preview:hover,
.reference-remove:hover {
  transform: translateY(-1px);
}

.ghost-button:active,
.secondary-button:active,
.primary-button:active,
.segment:active,
.reference-preview:active,
.reference-remove:active {
  transform: translateY(0);
}

.main-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: var(--panel-frame-height);
  max-height: var(--panel-frame-height);
  padding: var(--panel-padding);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.thread-head {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 6px 0 2px;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0;
  height: 100%;
  max-height: min(100%, var(--thread-max-height-desktop));
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scroll-padding-block-end: 12px;
}

.message {
  max-width: min(860px, 100%);
  padding: 11px 13px;
  border-radius: 16px;
  border: 1px solid rgba(76, 55, 35, 0.14);
  background: linear-gradient(180deg, rgba(255, 252, 247, 0.92) 0%, rgba(251, 245, 237, 0.78) 100%);
  box-shadow: 0 14px 34px rgba(58, 39, 22, 0.08);
  animation: message-rise 240ms ease;
}

.message[data-role="assistant"] {
  align-self: flex-start;
  width: min(700px, 64%);
}

.message.has-image-batch[data-role="assistant"] {
  width: min(920px, 88%);
}

.message[data-role="user"] {
  align-self: flex-end;
  width: min(440px, 40%);
  background: linear-gradient(180deg, rgba(255, 247, 238, 0.98) 0%, rgba(248, 235, 223, 0.92) 100%);
}

.message[data-role="system"] {
  align-self: flex-start;
  width: min(760px, 76%);
  background: linear-gradient(180deg, rgba(252, 246, 238, 0.96) 0%, rgba(246, 237, 226, 0.9) 100%);
}

.message-meta {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
}

.message-body {
  display: grid;
  gap: 8px;
  line-height: 1.54;
  word-break: break-word;
}

.message-body p {
  margin: 0;
}

.message-section-title {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.image-card {
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid rgba(64, 48, 34, 0.12);
  background: rgba(255, 255, 255, 0.64);
}

.image-card-preview {
  border-style: dashed;
  border-color: rgba(162, 75, 42, 0.22);
  background:
    linear-gradient(180deg, rgba(255, 248, 239, 0.92) 0%, rgba(255, 252, 247, 0.68) 100%);
}

.image-card img {
  display: block;
  width: 100%;
  height: auto;
  max-height: clamp(150px, 26dvh, 360px);
  object-fit: contain;
  background: linear-gradient(135deg, rgba(162, 75, 42, 0.08), rgba(28, 30, 34, 0.08));
}

.zoomable-image {
  cursor: zoom-in;
}

.image-toolbar {
  flex-wrap: wrap;
  padding: 8px 10px;
  border-top: 1px solid rgba(64, 48, 34, 0.1);
}

.image-batch {
  display: grid;
  gap: 12px;
}

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

.image-batch-copy {
  display: grid;
  gap: 6px;
  min-width: 0;
}

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

.image-card-compact {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
}

.image-card-compact img,
.zoomable-image.is-compact {
  width: 100%;
  max-height: clamp(96px, 14dvh, 142px);
  object-fit: contain;
}

.image-card-label {
  padding: 6px 8px 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.4;
}

.image-toolbar.is-compact {
  align-items: flex-start;
  gap: 6px;
  padding: 7px 8px 8px;
}

.image-meta.is-compact {
  gap: 4px 6px;
  font-size: 0.66rem;
}

.image-meta.is-compact .pill {
  min-height: 28px;
  padding: 0 10px;
}

.diagnostic-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(76, 55, 35, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.62);
}

.diagnostic-row {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.diagnostic-label {
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.diagnostic-value {
  display: block;
  overflow-wrap: anywhere;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(33, 28, 24, 0.06);
  color: #34271f;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.87rem;
}

.image-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 0.88rem;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(162, 75, 42, 0.08);
}

.assist-details {
  display: grid;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid rgba(76, 55, 35, 0.12);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.58);
}

.assist-details[open] {
  background: rgba(255, 255, 255, 0.68);
}

.assist-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
  list-style: none;
}

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

.assist-summary-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.assist-summary-title {
  font-weight: 600;
  color: var(--ink);
}

.assist-summary-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.assist-state-pill {
  white-space: nowrap;
}

.assist-details.is-pending .assist-state-pill {
  background: rgba(162, 75, 42, 0.12);
  color: #8c4f1c;
}

.assist-details.is-complete .assist-state-pill {
  background: rgba(46, 115, 73, 0.12);
  color: #2d6a43;
}

.assist-details.is-failed .assist-state-pill {
  background: rgba(145, 65, 49, 0.12);
  color: #8a3e31;
}

.assist-content {
  display: grid;
  gap: 12px;
}

.reverse-details .assist-summary-title,
.reverse-details .assist-summary-meta {
  overflow-wrap: anywhere;
}

.reverse-content {
  gap: 14px;
}

.reverse-prompt-card {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid rgba(76, 55, 35, 0.1);
  border-radius: 18px;
  background: rgba(255, 252, 247, 0.88);
}

.reverse-prompt-card.is-primary {
  background:
    linear-gradient(180deg, rgba(255, 248, 239, 0.98) 0%, rgba(250, 239, 227, 0.9) 100%);
  border-color: rgba(162, 75, 42, 0.18);
}

.reverse-prompt-text {
  margin: 0;
  color: var(--ink);
  line-height: 1.72;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.reverse-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

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

.reverse-breakdown-item {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(76, 55, 35, 0.1);
  background: rgba(255, 255, 255, 0.66);
}

.reverse-chip-section,
.reverse-point-section,
.reverse-breakdown-section,
.reverse-variant-section {
  display: grid;
  gap: 10px;
}

.reverse-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.reverse-point-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
}

.reverse-point-list li {
  overflow-wrap: anywhere;
}

.assist-prompt-list {
  display: grid;
  gap: 10px;
}

.assist-prompt-item {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(76, 55, 35, 0.1);
  background: rgba(255, 252, 247, 0.88);
}

.assist-prompt-heading {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.assist-prompt-text {
  margin: 0;
  color: var(--ink);
  line-height: 1.65;
  word-break: break-word;
}

.composer {
  position: relative;
  display: grid;
  gap: 8px;
  align-self: end;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 251, 245, 0.94) 0%, rgba(248, 240, 230, 0.9) 100%);
  box-shadow:
    0 12px 28px rgba(58, 39, 22, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.36);
}

.composer-mode-row {
  margin-bottom: 0;
}

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

.composer-edit-banner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 0;
  padding: 7px 8px;
  border: 1px solid rgba(162, 75, 42, 0.18);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255, 248, 239, 0.96) 0%, rgba(250, 239, 227, 0.88) 100%);
}

.composer-edit-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.composer-edit-copy strong {
  color: var(--ink);
  font-size: 0.8rem;
}

.composer-edit-copy span {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.34;
  overflow-wrap: anywhere;
}

.composer-label {
  display: block;
  margin-bottom: 0;
  font-size: 0.8rem;
  font-weight: 600;
}

.composer-run-controls {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.composer-reference-head {
  margin-bottom: 0;
  align-items: flex-start;
}

.composer-reference-tip {
  display: block;
  min-width: 0;
  font-size: 0.78rem;
  line-height: 1.34;
}

.composer-reference-tip[data-tone="warning"] {
  color: #8c4f1c;
}

.composer-reference-clear {
  flex: 0 0 auto;
  padding-inline: 8px;
}

.composer-reference-strip {
  margin-bottom: 0;
  padding-right: 2px;
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(102px, 1fr));
  gap: 6px;
}

.reference-grid.is-compact {
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
}

.reference-card {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 8px;
  border: 1px solid rgba(76, 55, 35, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.68);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.32);
}

.reference-preview {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 76px;
  padding: 0;
  overflow: hidden;
  border-radius: 10px;
  border-color: rgba(76, 55, 35, 0.12);
  background:
    radial-gradient(circle at top left, rgba(162, 75, 42, 0.12), transparent 26%),
    rgba(255, 255, 255, 0.82);
}

.reference-preview:disabled {
  cursor: default;
}

.reference-preview img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 76px;
  max-height: 104px;
  object-fit: cover;
}

.reference-placeholder {
  padding: 18px;
  color: var(--muted);
  font-size: 0.84rem;
}

.reference-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.reference-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.74rem;
}

.reference-meta span {
  font-size: 0.66rem;
}

.reference-remove {
  justify-self: start;
  padding: 4px 8px;
  font-size: 0.7rem;
}

.message-reference-section {
  display: grid;
  gap: 10px;
}

.settings-dialog {
  width: min(680px, calc(100vw - 24px));
  padding: 0;
  border: none;
  background: transparent;
}

.settings-dialog::backdrop {
  background: rgba(17, 15, 13, 0.46);
  backdrop-filter: blur(6px);
}

.settings-panel {
  padding: clamp(14px, 1.2vw, 18px);
  border-radius: 20px;
  background: var(--panel-strong);
}

.image-preview-dialog {
  width: min(1120px, calc(100vw - 24px));
  padding: 0;
  border: none;
  background: transparent;
}

.image-preview-dialog::backdrop {
  background: rgba(17, 15, 13, 0.72);
  backdrop-filter: blur(10px);
}

.image-preview-panel {
  padding: 18px;
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(31, 26, 22, 0.88);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.34);
}

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

.image-preview-frame {
  display: grid;
  place-items: center;
  min-height: min(72dvh, 780px);
  max-height: 78dvh;
  overflow: auto;
  border-radius: 22px;
  background:
    radial-gradient(circle at top left, rgba(162, 75, 42, 0.12), transparent 26%),
    rgba(255, 255, 255, 0.04);
}

.image-preview-frame img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 74dvh;
  object-fit: contain;
  border-radius: 18px;
}

.settings-actions {
  margin-top: 20px;
}

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

.status-grid > div {
  padding: 8px 10px;
  border: 1px solid rgba(76, 55, 35, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
}

.status-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 0.86rem;
}

.empty-state {
  padding: 40px 28px;
  border: 1px dashed rgba(76, 55, 35, 0.22);
  border-radius: 28px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.4);
}

.loading-dots {
  display: inline-flex;
  gap: 6px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 900ms infinite ease-in-out;
}

.loading-dots span:nth-child(2) {
  animation-delay: 120ms;
}

.loading-dots span:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes blink {
  0%,
  80%,
  100% {
    transform: scale(0.8);
    opacity: 0.3;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes message-rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.thread,
.control-card-scrollable,
.composer-reference-strip,
.image-preview-frame {
  scrollbar-width: thin;
  scrollbar-color: rgba(97, 72, 49, 0.44) transparent;
}

.thread::-webkit-scrollbar,
.control-card-scrollable::-webkit-scrollbar,
.composer-reference-strip::-webkit-scrollbar,
.image-preview-frame::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.thread::-webkit-scrollbar-thumb,
.control-card-scrollable::-webkit-scrollbar-thumb,
.composer-reference-strip::-webkit-scrollbar-thumb,
.image-preview-frame::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(97, 72, 49, 0.4);
  background-clip: padding-box;
}

.thread::-webkit-scrollbar-track,
.control-card-scrollable::-webkit-scrollbar-track,
.composer-reference-strip::-webkit-scrollbar-track,
.image-preview-frame::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(1280px, calc(100vw - (var(--app-shell-padding) * 2)));
  }

  .sidebar {
    display: flex;
    gap: 14px;
    min-height: auto;
    max-height: none;
    overflow: visible;
  }

  .control-card-scrollable {
    height: auto;
    max-height: var(--control-panel-max-height-tablet);
  }

  .main-panel {
    padding: 16px;
  }

  .thread {
    gap: 12px;
    padding: 10px 4px 0 0;
    max-height: min(100%, var(--thread-max-height-tablet));
  }

  .message {
    max-width: 100%;
    padding: 14px 16px;
    border-radius: 18px;
  }

  .message[data-role="assistant"] {
    width: min(720px, 80%);
  }

  .message.has-image-batch[data-role="assistant"] {
    width: min(100%, 920px);
  }

  .message[data-role="user"] {
    width: min(460px, 54%);
  }

  .message[data-role="system"] {
    width: min(100%, 820px);
  }

  .composer {
    padding: 12px;
  }
}

@media (max-width: 640px) {
  :root {
    --app-shell-padding: 10px;
    --app-shell-gap: 10px;
  }

  .app-shell {
    padding: var(--app-shell-padding);
    gap: var(--app-shell-gap);
  }

  .sidebar,
  .main-panel {
    padding: 14px;
    border-radius: 22px;
  }

  .control-card {
    padding: 14px;
    border-radius: 20px;
  }

  .thread {
    gap: 14px;
    padding: 8px 0 0;
    max-height: min(100%, var(--thread-max-height-mobile));
  }

  .control-card-scrollable {
    max-height: var(--control-panel-max-height-mobile);
  }

  .message {
    width: 100%;
    max-width: 100%;
    padding: 14px 16px;
    border-radius: 20px;
  }

  .message[data-role="assistant"],
  .message[data-role="user"],
  .message[data-role="system"] {
    width: 100%;
  }

  .diagnostic-panel {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .image-card img {
    max-height: clamp(220px, 34dvh, 380px);
  }

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

  .image-batch-head {
    flex-direction: column;
    align-items: stretch;
  }

  .image-card-compact img,
  .zoomable-image.is-compact {
    max-height: clamp(120px, 20dvh, 160px);
  }

  .image-toolbar.is-compact {
    padding: 10px;
  }

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

  .image-preview-panel {
    padding: 14px;
    border-radius: 22px;
  }

  .image-preview-head,
  .reverse-actions,
  .composer-edit-banner,
  .composer-reference-head,
  .thread-head,
  .composer-actions,
  .composer-run-controls,
  .card-head,
  .settings-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .thread-head h2 {
    margin: 4px 0 0;
    font-size: clamp(1.9rem, 10vw, 2.6rem);
  }

  input,
  textarea,
  select {
    min-height: 48px;
    padding: 12px 14px;
  }

  .composer {
    gap: 10px;
    padding: 12px;
    border-radius: 22px;
  }

  .composer-tip,
  .meta-note,
  .composer-reference-tip {
    font-size: 0.86rem;
  }

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

  .image-preview-frame {
    min-height: min(56dvh, 560px);
    max-height: 68dvh;
  }

  .image-preview-frame img {
    max-height: 64dvh;
  }

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

  .reverse-breakdown {
    grid-template-columns: 1fr;
  }

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