* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #fafafa;
  --card: #fff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-light: #718096;
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --sidebar-w: 260px;
}

body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--card); border-right: 1px solid var(--border); padding: 1rem; position: fixed; height: 100vh; overflow-y: auto; }
.main { margin-left: var(--sidebar-w); flex: 1; padding: 2rem; max-width: 900px; }
.main:has(.graph-wrapper) { max-width: none; }

/* Country switcher */
.country-switcher { margin-bottom: 0.6rem; }
.country-switcher:empty { display: none; }
.country-select { width: 100%; padding: 0.45rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; background: #f8fafc; font-size: 0.9rem; cursor: pointer; }
.country-select:hover { border-color: var(--primary); }
.country-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }

/* Country picker (根路徑) */
.country-picker { max-width: 720px; margin: 2rem auto; text-align: center; }
.country-picker h1 { font-size: 2rem; margin-bottom: 0.5rem; }
.country-picker-subtitle { color: var(--text-light); margin-bottom: 2rem; }
.country-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.country-card { background: var(--card); border: 2px solid var(--border); border-radius: 12px; padding: 1.5rem 1rem; text-decoration: none; color: var(--text); transition: all 0.15s; display: block; }
.country-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(37,99,235,0.12); }
.country-flag { font-size: 3rem; line-height: 1; margin-bottom: 0.5rem; }
.country-brand { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.3rem; }
.country-desc { font-size: 0.85rem; color: var(--text-light); }

.empty-hint { color: var(--text-light); padding: 1rem; background: #f8fafc; border-radius: 6px; font-size: 0.9rem; }
.empty-hint code { background: #e2e8f0; padding: 0.1rem 0.4rem; border-radius: 3px; font-size: 0.85em; }

/* Export bundle buttons (graph page) */
.export-title { font-size: 0.9rem; font-weight: 600; color: var(--text); margin-bottom: 0.5rem; }
.export-buttons { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.export-buttons button { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.55rem 1rem; border-radius: 6px; border: 1px solid var(--border); background: var(--card); cursor: pointer; font-size: 0.9rem; font-weight: 500; transition: all 0.15s; }
.export-buttons button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 2px 6px rgba(0,0,0,0.08); }
.export-buttons button:disabled { opacity: 0.5; cursor: not-allowed; }
.export-buttons .btn-export-quote { background: #fef3c7; border-color: #fbbf24; color: #92400e; }
.export-buttons .btn-export-quote:hover:not(:disabled) { background: #fde68a; border-color: #f59e0b; }
.export-buttons .btn-export-chat { background: #dbeafe; border-color: #60a5fa; color: #1e40af; }
.export-buttons .btn-export-chat:hover:not(:disabled) { background: #bfdbfe; border-color: #3b82f6; }
.export-count { font-size: 0.8rem; opacity: 0.7; }

/* Sidebar */
.sidebar h1 { font-size: 1.1rem; margin-bottom: 0.3rem; }
.sidebar h1 a { color: var(--text); text-decoration: none; }
.sidebar .subtitle { font-size: 0.75rem; color: var(--text-light); margin-bottom: 1.2rem; }
.nav-section { margin-bottom: 1rem; }
.nav-section h3 { font-size: 0.8rem; text-transform: uppercase; color: var(--text-light); margin-bottom: 0.3rem; letter-spacing: 0.05em; }
.nav-link { display: block; padding: 0.3rem 0.5rem; color: var(--text); text-decoration: none; border-radius: 4px; font-size: 0.9rem; }
.nav-link:hover, .nav-link.active { background: var(--primary-light); color: var(--primary); }
.nav-count { font-size: 0.75rem; color: var(--text-light); }

/* Search */
.search-box { width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; margin-bottom: 1rem; }
.search-box:focus { outline: none; border-color: var(--primary); }

/* Cards */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin-bottom: 1rem; }
.card:hover { border-color: var(--primary); }
.card h3 a { color: var(--text); text-decoration: none; }
.card h3 a:hover { color: var(--primary); }
a.card-link { display: block; color: var(--text); text-decoration: none; cursor: pointer; }
a.card-link:hover { border-color: var(--primary); }
a.card-link h3 { color: var(--text); }

/* Badges */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.7rem; font-weight: 600; }
.badge-complete { background: #d1fae5; color: var(--success); }
.badge-draft { background: #fef3c7; color: var(--warning); }
.badge-pending-verification { background: #fee2e2; color: var(--danger); }
.badge-needs-review { background: #e0e7ff; color: #4338ca; }
.badge-category { background: var(--primary-light); color: var(--primary); }

.tags { margin-top: 0.3rem; }
.tag { display: inline-block; background: #f1f5f9; color: var(--text-light); padding: 0.1rem 0.4rem; border-radius: 4px; font-size: 0.7rem; margin-right: 0.3rem; }

/* Content */
.content h1 { font-size: 1.8rem; margin-bottom: 1rem; }
.content h2 { font-size: 1.4rem; margin: 1.5rem 0 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
.content h3 { font-size: 1.1rem; margin: 1rem 0 0.5rem; }
.content p { margin-bottom: 0.8rem; }
.content ul, .content ol { margin-bottom: 0.8rem; padding-left: 1.5rem; }
.content table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; font-size: 0.9rem; }
.content th, .content td { border: 1px solid var(--border); padding: 0.5rem; text-align: left; }
.content th { background: #f8fafc; font-weight: 600; }
.content code { background: #f1f5f9; padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.85em; }
.content pre { background: #1e293b; color: #e2e8f0; padding: 1rem; border-radius: 6px; overflow-x: auto; margin-bottom: 1rem; }
.content pre code { background: none; color: inherit; }
.content blockquote { border-left: 3px solid var(--primary); padding: 0.5rem 1rem; margin-bottom: 1rem; background: #f8fafc; }

/* Wikilinks */
.wikilink { color: var(--primary); text-decoration: none; border-bottom: 1px dashed var(--primary); }
.wikilink:hover { border-bottom-style: solid; }
.wikilink-broken { color: var(--danger); border-bottom: 1px dashed var(--danger); cursor: help; }

/* Callouts */
.callout { border-radius: 6px; padding: 1rem; margin-bottom: 1rem; border-left: 4px solid; }
.callout-title { font-weight: 600; margin-bottom: 0.3rem; }
.callout-tip { background: #f0fdf4; border-color: var(--success); }
.callout-warning { background: #fffbeb; border-color: var(--warning); }
.callout-info { background: #eff6ff; border-color: var(--primary); }
.callout-note { background: #f8fafc; border-color: #64748b; }

/* Meta bar */
.meta-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.meta-bar .updated { font-size: 0.8rem; color: var(--text-light); margin-left: auto; }

/* Edit */
.editor { width: 100%; min-height: 400px; font-family: "Cascadia Code", "Fira Code", monospace; font-size: 0.9rem; padding: 1rem; border: 1px solid var(--border); border-radius: 6px; resize: vertical; line-height: 1.6; }
.btn { padding: 0.5rem 1rem; border-radius: 6px; border: none; cursor: pointer; font-size: 0.9rem; font-weight: 500; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #f1f5f9; color: var(--text); }
.btn-secondary:hover { background: #e2e8f0; }
.toolbar { display: flex; gap: 0.5rem; margin-bottom: 1rem; }

/* Dashboard stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; text-align: center; }
a.stat-card-link { display: block; text-decoration: none; color: var(--text); cursor: pointer; }
a.stat-card-link:hover { border-color: var(--primary); background: var(--primary-light); }
.stat-number { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.8rem; color: var(--text-light); }

/* Page header with action button */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.page-header h1 { margin: 0; }

/* Forms */
.form-section { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1.5rem; margin-bottom: 1rem; }
.form-section h2 { font-size: 1.1rem; margin: 0 0 1rem; padding: 0; border: none; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.8rem; }
.form-grid label { display: flex; flex-direction: column; font-size: 0.8rem; font-weight: 600; color: var(--text-light); gap: 0.3rem; }
.form-grid input, .form-grid select { padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; color: var(--text); background: #fff; }
.form-grid input:focus, .form-grid select:focus { outline: none; border-color: var(--primary); }

/* Danger button */
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }

/* Graph */
.graph-toolbar { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.graph-search { padding: 0.4rem 0.75rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.85rem; width: 180px; }
.graph-search:focus { outline: none; border-color: var(--primary); }
.graph-filters { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.graph-chip { padding: 0.2rem 0.6rem; border-radius: 999px; border: 2px solid var(--chip-color, #94a3b8); background: transparent; color: var(--text); font-size: 0.75rem; cursor: pointer; transition: all 0.15s; }
.graph-chip.active { background: var(--chip-color, #94a3b8); color: #fff; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

.graph-wrapper { display: flex; gap: 0; height: calc(100vh - 12rem); }
.graph-export-bar { display: flex; align-items: center; gap: 1rem; padding: 0.75rem 0 0.25rem; }
.export-hint { font-size: 0.85rem; }
.graph-container { position: relative; flex: 1; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px 0 0 8px; overflow: hidden; }
.graph-container svg { width: 100%; height: 100%; }
.graph-container .link { stroke: #cbd5e1; stroke-opacity: 0.6; transition: opacity 0.2s, stroke-width 0.2s; }
.graph-container .node { cursor: pointer; stroke: #fff; stroke-width: 1.5px; transition: opacity 0.2s; }
.graph-container .node:hover { stroke-width: 3px; }
.graph-container .node-label { font-size: 11px; fill: var(--text); pointer-events: none; text-anchor: middle; dominant-baseline: central; transition: opacity 0.2s; }
.graph-tooltip { position: absolute; background: var(--card); border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.75rem; font-size: 0.8rem; pointer-events: none; box-shadow: 0 2px 8px rgba(0,0,0,0.1); z-index: 10; white-space: nowrap; }
.graph-tooltip .tt-title { font-weight: 600; }
.graph-tooltip .tt-cat { font-size: 0.7rem; color: var(--text-light); }
.graph-legend { position: absolute; top: 0.75rem; right: 0.75rem; background: rgba(255,255,255,0.92); border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.75rem; font-size: 0.75rem; }
.graph-legend-item { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.2rem; }
.graph-legend-dot { width: 10px; height: 10px; border-radius: 50%; }

/* Graph side panel */
.graph-panel { width: 280px; background: var(--card); border: 1px solid var(--border); border-left: none; border-radius: 0 8px 8px 0; padding: 1rem; overflow-y: auto; position: relative; animation: panelSlide 0.2s ease; }
@keyframes panelSlide { from { width: 0; opacity: 0; padding: 0; } to { width: 280px; opacity: 1; } }
.graph-panel-close { position: absolute; top: 0.5rem; right: 0.5rem; background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-light); line-height: 1; }
.graph-panel-close:hover { color: var(--text); }
.graph-panel h3 { font-size: 1.1rem; margin: 0 0 0.5rem; padding-right: 1.5rem; }
.graph-panel h4 { font-size: 0.85rem; color: var(--text-light); margin: 0.75rem 0 0.4rem; }
.panel-meta { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; }
.panel-link-count { font-size: 0.75rem; color: var(--text-light); }
.panel-view-btn { display: inline-block; margin-bottom: 0.5rem; text-decoration: none; text-align: center; }
.panel-links { list-style: none; padding: 0; margin: 0; }
.panel-link-item { display: flex; align-items: center; gap: 0.4rem; padding: 0.4rem 0.5rem; border-radius: 5px; cursor: pointer; font-size: 0.85rem; }
.panel-link-item:hover { background: var(--primary-light); }
.panel-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.panel-link-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-link-cat { font-size: 0.7rem; color: var(--text-light); flex-shrink: 0; }

/* Guide page */
.main:has(.guide-layout) { max-width: none; }
.guide-layout { display: flex; gap: 2rem; align-items: flex-start; }
.guide-toc { width: 200px; flex-shrink: 0; position: sticky; top: 1rem; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; font-size: 0.82rem; max-height: calc(100vh - 4rem); overflow-y: auto; }
.toc-title { font-weight: 700; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-light); margin-bottom: 0.6rem; }
.toc-link { display: block; padding: 0.2rem 0.4rem; color: var(--text-light); text-decoration: none; border-radius: 4px; line-height: 1.4; transition: all 0.15s; border-left: 2px solid transparent; }
.toc-link:hover { color: var(--primary); background: var(--primary-light); }
.toc-link.toc-active { color: var(--primary); border-left-color: var(--primary); font-weight: 500; }
.toc-h3 { padding-left: 1rem; font-size: 0.78rem; }
.guide-body { flex: 1; min-width: 0; }
.guide-body h1 { font-size: 2rem; font-weight: 800; margin-bottom: 0.4rem; }
.guide-body h2 { font-size: 1.35rem; font-weight: 700; margin: 2rem 0 0.75rem; padding-bottom: 0.4rem; border-bottom: 2px solid var(--border); }
.guide-body h3 { font-size: 1.05rem; font-weight: 600; margin: 1.25rem 0 0.5rem; color: #374151; }
.guide-body p { margin-bottom: 0.9rem; line-height: 1.75; }
.guide-body ul, .guide-body ol { margin-bottom: 0.9rem; padding-left: 1.5rem; line-height: 1.75; }
.guide-body li { margin-bottom: 0.2rem; }
.guide-body table { width: 100%; border-collapse: collapse; margin-bottom: 1.25rem; font-size: 0.9rem; border-radius: 8px; overflow: hidden; box-shadow: 0 0 0 1px var(--border); }
.guide-body th { background: #f1f5f9; font-weight: 600; padding: 0.6rem 0.9rem; text-align: left; border-bottom: 1px solid var(--border); }
.guide-body td { padding: 0.55rem 0.9rem; border-bottom: 1px solid var(--border); }
.guide-body tr:last-child td { border-bottom: none; }
.guide-body tr:hover td { background: #f8fafc; }
.guide-body code { background: #f1f5f9; padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.83em; color: #be185d; font-family: "Cascadia Code", "Fira Code", monospace; }
.guide-body pre { background: #0f172a; color: #e2e8f0; padding: 1.1rem 1.25rem; border-radius: 8px; overflow-x: auto; margin-bottom: 1.25rem; font-size: 0.85rem; line-height: 1.65; }
.guide-body pre code { background: none; color: inherit; padding: 0; font-size: inherit; }
.guide-body blockquote { border-left: 4px solid var(--primary); padding: 0.6rem 1.1rem; margin: 0 0 1rem; background: var(--primary-light); border-radius: 0 6px 6px 0; color: #1e40af; }
.guide-body hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }
.guide-body strong { font-weight: 600; }

/* Health bar (home page + lint summary) */
.health-bar { margin: 1.5rem 0 2rem; }
.health-bar-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 0.6rem; }
.health-bar-header h2 { margin: 0; font-size: 1.2rem; border: none; padding: 0; }
.health-link { font-size: 0.85rem; color: var(--primary); text-decoration: none; }
.health-link:hover { text-decoration: underline; }
.health-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.6rem; }
.health-card { display: block; text-decoration: none; color: var(--text); background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 0.85rem 0.5rem; text-align: center; transition: transform 0.15s, box-shadow 0.15s; }
.health-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.health-card.ok { background: #f0fdf4; border-color: #bbf7d0; }
.health-card.warning { background: #fffbeb; border-color: #fde68a; }
.health-card.danger { background: #fef2f2; border-color: #fecaca; }
.health-icon { font-size: 1.3rem; margin-bottom: 0.2rem; }
.health-num { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.health-card.ok .health-num { color: var(--success); }
.health-card.warning .health-num { color: var(--warning); }
.health-card.danger .health-num { color: var(--danger); }
.health-label { font-size: 0.75rem; color: var(--text-light); margin-top: 0.15rem; }

/* Lint page */
.lint-overview { margin-bottom: 1.5rem; }
.lint-meta { color: var(--text-light); font-size: 0.85rem; margin-bottom: 0.8rem; }
.lint-section { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.2rem; margin-bottom: 1rem; scroll-margin-top: 1rem; }
.lint-section-header { display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 1rem; margin-bottom: 0.2rem; }
.lint-count { font-size: 0.8rem; padding: 0.15rem 0.55rem; border-radius: 999px; }
.lint-count.ok { background: #d1fae5; color: var(--success); }
.lint-count.warn { background: #fee2e2; color: var(--danger); }
.lint-section-desc { font-size: 0.8rem; color: var(--text-light); margin-bottom: 0.7rem; }
.lint-empty { color: var(--success); font-size: 0.9rem; padding: 0.4rem 0; }
.lint-items { display: flex; flex-direction: column; gap: 0.3rem; }
.lint-item { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: baseline; padding: 0.4rem 0.6rem; background: #f8fafc; border-radius: 5px; text-decoration: none; color: var(--text); border-left: 3px solid transparent; transition: all 0.15s; }
.lint-item:hover { background: var(--primary-light); border-left-color: var(--primary); }
.lint-item-title { font-weight: 500; font-size: 0.9rem; }
.lint-item-meta { font-size: 0.78rem; color: var(--text-light); }
.lint-item-meta code { background: #fff; padding: 0.05rem 0.3rem; border-radius: 3px; font-size: 0.85em; }

/* Save Answer form */
.save-answer-form { display: flex; flex-direction: column; gap: 0.5rem; max-width: 800px; }
.save-answer-form label { font-size: 0.85rem; font-weight: 600; margin-top: 0.5rem; }
.save-answer-form .required { color: var(--danger); }
.save-answer-form textarea, .save-answer-form input[type=text], .save-answer-form select {
  width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; font-family: inherit; line-height: 1.5;
}
.save-answer-form textarea:focus, .save-answer-form input:focus, .save-answer-form select:focus { outline: none; border-color: var(--primary); }
.save-answer-form textarea { resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 0.5rem; }
.form-col { display: flex; flex-direction: column; gap: 0.3rem; }
.form-col label { margin-top: 0; }
.form-actions { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }
.form-hint { color: var(--text-light); font-size: 0.85rem; margin-bottom: 1rem; }
.form-hint-inline { color: var(--text-light); font-size: 0.8rem; font-weight: normal; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .guide-toc { display: none; }
  .health-grid { grid-template-columns: repeat(3, 1fr); }
  .form-row { grid-template-columns: 1fr; }
}

/* ===== Chat Page ===== */

.chat-page { display: flex; flex-direction: column; height: calc(100vh - 4rem); max-width: 800px; }
.chat-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.75rem; flex-shrink: 0; }
.chat-header h1 { font-size: 1.5rem; }
.chat-model-badge { font-size: 0.7rem; background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; padding: 0.2rem 0.6rem; border-radius: 999px; font-weight: 600; }

.chat-key-bar { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.75rem; border-radius: 6px; margin-bottom: 0.5rem; font-size: 0.85rem; flex-shrink: 0; }
.chat-key-bar.key-set { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; }
.chat-key-bar.key-missing { background: #fff7ed; border: 1px solid #fed7aa; color: #c2410c; }
.key-icon { font-size: 1rem; }
.key-label { flex: 1; }
.key-help { font-size: 0.8rem; color: var(--primary); text-decoration: none; margin-left: auto; }
.key-help:hover { text-decoration: underline; }

.chat-key-form { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem; background: var(--card); border: 1px solid var(--border); border-radius: 6px; margin-bottom: 0.5rem; flex-shrink: 0; flex-wrap: wrap; }
.chat-key-input { flex: 1; min-width: 200px; padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.85rem; font-family: monospace; }
.chat-key-input:focus { outline: none; border-color: var(--primary); }

.chat-messages { flex: 1; overflow-y: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; min-height: 200px; }
.chat-empty { color: var(--text-light); text-align: center; margin: auto; font-size: 0.9rem; }

.chat-message { display: flex; flex-direction: column; max-width: 85%; }
.chat-message.user { align-self: flex-end; align-items: flex-end; }
.chat-message.assistant { align-self: flex-start; align-items: flex-start; }

.chat-bubble { padding: 0.6rem 0.9rem; border-radius: 12px; font-size: 0.9rem; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.chat-message.user .chat-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 3px; }
.chat-message.assistant .chat-bubble { background: var(--card); border: 1px solid var(--border); border-bottom-left-radius: 3px; color: var(--text); }
.chat-bubble.streaming::after { content: '▋'; animation: blink 0.7s infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

.chat-save-btn { margin-top: 0.3rem; font-size: 0.72rem !important; padding: 0.2rem 0.5rem !important; }

.chat-input-area { flex-shrink: 0; margin-top: 0.75rem; }
.chat-textarea { width: 100%; padding: 0.6rem 0.8rem; border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem; font-family: inherit; resize: none; line-height: 1.5; }
.chat-textarea:focus { outline: none; border-color: var(--primary); }
.chat-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.4rem; }

.btn-xs { padding: 0.15rem 0.45rem !important; font-size: 0.72rem !important; }


/* --- 神經元（Memory）樣式 --- */
.memory-index { max-width: 860px; }
.memory-index h1 { font-size: 1.6rem; margin-bottom: 0.25rem; }
.memory-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.5rem; }
.memory-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.9rem; margin-top: 0.75rem; }
.memory-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 0.9rem 1rem; }
.memory-card-new { border-left: 3px solid #22c55e; }
.memory-card-primary { background: var(--primary-light, #f0f4ff); border-color: var(--primary); margin-bottom: 1.5rem; }
.memory-card-meta { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.3rem; min-height: 1.2rem; }
.memory-new-badge { font-size: 0.65rem; padding: 0.1rem 0.45rem; border-radius: 8px; background: #22c55e; color: #fff; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.memory-date { font-size: 0.68rem; color: var(--text-muted); margin-left: auto; white-space: nowrap; }
.memory-title { font-weight: 600; font-size: 0.95rem; color: var(--primary); text-decoration: none; display: block; margin-bottom: 0.3rem; }
.memory-title:hover { text-decoration: underline; }
.memory-filename { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 0.3rem; font-family: monospace; }
.memory-preview { font-size: 0.82rem; color: var(--text-muted); line-height: 1.5; margin: 0; }
.memory-file-view { max-width: 860px; }
.memory-breadcrumb { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 1.25rem; }
.memory-breadcrumb a { color: var(--primary); text-decoration: none; }
.memory-breadcrumb a:hover { text-decoration: underline; }
.memory-data-section { margin: 0 0 1.35rem; padding: 1rem; border: 1px solid var(--border); border-radius: 14px; background: linear-gradient(180deg, rgba(248,250,252,0.98), rgba(255,255,255,0.96)); }
.memory-data-header { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.8rem; }
.memory-data-header h2 { margin: 0; font-size: 1.05rem; }
.memory-data-header span { color: var(--text-muted); font-size: 0.8rem; }
.memory-data-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.75rem; }
.memory-attraction-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.memory-data-card { border: 1px solid rgba(148, 163, 184, 0.35); border-radius: 12px; padding: 0.85rem; background: var(--card); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04); }
.memory-data-card h3, .memory-data-card h4 { margin: 0.35rem 0 0.45rem; font-size: 0.95rem; line-height: 1.35; }
.memory-data-card p { margin: 0.45rem 0 0; color: var(--text-muted); font-size: 0.82rem; line-height: 1.55; }
.memory-data-chip { display: inline-flex; max-width: 100%; padding: 0.15rem 0.5rem; border-radius: 999px; background: rgba(16, 185, 129, 0.12); color: #047857; font-size: 0.7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.memory-data-line { display: flex; justify-content: space-between; gap: 0.6rem; padding: 0.22rem 0; border-top: 1px solid rgba(148, 163, 184, 0.16); font-size: 0.78rem; }
.memory-data-line b { color: var(--text-muted); font-weight: 600; }
.memory-data-line span { text-align: right; }
.memory-city-group { margin-top: 1rem; }
.memory-city-group h3 { margin: 0 0 0.55rem; font-size: 0.95rem; }
.memory-city-group h3 span { color: var(--text-muted); font-weight: 400; font-size: 0.78rem; }
.memory-city-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.8rem; }
.memory-city-card { border: 1px solid rgba(249, 115, 22, 0.24); border-radius: 14px; background: linear-gradient(180deg, #fff7ed, #fff); overflow: hidden; }
.memory-city-card summary { cursor: pointer; list-style: none; padding: 0.9rem; min-height: 96px; display: flex; flex-direction: column; gap: 0.35rem; }
.memory-city-card summary::-webkit-details-marker { display: none; }
.memory-city-card summary::after { content: '點開餐廳'; margin-top: auto; color: #ea580c; font-size: 0.74rem; font-weight: 700; }
.memory-city-card[open] { grid-column: 1 / -1; background: #fff; }
.memory-city-card[open] summary { min-height: auto; border-bottom: 1px solid rgba(249, 115, 22, 0.18); }
.memory-city-card[open] summary::after { content: '收合'; }
.memory-city-name { font-size: 1rem; font-weight: 800; color: #9a3412; }
.memory-city-count { width: fit-content; padding: 0.12rem 0.48rem; border-radius: 999px; background: rgba(249, 115, 22, 0.14); color: #c2410c; font-size: 0.72rem; font-weight: 700; }
.memory-city-preview { color: var(--text-muted); font-size: 0.78rem; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.memory-city-restaurants { padding: 0.9rem; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.memory-raw-details { margin-top: 1rem; border: 1px dashed var(--border); border-radius: 10px; background: rgba(148, 163, 184, 0.06); }
.memory-raw-details summary { cursor: pointer; padding: 0.65rem 0.85rem; color: var(--text-muted); font-size: 0.8rem; font-weight: 700; }
.memory-raw-details .kb-article { padding: 0.85rem; border-top: 1px dashed var(--border); background: var(--card); }

/* Memory tabs & group titles */
.memory-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.5rem; }
.memory-tab { padding: 0.35rem 0.75rem; border-radius: 20px; font-size: 0.83rem; text-decoration: none; color: var(--text); background: var(--card); border: 1px solid var(--border); transition: all 0.15s; white-space: nowrap; }
.memory-tab:hover { border-color: var(--primary); color: var(--primary); }
.memory-tab-active { background: var(--primary); color: #fff !important; border-color: var(--primary); }
.memory-tab-count { display: inline-block; background: rgba(255,255,255,0.25); border-radius: 10px; padding: 0 0.35rem; font-size: 0.75rem; margin-left: 0.2rem; }
.memory-tab:not(.memory-tab-active) .memory-tab-count { background: var(--border); color: var(--text-muted); }
.memory-group-title { font-size: 1rem; font-weight: 600; margin: 1.5rem 0 0.5rem; color: var(--text); }
.memory-group-count { font-size: 0.78rem; font-weight: 400; color: var(--text-muted); margin-left: 0.3rem; }
.memory-empty { color: var(--text-muted); font-style: italic; margin-top: 0.5rem; }
.nav-link-strong { font-weight: 600; }
.nav-link-qa { font-weight: 500; border-left: 2px solid var(--primary); padding-left: 0.7rem; }

/* Memory tag grouping */
.memory-tag-title { font-size: 0.88rem; font-weight: 600; color: var(--text-muted); margin: 1.2rem 0 0.4rem; text-transform: uppercase; letter-spacing: 0.03em; }
.memory-tag-badge { display: inline-block; font-size: 0.7rem; padding: 0.1rem 0.45rem; border-radius: 10px; background: var(--border); color: var(--text-muted); margin-bottom: 0.3rem; }

/* Memory graph edge styles */
.link-mention { stroke: #64748b; stroke-width: 1.5px; opacity: 0.7; fill: none; }
.link-tag     { stroke: #94a3b8; stroke-width: 1px; stroke-dasharray: 4,4; opacity: 0.25; fill: none; }

.memory-report-strip { display: flex; flex-wrap: wrap; align-items: stretch; gap: 0.6rem; margin: -0.4rem 0 1rem; }
.memory-report-card { min-width: 108px; padding: 0.65rem 0.8rem; border: 1px solid var(--border); border-radius: 10px; background: var(--card); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04); }
.memory-report-card b { display: block; font-size: 1.15rem; line-height: 1.1; color: var(--primary); }
.memory-report-card span { display: block; margin-top: 0.25rem; font-size: 0.74rem; color: var(--text-muted); }
.memory-report-note { padding: 0.65rem 0.8rem; border: 1px dashed var(--border); border-radius: 10px; color: var(--text-muted); background: rgba(148, 163, 184, 0.08); font-size: 0.78rem; display: flex; align-items: center; }
.memory-monthly-box { margin: 0.8rem 0; padding: 0.75rem; border: 1px solid var(--border); border-radius: 8px; background: rgba(15, 23, 42, 0.03); }
.memory-monthly-box.muted { color: var(--text-muted); font-size: 0.8rem; }
.memory-monthly-title { font-weight: 700; margin-bottom: 0.45rem; font-size: 0.82rem; }
.memory-monthly-row { display: flex; justify-content: space-between; gap: 0.6rem; padding: 0.18rem 0; font-size: 0.76rem; border-bottom: 1px solid rgba(148, 163, 184, 0.16); }
.memory-monthly-row:last-child { border-bottom: 0; }
.memory-monthly-row span { color: var(--text-muted); }
.memory-status-danger, .memory-status-critical { color: #dc2626; }
.memory-status-warn { color: #d97706; }
.memory-status-ok { color: #16a34a; }
.memory-status-neutral { color: #64748b; }

/* --- Organs Dashboard --- */
.organ-summary {
  display: flex; gap: 12px; flex-wrap: wrap; margin: 1rem 0 1.5rem;
}
.organ-summary-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 24px;
  border: 2px solid; background: var(--bg-secondary, #f8fafc);
}
.organ-summary-pill strong { font-size: 1.25em; }
.organ-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}
.organ-card {
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border, #e2e8f0);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
  transition: transform .1s, box-shadow .1s;
}
.organ-card:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.06); }
.organ-status-green      { border-left-color: #22c55e; }
.organ-status-yellow     { border-left-color: #eab308; }
.organ-status-red        { border-left-color: #ef4444; background: #fef2f2; }
.organ-status-deprecated { border-left-color: #94a3b8; opacity: 0.7; }
.organ-status-external   { border-left-color: #3b82f6; }
.organ-card-header {
  display: grid; grid-template-columns: 32px 1fr auto; gap: 10px; align-items: start;
}
.organ-icon { font-size: 1.6em; line-height: 1; }
.organ-name { font-weight: 600; font-size: 1.02em; }
.organ-role { font-size: 0.8em; color: var(--text-light, #64748b); margin-top: 2px; }
.organ-status { text-align: center; min-width: 48px; }
.organ-status-emoji { font-size: 1.2em; }
.organ-status-label { font-size: 0.72em; font-weight: 600; }
.organ-badge {
  display: inline-block; padding: 1px 8px; border-radius: 12px;
  font-size: 0.7em; font-weight: 600; margin-left: 6px; vertical-align: middle;
}
.organ-badge-warn { background: #fef3c7; color: #92400e; }
.organ-badge-new  { background: #dcfce7; color: #166534; }
.organ-badge-ext  { background: #dbeafe; color: #1e40af; }
.organ-checks-summary {
  margin-top: 10px; font-size: 0.82em; color: var(--text-light, #64748b);
  display: flex; justify-content: space-between; align-items: center;
}
.organ-expand-hint { font-size: 0.9em; opacity: 0.7; }
.organ-details {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px dashed var(--border, #e2e8f0);
  font-size: 0.88em;
}
.organ-detail-row {
  display: grid; grid-template-columns: 60px 1fr; gap: 12px; padding: 3px 0;
}
.organ-detail-row strong { color: var(--text-light, #64748b); font-weight: 500; }
.organ-checks { margin-top: 10px; }
.organ-checks > strong { display: block; margin-bottom: 6px; color: var(--text-light, #64748b); }
.organ-check {
  display: grid; grid-template-columns: 20px 1fr; gap: 8px;
  padding: 3px 0; align-items: start;
}
.organ-check.ok   > span:first-child { color: #22c55e; font-weight: 700; }
.organ-check.fail > span:first-child { color: #ef4444; font-weight: 700; }
.organ-check-detail {
  grid-column: 2; font-size: 0.85em; color: var(--text-light, #64748b);
  margin-top: 2px; padding: 4px 8px;
  background: rgba(148,163,184,.1); border-radius: 4px;
}
.organ-minigraph {
  margin: 12px 0; padding: 10px;
  background: var(--bg, #fff);
  border: 1px dashed var(--border, #e2e8f0);
  border-radius: 6px;
}
.organ-minigraph-title {
  font-size: 0.82em; font-weight: 600;
  color: var(--text-light, #64748b); margin-bottom: 6px;
}
.organ-graph-node:hover rect { filter: brightness(1.08); }
.organ-drill-btn {
  padding: 3px 10px; background: #3b82f6; color: #fff;
  border-radius: 4px; text-decoration: none; font-size: 0.82em;
  margin-right: 8px;
}
.organ-drill-btn:hover { background: #2563eb; }

/* === Infra Dashboard === */
.infra-kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.infra-kpi {
  background: var(--bg-secondary, #f8fafc); border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px; padding: 14px 16px; text-align: center;
}
.infra-kpi-value { font-size: 1.6em; font-weight: 700; line-height: 1.2; }
.infra-kpi-label { font-size: 0.78em; color: var(--text-light, #64748b); margin-top: 4px; }

.infra-status-bar {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px;
}
.infra-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px; border-radius: 20px; font-size: 0.8em; font-weight: 500;
}
.infra-pill-ok { background: #dcfce7; color: #15803d; }
.infra-pill-fail { background: #fee2e2; color: #dc2626; }

.infra-section {
  background: var(--bg-secondary, #f8fafc); border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px; padding: 18px 20px; margin-bottom: 16px;
}
.infra-section h3 { margin: 0 0 12px; font-size: 1.05em; }
.infra-section h4 { margin: 0 0 8px; font-size: 0.88em; color: var(--text-light, #64748b); }

.infra-detail-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; border-bottom: 1px solid var(--border, #e2e8f0);
  font-size: 0.88em;
}
.infra-detail-row:last-child { border-bottom: none; }

.infra-table {
  width: 100%; border-collapse: collapse; font-size: 0.85em; margin-top: 10px;
}
.infra-table th {
  text-align: left; padding: 6px 10px; font-weight: 600;
  border-bottom: 2px solid var(--border, #e2e8f0); color: var(--text-light, #64748b);
}
.infra-table td {
  padding: 5px 10px; border-bottom: 1px solid var(--border, #e2e8f0);
}

.infra-services-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
.infra-svc {
  font-size: 0.82em; padding: 4px 8px; background: var(--bg, #fff);
  border: 1px solid var(--border, #e2e8f0); border-radius: 5px; margin-bottom: 4px;
}

.infra-safety-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.infra-safety-item {
  padding: 10px 12px; background: var(--bg, #fff);
  border: 1px solid var(--border, #e2e8f0); border-radius: 8px;
}
.infra-safety-item strong { display: block; font-size: 0.9em; margin-bottom: 3px; }
.infra-safety-item span { font-size: 0.8em; color: var(--text-light, #64748b); }

.infra-cli-grid {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.infra-cli-cmd {
  padding: 5px 12px; background: #1e293b; color: #e2e8f0;
  border-radius: 6px; font-size: 0.82em;
}

@media (max-width: 640px) {
  .infra-services-grid, .infra-safety-grid { grid-template-columns: 1fr; }
  .infra-kpi-grid { grid-template-columns: repeat(3, 1fr); }
}

/* --- Infra Card (字卡) --- */
.icard-container { max-width: 720px; margin: 0 auto; }
.icard-hero {
  background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
  border-radius: 16px; padding: 28px 28px 20px; color: #e2e8f0;
  margin-bottom: 12px; position: relative; overflow: hidden;
}
.icard-hero::after {
  content: ''; position: absolute; top: -40px; right: -40px;
  width: 140px; height: 140px; border-radius: 50%; background: rgba(59,130,246,.12);
}
.icard-hero-title { font-size: 1.35em; font-weight: 700; letter-spacing: -0.3px; }
.icard-hero-sub { font-size: 0.75em; color: #94a3b8; margin: 4px 0 16px; }
.icard-hero-kpi { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.icard-kpi {
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px; padding: 10px 12px; text-align: center;
}
.icard-kpi-val { font-size: 1.35em; font-weight: 700; color: #60a5fa; font-family: var(--font-mono, monospace); }
.icard-kpi-label { font-size: 0.65em; color: #94a3b8; margin-top: 2px; letter-spacing: 0.3px; }

.icard-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.icard-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 14px; font-size: 0.72em; font-weight: 500;
}
.icard-pill-ok { background: #f0fdf4; color: #16a34a; }
.icard-pill-fail { background: #fef2f2; color: #ef4444; }

.icard {
  background: var(--bg-card, #fff); border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px; margin-bottom: 10px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.icard-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; cursor: pointer; user-select: none;
  transition: background 0.15s;
}
.icard-header:hover { background: var(--bg-hover, #f8fafc); }
.icard-icon { font-size: 1.1em; flex-shrink: 0; }
.icard-title { font-size: 0.9em; font-weight: 600; flex: 1; }
.icard-badge {
  font-size: 0.65em; font-weight: 600; padding: 2px 8px;
  border-radius: 10px; background: var(--accent-soft, #eff6ff); color: var(--accent, #3b82f6);
}
.icard-arrow { font-size: 0.75em; color: var(--text-light, #94a3b8); transition: transform 0.2s; }
.icard-open .icard-arrow { transform: rotate(90deg); }
.icard-body { display: none; padding: 0 18px 16px; font-size: 0.85em; color: var(--text-light, #64748b); }
.icard-open .icard-body { display: block; }

.icard-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; border-bottom: 1px solid var(--border, #e2e8f0);
}
.icard-row:last-child { border-bottom: none; }

.icard-table { width: 100%; border-collapse: collapse; font-size: 0.9em; margin-top: 8px; }
.icard-table th {
  text-align: left; padding: 5px 8px; color: var(--text-light, #94a3b8);
  font-size: 0.75em; text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border, #e2e8f0);
}
.icard-table td { padding: 5px 8px; border-bottom: 1px solid var(--border, #e2e8f0); }

.icard-svc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; }
.icard-svc { font-size: 0.85em; padding: 3px 0; font-family: var(--font-mono, monospace); }
.icard-svc-section {
  font-size: 0.72em; font-weight: 600; color: var(--text-light, #94a3b8);
  margin-top: 10px; text-transform: uppercase; letter-spacing: 0.5px; grid-column: 1 / -1;
}
.icard-svc-section:first-child { margin-top: 0; }

.icard-safety-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.icard-safety-item {
  background: var(--bg-hover, #f8fafc); border-radius: 8px; padding: 10px 12px;
}
.icard-safety-item strong { font-size: 0.85em; display: block; margin-bottom: 2px; font-family: var(--font-mono, monospace); }
.icard-safety-item span { font-size: 0.75em; color: var(--text-light, #94a3b8); }

.icard-cli-row { display: flex; flex-wrap: wrap; gap: 6px; }
.icard-cli-tag {
  font-family: var(--font-mono, monospace); font-size: 0.75em; padding: 4px 10px;
  background: #0f172a; color: #e2e8f0; border-radius: 6px;
}

.icard-alert-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 0.85em; }
.icard-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.icard-dot-ok { background: var(--green, #16a34a); }
.icard-dot-fail { background: #ef4444; }

@media (max-width: 480px) {
  .icard-hero-kpi { grid-template-columns: repeat(2, 1fr); }
  .icard-safety-grid, .icard-svc-grid { grid-template-columns: 1fr; }
}
