/* =============================================
   Design System — CSS Custom Properties
   Theme: Apple Warm White (default)
   Switch to Linear: change data-theme on <html>
   ============================================= */

/* === Apple Warm White (default) === */
:root {
  --bg-page:        #f5f5f7;
  --bg-surface:     #ffffff;
  --bg-surface-alt: #fafafa;
  --bg-hover:       #f0f0f2;

  --text-primary:   #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary:  #aeaeb2;

  --border:         #e8e8ed;
  --border-light:   #f0f0f2;

  --accent:         #0071e3;
  --accent-hover:   #0077ed;
  --accent-subtle:  #e8f2fd;

  --red:            #e53935;
  --green:          #2e7d32;

  --radius-sm:      6px;
  --radius-md:      10px;
  --radius-lg:      14px;

  --shadow-sm:      0 1px 2px rgba(0,0,0,0.04);
  --font-sans:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:      'JetBrains Mono', 'SF Mono', 'Fira Code', 'Consolas', monospace;

  /* Font size scale — single source of truth for all type sizing */
  --fs-hero:    36px;
  --fs-display: 32px;
  --fs-h1:      28px;
  --fs-h2:      22px;
  --fs-h3:      18px;
  --fs-title:   16px;
  --fs-body:    16px;
  --fs-ui:      14px;
  --fs-small:   13px;
  --fs-tiny:    12px;
}

/* === Semantic font-size classes (use these, not inline font-size) === */
.text-hero    { font-size: var(--fs-hero); }
.text-display { font-size: var(--fs-display); }
.text-h1      { font-size: var(--fs-h1); }
.text-h2      { font-size: var(--fs-h2); }
.text-h3      { font-size: var(--fs-h3); }
.text-title   { font-size: var(--fs-title); }
.text-body    { font-size: var(--fs-body); }
.text-ui      { font-size: var(--fs-ui); }
.text-small   { font-size: var(--fs-small); }
.text-tiny    { font-size: var(--fs-tiny); }

/* === Linear Cool Gray (add data-theme="linear" to <html>) === */
[data-theme="linear"] {
  --bg-page:        #fafafa;
  --bg-surface:     #ffffff;
  --bg-surface-alt: #f7f7f8;
  --bg-hover:       #f2f2f3;

  --text-primary:   #0a0a0a;
  --text-secondary: #5c5c5c;
  --text-tertiary:  #a0a0a0;

  --border:         #e5e5e5;
  --border-light:   #ededed;

  --accent:         #5e6ad2;
  --accent-hover:   #4f5ac7;
  --accent-subtle:  #f0f1fa;

  --red:            #e54d4d;
  --green:          #3b995b;

  --radius-sm:      4px;
  --radius-md:      6px;
  --radius-lg:      8px;
}

/* === Base === */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--accent-subtle); color: var(--text-primary); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d0d0d5; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #b0b0b5; }

/* === Typography === */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.25;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s;
}
a:hover { color: var(--accent-hover); }

/* === Utility === */
.surface {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.surface-flat {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
}
.text-primary   { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary  { color: var(--text-tertiary); }
.mono { font-family: var(--font-mono); }

/* === Nav === */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(245,245,247,0.8);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}
[data-theme="linear"] .site-nav {
  background: rgba(250,250,250,0.8);
}

.site-nav-inner {
  max-width: 1024px;
  margin: 0 auto;
  padding: 0 24px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.site-nav-brand {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.site-nav-links {
  display: flex;
  align-items: center;
  gap: 24px;
}
.site-nav-links a {
  font-size: 13px;
  color: var(--text-tertiary);
  transition: color 0.15s;
}
.site-nav-links a:hover,
.site-nav-links a.active {
  color: var(--text-primary);
}

/* === Page header === */
.page-header {
  max-width: 1024px;
  margin: 0 auto;
  padding: 60px 24px 32px;
}
.page-header h1 {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}
.page-header p {
  font-size: 17px;
  color: var(--text-tertiary);
  margin-top: 6px;
}

/* === Section box === */
.section-box {
  max-width: 1024px;
  margin: 0 auto 28px;
  padding: 28px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.section-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-box-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.section-box-link {
  font-size: 12px;
  color: var(--accent);
}

/* === Article row (list style, not card) === */
.article-row {
  display: block;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-light);
  transition: opacity 0.15s;
  color: inherit;
  text-decoration: none;
}
.article-row:last-child { border-bottom: none; }
.article-row:hover { opacity: 0.7; }
.article-row-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 2px;
}
.article-row-meta .tag {
  color: var(--accent);
}
.article-row-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}
.article-row-excerpt {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 3px;
  line-height: 1.5;
}

/* === Market data row === */
.market-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 20px;
}
.market-item {
  padding: 12px 0;
}
.market-item-label {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 2px;
}
.market-item-price {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}
.market-item-change {
  font-size: 13px;
  font-weight: 500;
}
.market-item-change.up { color: var(--green); }
.market-item-change.down { color: var(--red); }

/* === News row === */
.news-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}
.news-row:last-child { border-bottom: none; }
.news-row-time { color: var(--text-tertiary); font-size: 11px; white-space: nowrap; min-width: 52px; }
.news-row-cat {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--accent-subtle);
  color: var(--accent);
  white-space: nowrap;
  font-weight: 500;
}
.news-row-title {
  color: var(--text-primary);
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.news-row-title:hover { color: var(--accent); }
.news-row-summary {
  color: var(--text-tertiary);
  font-size: 11px;
}

/* === Filter tags === */
.filter-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-tag {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--bg-surface);
  cursor: pointer;
  transition: all 0.15s;
}
.filter-tag:hover { border-color: var(--accent); color: var(--accent); }
.filter-tag.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* === Split editor === */
.editor-container {
  display: flex;
  height: calc(100vh - 48px);
}
.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.editor-pane-left {
  border-right: 1px solid var(--border);
}
.editor-pane-header {
  padding: 10px 20px;
  font-size: var(--fs-tiny);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-alt);
}
.editor-pane-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.editor-textarea {
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
  background: transparent;
}
.editor-textarea::placeholder { color: var(--text-tertiary); }

.editor-preview {
  font-size: var(--fs-body);
  line-height: 1.8;
  color: var(--text-primary);
}
.editor-preview a {
  color: var(--accent);
  text-decoration: underline;
}
.editor-preview h1 { font-size: 28px; margin: 24px 0 12px; }
.editor-preview h2 { font-size: 22px; margin: 20px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border-light); }
.editor-preview h3 { font-size: 18px; margin: 16px 0 8px; }
.editor-preview p  { margin: 0 0 14px; }
.editor-preview pre {
  background: #2d2d2d;
  color: #e0e0e0;
  padding: 16px 20px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}
.editor-preview code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-hover);
  padding: 2px 5px;
  border-radius: 3px;
}
.editor-preview pre code { background: none; padding: 0; color: inherit; }
.editor-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 14px;
}
.editor-preview th, .editor-preview td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}
.editor-preview th {
  background: var(--bg-hover);
  font-weight: 600;
  color: var(--text-primary);
}
.editor-preview blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  color: var(--text-secondary);
  margin: 14px 0;
}
.editor-preview ul, .editor-preview ol { margin: 10px 0; padding-left: 22px; }
.editor-preview li { margin-bottom: 4px; }

/* Editor toolbar */
.editor-toolbar {
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.editor-toolbar-left { display: flex; align-items: center; gap: 10px; }
.editor-toolbar-right { display: flex; align-items: center; gap: 8px; }

/* === Format toolbar (markdown insert buttons) === */
.fmt-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-wrap: wrap;
}
.fmt-toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.1s;
  white-space: nowrap;
}
.fmt-toolbar button:hover { background: var(--bg-hover); color: var(--text-primary); }
.fmt-toolbar .fmt-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
}

/* === TOC Sidebar === */
.toc-wrap {
  display: flex;
  gap: 0;
  min-height: 0;
  flex: 1;
}
.toc-sidebar {
  width: 200px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  padding: 20px 16px;
  overflow-y: auto;
  display: none;
}
.toc-sidebar.show { display: block; }
.toc-sidebar-title {
  font-size: var(--fs-tiny);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}
.toc-link {
  display: block;
  padding: 3px 0 3px 0;
  font-size: 12px;
  color: var(--text-tertiary);
  text-decoration: none;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.1s;
}
.toc-link:hover { color: var(--text-primary); }
.toc-link.toc-h2 { padding-left: 12px; }
.toc-link.toc-h3 { padding-left: 24px; }
.toc-link.toc-h4 { padding-left: 36px; }
.toc-link.active { color: var(--accent); font-weight: 500; }

/* === Mermaid === */
.mermaid {
  text-align: center;
  margin: 1.2rem 0;
  padding: 16px;
  background: var(--bg-page);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

/* === Article page layout with TOC === */
.article-layout {
  max-width: 1024px;
  margin: 0 auto;
  display: flex;
  gap: 32px;
  align-items: flex-start;
}
.article-main {
  flex: 1;
  min-width: 0;
  max-width: 720px;
}
.article-toc {
  width: 220px;
  flex-shrink: 0;
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding: 0 8px;
}
.article-toc .toc-link {
  font-size: 13px;
  padding-top: 4px;
  padding-bottom: 4px;
}
@media (max-width: 900px) {
  .article-layout { flex-direction: column; }
  .article-toc { display: none; }
  .toc-sidebar { display: none !important; }
}

/* === Buttons === */
.btn-primary {
  display: inline-flex;
  align-items: center;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: var(--text-primary);
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--text-secondary); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:hover { border-color: var(--text-tertiary); }

/* === Form inputs === */
.form-input {
  padding: 7px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-tertiary); }

/* === Footer === */
.site-footer {
  max-width: 1024px;
  margin: 0 auto;
  padding: 32px 24px 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border-light);
}
.site-footer a { color: var(--text-tertiary); }
.site-footer a:hover { color: var(--text-secondary); }

/* === Chat (kept minimal but adapted to light palette) === */
.chat-layout { height: calc(100vh - 48px); display: flex; }
.chat-sidebar {
  width: 260px; min-width: 260px;
  border-right: 1px solid var(--border);
  background: var(--bg-surface-alt);
  display: flex; flex-direction: column;
}
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg-surface); }
.chat-messages { flex: 1; overflow-y: auto; padding: 24px; }
.chat-input-area { border-top: 1px solid var(--border); padding: 14px 20px; background: var(--bg-surface); }

.msg-user .msg-bubble { background: var(--accent); color: #fff; border-radius: 14px 14px 4px 14px; }
.msg-ai .msg-bubble { background: var(--bg-page); color: var(--text-primary); border-radius: 14px 14px 14px 4px; }
.msg-bubble { max-width: 74%; padding: 12px 16px; font-size: 14px; line-height: 1.6; }
.msg-bubble p { margin: 0.4em 0; }
.msg-bubble p:first-child { margin-top: 0; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble pre { background: rgba(0,0,0,0.05); padding: 10px 14px; border-radius: 6px; overflow-x: auto; font-size: 13px; margin: 0.5em 0; }
.msg-bubble code { font-family: var(--font-mono); font-size: 0.85em; }
.msg-user .msg-bubble pre { background: rgba(0,0,0,0.15); }
.msg-user .msg-bubble code { color: rgba(255,255,255,0.9); }

.session-item {
  padding: 10px 16px; cursor: pointer; transition: background 0.1s;
  border-left: 3px solid transparent; color: var(--text-secondary); font-size: 13px;
}
.session-item:hover { background: var(--bg-hover); }
.session-item.active { background: var(--accent-subtle); border-left-color: var(--accent); color: var(--text-primary); }

.source-card {
  background: var(--accent-subtle); border-radius: 6px;
  padding: 6px 12px; font-size: 12px; margin-top: 6px;
  cursor: pointer; color: var(--text-secondary);
}
.source-snippet { display: none; font-size: 11px; color: var(--text-tertiary); margin-top: 4px; }
.source-card.expanded .source-snippet { display: block; }

.quick-q {
  display: inline-block; padding: 6px 14px; border-radius: 16px;
  font-size: 12px; border: 1px solid var(--border); color: var(--text-secondary);
  cursor: pointer; transition: all 0.15s; margin: 2px; background: var(--bg-surface);
}
.quick-q:hover { border-color: var(--accent); color: var(--accent); }

.role-btn {
  padding: 2px 10px; border-radius: 12px; font-size: 11px;
  border: 1px solid var(--border); color: var(--text-tertiary);
  background: transparent; cursor: pointer; transition: all 0.15s;
}
.role-btn:hover { border-color: var(--text-secondary); color: var(--text-secondary); }
.role-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* === Article body (for rendered .md) === */
.article-body {
  font-size: 16px;
  line-height: 1.85;
  color: var(--text-primary);
}
.article-body h1 { font-size: 28px; margin: 2rem 0 0.8rem; }
.article-body h2 { font-size: 22px; margin: 1.8rem 0 0.6rem; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.article-body h3 { font-size: 18px; margin: 1.4rem 0 0.5rem; }
.article-body p { margin: 0 0 1rem; }
.article-body a { color: var(--accent); }
.article-body strong { color: var(--text-primary); font-weight: 600; }
.article-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 0 4px 16px;
  margin: 1.2rem 0;
  color: var(--text-secondary);
}
.article-body pre {
  background: var(--bg-page);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-size: 13px;
  margin: 1.2rem 0;
}
.article-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-page);
  padding: 2px 5px;
  border-radius: 3px;
}
.article-body pre code { background: none; padding: 0; }
.article-body ul, .article-body ol { margin: 0.8rem 0; padding-left: 1.4rem; }
.article-body li { margin-bottom: 0.3rem; }
.article-body img { max-width: 100%; border-radius: var(--radius-md); margin: 1.2rem 0; }
.article-body hr { margin: 2rem 0; border: none; border-top: 1px solid var(--border); }
.article-body table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 14px; }
.article-body th, .article-body td { padding: 10px 14px; border: 1px solid var(--border); text-align: left; }
.article-body th { background: var(--bg-hover); font-weight: 600; color: var(--text-primary); }
.article-body table tr:nth-child(even) { background: var(--bg-surface-alt); }
.article-body table tr:hover { background: var(--bg-hover); }
.article-body pre {
  background: #2d2d2d;
  color: #e0e0e0;
}

/* === Dashboard === */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat-card { padding: 20px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.stat-card-value { font-size: 28px; font-weight: 700; color: var(--text-primary); font-family: var(--font-mono); }
.stat-card-label { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }

/* =============================================
   Responsive — Scroll the whole section at once
   ============================================= */

/* ---- Hamburger (base.html) ---- */
.hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
  padding: 4px;
  border: none;
  background: transparent;
  z-index: 60;
}
.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-tertiary);
  border-radius: 2px;
  transition: all 0.25s;
  transform-origin: center;
}
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---- Hero avatar/text row (index) ---- */
.hero-section {
  display: flex;
  align-items: flex-start;
  gap: 32px;
  padding: 48px 0 36px;
}

/* ---- Generic content+sidebar row ---- */
.content-with-sidebar {
  display: flex;
  gap: 32px;
  align-items: flex-start;
}

/* ---- Blog 3-col layout ---- */
.blog-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

/* ---- Dashboard layout ---- */
.dashboard-layout {
  display: flex;
  min-height: calc(100vh - 48px);
}

/* === Mobile (max-width: 768px) === */
@media (max-width: 768px) {
  /* ------ Nav ------ */
  .hamburger { display: flex; }
  .site-nav-inner { padding: 0 16px; }
  .site-nav-links {
    display: none;
    position: absolute;
    top: 48px;
    left: 0;
    right: 0;
    background: var(--bg-page);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    flex-direction: column;
    padding: 16px 24px;
    gap: 14px;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
  }
  .site-nav-links.open { display: flex; }
  .site-nav-links a { font-size: 15px; }

  /* ------ Chat ------ */
  .chat-sidebar { position: absolute; z-index: 20; width: 100%; min-width: 100%; height: 100%; transform: translateX(-100%); transition: transform 0.2s; }
  .chat-sidebar.open { transform: translateX(0); }
  .msg-bubble { max-width: 88%; }

  /* ------ Editor ------ */
  .editor-container { flex-direction: column; }
  .editor-pane-left { border-right: none; border-bottom: 1px solid var(--border); }
  .editor-pane { height: 50%; }

  /* ------ Stats (dashboard / homepage) ------ */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }

  /* ------ Page ------ */
  .page-header { padding: 32px 16px 20px; }
  .page-header h1 { font-size: 26px; }
  .page-header p { font-size: 15px; }
  .page-header-actions { flex-direction: column; align-items: flex-start; gap: 6px; }
  .page-inner { padding: 0 16px; }
  .page-header-bordered { padding-bottom: 16px; margin-bottom: 16px; }

  /* ------ Section box ------ */
  .section-box { padding: 20px 16px; margin-bottom: 16px; }
  .section-box-header { flex-direction: column; align-items: flex-start; gap: 6px; }

  /* ------ Footer ------ */
  .site-footer {
    flex-direction: column;
    gap: 8px;
    text-align: center;
    padding: 24px 16px 32px;
  }

  /* ------ Market rows ------ */
  .market-row { grid-template-columns: repeat(2, 1fr); gap: 12px; }

  /* ------ Toolbar ------ */
  .toolbar { flex-direction: column; align-items: flex-start; gap: 8px; }

  /* ------ Segmented control ------ */
  .segmented-control { overflow-x: auto; max-width: 100%; }

  /* ------ Article layout ------ */
  .article-layout { flex-direction: column; padding: 24px 16px 40px !important; }
  .article-toc { display: none; }
  .toc-sidebar { display: none !important; }
  .article-main { max-width: 100%; }

  /* ------ Article meta row ------ */
  .article-main > div:first-child { flex-wrap: wrap; gap: 4px; }

  /* ------ Related articles ------ */
  .related-section { margin-top: 24px; }

  /* ------ Comments ------ */
  .comment-form-row { flex-direction: column; }
  .comment-avatar-col { flex-direction: row; width: auto; padding-top: 0; gap: 8px; align-items: center; }
  .comment-subrow { flex-direction: column; gap: 8px; }
  .comment-actions { flex-direction: column; align-items: stretch; }
  .comment-btn { text-align: center; }
  .comment-item { gap: 10px; }

  /* ------ Hero section (index) ------ */
  .hero-section { flex-direction: column; gap: 16px !important; padding: 28px 0 24px !important; }
  .hero-section img,
  .hero-section > div:first-child { width: 56px !important; height: 56px !important; font-size: 22px !important; }
  .hero-section h1 { font-size: var(--fs-h3) !important; }

  /* ------ Content+sidebar (index) ------ */
  .content-with-sidebar { flex-direction: column; gap: 24px; }

  /* ------ Blog layout (3-col → stack) ------ */
  .blog-layout { flex-direction: column; gap: 16px; }
  .blog-layout aside,
  .blog-layout > aside { width: 100% !important; position: static !important; }
  .blog-layout .layout-sidebar { width: 100% !important; position: static !important; }

  /* ------ Dashboard ------ */
  .dashboard-layout { flex-direction: column; }
  .dash-sidebar {
    width: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border);
    padding: 12px 0 !important;
    overflow-x: auto;
    display: flex;
    flex-wrap: nowrap;
  }
  .dash-sidebar nav { flex-direction: row !important; gap: 0; flex-wrap: nowrap; }
  .dash-sidebar > div:first-child { display: none; }
  .dash-sidebar button,
  .dash-sidebar nav button {
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 12px !important;
    padding: 6px 12px !important;
  }
  .dash-sidebar > div:last-child { display: none; }
  .dash-main {
    padding: 16px !important;
    overflow-y: visible !important;
  }

  /* ------ Dashboard sections ------ */
  .dash-main [style*="grid-template-columns"] { grid-template-columns: 1fr 1fr !important; gap: 10px; }
  .dash-main .section-box-header [style*="display: flex"] { flex-wrap: wrap; gap: 6px; }

  /* ------ Dashboard articles list items ------ */
  .dash-main [x-show="tab==='articles'"] > div:first-child {
    flex-direction: column;
    align-items: stretch;
  }
  .dash-main [x-show="tab==='articles'"] > div:first-child input,
  .dash-main [x-show="tab==='articles'"] > div:first-child select {
    width: 100% !important;
  }
  .dash-main [x-show="tab==='articles'"] > div:first-child > div {
    flex-direction: column;
    gap: 8px;
  }

  /* ------ Dashboard settings ------ */
  .dash-main [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* ------ World page grids ------ */
  .two-col-grid { grid-template-columns: 1fr !important; gap: 16px !important; }
  .three-col-grid { grid-template-columns: 1fr !important; gap: 16px !important; }

  /* ------ World page hot section ------ */
  .world-hot-grid { grid-template-columns: 1fr !important; gap: 16px !important; }

  /* ------ Chat ------ */
  .chat-main [style*="overflow-x: auto"] { flex-wrap: wrap; gap: 4px; }
  #quick-questions { max-width: 100% !important; }

  /* ------ Price monitor ------ */
  .price-stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }

  /* ------ Finance page ------ */
  .finance-price-grid { gap: 10px; }

  /* ------ Filter tags ------ */
  .filter-tags { gap: 4px; }
  .filter-tag { font-size: 11px; padding: 3px 10px; }

  /* ------ Pagination ------ */
  .pagination { flex-wrap: wrap; gap: 6px; }

  /* ------ Tag list ------ */
  .tag-list { flex-wrap: wrap; gap: 4px; }

  /* ------ Share bar ------ */
  .share-bar { flex-wrap: wrap; gap: 10px; }
}

/* === Tablet (max-width: 1024px) — slight adjustments === */
@media (max-width: 1024px) and (min-width: 769px) {
  .page-header { padding: 40px 24px 24px; }
  .site-nav-inner { padding: 0 16px; }
  .page-inner { padding: 0 16px; }
  .section-box { padding: 24px 20px; }
  .article-layout { padding: 40px 16px 40px !important; }
  .dash-main { padding: 24px 20px !important; }
}

/* === Small phone (max-width: 480px) === */
@media (max-width: 480px) {
  .page-header h1 { font-size: 22px; }
  .section-box { padding: 16px 12px; }
  .stat-grid { grid-template-columns: 1fr; }
  .market-row { grid-template-columns: 1fr; gap: 8px; }
  .site-footer { font-size: 11px; }

  /* Chat */
  .msg-bubble { max-width: 95%; }
  .chat-messages { padding: 12px; }

  /* Finance / price monitor cards */
  .finance-price-grid .stat-card,
  .price-stat-grid .stat-card { padding: 12px !important; }

  /* Dashboard content list */
  .dash-main [x-for]:not([x-show]) { flex-wrap: wrap; }
  .dash-main [x-for]:not([x-show]) > div:last-child { margin-left: 0; }

  /* Price monitor product cards */
  .pm-card-grid { grid-template-columns: 1fr !important; }

  /* Filter items */
  a.filter-item { font-size: 12px; padding: 4px 8px; }

  /* Tools page */
  .tools-grid { grid-template-columns: 1fr; }
}

/* === ECharts dark container fix (light theme uses white bg) === */
.chart-container {
  width: 100%;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
}

/* =============================================
   Design Spec Additions — CSS 类补充
   ============================================= */

/* ---- Page inner (内容区容器) ---- */
.page-inner {
  max-width: 1024px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---- Page Header variants ---- */
.page-header-bordered {
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 28px;
}
.page-header-actions {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.page-header-actions h1 { margin-bottom: 0; }

/* ---- Item row (内容列表行) ---- */
.item-row {
  display: block;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-light);
  text-decoration: none;
  color: inherit;
  transition: opacity 0.15s;
}
.item-row:last-child { border-bottom: none; }
.item-row:hover { opacity: 0.7; }

.item-row-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 2px;
}
.item-row-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}
.item-row-title a { color: inherit; text-decoration: none; }
.item-row-title a:hover { color: var(--accent); }
.item-row-summary {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 3px;
  line-height: 1.5;
}
.meta-sep {
  margin: 0 6px;
  color: var(--border);
}

/* ---- Section Box inner ---- */
.section-box-body {
  padding: 0;
}
.section-box-desc {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 400;
}

/* ---- Filter sidebar items ---- */
a.filter-item {
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 2px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
}
a.filter-item:hover { background: var(--bg-hover); color: var(--text-primary); }
a.filter-item-active,
a.filter-item-active:hover {
  background: #1d1d1f;
  color: #fff;
}

/* ---- Tag pills ---- */
a.tag-pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 12px;
  background: var(--bg-page);
  color: var(--text-secondary);
  text-decoration: none;
}
a.tag-pill:hover { background: var(--bg-hover); color: var(--text-primary); }
a.tag-pill-active,
a.tag-pill-active:hover {
  background: #1d1d1f;
  color: #fff;
}

/* ---- Segmented control (排序切换) ---- */
.segmented-control {
  display: inline-flex;
  background: var(--bg-page);
  border-radius: 8px;
  padding: 2px;
  gap: 0;
}
.segmented-control a {
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 12px;
  text-decoration: none;
  color: var(--text-tertiary);
  transition: all 0.12s;
}
.segmented-control a.seg-active {
  background: #fff;
  color: var(--text-primary);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.segmented-control a:hover:not(.seg-active) { color: var(--text-secondary); }

/* ---- Toolbar (列表排序/操作栏) ---- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ---- Pagination ---- */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 40px;
}
.pagination-info {
  font-size: 12px;
  color: var(--text-tertiary);
  padding: 7px 12px;
}

/* ---- Empty state ---- */
.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-tertiary);
}

/* ---- Tag list （详情页标签区）---- */
.tag-list {
  display: flex;
  gap: 8px;
  margin-bottom: 32px;
}
.tag-list a {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  background: var(--bg-hover);
  color: var(--text-secondary);
  text-decoration: none;
}

/* ---- Share bar ---- */
.share-bar {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-tertiary);
}
.share-bar a { color: var(--text-tertiary); }
.share-bar a:hover { color: var(--accent); }

/* =============================================
   Comments
   ============================================= */
.comments-section {
    margin-top: 48px;
    padding-top: 32px;
    border-top: 1px solid var(--border);
}
.comments-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 24px;
}

/* 写评论卡片 */
.comment-form-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 24px;
}
.comment-form-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

/* 表单行：头像列 + 右侧字段 */
.comment-form-row {
    display: flex;
    gap: 16px;
}

/* 头像列 */
.comment-avatar-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
    width: 60px;
    padding-top: 22px;
}
.avatar-preview-img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--border);
    object-fit: cover;
    background: var(--bg-page);
}
.avatar-change-btn {
    font-size: 11px;
    color: var(--accent);
    background: none;
    border: none;
    cursor: pointer;
    padding: 1px 0;
    line-height: 1.2;
}
.avatar-change-btn:hover {
    opacity: 0.7;
}

/* 右侧字段区 */
.comment-fields {
    flex: 1;
    min-width: 0;
}
.comment-subrow {
    display: flex;
    gap: 12px;
}
.comment-field {
    flex: 1;
    min-width: 0;
}
.comment-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}
.comment-input {
    display: block;
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.comment-textarea {
    display: block;
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    box-sizing: border-box;
    resize: vertical;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.comment-input:focus,
.comment-textarea:focus {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 2px var(--accent-subtle);
}

/* 操作按钮行 */
.comment-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.comment-btn {
    padding: 8px 24px;
    border: none;
    border-radius: 20px;
    background: var(--text-primary);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
}
.comment-btn:hover {
    opacity: 0.8;
}
.comment-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* 评论列表 */
.comment-list {
    margin-bottom: 8px;
}
.comment-item {
    display: flex;
    gap: 12px;
    padding: 16px 0;
    border-bottom: 1px solid var(--border-light);
}
.comment-item:last-child {
    border-bottom: none;
}
.comment-item-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
    background: var(--bg-page);
}
.comment-item-body {
    flex: 1;
    min-width: 0;
}
.comment-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}
.comment-author {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}
.comment-date {
    font-size: 11px;
    color: var(--text-tertiary);
}
.comment-body {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
}
