:root {
  --bg: #f7f4ee;
  --panel: #fffaf2;
  --panel-2: #fbf7ef;
  --text: #2d2a26;
  --muted: #7a7168;
  --line: #e7ded1;
  --accent: #6f5b45;
  --accent-2: #8d7358;
  --danger: #a94442;
  --shadow: 0 14px 40px rgba(48, 38, 26, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.brand {
  font-size: 28px;
  font-weight: 760;
  letter-spacing: -0.03em;
}

.login-subtitle {
  margin-top: 6px;
  margin-bottom: 22px;
  color: var(--muted);
}

.login-input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  outline: none;
}

.primary-btn {
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  padding: 11px 16px;
  margin-top: 14px;
}

.primary-btn:hover {
  background: var(--accent-2);
}

.error-text {
  color: var(--danger);
  min-height: 22px;
  margin-top: 10px;
  font-size: 14px;
}

.app-view {
  height: 100dvh;
  display: flex;
  overflow: hidden;
}

.sidebar {
  width: 300px;
  min-width: 260px;
  background: var(--panel-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 12px;
}

.side-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.app-title {
  font-size: 22px;
  font-weight: 760;
  letter-spacing: -0.03em;
}

.side-btn,
.tool-btn,
.icon-btn,
.mobile-menu-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 12px;
  padding: 8px 10px;
}

.side-btn.ghost {
  color: var(--muted);
}

.search-box {
  display: flex;
  gap: 6px;
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 10px;
  background: #fff;
  outline: none;
}

.search-box button {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 8px 10px;
}

.search-results {
  max-height: 150px;
  overflow: auto;
  font-size: 13px;
  color: var(--muted);
}

.search-result {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 7px 8px;
  margin-bottom: 6px;
}

.session-list {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.session-item {
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 10px;
  color: var(--text);
  background: transparent;
}

.session-item:hover,
.session-item.active {
  background: #fff;
  border-color: var(--line);
}

.session-title {
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-time {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

.side-bottom {
  display: flex;
  gap: 8px;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.chat-header {
  height: 64px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: rgba(247, 244, 238, 0.92);
  backdrop-filter: blur(12px);
}

.chat-title {
  font-size: 17px;
  font-weight: 720;
}

.chat-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.mobile-menu-btn {
  display: none;
}

.message-list {
  flex: 1;
  overflow: auto;
  padding: 28px 24px 120px;
  scroll-behavior: smooth;
}

.message {
  max-width: 860px;
  margin: 0 auto 22px;
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 14px;
}

.role {
  color: var(--muted);
  font-size: 14px;
  padding-top: 2px;
  text-transform: lowercase;
}

.bubble {
  line-height: 1.72;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .bubble {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
}

.message.assistant .bubble {
  padding: 2px 0;
}

.reasoning {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
  border-radius: 14px;
  margin-bottom: 12px;
  overflow: hidden;
}

.reasoning summary {
  color: var(--muted);
  cursor: pointer;
  padding: 10px 12px;
  user-select: none;
}

.reasoning-content {
  border-top: 1px solid var(--line);
  color: #5f5850;
  padding: 12px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.msg-highlight {
  outline: 3px solid rgba(111, 91, 69, 0.28);
  border-radius: 16px;
}

.code-block {
  position: relative;
  margin: 12px 0;
}

.code-block pre {
  overflow: auto;
  background: #27231f;
  color: #f8efe2;
  border-radius: 14px;
  padding: 14px;
}

.preview-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid rgba(255,255,255,0.24);
  background: rgba(255,255,255,0.12);
  color: #fff;
  border-radius: 10px;
  padding: 5px 8px;
  font-size: 12px;
}

.composer-wrap {
  border-top: 1px solid var(--line);
  background: rgba(247, 244, 238, 0.94);
  padding: 10px 18px calc(12px + env(safe-area-inset-bottom));
}

.composer-tools {
  max-width: 900px;
  margin: 0 auto 8px;
  display: flex;
  gap: 8px;
}

.composer {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 180px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  padding: 13px 15px;
  outline: none;
  line-height: 1.5;
}

.send-btn {
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  padding: 13px 18px;
}

.settings-panel,
.html-preview-panel {
  position: fixed;
  inset: 0;
  background: rgba(42, 35, 28, 0.34);
  display: flex;
  justify-content: flex-end;
  z-index: 20;
}

.settings-card,
.html-preview-card {
  width: min(560px, 100%);
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 20px;
  overflow: auto;
}

.settings-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.settings-card label {
  display: block;
  color: var(--muted);
  margin: 14px 0 7px;
  font-size: 14px;
}

.settings-card input,
.settings-card select,
.prompt-box {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 10px 12px;
  outline: none;
}

.prompt-box {
  min-height: 220px;
  resize: vertical;
  line-height: 1.55;
}

.settings-actions {
  margin-top: 16px;
}

#htmlPreviewFrame {
  width: 100%;
  height: calc(100dvh - 92px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

@media (max-width: 760px) {
  .app-view {
    position: relative;
  }

  .sidebar {
    position: fixed;
    z-index: 15;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-105%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

  .chat-header {
    padding: 0 14px;
  }

  .message-list {
    padding: 20px 14px 110px;
  }

  .message {
    grid-template-columns: 1fr;
    gap: 6px;
    margin-bottom: 20px;
  }

  .role {
    font-size: 12px;
  }

  .composer-wrap {
    padding-left: 10px;
    padding-right: 10px;
  }

  .send-btn {
    padding: 13px 14px;
  }
}
