:root {
  --bg: #f3f6fc;
  --panel: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e6ebf2;
  --primary: #2563eb;
  --primary-deep: #1d4ed8;
  --accent: #4f46e5;
  --ok: #10b981;
  --warn: #f59e0b;
  --err: #ef4444;
  --shadow: 0 8px 28px rgba(30, 41, 59, 0.08);
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, textarea, input { font: inherit; }
button { cursor: pointer; }
svg { width: 1em; height: 1em; display: block; }

.app-shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- Topbar ---------- */
.topbar {
  flex: 0 0 auto;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 6px rgba(30, 41, 59, 0.04);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; flex: 0 0 38px;
  display: grid; place-items: center;
  border-radius: 11px;
  color: #fff;
  font-size: 21px;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}
.brand-title { font-size: 17px; font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.brand-tag { font-size: 10px; font-weight: 700; color: var(--primary); background: #e8f0ff; padding: 1px 6px; border-radius: 5px; letter-spacing: .5px; }
.brand-sub { font-size: 11px; color: var(--muted); white-space: nowrap; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn, .settings-btn, .view-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 10px;
  transition: all .18s ease;
}
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; font-size: 17px; }
.settings-btn { height: 36px; padding: 0 13px; display: flex; align-items: center; gap: 7px; color: var(--ink); font-weight: 500; }
.settings-btn svg { font-size: 15px; }
.icon-btn:hover, .settings-btn:hover { border-color: #bfd2ff; color: var(--primary); background: #f7faff; }
.icon-btn:disabled, .icon-btn:disabled:hover {
  opacity: .4;
  color: var(--muted);
  background: #fff;
  border-color: var(--line);
  cursor: not-allowed;
}
.view-switch { display: none; gap: 3px; padding: 3px; background: #eef2f9; border-radius: 10px; }
.view-btn { border: 0; background: transparent; padding: 6px 11px; font-size: 12px; border-radius: 7px; white-space: nowrap; }
.view-btn.is-active { background: #fff; color: var(--primary); box-shadow: 0 1px 4px rgba(30,41,59,.12); font-weight: 600; }

/* ---------- Layout ---------- */
.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(340px, 40%) 1fr;
  gap: 16px;
  padding: 16px;
}
.panel {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Chat ---------- */
.chat-scroll { flex: 1 1 auto; overflow-y: auto; padding: 20px 18px 8px; scroll-behavior: smooth; }
.msg { display: flex; gap: 10px; margin-bottom: 18px; align-items: flex-start; }
.msg-avatar {
  flex: 0 0 32px; width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  box-shadow: 0 3px 8px rgba(37,99,235,.22);
}
.msg-user .msg-avatar { background: linear-gradient(135deg, #64748b, #475569); box-shadow: none; }
.msg-main { min-width: 0; max-width: 86%; }
.msg-bubble {
  display: inline-block;
  padding: 11px 14px;
  border-radius: 4px 14px 14px 14px;
  background: #f5f7fb;
  border: 1px solid var(--line);
  word-break: break-word;
}
.msg-user { flex-direction: row-reverse; }
.msg-user .msg-main { text-align: right; }
.msg-user .msg-bubble {
  text-align: left;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  border-color: transparent;
  border-radius: 14px 4px 14px 14px;
  box-shadow: 0 4px 12px rgba(37,99,235,.18);
}
.msg-meta { font-size: 11px; color: #94a3b8; margin-top: 5px; }
.welcome-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.msg-bubble p { margin: 0 0 12px; color: var(--muted); }
.cap-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cap { display: flex; align-items: center; gap: 9px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; }
.cap b { display: block; font-size: 12px; font-weight: 600; }
.cap small { display: block; font-size: 10px; color: var(--muted); }
.cap-icon { width: 20px; height: 20px; border-radius: 6px; flex: 0 0 20px; background: #e8f0ff; position: relative; }
.cap-icon::after { content: ""; position: absolute; inset: 5px; border: 2px solid var(--primary); border-radius: 3px; }
.cap-route::after { border-radius: 50%; border-width: 2px 0 0 2px; transform: rotate(45deg); }
.cap-weather::after { border-radius: 50%; background: var(--warn); border: 0; inset: 6px; }
.cap-map::after { border-radius: 2px; background: var(--ok); border: 0; transform: rotate(45deg) scale(.8); }

.intent-badge { display: inline-block; font-size: 11px; font-weight: 600; color: var(--primary); background: #e8f0ff; padding: 1px 8px; border-radius: 5px; margin-bottom: 6px; }
.reply-text { font-size: 13px; }
.notice { margin-top: 7px; font-size: 11px; color: #b45309; background: #fffbeb; border: 1px solid #fde68a; padding: 5px 8px; border-radius: 7px; }
.jump-btn { margin-top: 9px; border: 0; background: transparent; color: var(--primary); font-size: 12px; font-weight: 600; padding: 0; }
.jump-btn:hover { text-decoration: underline; }
.err-text { color: var(--err); }

.dots { display: inline-flex; gap: 4px; padding: 3px 0; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: #94a3b8; animation: bounce 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

.composer { flex: 0 0 auto; padding: 10px 16px 14px; border-top: 1px solid var(--line); background: #fbfcfe; }
.quick-chips { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 9px; scrollbar-width: none; }
.quick-chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid #dbe6fb; background: #fff; color: var(--primary); font-size: 12px; padding: 5px 11px; border-radius: 999px; transition: all .15s; }
.chip:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.composer-box { display: flex; gap: 9px; align-items: flex-end; background: #fff; border: 1px solid #dbe3ef; border-radius: 12px; padding: 7px 7px 7px 13px; transition: border-color .18s, box-shadow .18s; }
.composer-box:focus-within { border-color: #93b4ff; box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.composer-box textarea { flex: 1 1 auto; min-height: 24px; max-height: 120px; resize: none; border: 0; outline: 0; padding: 5px 0; line-height: 1.5; background: transparent; color: var(--ink); }
.composer-box textarea::placeholder { color: #a6b1c2; }
#sendBtn { flex: 0 0 36px; width: 36px; height: 36px; border: 0; border-radius: 9px; color: #fff; background: linear-gradient(135deg, var(--primary), var(--accent)); display: grid; place-items: center; font-size: 16px; transition: opacity .18s, transform .18s; }
#sendBtn:hover:not(:disabled) { transform: translateY(-1px); }
#sendBtn:disabled { opacity: .5; cursor: not-allowed; }
#sendBtn.loading svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.composer-hint { font-size: 10px; color: #a1adbf; margin-top: 7px; text-align: center; }

/* ---------- Result panel ---------- */
.result-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.result-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.result-head p { margin: 1px 0 0; font-size: 11px; color: var(--muted); }
.status-pill { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: #f1f5f9; color: var(--muted); }
.status-pill.ready { background: #ecfdf5; color: #059669; }
.status-pill.warn { background: #fffbeb; color: #b45309; }
.result-scroll { flex: 1 1 auto; overflow-y: auto; padding: 16px 18px 24px; }
.map-frame { position: relative; width: 100%; border-radius: 12px; overflow: hidden; background: #eef2f7; border: 1px solid var(--line); }
.map-placeholder { height: 260px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #94a3b8; text-align: center; gap: 5px; }
.map-placeholder svg { font-size: 34px; margin-bottom: 4px; color: #b7c4d6; }
.map-placeholder p { margin: 0; font-size: 13px; font-weight: 600; color: #7c8ca3; }
.map-placeholder small { font-size: 11px; }
.static-map { display: block; width: 100%; height: auto; }
.map-caption { position: absolute; left: 10px; bottom: 10px; background: rgba(15, 23, 42, .76); color: #fff; font-size: 11px; padding: 4px 9px; border-radius: 6px; backdrop-filter: blur(4px); max-width: calc(100% - 20px); }

.result-cards { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.section-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: #fff; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 11px; gap: 8px; }
.section-head h3 { margin: 0; font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { font-size: 11px; color: var(--muted); background: #f1f5f9; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.empty-card { text-align: center; padding: 30px 12px; color: var(--muted); border: 1px dashed var(--line); border-radius: 12px; }
.empty-card .empty-icon { font-size: 26px; color: #cbd5e1; }
.empty-card p { margin: 4px 0 0; font-size: 12px; }

/* POI list */
.poi-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px dashed var(--line); }
.poi-item:first-child { border-top: 0; }
.poi-idx { flex: 0 0 22px; width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--primary); background: #e8f0ff; }
.poi-main { flex: 1 1 auto; min-width: 0; }
.poi-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.poi-addr { font-size: 11px; color: var(--muted); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.poi-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.poi-tags span { font-size: 10px; color: #64748b; background: #f5f7fb; border-radius: 4px; padding: 1px 6px; }
.mini-btn { flex: 0 0 auto; border: 1px solid #dbe6fb; background: #fff; color: var(--primary); font-size: 11px; padding: 4px 8px; border-radius: 7px; }
.mini-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Route */
.route-endpoints { display: flex; flex-direction: column; gap: 8px; margin-bottom: 13px; }
.endpoint { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.endpoint span { color: var(--muted); flex: 0 0 28px; }
.endpoint strong { font-weight: 600; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; }
.dot.start { background: var(--ok); box-shadow: 0 0 0 3px #d1fae5; }
.dot.end { background: var(--err); box-shadow: 0 0 0 3px #fee2e2; }
.route-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 13px; }
.route-metrics > div { background: #f7f9fc; border-radius: 9px; padding: 8px 6px; text-align: center; }
.route-metrics b { display: block; font-size: 14px; font-weight: 700; color: var(--primary); }
.route-metrics span { font-size: 10px; color: var(--muted); }
.step-list { display: flex; flex-direction: column; gap: 10px; border-top: 1px dashed var(--line); padding-top: 12px; }
.step { display: flex; gap: 9px; font-size: 12px; }
.step-dot { flex: 0 0 18px; width: 18px; height: 18px; border-radius: 50%; background: #e8f0ff; color: var(--primary); font-size: 10px; font-weight: 700; display: grid; place-items: center; }
.step small { display: block; color: var(--muted); font-size: 10px; }
.transit-opt { border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; margin-bottom: 8px; }
.transit-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 600; }
.transit-top span { color: var(--primary); font-weight: 600; font-size: 11px; white-space: nowrap; }
.transit-segs { font-size: 11px; color: var(--muted); margin-top: 4px; line-height: 1.5; }

/* Weather */
.weather-now { display: flex; align-items: center; gap: 18px; padding: 8px 4px 14px; border-bottom: 1px dashed var(--line); }
.temp-big { font-size: 42px; font-weight: 300; line-height: 1; color: var(--primary); }
.temp-big sup { font-size: 18px; vertical-align: super; }
.weather-info strong { display: block; font-size: 16px; }
.weather-info span { display: block; font-size: 11px; color: var(--muted); }
.forecast-list { margin-top: 10px; }
.forecast-day { display: grid; grid-template-columns: 1.1fr 1fr 1.2fr 1fr; gap: 6px; align-items: center; font-size: 11px; padding: 7px 2px; border-bottom: 1px dashed var(--line); }
.forecast-day:last-child { border-bottom: 0; }
.forecast-day .temp { color: var(--primary); font-weight: 600; text-align: center; }
.forecast-day span:last-child { text-align: right; color: var(--muted); }

/* Location */
.loc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.loc-grid > div { background: #f7f9fc; border-radius: 9px; padding: 9px 11px; }
.loc-grid span { display: block; font-size: 10px; color: var(--muted); }
.loc-grid strong { display: block; font-size: 13px; font-weight: 600; margin-top: 2px; word-break: break-all; }

/* ---------- Modal & toast ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: grid; place-items: center; padding: 18px; z-index: 50; backdrop-filter: blur(3px); }
.modal { width: min(440px, 100%); background: #fff; border-radius: 16px; box-shadow: 0 24px 60px rgba(15,23,42,.28); overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close { border: 0; background: transparent; font-size: 24px; line-height: 1; color: var(--muted); padding: 0 4px; }
.modal-body { padding: 18px 20px; }
.modal-note { margin: 0 0 16px; font-size: 12px; color: var(--muted); background: #f0f7ff; border: 1px solid #dbeafe; padding: 9px 11px; border-radius: 9px; }
.field { display: block; margin-bottom: 15px; }
.field > span { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.field input { width: 100%; border: 1px solid #dbe3ef; border-radius: 9px; padding: 9px 11px; outline: 0; transition: border-color .18s, box-shadow .18s; }
.field input:focus { border-color: #93b4ff; box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.field a { display: inline-block; font-size: 11px; color: var(--primary); text-decoration: none; margin-top: 5px; }
.field a:hover { text-decoration: underline; }
.modal-tip { font-size: 11px; color: #92400e; background: #fffbeb; border: 1px solid #fde68a; border-radius: 9px; padding: 9px 11px; line-height: 1.6; }
.modal-foot { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 20px; border-top: 1px solid var(--line); background: #fbfcfe; }
.btn { border-radius: 9px; padding: 8px 17px; font-size: 13px; font-weight: 600; border: 1px solid var(--line); background: #fff; color: var(--ink); }
.btn.primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-deep); }
.btn.ghost:hover { border-color: #bfd2ff; color: var(--primary); }

.toast { position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 16px); background: #1e293b; color: #fff; font-size: 12px; padding: 9px 16px; border-radius: 9px; box-shadow: 0 10px 30px rgba(15,23,42,.25); opacity: 0; pointer-events: none; transition: opacity .22s, transform .22s; z-index: 80; max-width: min(90vw, 460px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b91c1c; }
.toast.success { background: #047857; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .topbar { height: 60px; padding: 0 12px; }
  .brand-sub { display: none; }
  .brand-title { font-size: 15px; }
  .brand-mark { width: 32px; height: 32px; flex-basis: 32px; font-size: 18px; }
  .view-switch { display: flex; }
  .settings-btn span { display: none; }
  .settings-btn { width: 36px; padding: 0; justify-content: center; }
  .workspace { display: block; padding: 10px; height: calc(100dvh - 60px); }
  .panel { height: 100%; }
  .chat-panel { display: flex; }
  .result-panel { display: none; }
  body.view-result .chat-panel { display: none; }
  body.view-result .result-panel { display: flex; }
  .chat-scroll { padding: 14px 12px 6px; }
  .composer { padding: 8px 12px 10px; }
  .result-scroll { padding: 12px; }
  .cap-grid { gap: 6px; }
  .map-placeholder { height: 210px; }
}
@media (max-width: 420px) {
  .topbar-actions { gap: 6px; }
  .icon-btn { width: 32px; height: 32px; font-size: 15px; }
  .settings-btn { width: 32px; height: 32px; }
  .view-btn { padding: 5px 8px; font-size: 11px; }
  .brand-title { font-size: 14px; }
  .brand-tag { display: none; }
  .cap-grid { grid-template-columns: 1fr; }
  .cap { padding: 7px 9px; }
  .loc-grid { grid-template-columns: 1fr; }
  .route-metrics b { font-size: 12px; }
}
