:root {
  color-scheme: light;
  --bg: #f2f5f8;
  --sidebar: #f8fafc;
  --panel: #ffffff;
  --panel-alt: #f7f8fa;
  --text: #1f2937;
  --muted: #667085;
  --line: #e6ebf2;
  --primary: #0f766e;
  --primary-strong: #0b5d57;
  --primary-soft: #e7f7f4;
  --assistant: #ffffff;
  --user: #ecfdf5;
  --user-border: #bfead6;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: "Segoe UI", Arial, "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1400px, 100%);
  height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), #20b292);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.35);
}

.brand-row h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.primary-button {
  border: none;
  background: var(--primary);
  color: #fff;
  height: 42px;
  border-radius: 12px;
  font-weight: 600;
  transition: background 0.2s ease;
}

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

.session-list-wrap {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-label {
  font-size: 12px;
  color: var(--muted);
  padding: 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.session-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.session-item {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: all 0.2s ease;
}

.session-item:hover {
  background: rgba(15, 118, 110, 0.04);
}

.session-item.active {
  background: #fff;
  border-color: var(--line);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
}

.session-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  flex: 1;
}

.session-badge {
  font-size: 11px;
  padding: 4px 6px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
}

.topbar {
  min-height: 72px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.model-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 7px 10px;
  color: var(--muted);
  font-size: 13px;
}

.model-select select {
  border: none;
  background: transparent;
  color: var(--text);
  outline: none;
  min-width: 150px;
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-weight: 500;
}

.ghost-button:hover {
  background: #f7f9fb;
}

.chat {
  overflow-y: auto;
  padding: 28px 24px 20px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.empty-state {
  min-height: 100%;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: clamp(24px, 2vw, 34px);
}

.empty-state p {
  margin: 0;
  font-size: 15px;
}

.message {
  display: flex;
  margin: 0 auto 18px;
  max-width: 900px;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  max-width: min(720px, 86%);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.03);
}

.assistant .bubble {
  background: var(--assistant);
}

.user .bubble {
  background: var(--user);
  border-color: var(--user-border);
}

.loading .bubble {
  color: var(--muted);
}

.dots {
  display: inline-flex;
  gap: 5px;
  vertical-align: middle;
}

.dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: blink 1s infinite ease-in-out;
}

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

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

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.2;
  }
  40% {
    opacity: 1;
  }
}

.composer {
  padding: 16px 22px 20px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  background: #fff;
}

textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  line-height: 1.6;
  outline: none;
  background: #fbfcfe;
}

textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

#sendBtn {
  min-width: 88px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  background: var(--primary);
  padding: 0 18px;
  font-weight: 600;
}

#sendBtn:hover:not(:disabled) {
  background: var(--primary-strong);
}

#sendBtn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

@media (max-width: 840px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    min-height: auto;
  }
}

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

  .topbar {
    padding: 14px 14px;
  }

  .chat {
    padding: 18px 14px;
  }

  .bubble {
    max-width: 92%;
  }

  .composer {
    padding: 12px 14px 14px;
    grid-template-columns: 1fr;
  }

  .model-select {
    display: none;
  }

  #sendBtn {
    height: 44px;
  }
}
