:root {
  --bg: #efe7da;
  --bg-shadow: rgba(32, 23, 12, 0.08);
  --panel: rgba(255, 251, 245, 0.9);
  --ink: #1d1a16;
  --muted: #6e665b;
  --accent: #0a6c60;
  --accent-strong: #034b42;
  --accent-soft: rgba(10, 108, 96, 0.1);
  --warm: #ba5a2c;
  --border: rgba(72, 56, 34, 0.14);
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --font-stack: "IBM Plex Sans", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.75), transparent 32%),
    linear-gradient(180deg, #f8f1e7 0%, var(--bg) 48%, #e6dccd 100%);
  color: var(--ink);
  font: 15px/1.55 var(--font-stack);
}

button,
textarea,
input {
  font: inherit;
}

.background-glow {
  position: fixed;
  inset: auto;
  width: 180px;
  height: 180px;
  border-radius: 999px;
  filter: blur(40px);
  opacity: 0.55;
  pointer-events: none;
}

.background-glow-left {
  top: 8%;
  left: -36px;
  background: rgba(186, 90, 44, 0.2);
}

.background-glow-right {
  bottom: 18%;
  right: -40px;
  background: rgba(10, 108, 96, 0.18);
}

.app-shell {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  height: var(--app-viewport-height, 100dvh);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: 0 18px 40px var(--bg-shadow);
  backdrop-filter: blur(12px);
}

.app-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 4px 8px;
  animation: rise-in 280ms ease-out both;
}

.header-copy {
  min-width: 0;
}

.header-copy h1 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.header-copy .eyebrow,
.header-copy .muted {
  display: none;
}

.eyebrow,
.section-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 11px;
  color: var(--accent);
}

.view-panel,
.thread-detail,
.thread-composer {
  padding: 14px;
  animation: rise-in 320ms ease-out both;
}

.thread-composer {
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.thread-detail {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 28px;
}

.view-panel {
  overflow-y: auto;
  min-height: 0;
}

.stack {
  display: grid;
  gap: 10px;
}

.form-stack {
  margin-top: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-size: 13px;
  color: var(--muted);
}

.field input,
.reply-textarea {
  width: 100%;
  border: 1px solid rgba(10, 108, 96, 0.18);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.9);
  padding: 13px 14px;
  color: var(--ink);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.field input:focus,
.reply-textarea:focus {
  border-color: rgba(10, 108, 96, 0.45);
  box-shadow: 0 0 0 4px rgba(10, 108, 96, 0.08);
  transform: translateY(-1px);
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button,
.send-button {
  border: none;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fffdf9;
}

.secondary-button {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.ghost-button {
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.66);
  color: var(--muted);
  border: 1px solid var(--border);
}

.icon-button,
.send-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  background: rgba(255, 255, 255, 0.68);
  color: var(--accent-strong);
  border: 1px solid var(--border);
  line-height: 1;
}

.send-button {
  background: var(--accent);
  color: #fffdf9;
  border-color: transparent;
}

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

.error-text {
  margin: 0;
  color: #9f2c2c;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.thread-drawer {
  position: fixed;
  inset: 0;
  z-index: 20;
  padding: 0;
  overflow-x: hidden;
  background: rgba(29, 26, 22, 0.28);
  backdrop-filter: blur(8px);
}

.drawer-panel {
  width: min(86vw, 360px);
  max-width: 100vw;
  height: 100%;
  overflow: auto;
  overflow-x: hidden;
  margin: 0;
  border-right: 1px solid var(--border);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  background: rgba(255, 249, 240, 0.96);
  box-shadow: 0 18px 40px var(--bg-shadow);
  padding: 18px;
  display: grid;
  gap: 14px;
  align-content: start;
  animation: slide-drawer-in 180ms ease-out both;
}

.drawer-header {
  display: grid;
  gap: 12px;
}

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

.drawer-header,
.drawer-actions,
.thread-card,
.child-thread-card,
.child-thread-group {
  min-width: 0;
}

.thread-list,
.child-thread-list {
  display: grid;
  gap: 12px;
}

.thread-card,
.child-thread-card {
  width: 100%;
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid rgba(10, 108, 96, 0.12);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(247, 241, 232, 0.9));
  text-align: left;
  cursor: pointer;
}

.thread-card[aria-current="true"],
.child-thread-card[aria-current="true"] {
  border-color: rgba(10, 108, 96, 0.35);
  box-shadow: 0 10px 24px rgba(10, 108, 96, 0.12);
}

.thread-card-topline,
.detail-statusline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.thread-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(10, 108, 96, 0.12);
  color: var(--accent-strong);
  font-weight: 700;
}

.status-badge {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}

.status-active {
  background: rgba(10, 108, 96, 0.12);
  color: var(--accent-strong);
}

.status-completed {
  background: rgba(186, 90, 44, 0.12);
  color: var(--warm);
}

.thread-card p,
.child-thread-card p,
.timeline-item p {
  margin: 0;
}

.thread-card p,
.child-thread-card p,
.thread-meta,
.child-thread-summary,
.child-thread-group summary {
  overflow-wrap: anywhere;
}

.thread-meta,
.child-thread-summary {
  font-size: 13px;
  color: var(--muted);
}

.child-thread-card {
  padding: 12px 13px;
  background: rgba(255, 255, 255, 0.78);
}

.child-thread-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.64);
  padding: 12px;
}

.child-thread-group summary {
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  color: var(--accent-strong);
}

.child-thread-group summary::-webkit-details-marker {
  display: none;
}

.timeline-list {
  display: grid;
  gap: 12px;
  align-content: start;
  padding-bottom: 12px;
}

.timeline-item {
  padding: 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(72, 56, 34, 0.12);
}

.timeline-item-user {
  background: rgba(10, 108, 96, 0.08);
  border-color: rgba(10, 108, 96, 0.16);
}

.timeline-item-assistant {
  background: rgba(255, 255, 255, 0.88);
}

.timeline-item-type {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 6px;
  color: var(--accent);
}

.timeline-item-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.reply-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
}

.reply-textarea {
  min-height: 38px;
  max-height: 32vh;
  resize: none;
  overflow-y: auto;
  line-height: 1.35;
  padding: 8px 12px;
}

.scroll-bottom-button {
  position: absolute;
  right: 20px;
  bottom: 92px;
  z-index: 5;
  box-shadow: 0 12px 24px rgba(10, 108, 96, 0.14);
}

.empty-state {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.reply-form .error-text {
  grid-column: 1 / -1;
}

.empty-state {
  padding: 18px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.68);
  border: 1px dashed rgba(72, 56, 34, 0.18);
}

@media (max-width: 420px) {
  .app-shell {
    padding: 8px;
  }

  .app-header,
  .view-panel,
  .thread-detail,
  .thread-composer {
    padding: 10px;
  }

  .drawer-panel {
    padding: 14px;
  }

  .scroll-bottom-button {
    right: 16px;
    bottom: 84px;
  }
}

@keyframes slide-drawer-in {
  from {
    transform: translateX(-24px);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

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

  to {
    opacity: 1;
    transform: translateY(0);
  }
}
