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

:root {
  --bg: #0f1117;
  --bg2: #161b22;
  --bg3: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #6e7681;
  --accent: #58a6ff;
  --accent2: #1f6feb;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --sidebar-w: 260px;
  --chat-w: 360px;
  --topbar-h: 52px;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --transition: .2s ease;
}

html, body { height: 100%; font-family: 'Segoe UI', -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; overflow: hidden; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── Topbar ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  backdrop-filter: blur(8px);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-weight: 600; font-size: 15px; letter-spacing: -.3px; }
.sidebar-toggle, .chat-toggle {
  background: none; border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius);
  padding: 5px 12px; cursor: pointer; font-size: 13px;
  transition: var(--transition);
}
.sidebar-toggle:hover, .chat-toggle:hover {
  background: var(--bg3); border-color: var(--accent);
}
.chat-toggle { background: var(--accent2); border-color: var(--accent2); font-weight: 600; }
.chat-toggle:hover { background: #388bfd; }

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--chat-w);
  grid-template-rows: calc(100vh - var(--topbar-h));
  margin-top: var(--topbar-h);
  transition: grid-template-columns var(--transition);
}
.layout.sidebar-hidden { grid-template-columns: 0 1fr var(--chat-w); }
.layout.chat-hidden { grid-template-columns: var(--sidebar-w) 1fr 0; }
.layout.sidebar-hidden.chat-hidden { grid-template-columns: 0 1fr 0; }

/* ── Sidebar ── */
.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: var(--transition);
}
.layout.sidebar-hidden .sidebar { width: 0; overflow: hidden; opacity: 0; }

.sidebar-header { padding: 16px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 14px; font-weight: 700; color: var(--text); }
.sidebar-sub { font-size: 12px; color: var(--text3); margin-top: 2px; }

.sidebar-filter { padding: 10px 12px; }
.sidebar-filter input {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); padding: 7px 10px;
  font-size: 13px; outline: none; transition: var(--transition);
}
.sidebar-filter input:focus { border-color: var(--accent); }

.sidebar-tags { padding: 0 12px 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  background: none; border: 1px solid var(--border); color: var(--text2);
  border-radius: 20px; padding: 3px 10px; font-size: 12px; cursor: pointer;
  transition: var(--transition);
}
.tag:hover, .tag.active {
  background: var(--accent2); border-color: var(--accent2); color: #fff;
}

.dest-list { flex: 1; overflow-y: auto; padding: 4px 8px 16px; }
.dest-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius);
  cursor: pointer; transition: var(--transition);
  border: 1px solid transparent;
}
.dest-item:hover { background: var(--bg3); }
.dest-item.active {
  background: rgba(31,111,235,.15); border-color: var(--accent2);
}
.dest-num { font-size: 11px; color: var(--text3); width: 22px; flex-shrink: 0; }
.dest-flag { font-size: 18px; flex-shrink: 0; }
.dest-info { min-width: 0; }
.dest-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dest-region { font-size: 11px; color: var(--text3); }
.dest-cost { margin-left: auto; font-size: 11px; color: var(--yellow); flex-shrink: 0; }

/* ── Main Content ── */
.content {
  overflow-y: auto; background: var(--bg);
  display: flex; flex-direction: column;
}
.content-inner { flex: 1; padding: 32px 48px; max-width: 860px; margin: 0 auto; width: 100%; }

/* Welcome Screen */
.welcome { text-align: center; padding: 60px 20px; }
.welcome-icon { font-size: 64px; margin-bottom: 20px; }
.welcome h1 { font-size: 28px; font-weight: 700; margin-bottom: 12px; }
.welcome p { color: var(--text2); font-size: 16px; line-height: 1.8; }
.welcome-stats {
  display: flex; justify-content: center; gap: 40px;
  margin: 36px 0; padding: 24px;
  background: var(--bg2); border-radius: 12px; border: 1px solid var(--border);
}
.stat { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stat-num { font-size: 32px; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 13px; color: var(--text2); }
.welcome-themes { margin-top: 32px; text-align: left; }
.welcome-themes h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.theme-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 12px;
  text-align: center; cursor: pointer; font-size: 13px;
  line-height: 1.8; transition: var(--transition);
}
.theme-card:hover { border-color: var(--accent); background: var(--bg3); transform: translateY(-2px); }

.hidden { display: none !important; }

/* ── Markdown Body ── */
.markdown-body { padding-bottom: 60px; }
.markdown-body h1 { font-size: 26px; font-weight: 800; border-bottom: 2px solid var(--border); padding-bottom: 12px; margin-bottom: 20px; }
.markdown-body h2 { font-size: 20px; font-weight: 700; margin: 32px 0 14px; color: var(--accent); }
.markdown-body h3 { font-size: 16px; font-weight: 600; margin: 20px 0 10px; color: var(--text); }
.markdown-body h4 { font-size: 14px; font-weight: 600; margin: 16px 0 8px; color: var(--text2); }
.markdown-body p { margin-bottom: 12px; color: var(--text2); line-height: 1.8; }
.markdown-body ul, .markdown-body ol { padding-left: 20px; margin-bottom: 12px; }
.markdown-body li { color: var(--text2); margin-bottom: 6px; line-height: 1.7; }
.markdown-body li strong { color: var(--text); }
.markdown-body strong { color: var(--text); font-weight: 600; }
.markdown-body code {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 6px; font-size: 13px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}
.markdown-body pre {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; overflow-x: auto;
  margin: 16px 0;
}
.markdown-body pre code {
  background: none; border: none; padding: 0;
  font-size: 13px; line-height: 1.6; color: var(--text);
}
.markdown-body table {
  width: 100%; border-collapse: collapse; margin: 16px 0;
  font-size: 14px;
}
.markdown-body th {
  background: var(--bg2); border: 1px solid var(--border);
  padding: 10px 14px; text-align: left; font-weight: 600; color: var(--text);
}
.markdown-body td {
  border: 1px solid var(--border); padding: 9px 14px; color: var(--text2);
}
.markdown-body tr:hover td { background: var(--bg2); }
.markdown-body blockquote {
  border-left: 3px solid var(--accent2); margin: 16px 0;
  padding: 12px 16px; background: rgba(31,111,235,.08); border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text2);
}
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }

/* ── Chat Panel ── */
.chat-panel {
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: var(--transition);
}
.layout.chat-hidden .chat-panel { width: 0; overflow: hidden; opacity: 0; }

.chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg3);
}
.chat-header-left { display: flex; align-items: center; gap: 10px; }
.chat-icon { font-size: 22px; }
.chat-title { font-size: 14px; font-weight: 600; }
.chat-subtitle { font-size: 11px; color: var(--text3); }
.chat-clear {
  background: none; border: 1px solid var(--border); color: var(--text2);
  border-radius: var(--radius); padding: 4px 10px; cursor: pointer;
  font-size: 16px; transition: var(--transition);
}
.chat-clear:hover { color: var(--red); border-color: var(--red); }

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

.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.assistant { justify-content: flex-start; }

.chat-bubble {
  max-width: 88%; padding: 10px 14px;
  border-radius: 14px; font-size: 13.5px; line-height: 1.6;
  word-break: break-word;
}
.chat-msg.user .chat-bubble {
  background: var(--accent2); color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant .chat-bubble {
  background: var(--bg3); color: var(--text);
  border-bottom-left-radius: 4px; border: 1px solid var(--border);
}

/* Markdown inside chat bubble */
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3 { font-size: 14px; margin: 8px 0 4px; color: var(--accent); }
.chat-bubble p { margin-bottom: 6px; }
.chat-bubble ul, .chat-bubble ol { padding-left: 16px; margin-bottom: 6px; }
.chat-bubble li { margin-bottom: 3px; }
.chat-bubble strong { color: var(--text); }
.chat-bubble code { background: rgba(0,0,0,.25); border-radius: 3px; padding: 1px 4px; font-size: 12px; }
.chat-bubble hr { border-color: var(--border); margin: 8px 0; }
.chat-bubble table { font-size: 12px; width: 100%; }
.chat-bubble th, .chat-bubble td { padding: 4px 8px; border: 1px solid var(--border); }

/* Typing indicator */
.chat-typing { display: flex; align-items: center; gap: 4px; padding: 10px 14px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text3); animation: bounce .8s infinite; }
.dot:nth-child(2) { animation-delay: .15s; }
.dot:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* Suggestions */
.chat-suggestions {
  padding: 8px 12px;
  display: flex; flex-wrap: wrap; gap: 6px;
  border-top: 1px solid var(--border);
}
.suggestion {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text2);
  border-radius: 20px; padding: 5px 12px; font-size: 12px; cursor: pointer;
  transition: var(--transition); white-space: nowrap;
}
.suggestion:hover { border-color: var(--accent); color: var(--accent); }

/* Chat Input */
.chat-input-area {
  padding: 12px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: flex-end;
}
.chat-input-area textarea {
  flex: 1; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  padding: 9px 12px; font-size: 13px; resize: none; outline: none;
  font-family: inherit; max-height: 120px; transition: var(--transition);
  line-height: 1.5;
}
.chat-input-area textarea:focus { border-color: var(--accent); }
.chat-input-area button {
  background: var(--accent2); border: none; color: #fff;
  border-radius: var(--radius); width: 38px; height: 38px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: var(--transition);
}
.chat-input-area button:hover { background: #388bfd; }
.chat-input-area button:disabled { background: var(--text3); cursor: not-allowed; }

/* ── Breadcrumb / Page Header ── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.page-header-left { display: flex; align-items: center; gap: 10px; }
.page-flag { font-size: 32px; }
.page-region { font-size: 12px; color: var(--text3); background: var(--bg2); border: 1px solid var(--border); border-radius: 20px; padding: 2px 10px; }
.ask-ai-btn {
  background: none; border: 1px solid var(--accent2); color: var(--accent);
  border-radius: var(--radius); padding: 6px 14px; cursor: pointer;
  font-size: 13px; transition: var(--transition);
}
.ask-ai-btn:hover { background: var(--accent2); color: #fff; }

/* ── Loading skeleton ── */
.skeleton { background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 50%, var(--bg2) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 4px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Responsive ── */
@media (max-width: 900px) {
  :root { --sidebar-w: 240px; --chat-w: 300px; }
}
@media (max-width: 700px) {
  .layout { grid-template-columns: 0 1fr 0; }
  .layout.sidebar-visible { grid-template-columns: 100vw 0 0; }
  .layout.chat-visible { grid-template-columns: 0 0 100vw; }
  .content-inner { padding: 20px 20px; }
}
