:root {
  --bg: #f5efe4;
  --bg-soft: #fbf7f0;
  --panel: rgba(255, 250, 242, 0.88);
  --panel-strong: rgba(255, 250, 242, 0.96);
  --line: rgba(87, 65, 44, 0.12);
  --text: #2f241a;
  --muted: #7b6552;
  --accent: #8fd06e;
  --accent-strong: #71bc4d;
  --accent-deep: #4a9d2a;
  --white-bubble: #ffffff;
  --shadow: 0 20px 60px rgba(73, 54, 34, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.65), transparent 32%),
    linear-gradient(180deg, #f8f1e5 0%, #f0e6d8 100%);
  color: var(--text);
  font-family: "Manrope", "Noto Sans SC", sans-serif;
}

body {
  height: 100dvh;
  overflow: hidden;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  height: 100dvh;
  padding: 18px;
  overflow: hidden;
  align-items: stretch;
}

.sidebar,
.chat-stage,
.modal-card {
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.sidebar-scrim,
.menu-btn,
.mobile-icon-btn {
  display: none;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  height: 100%;
  padding: 22px;
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, var(--panel-strong), rgba(245, 236, 223, 0.88));
  overflow: hidden;
}

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

.brand {
  min-width: 0;
}

.brand h1,
.empty-card h2,
.modal-head h2 {
  margin: 0;
  font-family: "Noto Sans SC", sans-serif;
  letter-spacing: -0.03em;
}

.brand-kicker,
.modal-kicker,
.empty-label,
.section-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.brand p,
.chat-subtitle,
.status-text {
  color: var(--muted);
}

.wide {
  width: 100%;
}

.primary-btn,
.ghost-btn,
.close-btn {
  border: 0;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

.primary-btn:hover,
.ghost-btn:hover,
.close-btn:hover {
  transform: translateY(-1px);
}

.primary-btn:disabled,
.ghost-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.primary-btn {
  border-radius: 999px;
  padding: 14px 18px;
  color: #1f3316;
  font-weight: 700;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
}

.ghost-btn {
  padding: 12px 16px;
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.ex-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

.ex-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.ex-item.active {
  border-color: rgba(74, 157, 42, 0.22);
  background: linear-gradient(180deg, rgba(160, 224, 132, 0.26), rgba(255, 255, 255, 0.82));
}

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

.ex-name {
  font-weight: 700;
}

.ex-meta,
.ex-snippet {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.chat-stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  height: 100%;
  border-radius: 34px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(250, 246, 238, 0.92), rgba(244, 237, 226, 0.92)),
    linear-gradient(90deg, rgba(125, 186, 92, 0.06) 0%, transparent 60%);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 22px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 242, 0.86);
  position: sticky;
  top: 0;
  z-index: 6;
}

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

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

.reply-status {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

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

.chat-title {
  font-size: 22px;
  font-weight: 800;
}

.chat-subtitle {
  display: none;
}

.message-list {
  position: relative;
  min-height: 0;
  overflow: auto;
  padding: 28px 24px 20px;
  background:
    radial-gradient(circle at 1px 1px, rgba(129, 110, 89, 0.06) 1px, transparent 0) 0 0 / 22px 22px,
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent);
}

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

.empty-card {
  max-width: 460px;
  padding: 28px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid var(--line);
  text-align: center;
}

.message-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}

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

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

.message-group.system {
  align-items: center;
  margin: 8px 0 18px;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  width: fit-content;
  max-width: 100%;
}

.message-row.user-row {
  margin-left: auto;
}

.message-group.user .message-row .avatar {
  order: 2;
}

.message-group.user .message-row .bubble {
  order: 1;
}

.message-row.assistant-row {
  margin-right: auto;
}

.avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(165, 214, 115, 0.95), rgba(118, 177, 73, 0.95));
  color: #233715;
  font-size: 14px;
  font-weight: 800;
  border: 1px solid rgba(79, 125, 40, 0.14);
  box-shadow: 0 10px 24px rgba(74, 157, 42, 0.14);
}

.message-group.assistant .avatar {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(243, 235, 224, 0.98));
  color: var(--text);
  border-color: rgba(120, 92, 66, 0.1);
  box-shadow: 0 10px 24px rgba(92, 73, 56, 0.08);
}

.bubble {
  max-width: min(72ch, 82%);
  padding: 14px 16px;
  border-radius: 22px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid rgba(120, 92, 66, 0.08);
}

.message-group.user .bubble {
  background: linear-gradient(180deg, #9ce078 0%, #86d15d 100%);
  color: #1d2f17;
  border-bottom-right-radius: 8px;
}

.message-group.assistant .bubble {
  background: var(--white-bubble);
  color: var(--text);
  border-bottom-left-radius: 8px;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 154px;
}

.typing-label {
  color: var(--muted);
  font-size: 14px;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: rgba(123, 101, 82, 0.7);
  animation: typingPulse 1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.message-group.system .bubble {
  max-width: 90%;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(92, 73, 56, 0.1);
  color: var(--muted);
  border: 0;
  font-size: 13px;
}

@keyframes typingPulse {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }

  40% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

.message-meta {
  font-size: 12px;
  color: var(--muted);
  padding: 0 48px;
}

.message-group.user .message-meta {
  text-align: right;
}

.message-group.assistant .message-meta {
  text-align: left;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 18px 22px 22px;
  border-top: 1px solid var(--line);
  background: rgba(255, 250, 242, 0.9);
  position: sticky;
  bottom: 0;
  z-index: 5;
}

.composer textarea,
.create-form input,
.create-form textarea,
.create-form select {
  width: 100%;
  border: 1px solid rgba(108, 83, 57, 0.14);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  resize: none;
  outline: none;
}

.composer textarea {
  min-height: 56px;
  padding: 16px 18px;
}

.composer textarea:focus,
.create-form input:focus,
.create-form textarea:focus,
.create-form select:focus {
  border-color: rgba(74, 157, 42, 0.35);
  box-shadow: 0 0 0 4px rgba(143, 208, 110, 0.12);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(24, 16, 10, 0.42);
  z-index: 20;
}

.hidden {
  display: none !important;
}

.modal-card {
  width: min(860px, 100%);
  max-height: min(92vh, 980px);
  overflow: auto;
  padding: 26px;
  border-radius: 30px;
  background: linear-gradient(180deg, rgba(255, 250, 242, 0.98), rgba(246, 239, 229, 0.94));
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.close-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--line);
  font-size: 24px;
}

.create-form {
  display: grid;
  gap: 16px;
}

.create-form label {
  display: grid;
  gap: 8px;
}

.create-form label span {
  font-weight: 700;
}

.create-form input,
.create-form textarea,
.create-form select {
  padding: 14px 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.file-field input {
  padding: 10px 12px;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-top: 8px;
}

.status-text {
  font-size: 14px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(42, 31, 22, 0.9);
  color: #fff;
  z-index: 30;
}

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

@media (max-width: 900px) {
  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(25, 18, 12, 0.42);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
    z-index: 35;
  }

  .app-shell.sidebar-open .sidebar-scrim {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(84vw, 340px);
    height: 100dvh;
    border-radius: 0 28px 28px 0;
    z-index: 40;
    transform: translateX(-110%);
    transition: transform 180ms ease;
  }

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

  .menu-btn,
  .mobile-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.78);
    color: var(--text);
  }

  .menu-btn {
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 14px;
    flex: 0 0 42px;
    flex-direction: column;
    gap: 4px;
  }

  .menu-btn span {
    display: block;
    width: 16px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
  }

  .mobile-icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    font-size: 24px;
    flex: 0 0 42px;
  }

  .chat-stage {
    border-radius: 0;
  }

  .chat-header {
    padding: 14px 16px;
  }

  .chat-title {
    font-size: 20px;
  }

  .chat-subtitle {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .message-list {
    padding: 18px 14px 14px;
  }

  .composer {
    padding: 14px 16px 16px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    height: 100dvh;
  }

  .chat-stage,
  .modal-card {
    border-radius: 24px;
  }

  .chat-stage {
    border-radius: 0;
  }

  .form-grid,
  .composer,
  .modal-actions {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions {
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .ghost-btn,
  .primary-btn {
    padding: 11px 14px;
  }

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

  .bubble {
    max-width: 90%;
  }

  .avatar {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
    border-radius: 12px;
  }

  .message-meta {
    padding: 0 42px;
  }
}
