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

:root {
  --bg: #faf8f5;
  --card: #ffffff;
  --accent: #e8906c;
  --accent-hover: #d47a56;
  --accent-light: #fdf0ea;
  --text: #2c2c2c;
  --text-secondary: #888888;
  --border: #eae6e1;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.05);
  --radius: 16px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
}

html {
  font-size: 15px;
}

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

/* ========== Top Bar ========== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: linear-gradient(135deg, #fdf6f0 0%, #faf5f0 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.nav-tagline {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ========== Main Container ========== */
.main-container {
  display: flex;
  height: calc(100vh - 61px);
  padding: 20px 24px;
  gap: 20px;
  max-width: 1440px;
  margin: 0 auto;
}

/* ========== Panel ========== */
.panel {
  flex: 1;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

/* ========== Blog Panel ========== */
.blog-list-view {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.article-list {
  padding: 0 16px;
}

.article-item {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  border: 1px solid transparent;
}

.article-item:hover {
  background: var(--accent-light);
}

.article-item.active {
  background: var(--accent-light);
  border-color: var(--accent);
}

.article-item .article-date {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.article-item .article-title {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
}

.empty-hint {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-hint code {
  background: var(--accent-light);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.88rem;
  color: var(--accent);
}

.hint-sub {
  margin-top: 8px;
  font-size: 0.82rem;
}

/* Reading View */
.blog-read-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.back-btn {
  align-self: flex-start;
  margin: 12px 24px 0;
  padding: 6px 16px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  flex-shrink: 0;
}

.back-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}

.article-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 28px 32px;
}

/* ========== Markdown Body Overrides ========== */
.markdown-body {
  font-size: 0.95rem;
  color: var(--text);
}

.markdown-body h1 { font-size: 1.6rem; margin-top: 1.2em; margin-bottom: 0.5em; font-weight: 700; }
.markdown-body h2 { font-size: 1.3rem; margin-top: 1.1em; margin-bottom: 0.4em; font-weight: 600; }
.markdown-body h3 { font-size: 1.1rem; margin-top: 1em; margin-bottom: 0.3em; font-weight: 600; }
.markdown-body p { margin-bottom: 0.8em; }
.markdown-body a { color: var(--accent); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 6px 16px;
  margin: 12px 0;
  background: var(--accent-light);
  border-radius: 0 8px 8px 0;
  color: #5a4a40;
}
.markdown-body ul, .markdown-body ol { padding-left: 1.5em; margin-bottom: 0.8em; }
.markdown-body li { margin-bottom: 0.3em; }
.markdown-body code {
  background: #f5f2ef;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.88em;
  color: #c76b4a;
}
.markdown-body pre {
  background: #f8f6f3;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
}
.markdown-body pre code {
  background: none;
  padding: 0;
  color: var(--text);
  font-size: 0.85rem;
}
.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.markdown-body th {
  background: #fdf9f5;
  font-weight: 600;
}
.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}
.markdown-body img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

/* ========== AI Panel ========== */
.ai-header {
  gap: 12px;
}

.clear-btn {
  padding: 4px 14px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}

.clear-btn:hover {
  color: #d4694a;
  border-color: #d4694a;
}

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

.message {
  display: flex;
  max-width: 85%;
  animation: fadeIn 0.25s ease;
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.msg-content {
  padding: 10px 16px;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.55;
  word-break: break-word;
}

.message.user .msg-content {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant .msg-content {
  background: #f5f2ef;
  border-bottom-left-radius: 4px;
}

.message.assistant .msg-content p { margin-bottom: 0.5em; }
.message.assistant .msg-content p:last-child { margin-bottom: 0; }
.message.assistant .msg-content code {
  background: #ebe6df;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.88em;
}
.message.assistant .msg-content pre {
  background: #ebe6df;
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0;
  font-size: 0.85rem;
}
.message.assistant .msg-content pre code {
  background: none;
  padding: 0;
}
.message.assistant .msg-content ul,
.message.assistant .msg-content ol {
  padding-left: 1.3em;
}
.message.assistant .msg-content blockquote {
  border-left: 2px solid var(--accent);
  padding-left: 10px;
  margin: 6px 0;
  color: #8a7a6a;
}

/* ========== Quick Actions ========== */
.quick-actions {
  display: flex;
  gap: 8px;
  padding: 10px 20px 4px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.quick-btn {
  padding: 5px 14px;
  background: var(--accent-light);
  border: 1px solid transparent;
  border-radius: 18px;
  font-size: 0.8rem;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}

.quick-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* ========== Chat Input ========== */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-area textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-family: var(--font);
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  max-height: 100px;
  line-height: 1.4;
  background: var(--bg);
}

.chat-input-area textarea:focus {
  border-color: var(--accent);
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:active {
  transform: scale(0.95);
}

/* ========== Mobile Tabs ========== */
.mobile-tabs {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 8px 24px 12px;
  z-index: 200;
  gap: 12px;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--card);
  font-size: 0.9rem;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-secondary);
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .topbar {
    padding: 12px 18px;
  }

  .main-container {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 53px - 60px);
    padding: 12px 14px;
    gap: 0;
  }

  .panel {
    display: none;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .panel.active {
    display: flex;
    flex: 1;
  }

  .mobile-tabs {
    display: flex;
  }

  .chat-messages {
    padding: 12px 14px;
  }

  .chat-input-area {
    padding: 10px 14px 14px;
  }

  .quick-actions {
    padding: 8px 14px 2px;
  }

  .article-content {
    padding: 12px 18px 24px;
  }
}

/* ========== Animation ========== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
