:root {
  color-scheme: light;
  --bg: #efe6d6;
  --panel: rgba(255, 250, 242, 0.82);
  --line: rgba(43, 54, 53, 0.12);
  --line-strong: rgba(43, 54, 53, 0.22);
  --text: #1d2524;
  --muted: #61706c;
  --sidebar: #162320;
  --sidebar-soft: #21312d;
  --sidebar-line: rgba(244, 240, 230, 0.08);
  --sidebar-text: #f4efe5;
  --accent: #c46e36;
  --accent-strong: #87461f;
  --assistant: #fffefb;
  --user: #f8e2d3;
  --tool: #edf2ef;
  --system: #f4eddc;
  --code: #10151d;
  --shadow: 0 22px 60px rgba(60, 44, 22, 0.16);
  --font-sans: "IBM Plex Sans", "Segoe UI Variable Text", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  --font-mono: "IBM Plex Mono", "Cascadia Code", "JetBrains Mono", "SFMono-Regular", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 230, 202, 0.8), transparent 32%),
    linear-gradient(160deg, #f6efe2 0%, #efe5d2 48%, #e6dcc7 100%);
  overflow: hidden;
}

.backdrop-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(10px);
  opacity: 0.48;
  pointer-events: none;
}

.backdrop-orb-a {
  top: -120px;
  right: -60px;
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, rgba(201, 111, 53, 0.42), transparent 65%);
}

.backdrop-orb-b {
  bottom: -140px;
  left: -60px;
  width: 380px;
  height: 380px;
  background: radial-gradient(circle, rgba(40, 104, 92, 0.22), transparent 68%);
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  height: 100vh;
  gap: 18px;
  padding: 18px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-soft) 100%);
  color: var(--sidebar-text);
  border-radius: 30px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sidebar-header,
.source-panel,
.sidebar-controls,
.conversation-summary {
  padding: 18px 20px;
}

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

.brand-lockup h1 {
  margin: 6px 0 8px;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}

.brand-lockup p,
.field-hint,
.conversation-summary,
.list-empty p {
  margin: 0;
  color: rgba(244, 239, 229, 0.72);
  font-size: 0.92rem;
  line-height: 1.5;
}

.brand-kicker,
.header-kicker,
.empty-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(244, 239, 229, 0.7);
}

.field-label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.84rem;
  color: rgba(244, 239, 229, 0.82);
}

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

.source-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.source-row input,
.search-input {
  width: 100%;
  border: 1px solid rgba(244, 239, 229, 0.08);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--sidebar-text);
  padding: 12px 14px;
  font: inherit;
  outline: none;
}

.source-row input::placeholder,
.search-input::placeholder {
  color: rgba(244, 239, 229, 0.45);
}

.source-row button,
.ghost-button,
.menu-button {
  border: none;
  border-radius: 16px;
  background: linear-gradient(135deg, #e49f67 0%, #c46e36 100%);
  color: #fff9f3;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

.source-row button:hover,
.ghost-button:hover,
.menu-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(116, 62, 26, 0.22);
}

.source-row button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.field-hint {
  margin-top: 10px;
}

.field-hint[data-tone="error"] {
  color: #ffd4d0;
}

.field-hint[data-tone="success"] {
  color: #d5f0dd;
}

.sidebar-controls {
  display: grid;
  gap: 12px;
  border-bottom: 1px solid var(--sidebar-line);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: rgba(244, 239, 229, 0.84);
}

.toggle input {
  accent-color: #f3bb88;
}

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

.conversation-list {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scroll-behavior: smooth;
  padding: 14px 10px 14px 14px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.conversation-item {
  width: 100%;
  flex: 0 0 auto;
  text-align: left;
  background: rgba(255, 255, 255, 0.05);
  color: var(--sidebar-text);
  border: 1px solid transparent;
  border-radius: 20px;
  padding: 14px;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.conversation-item:hover {
  background: rgba(255, 255, 255, 0.09);
  transform: translateY(-1px);
}

.conversation-item.is-active {
  background: rgba(245, 214, 188, 0.14);
  border-color: rgba(244, 190, 145, 0.34);
}

.conversation-item-top {
  display: flex;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
}

.conversation-item-top h3 {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 0.98rem;
  line-height: 1.4;
}

.conversation-item-top time,
.conversation-item p {
  color: rgba(244, 239, 229, 0.68);
}

.conversation-item-top time {
  flex: 0 0 auto;
  white-space: nowrap;
}

.conversation-item p {
  margin: 8px 0 0;
  font-size: 0.88rem;
  line-height: 1.45;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.conversation-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.conversation-badges span {
  border-radius: 999px;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.76rem;
  color: rgba(244, 239, 229, 0.76);
}

.list-empty {
  padding: 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.05);
}

.main-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
}

.main-header,
.chat-pane {
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: var(--shadow);
}

.main-header {
  border-radius: 28px;
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.header-start {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.header-kicker {
  color: var(--muted);
}

.conversation-title {
  margin: 6px 0 6px;
  font-size: 1.55rem;
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.conversation-meta {
  margin: 0;
  color: var(--muted);
}

.menu-button {
  display: none;
}

.ghost-button {
  background: rgba(196, 110, 54, 0.12);
  color: var(--accent-strong);
  border: 1px solid rgba(196, 110, 54, 0.18);
}

.chat-pane {
  min-height: 0;
  border-radius: 34px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable both-edges;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  padding: 28px;
}

.empty-state[hidden] {
  display: none !important;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 100%;
}

.empty-card {
  width: min(620px, 100%);
  padding: 34px;
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.82), rgba(250, 240, 226, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 22px 54px rgba(85, 60, 29, 0.12);
}

.empty-card h3 {
  margin: 10px 0 12px;
  font-size: 1.85rem;
  letter-spacing: -0.04em;
}

.empty-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.empty-note {
  margin-top: 14px !important;
}

.message-list {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 18px;
  min-height: min-content;
  padding-bottom: 28px;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  width: min(100%, 960px);
  flex: 0 0 auto;
  animation: rise-in 280ms ease both;
}

.message-row.is-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-row.is-status-row {
  align-self: center;
  justify-content: center;
  width: min(100%, 960px);
}

.message-row.is-status-row .avatar {
  display: none;
}

.avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  color: var(--accent-strong);
  font-size: 0.8rem;
  font-weight: 700;
}

.message-card {
  min-width: 0;
  max-width: min(780px, 100%);
  border-radius: 24px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  background: var(--assistant);
  box-shadow: 0 10px 26px rgba(48, 37, 22, 0.08);
}

.is-user .message-card {
  background: var(--user);
}

.is-tool .message-card {
  background: var(--tool);
}

.is-system .message-card {
  background: var(--system);
}

.is-status-row .message-card {
  padding: 0;
  border: none;
  box-shadow: none;
  background: transparent;
}

.is-internal .message-card {
  background: rgba(237, 242, 239, 0.88);
  border-style: dashed;
}

.message-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.message-meta span {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(29, 37, 36, 0.05);
}

.message-action-button {
  flex: 0 0 auto;
  border: 1px solid rgba(29, 37, 36, 0.1);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--accent-strong);
  padding: 7px 12px;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease, opacity 160ms ease;
}

.message-action-button:hover:not(:disabled) {
  background: #fff;
  transform: translateY(-1px);
}

.message-action-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.message-body {
  display: grid;
  gap: 14px;
}

.markdown-block {
  line-height: 1.72;
  color: var(--text);
}

.markdown-block :first-child {
  margin-top: 0;
}

.markdown-block :last-child {
  margin-bottom: 0;
}

.markdown-block a {
  color: var(--accent-strong);
  text-decoration-thickness: 1.5px;
}

.markdown-block pre {
  margin: 16px 0;
  border-radius: 18px;
  background: var(--code);
  color: #f4f7fb;
  padding: 16px;
  overflow: auto;
}

.markdown-block code {
  font-family: var(--font-mono);
}

.code-block,
.output-block,
.json-block pre {
  border-radius: 18px;
  background: var(--code);
  color: #f4f7fb;
  padding: 16px;
  overflow: auto;
  font-family: var(--font-mono);
}

.code-block {
  padding-top: 12px;
}

.code-block-label {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(244, 247, 251, 0.62);
  margin-bottom: 10px;
}

.code-block pre,
.json-block pre {
  margin: 0;
}

.image-block {
  margin: 0;
  display: grid;
  gap: 10px;
}

.image-open-button {
  border: none;
  background: transparent;
  padding: 0;
  cursor: zoom-in;
  text-align: left;
}

.image-block img {
  max-width: min(100%, 640px);
  width: auto;
  border-radius: 20px;
  display: block;
  box-shadow: 0 12px 26px rgba(38, 29, 17, 0.12);
}

.image-block figcaption {
  color: var(--muted);
  font-size: 0.86rem;
}

.audio-block {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(29, 37, 36, 0.05);
}

.audio-block audio {
  width: min(100%, 440px);
}

.audio-block-meta,
.asset-missing {
  color: var(--muted);
  font-size: 0.86rem;
}

.transcript-block {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.56);
  border: 1px dashed var(--line-strong);
}

.transcript-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
}

.transcript-pill {
  margin-bottom: 10px;
  background: rgba(196, 110, 54, 0.12);
  color: var(--accent-strong);
}

.status-pill {
  background: rgba(29, 37, 36, 0.08);
  color: var(--muted);
}

.transcript-block p {
  margin: 0;
  line-height: 1.66;
}

.json-block {
  border-radius: 18px;
  background: rgba(29, 37, 36, 0.04);
  border: 1px solid var(--line);
}

.json-block summary {
  cursor: pointer;
  padding: 12px 14px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.loading-card {
  width: min(720px, 100%);
  padding: 22px 24px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  box-shadow: 0 10px 26px rgba(48, 37, 22, 0.08);
}

.loading-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.loading-subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.loading-line {
  height: 12px;
  margin-top: 16px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(196, 110, 54, 0.12), rgba(29, 37, 36, 0.08));
}

.loading-line.is-wide {
  width: 92%;
}

.loading-line.is-short {
  width: 58%;
}

.image-viewer[hidden] {
  display: none !important;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.image-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 21, 29, 0.72);
  backdrop-filter: blur(10px);
}

.image-viewer-dialog {
  position: absolute;
  inset: 24px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
  padding: 18px;
  border-radius: 28px;
  background: rgba(255, 252, 247, 0.94);
  box-shadow: 0 30px 80px rgba(17, 20, 23, 0.3);
}

.image-viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.image-viewer-meta {
  font-size: 0.95rem;
  color: var(--muted);
}

.image-viewer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.image-viewer-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #e49f67 0%, #c46e36 100%);
  color: #fff9f3;
  padding: 10px 16px;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.image-viewer-button.is-secondary {
  background: rgba(29, 37, 36, 0.1);
  color: var(--text);
}

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

.image-viewer-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 20px;
  box-shadow: 0 16px 36px rgba(17, 20, 23, 0.18);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 32px));
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(25, 34, 33, 0.92);
  color: #fffdf7;
  box-shadow: 0 18px 40px rgba(23, 28, 28, 0.28);
}

.toast[data-tone="error"] {
  background: rgba(129, 42, 35, 0.95);
}

.toast[data-tone="success"] {
  background: rgba(27, 96, 71, 0.95);
}

.conversation-list,
.chat-pane {
  scrollbar-width: thin;
  scrollbar-color: rgba(122, 104, 82, 0.72) transparent;
}

.conversation-list::-webkit-scrollbar,
.chat-pane::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.conversation-list::-webkit-scrollbar-track,
.chat-pane::-webkit-scrollbar-track {
  background: transparent;
}

.conversation-list::-webkit-scrollbar-thumb,
.chat-pane::-webkit-scrollbar-thumb {
  background: rgba(122, 104, 82, 0.72);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}

.conversation-list::-webkit-scrollbar-thumb:hover,
.chat-pane::-webkit-scrollbar-thumb:hover {
  background: rgba(122, 104, 82, 0.88);
  background-clip: padding-box;
}

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

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .sidebar {
    position: fixed;
    top: 12px;
    left: 12px;
    bottom: 12px;
    width: min(88vw, 360px);
    z-index: 12;
    transform: translateX(calc(-100% - 24px));
    transition: transform 220ms ease;
  }

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

  .menu-button {
    display: inline-flex;
  }

  .main-header,
  .chat-pane {
    border-radius: 24px;
  }

  .chat-pane {
    padding: 18px;
  }

  .message-card {
    max-width: 100%;
  }

  .image-viewer-dialog {
    inset: 12px;
    padding: 14px;
  }
}

@media (max-width: 640px) {
  .main-header {
    flex-direction: column;
    align-items: stretch;
  }

  .header-start {
    align-items: flex-start;
  }

  .conversation-title {
    font-size: 1.28rem;
  }

  .empty-card {
    padding: 22px;
  }

  .empty-card h3 {
    font-size: 1.45rem;
  }

  .message-row {
    gap: 10px;
  }

  .avatar {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
  }
}
