:root {
  color-scheme: light dark;
  --bg: #f7f5f2;
  --panel: #ffffff;
  --sidebar-bg: #efece6;
  --text: #2a2a2a;
  --muted: #767676;
  --accent: #6b5b95;
  --user-bubble: #6b5b95;
  --user-bubble-text: #ffffff;
  --bot-bubble: #f0eef8;
  --bot-bubble-text: #2a2a2a;
  --border: #e4e0da;
  --item-hover: #e4e0da;
  --item-active: #ded7ea;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b1f;
    --panel: #26242b;
    --sidebar-bg: #1f1d23;
    --text: #ececec;
    --muted: #a3a0a8;
    --accent: #9a8cc2;
    --user-bubble: #6b5b95;
    --user-bubble-text: #ffffff;
    --bot-bubble: #322f3a;
    --bot-bubble-text: #ececec;
    --border: #3a3742;
    --item-hover: #322f3a;
    --item-active: #3d3949;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
}

.app-layout {
  display: flex;
  height: 100vh;
  max-width: 1000px;
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 10px;
}

.new-chat-btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
}

.new-chat-btn:hover {
  background: var(--item-hover);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text);
}

.conversation-item:hover {
  background: var(--item-hover);
}

.conversation-item.active {
  background: var(--item-active);
}

.conversation-item .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item .title-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 0.88rem;
  font-family: inherit;
  background: var(--panel);
  color: var(--text);
}

.conversation-item .rename-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 4px;
  visibility: hidden;
}

.conversation-item:hover .rename-btn {
  visibility: visible;
}

.chat-container {
  flex: 1;
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.sidebar-toggle {
  display: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.sidebar-overlay {
  display: none;
}

.chat-header h1 {
  margin: 0 0 4px;
  font-size: 1.15rem;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 6px;
}

.avatar-header {
  width: 40px;
  height: 40px;
  margin-right: 0;
  flex-shrink: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.messages[hidden] {
  display: none;
}

.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
}

.bubble.bot {
  align-self: flex-start;
  background: var(--bot-bubble);
  color: var(--bot-bubble-text);
  border-bottom-left-radius: 4px;
}

.bubble.error {
  align-self: flex-start;
  background: transparent;
  color: #c0392b;
  font-size: 0.85rem;
}

.bubble img.chat-image {
  display: block;
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  margin-bottom: 6px;
}

.image-preview {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 24px 0;
}

.image-preview.show {
  display: flex;
}

.image-preview img {
  max-height: 64px;
  max-width: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.image-preview .remove-image-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}

.attach-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  width: 40px;
  flex-shrink: 0;
  font-size: 1.1rem;
  cursor: pointer;
}

.attach-btn:hover {
  background: var(--item-hover);
}

.chat-form {
  display: flex;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

#chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  max-height: 140px;
}

#send-btn {
  border: none;
  border-radius: 10px;
  padding: 0 20px;
  background: var(--accent);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
}

#send-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}

.auth-stack {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-card h1 {
  margin: 0;
  font-size: 1.3rem;
}

.auth-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.field-hint {
  font-size: 0.78rem;
  color: var(--muted);
  opacity: 0.85;
}

.auth-card input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}

.auth-card button[type="submit"] {
  border: none;
  border-radius: 10px;
  padding: 11px;
  background: var(--accent);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
}

.auth-card button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: default;
}

.auth-notice {
  display: none;
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bot-bubble);
  color: var(--bot-bubble-text);
  font-size: 0.85rem;
}

.auth-notice.show {
  display: block;
}

.auth-error {
  margin: 0;
  color: #c0392b;
  font-size: 0.85rem;
  min-height: 1em;
}

.auth-switch {
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.auth-switch a {
  color: var(--accent);
}

.logout-link {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
}

.admin-page {
  max-width: 1000px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--panel);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.admin-content {
  padding: 20px 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.admin-section h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.admin-section-header h2 {
  margin: 0;
}

.admin-stat-cards {
  display: flex;
  gap: 12px;
}

.admin-stat-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bot-bubble);
  min-width: 130px;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.admin-table th {
  color: var(--muted);
  font-weight: 500;
}

.admin-empty {
  text-align: center;
  color: var(--muted);
  padding: 18px 10px;
}

.footprint-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.footprint-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  background: var(--bot-bubble);
}

.footprint-date {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.footprint-summary {
  color: var(--bot-bubble-text);
  line-height: 1.6;
  white-space: pre-wrap;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px 24px;
  gap: 4px;
  overflow-y: auto;
}

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

.empty-state-avatar {
  width: 88px;
  height: 88px;
  margin-bottom: 12px;
}

.empty-state-greeting {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.empty-state-sub {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 360px;
}

.empty-state-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 360px;
}

.empty-state-option {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--bot-bubble);
  color: var(--bot-bubble-text);
  font-size: 0.92rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  box-sizing: border-box;
  transition: background 0.15s ease;
}

.empty-state-option:hover {
  background: var(--item-hover);
}

.empty-state-option:disabled {
  opacity: 0.6;
  cursor: default;
}

@media (max-width: 768px) {
  .admin-page {
    border-left: none;
    border-right: none;
  }

  .admin-table {
    display: block;
    overflow-x: auto;
  }
}

@media (max-width: 768px) {
  .app-layout {
    border-left: none;
    border-right: none;
  }

  .sidebar-toggle {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
  }

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

  .sidebar-overlay.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 10;
  }
}
