:root {
  color-scheme: dark;
  --bg: #0f1419;
  --surface: #171e27;
  --surface-2: #1d2733;
  --surface-3: #263444;
  --line: #34465a;
  --line-soft: #293746;
  --text: #f1f4f6;
  --muted: #a7b2bf;
  --quiet: #7e8b99;
  --gold: #ffd166;
  --gold-deep: #5e4c1f;
  --blue: #68c5ff;
  --green: #7fe0aa;
  --green-bg: #173b2d;
  --red: #ff857c;
  --orange: #ffb65a;
  --shadow: 0 18px 55px rgba(0, 0, 0, .34);
  --radius: 16px;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; overflow: hidden; }
button, input, textarea, select { font: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; }

.boot-screen, .locked-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px;
  text-align: center;
}
.boot-screen { align-content: center; color: var(--muted); gap: 14px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.locked-card { width: min(430px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.locked-icon { width: 58px; height: 58px; display: grid; place-items: center; margin: 0 auto 18px; border-radius: 18px; background: var(--gold-deep); color: var(--gold); font-size: 30px; }
.locked-card h1 { margin: 0 0 8px; font-size: 24px; }
.locked-card p { color: var(--muted); line-height: 1.65; margin: 0 0 20px; }
.token-form { display: grid; gap: 10px; }

.app-shell { height: 100dvh; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
.topbar { height: 62px; display: flex; align-items: center; gap: 14px; padding: 0 20px; border-bottom: 1px solid var(--line-soft); background: rgba(15, 20, 25, .96); }
.brand { min-width: 0; flex: 1; }
.brand strong { display: block; color: var(--gold); font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.desktop-tabs { display: flex; gap: 5px; padding: 4px; border-radius: 12px; background: var(--surface); }
.desktop-tabs button { min-height: 38px; padding: 0 14px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; }
.desktop-tabs button.active { background: var(--surface-3); color: var(--gold); }

.sync-pill { display: inline-flex; align-items: center; gap: 7px; min-height: 34px; padding: 0 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--surface); font-size: 12px; white-space: nowrap; }
.sync-pill.syncing { color: var(--blue); }
.sync-pill.error { color: var(--red); border-color: rgba(255,133,124,.5); }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.workspace { min-height: 0; height: 100%; overflow: hidden; display: grid; grid-template-columns: minmax(390px, 480px) 1fr; }
.workspace.editing { grid-template-columns: minmax(720px, 62vw) minmax(0, 1fr); }
.content-pane { min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 18px 18px 100px; scrollbar-color: var(--line) transparent; }
.map-pane { min-width: 0; min-height: 0; position: relative; border-left: 1px solid var(--line-soft); }
#map { width: 100%; height: 100%; background: #dce5eb; }
.view-hidden { display: none !important; }

.section-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-title > div { min-width: 0; }
.section-title h1, .section-title h2 { margin: 0; }
.section-title h1 { font-size: 21px; color: var(--gold); }
.section-title h2 { font-size: 18px; }
.section-title p { margin: 5px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }

.card { border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--surface); box-shadow: 0 8px 24px rgba(0,0,0,.1); }
.hero-card { padding: 20px; border-color: #3b526c; background: #19232e; }
.eyebrow { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.hero-card h2 { margin: 8px 0 5px; font-size: 27px; line-height: 1.22; }
.hero-card .route { color: var(--muted); font-size: 15px; }
.metric-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.metric { min-width: 0; padding: 11px; border-radius: 12px; background: rgba(255,255,255,.035); }
.metric span { display: block; color: var(--quiet); font-size: 11px; }
.metric strong { display: block; margin-top: 4px; color: var(--blue); font-size: 16px; }

.notice { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; padding: 11px 13px; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--surface-2); color: var(--muted); font-size: 13px; line-height: 1.55; }
.notice.warning { border-color: rgba(255,182,90,.35); color: #ffd29c; }
.notice.success { border-color: rgba(127,224,170,.28); color: var(--green); }

.primary-button, .secondary-button, .ghost-button, .danger-button, .icon-button {
  min-height: 44px;
  border-radius: 11px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  text-decoration: none;
}
.primary-button { padding: 0 16px; background: #1d6542; border-color: #2d8058; color: #c3f7d8; font-weight: 700; }
.secondary-button { padding: 0 14px; background: var(--surface-3); border-color: var(--line); color: #d6e5f2; }
.ghost-button { padding: 0 12px; background: transparent; border-color: var(--line); color: var(--muted); }
.danger-button { padding: 0 12px; background: rgba(138,42,43,.28); border-color: rgba(255,133,124,.4); color: var(--red); }
.icon-button { width: 44px; padding: 0; background: var(--surface-3); border-color: var(--line); }
.primary-button:disabled, .secondary-button:disabled, .ghost-button:disabled { opacity: .45; cursor: not-allowed; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }

.today-stack { display: grid; gap: 12px; }
.next-card { padding: 16px; }
.next-card .label { color: var(--muted); font-size: 12px; }
.next-card h3 { margin: 5px 0 3px; font-size: 20px; line-height: 1.3; }
.next-card .meta { color: var(--muted); font-size: 13px; line-height: 1.55; }
.next-card .primary-button, .next-card .secondary-button { width: 100%; margin-top: 12px; }
.risk-card { border-left: 3px solid var(--orange); }

.progress-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.progress-track { flex: 1; height: 7px; overflow: hidden; border-radius: 999px; background: #0f151c; }
.progress-value { height: 100%; border-radius: inherit; background: var(--gold); }
.progress-row span { color: var(--muted); font-size: 12px; }

.timeline { margin: 12px 0 0 6px; padding-left: 17px; border-left: 2px solid #3b5268; }
.timeline-item { position: relative; padding: 0 0 11px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.timeline-item::before { content: ""; position: absolute; left: -22px; top: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 3px var(--surface); }
.timeline-item strong { color: var(--text); margin-right: 7px; }

.itinerary-toolbar { position: sticky; top: -18px; z-index: 30; margin: -2px -18px 13px; padding: 12px 18px; background: rgba(15,20,25,.94); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line-soft); }
.day-strip { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 7px; scrollbar-width: none; }
.day-strip::-webkit-scrollbar { display: none; }
.day-chip { min-width: 48px; height: 42px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--muted); cursor: pointer; }
.day-chip.active { border-color: var(--gold); background: var(--gold-deep); color: var(--gold); font-weight: 700; }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.summary-card { padding: 14px; }
.summary-card .top { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.summary-card strong { display: block; margin-top: 7px; color: var(--gold); font-size: 20px; }

.day-card { margin-bottom: 11px; overflow: hidden; }
.day-card.selected { border-color: #506b87; }
.day-header { width: 100%; min-height: 78px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 11px; padding: 12px 14px; border: 0; background: transparent; text-align: left; cursor: pointer; }
.day-number { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--gold); color: #161616; font-weight: 800; }
.day-heading { min-width: 0; }
.day-heading strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.day-heading span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day-stats { text-align: right; color: var(--blue); font-size: 12px; line-height: 1.5; white-space: nowrap; }
.day-body { padding: 0 14px 14px; border-top: 1px solid var(--line-soft); }
.drive-summary { margin: 12px 0; padding: 10px 12px; border-radius: 10px; background: #162532; color: var(--blue); font-size: 13px; line-height: 1.6; }
.status-tag { display: inline-flex; align-items: center; min-height: 22px; padding: 0 7px; border-radius: 7px; font-size: 10px; }
.status-tag.tight { background: #55272a; color: #ff9b94; }
.status-tag.locked { background: #523324; color: #ffb48f; }
.status-tag.active { background: #4e4520; color: var(--gold); }
.status-tag.stale { background: #4e3921; color: var(--orange); }

.slot { margin-top: 10px; padding: 12px; border-left: 3px solid #53687e; border-radius: 11px; background: var(--surface-2); }
.slot.locked { border-left-color: #ff8a65; }
.option { padding: 10px 0; border-top: 1px solid var(--line-soft); }
.option:first-of-type { border-top: 0; }
.option.inactive { opacity: .74; }
.option-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.option-head strong { font-size: 14px; }
.option p { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.option .tip { color: #8fd4aa; }
.option-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }

.booking-box { margin-top: 12px; display: grid; gap: 8px; }
.field-label { color: var(--muted); font-size: 12px; }
.text-input, .number-input, .select-input, .text-area {
  width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: #111820; color: var(--text); padding: 10px 11px; outline: none;
}
.text-area { min-height: 76px; resize: vertical; line-height: 1.55; }
.text-input:focus, .number-input:focus, .select-input:focus, .text-area:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255,209,102,.11); }
.cost-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.cost-field { display: grid; gap: 5px; }

.budget-list, .checklist { display: grid; gap: 8px; }
.budget-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; font-size: 13px; }
.budget-row .amount { color: var(--gold); }
.budget-row .actual { color: var(--muted); }
.check-item { min-height: 44px; display: flex; align-items: flex-start; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.check-item:last-child { border-bottom: 0; }
.check-item input { width: 19px; height: 19px; margin-top: 1px; accent-color: var(--gold); }
.check-item.checked span { color: var(--quiet); text-decoration: line-through; }

.edit-panel { display: grid; gap: 12px; margin-bottom: 14px; padding: 14px; border: 1px solid #4d6074; border-radius: 14px; background: #151e28; }
.edit-panel h3 { margin: 0; color: var(--gold); font-size: 15px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.form-field { display: grid; gap: 5px; }
.form-field.full { grid-column: 1 / -1; }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.desktop-preview { position: sticky; top: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 24px; background: #090d11; box-shadow: var(--shadow); }
.desktop-preview .phone-screen { max-height: calc(100dvh - 130px); overflow-y: auto; border-radius: 18px; padding: 14px; background: var(--bg); }
.desktop-preview .hero-card h2 { font-size: 21px; }

.map-tools { position: absolute; z-index: 700; top: 12px; right: 12px; display: grid; gap: 8px; }
.map-tools button { min-height: 44px; padding: 0 12px; border: 1px solid #4c6076; border-radius: 11px; background: rgba(19,27,36,.93); color: var(--text); box-shadow: 0 5px 18px rgba(0,0,0,.24); cursor: pointer; }
.map-tools button.active { color: var(--gold); border-color: #8b7130; background: rgba(87,70,27,.95); }
.map-day-label { position: absolute; z-index: 700; left: 58px; top: 12px; max-width: calc(100% - 238px); padding: 10px 12px; border-radius: 11px; background: rgba(19,27,36,.93); box-shadow: 0 5px 18px rgba(0,0,0,.22); }
.map-day-label strong { display: block; color: var(--gold); font-size: 13px; }
.map-day-label span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.map-legend { position: absolute; z-index: 700; left: 12px; bottom: 14px; padding: 9px 11px; border-radius: 10px; background: rgba(19,27,36,.93); color: var(--muted); font-size: 12px; box-shadow: 0 5px 18px rgba(0,0,0,.22); }
.marker-dot { width: 28px; height: 28px; display: grid; place-items: center; border: 2px solid white; border-radius: 50%; background: #e65454; color: #fff; font-size: 12px; font-weight: 800; box-shadow: 0 2px 8px rgba(0,0,0,.42); }
.marker-dot.stay { background: var(--gold); color: #111; }
.marker-dot.start { background: #4f9e71; }
.marker-dot.custom { background: #13a88b; }

.mobile-nav { display: none; }
.toast-region { position: fixed; z-index: 2000; right: 16px; bottom: 16px; display: grid; gap: 8px; pointer-events: none; }
.toast { min-width: 240px; max-width: min(390px, calc(100vw - 32px)); padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: #202c39; box-shadow: var(--shadow); color: var(--text); font-size: 13px; animation: toast-in .2s ease-out; }
.toast.error { border-color: rgba(255,133,124,.5); color: #ffc1bc; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

.modal-backdrop { position: fixed; z-index: 1600; inset: 0; display: grid; place-items: center; padding: 18px; background: rgba(0,0,0,.68); }
.modal { width: min(520px, 100%); max-height: min(760px, calc(100dvh - 36px)); overflow-y: auto; padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 8px; font-size: 20px; }
.modal p { margin: 0 0 16px; color: var(--muted); line-height: 1.65; }

@media (max-width: 1200px) {
  .workspace.editing { grid-template-columns: minmax(540px, 58vw) minmax(0, 1fr); }
  .editor-layout { grid-template-columns: 1fr; }
  .desktop-preview { display: none; }
}

@media (max-width: 800px) {
  body { overflow: hidden; }
  .app-shell { grid-template-rows: 1fr; }
  .topbar { display: none; }
  .workspace { display: block; height: 100dvh; }
  .content-pane, .map-pane { width: 100%; height: calc(100dvh - 66px - env(safe-area-inset-bottom)); border: 0; }
  .content-pane { padding: max(16px, env(safe-area-inset-top)) 16px 96px; }
  .map-pane { position: relative; }
  .mobile-nav {
    position: fixed; z-index: 1200; left: 0; right: 0; bottom: 0;
    height: calc(66px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    display: grid; grid-template-columns: repeat(3, 1fr);
    background: rgba(13,19,25,.98); border-top: 1px solid var(--line-soft);
  }
  .mobile-nav button { min-height: 58px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; align-content: center; gap: 3px; cursor: pointer; }
  .mobile-nav i { font-size: 22px; }
  .mobile-nav span { font-size: 12px; }
  .mobile-nav button.active { color: var(--gold); font-weight: 700; }
  .mobile-sync { position: fixed; z-index: 1100; top: max(10px, env(safe-area-inset-top)); right: 12px; }
  .section-title { padding-right: 86px; }
  .section-title h1 { overflow-wrap: anywhere; }
  .section-title h1 { font-size: 19px; }
  .hero-card { padding: 18px; }
  .hero-card h2 { font-size: 25px; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-field.full { grid-column: auto; }
  .edit-only-desktop { display: none !important; }
  .itinerary-toolbar { top: calc(-1 * max(16px, env(safe-area-inset-top))); }
  .map-tools { top: max(12px, env(safe-area-inset-top)); }
  .map-day-label { top: max(12px, env(safe-area-inset-top)); }
  .map-legend { bottom: 12px; }
  .toast-region { bottom: calc(82px + env(safe-area-inset-bottom)); }
}

@media (max-width: 380px) {
  .metric-row { grid-template-columns: 1fr 1fr; }
  .metric:last-child { grid-column: 1 / -1; }
  .cost-grid, .summary-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
