/* ===== CSS Variables ===== */
:root {
  /* 色彩系统 - 极简灰白 + 朱砂红点缀 */
  --bg-primary: #F5F3EE;
  --bg-card: #FFFFFF;
  --bg-sidebar: #F0EDE7;
  --bg-hover: #EBE7DF;
  --bg-active: #E5E0D7;

  --text-primary: #2C2C2C;
  --text-secondary: #6B6B6B;
  --text-tertiary: #999999;
  --text-muted: #BFBFBF;

  --accent: #C44F3A;
  --accent-light: #D46955;
  --accent-bg: rgba(196, 79, 58, 0.08);

  --border: #E0DCD4;
  --border-light: #EDE9E2;

  --green-dot: #5B9A6B;
  --green-bg: rgba(91, 154, 107, 0.12);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.10);

  /* 排版 */
  --font-serif: 'Noto Serif SC', 'Songti SC', 'STSong', 'SimSun', serif;
  --font-sans: 'Noto Sans SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;

  --sidebar-width: 220px;
  --content-max: 900px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --transition: 0.2s ease;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== App Container ===== */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 28px 20px;
}

.profile-section {
  text-align: center;
  margin-bottom: 32px;
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 2px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
  overflow: hidden;
}
.avatar:hover { border-color: var(--accent); transform: scale(1.05); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.profile-name {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.profile-bio {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

/* Nav Tabs */
.nav-tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
}
.nav-tab:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-tab.active { background: var(--bg-card); color: var(--text-primary); font-weight: 500; box-shadow: var(--shadow-sm); }

.nav-icon { display: flex; align-items: center; flex-shrink: 0; }

/* Sidebar Footer */
.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.settings-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-tertiary);
  font-size: 0.82rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
}
.settings-btn:hover { background: var(--bg-hover); color: var(--text-secondary); }

/* ===== Main Content ===== */
.content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 40px 48px;
  min-height: 100vh;
  max-width: calc(var(--content-max) + var(--sidebar-width));
}

/* ===== Tab Pages ===== */
.tab-page { display: none; }
.tab-page.active { display: block; animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Section Header */
.section-header { margin-bottom: 24px; }

.section-title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.section-subtitle {
  font-size: 0.88rem;
  color: var(--text-tertiary);
}

/* ===== Daily Layout ===== */
.daily-layout {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* ===== Generate Layout ===== */
.generate-layout {
  max-width: 720px;
}

.generate-form {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
}

.form-row {
  display: flex;
  gap: 16px;
}

.form-group {
  margin-bottom: 20px;
  flex: 1;
}
.form-group:last-child { margin-bottom: 0; }

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}

.form-group input[type="text"],
.form-group input[type="date"],
.form-group input[type="password"],
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--bg-card);
  transition: border-color var(--transition);
  outline: none;
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Chat Input */
.chat-input-wrapper {
  position: relative;
}

#chatInput {
  width: 100%;
  min-height: 240px;
  padding: 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', 'Menlo', monospace;
  color: var(--text-primary);
  background: #FAFAF8;
  resize: vertical;
  outline: none;
  line-height: 1.7;
  transition: border-color var(--transition);
}
#chatInput:focus { border-color: var(--accent); }
#chatInput::placeholder { color: var(--text-muted); }

.drop-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(245, 243, 238, 0.92);
  border: 2px dashed var(--accent);
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.drop-overlay.active { display: flex; }

.drop-hint {
  text-align: center;
  color: var(--text-secondary);
}
.drop-hint p { margin-top: 8px; font-size: 0.9rem; }

.input-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.btn-text {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.82rem;
  font-family: var(--font-sans);
  cursor: pointer;
  padding: 4px 0;
}
.btn-text:hover { text-decoration: underline; }

.char-count {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Buttons */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #FFFFFF;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-primary:hover { background: var(--accent-light); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.generate-btn { margin-top: 8px; }

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }

/* ===== Generate Progress ===== */
.generate-progress {
  margin-top: 24px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
}

.progress-steps {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}

.progress-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  opacity: 0.3;
  transition: opacity var(--transition);
}
.progress-step.active { opacity: 1; }
.progress-step.done { opacity: 0.7; }

.step-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all var(--transition);
}
.progress-step.active .step-dot { background: var(--accent); box-shadow: 0 0 0 6px var(--accent-bg); }
.progress-step.done .step-dot { background: var(--green-dot); }

.step-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.progress-bar {
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.5s ease;
}

.progress-text {
  margin-top: 12px;
  font-size: 0.82rem;
  color: var(--text-tertiary);
  text-align: center;
}

/* ===== Generate Result ===== */
.generate-result {
  margin-top: 32px;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.result-header h3 {
  font-family: var(--font-serif);
  font-size: 1.1rem;
}
.result-actions { display: flex; gap: 8px; }

.report-preview {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-light);
}

/* ===== Archive Layout ===== */
.archive-layout {
  max-width: 720px;
}

.archive-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

.archive-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.archive-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  cursor: pointer;
  transition: all var(--transition);
}
.archive-item:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }

.archive-item-date {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 90px;
}

.archive-item-group {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.archive-item-meta {
  font-size: 0.78rem;
  color: var(--text-tertiary);
}

.archive-item-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all var(--transition);
}
.archive-item-delete:hover { color: var(--accent); background: var(--accent-bg); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
}

.empty-icon { margin-bottom: 16px; }

.empty-title {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-desc {
  font-size: 0.88rem;
  color: var(--text-tertiary);
}

.dot-demo {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green-dot);
  vertical-align: middle;
  margin: 0 2px;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

.modal-card {
  width: 400px;
  max-width: 90vw;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
}
.modal-header h3 {
  font-family: var(--font-serif);
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
}
.modal-close:hover { color: var(--text-primary); background: var(--bg-hover); }

.modal-body { padding: 24px; }
.modal-body .btn-primary { margin-top: 16px; }

.save-status {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--green-dot);
  text-align: center;
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: 0.85rem;
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  animation: slideIn 0.3s ease;
  max-width: 320px;
}
.toast.success { border-left: 3px solid var(--green-dot); }
.toast.error { border-left: 3px solid var(--accent); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Hamburger Button ===== */
.hamburger-btn {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px;
}
.hamburger-btn span {
  display: block;
  width: 18px;
  height: 1.5px;
  background: var(--text-primary);
  border-radius: 1px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }

  .hamburger-btn { display: flex; }

  .content {
    margin-left: 0;
    padding: 20px 16px;
    padding-top: 64px;
  }

  .form-row { flex-direction: column; gap: 0; }

  .progress-steps { flex-wrap: wrap; gap: 12px; justify-content: center; }
  .step-label { font-size: 0.68rem; }

  .result-header { flex-direction: column; gap: 12px; align-items: flex-start; }

  .archive-toolbar { flex-wrap: wrap; }
}

/* ===== Input Mode Tabs ===== */
.input-mode-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.mode-tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
}
.mode-tab:hover { color: var(--text-secondary); }
.mode-tab.active { background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }

.input-panel { display: none; }
.input-panel.active { display: block; }

/* ===== ChatLog Status ===== */
.chatlog-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #FAFAF8;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  margin-bottom: 12px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.status-indicator.online { background: var(--green-dot); box-shadow: 0 0 0 4px var(--green-bg); }
.status-indicator.offline { background: var(--accent); }

#statusText {
  font-size: 0.82rem;
  color: var(--text-secondary);
  flex: 1;
}

.chatlog-config {
  background: #FAFAF8;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  padding: 16px;
  margin-bottom: 12px;
}
.chatlog-config .form-row { align-items: flex-end; }

/* Select with refresh button */
.select-with-refresh {
  display: flex;
  gap: 6px;
}
.select-with-refresh select { flex: 1; }

.btn-icon-only {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-icon-only:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.btn-icon-only:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-icon-only.spinning svg { animation: spin 1s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Fetch Result ===== */
.fetch-result {
  margin-top: 16px;
  background: #FAFAF8;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  overflow: hidden;
}

.fetch-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
}

.fetch-result-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.fetch-result-actions { display: flex; gap: 4px; }

.fetch-result-info {
  padding: 12px 16px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.message-preview { border-top: 1px solid var(--border-light); }
.message-preview textarea {
  width: 100%;
  min-height: 120px;
  max-height: 300px;
  padding: 14px;
  border: none;
  background: #FFFEFA;
  font-size: 0.78rem;
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  line-height: 1.6;
  color: var(--text-secondary);
  resize: vertical;
  outline: none;
}

/* ===== ChatLog connect button in sidebar ===== */
.chatlog-connect-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
  line-height: 1.5;
}
.chatlog-connect-hint a {
  color: var(--accent);
  text-decoration: none;
}
.chatlog-connect-hint a:hover { text-decoration: underline; }
