/* ============ MapFly 自驾路书 ============ */
:root {
  --bg: #f4f5f7;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --panel-border: rgba(0, 0, 0, 0.08);
  --text: #1c1f26;
  --text-2: #5b6170;
  --text-3: #9aa0ad;
  --accent: #ff6a3d;
  --accent-2: #ff3d71;
  --accent-grad: linear-gradient(135deg, #ff7a45 0%, #ff3d71 100%);
  --accent-soft: rgba(255, 106, 61, 0.12);
  --ok: #10b981;
  --danger: #ef4444;
  --hover: rgba(0, 0, 0, 0.045);
  --shadow: 0 10px 30px rgba(20, 24, 40, 0.14), 0 2px 6px rgba(20, 24, 40, 0.06);
  --shadow-sm: 0 2px 8px rgba(20, 24, 40, 0.10);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 360px;
  --topbar-h: 58px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}
[data-theme="dark"] {
  --bg: #0f1117;
  --panel: rgba(22, 25, 34, 0.84);
  --panel-solid: #171a23;
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #eef0f5;
  --text-2: #a7adbb;
  --text-3: #6b7180;
  --accent: #ff7a52;
  --accent-2: #ff4d7d;
  --accent-soft: rgba(255, 122, 82, 0.16);
  --hover: rgba(255, 255, 255, 0.06);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(128, 128, 140, 0.35); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(128, 128, 140, 0.6); }

.app { position: relative; width: 100%; height: 100%; }
#map { position: absolute; inset: 0; background: var(--bg); z-index: 0; }

/* ---------- Top bar ---------- */
.topbar {
  position: absolute; top: 12px; left: 12px; right: 12px; height: var(--topbar-h);
  z-index: 1000; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 14px 0 12px;
  background: var(--panel); backdrop-filter: blur(18px) saturate(160%); -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--panel-border); border-radius: var(--radius); box-shadow: var(--shadow);
  pointer-events: auto;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .logo {
  width: 36px; height: 36px; border-radius: 11px; background: var(--accent-grad);
  display: grid; place-items: center; font-size: 19px; color: #fff; box-shadow: 0 4px 12px rgba(255, 90, 80, 0.4);
}
.brand .title { font-weight: 700; font-size: 15px; letter-spacing: .2px; line-height: 1.1; }
.brand .sub { font-size: 11.5px; color: var(--text-2); margin-top: 2px; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 13px;
  border-radius: 10px; border: 1px solid var(--panel-border); background: var(--panel-solid);
  color: var(--text); font-weight: 500; transition: all .15s ease; white-space: nowrap;
}
.btn:hover { background: var(--hover); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--accent-grad); color: #fff; border: none; box-shadow: 0 4px 14px rgba(255, 90, 80, 0.35); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.icon { width: 34px; padding: 0; justify-content: center; font-size: 16px; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(239, 68, 68, 0.1); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

select.select, input.input {
  height: 34px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--panel-border);
  background: var(--panel-solid); color: var(--text); outline: none;
}
select.select { padding-right: 26px; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
input.input:focus, select.select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- Sidebar ---------- */
.sidebar {
  position: absolute; top: calc(var(--topbar-h) + 24px); left: 12px; bottom: 12px; width: var(--sidebar-w);
  z-index: 900; display: flex; flex-direction: column;
  background: var(--panel); backdrop-filter: blur(18px) saturate(160%); -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--panel-border); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .25s cubic-bezier(.4, 0, .2, 1), opacity .2s;
  overflow: hidden;
}
.sidebar.collapsed { transform: translateX(calc(-100% - 20px)); opacity: 0; pointer-events: none; }
.sidebar-toggle {
  position: absolute; top: calc(var(--topbar-h) + 34px); left: calc(var(--sidebar-w) + 20px); z-index: 901;
  width: 26px; height: 40px; border-radius: 0 10px 10px 0; border: 1px solid var(--panel-border); border-left: none;
  background: var(--panel); backdrop-filter: blur(10px); box-shadow: var(--shadow-sm); color: var(--text-2);
  transition: left .25s cubic-bezier(.4, 0, .2, 1);
}
.sidebar-toggle.collapsed { left: 12px; border-radius: 10px; border-left: 1px solid var(--panel-border); }
.tabs { display: flex; padding: 8px 8px 0; gap: 4px; border-bottom: 1px solid var(--panel-border); }
.tabs button {
  flex: 1; height: 36px; border: none; background: transparent; color: var(--text-2); font-weight: 600;
  border-bottom: 2px solid transparent; border-radius: 8px 8px 0 0; transition: all .15s;
}
.tabs button:hover { background: var(--hover); color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.tab-panel[hidden] { display: none; }

.empty {
  text-align: center; padding: 32px 16px; color: var(--text-3); line-height: 1.7;
  border: 1.5px dashed var(--panel-border); border-radius: var(--radius-sm);
}
.empty .big { font-size: 36px; margin-bottom: 8px; }
.empty b { color: var(--text-2); }

/* File cards */
.file-card { border: 1px solid var(--panel-border); border-radius: var(--radius-sm); background: var(--panel-solid); overflow: hidden; }
.file-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 8px; }
.file-head .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.file-head .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-head .meta { font-size: 11.5px; color: var(--text-3); white-space: nowrap; }
.file-actions { display: flex; gap: 2px; }
.iconbtn {
  width: 26px; height: 26px; border-radius: 7px; border: none; background: transparent; color: var(--text-2);
  display: grid; place-items: center; font-size: 13px; transition: all .12s;
}
.iconbtn:hover { background: var(--hover); color: var(--text); }
.iconbtn.danger:hover { background: rgba(239, 68, 68, 0.12); color: var(--danger); }
.iconbtn.off { opacity: .35; }

.tree { padding: 0 6px 8px; }
.tree-node { user-select: none; }
.tree-row {
  display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 7px; cursor: pointer;
  transition: background .12s;
}
.tree-row:hover { background: var(--hover); }
.tree-row.selected { background: var(--accent-soft); }
.tree-row input[type="checkbox"] { accent-color: var(--accent); margin: 0; flex: none; }
.tree-row .caret { width: 14px; font-size: 10px; color: var(--text-3); text-align: center; transition: transform .15s; flex: none; }
.tree-row .caret.open { transform: rotate(90deg); }
.tree-row .glyph { width: 16px; text-align: center; flex: none; font-size: 12px; }
.tree-row .dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .15); flex: none; }
.tree-row .line { width: 16px; height: 4px; border-radius: 2px; flex: none; }
.tree-row .poly { width: 14px; height: 10px; border-radius: 2px; opacity: .75; flex: none; }
.tree-row .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .meta { font-size: 11px; color: var(--text-3); font-family: var(--mono); white-space: nowrap; }
.tree-row.folder .label { font-weight: 600; }
.tree-children { margin-left: 16px; border-left: 1px solid var(--panel-border); padding-left: 2px; }
.tree-children[hidden] { display: none; }

.options { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--text-2); }
.options label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.options input { accent-color: var(--accent); margin: 0; }

/* ---------- Detail panel ---------- */
.detail-title { font-size: 16px; font-weight: 700; line-height: 1.3; display: flex; align-items: center; gap: 8px; }
.detail-title .swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.detail-sub { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--panel-solid); border: 1px solid var(--panel-border); border-radius: var(--radius-sm); padding: 10px 12px; }
.stat .k { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .5px; }
.stat .v { font-size: 18px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 11px; color: var(--text-2); font-weight: 500; margin-left: 2px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.desc {
  background: var(--panel-solid); border: 1px solid var(--panel-border); border-radius: var(--radius-sm);
  padding: 10px 12px; line-height: 1.6; color: var(--text-2); font-size: 12.5px; word-break: break-word; overflow: auto; max-height: 220px;
}
.desc img { max-width: 100%; border-radius: 6px; }
.desc a { color: var(--accent); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 12.5px; }
.kv .k { color: var(--text-3); }
.kv .v { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.section-title { font-size: 11.5px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .6px; margin-top: 4px; }
.color-row { display: flex; align-items: center; gap: 8px; }
.color-row input[type="color"] { width: 32px; height: 28px; border: 1px solid var(--panel-border); border-radius: 7px; padding: 2px; background: var(--panel-solid); cursor: pointer; }
.color-row input[type="range"] { flex: 1; accent-color: var(--accent); }

/* ---------- Plan panel ---------- */
.search-wrap { position: relative; }
.search-wrap input { width: 100%; padding-left: 32px; }
.search-wrap .ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search-results {
  position: absolute; left: 0; right: 0; top: 38px; z-index: 5; background: var(--panel-solid);
  border: 1px solid var(--panel-border); border-radius: var(--radius-sm); box-shadow: var(--shadow); overflow: hidden; max-height: 260px; overflow-y: auto;
}
.search-results div { padding: 9px 12px; cursor: pointer; font-size: 12.5px; border-bottom: 1px solid var(--panel-border); line-height: 1.4; }
.search-results div:last-child { border-bottom: none; }
.search-results div:hover { background: var(--hover); }
.search-results .muted { color: var(--text-3); font-size: 11.5px; }
.plan-toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.wp-list { display: flex; flex-direction: column; gap: 6px; }
.wp {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--panel-solid);
  border: 1px solid var(--panel-border); border-radius: var(--radius-sm); transition: all .12s;
}
.wp:hover { border-color: var(--accent); }
.wp .num {
  width: 24px; height: 24px; border-radius: 50%; background: var(--accent-grad); color: #fff; font-weight: 700; font-size: 12px;
  display: grid; place-items: center; flex: none;
}
.wp .num.start { background: var(--ok); }
.wp .num.end { background: var(--danger); }
.wp .wp-name { flex: 1; min-width: 0; }
.wp .wp-name input { width: 100%; border: none; background: transparent; padding: 0; font-weight: 600; outline: none; }
.wp .wp-name input:focus { border-bottom: 1px solid var(--accent); }
.wp .wp-coord { font-size: 11px; color: var(--text-3); font-family: var(--mono); }
.wp .wp-btns { display: flex; gap: 0; }
.leg { font-size: 11.5px; color: var(--text-3); padding: 0 0 0 44px; display: flex; gap: 10px; font-family: var(--mono); }
.plan-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hint { font-size: 12px; color: var(--text-3); line-height: 1.6; }
.hint kbd { font-family: var(--mono); font-size: 11px; background: var(--hover); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--panel-border); }

/* ---------- Bottom panel ---------- */
.bottom-panel {
  position: absolute; left: calc(var(--sidebar-w) + 36px); right: 12px; bottom: 12px; z-index: 900;
  background: var(--panel); backdrop-filter: blur(18px) saturate(160%); -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--panel-border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 14px 12px; transition: left .25s cubic-bezier(.4, 0, .2, 1);
  animation: slideUp .25s ease;
}
.bottom-panel.full { left: 12px; }
.bottom-panel[hidden] { display: none; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
.bp-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.bp-head .t { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bp-head .m { font-size: 12px; color: var(--text-2); font-family: var(--mono); }
.fly { display: flex; align-items: center; gap: 10px; }
.fly .progress { flex: 1; height: 6px; background: var(--hover); border-radius: 4px; position: relative; cursor: pointer; }
.fly .progress > i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--accent-grad); border-radius: 4px; }
.fly .speed { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.fly .speed input { width: 90px; accent-color: var(--accent); }
.fly .pos { font-family: var(--mono); font-size: 12px; color: var(--text-2); min-width: 130px; text-align: right; }
canvas#elev { width: 100%; height: 110px; display: block; border-radius: 8px; }
.elev-wrap { position: relative; margin-top: 6px; }
.elev-wrap.hidden { display: none; }
.elev-tip {
  position: absolute; top: 4px; left: 8px; font-size: 11.5px; font-family: var(--mono); color: var(--text-2);
  background: var(--panel-solid); padding: 2px 8px; border-radius: 6px; border: 1px solid var(--panel-border); pointer-events: none;
}

/* ---------- Map overlays ---------- */
.drop-overlay {
  position: absolute; inset: 0; z-index: 2000; display: grid; place-items: center;
  background: rgba(255, 106, 61, 0.14); backdrop-filter: blur(6px); border: 4px dashed var(--accent); border-radius: 20px;
  font-size: 22px; font-weight: 700; color: var(--accent); pointer-events: none;
}
.drop-overlay[hidden] { display: none; }
.toast {
  position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); z-index: 3000;
  background: #1c1f26; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  opacity: 0; transition: all .25s; pointer-events: none; font-size: 13px; max-width: 70vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
.map-hint {
  position: absolute; top: calc(var(--topbar-h) + 24px); left: 50%; transform: translateX(-50%); z-index: 950;
  background: var(--accent-grad); color: #fff; padding: 8px 16px; border-radius: 10px; font-weight: 600; box-shadow: var(--shadow);
  animation: slideUp .2s ease;
}
.map-hint[hidden] { display: none; }
.crosshair-cursor { cursor: crosshair !important; }

/* Leaflet restyle */
.leaflet-container { font-family: var(--font); }
.leaflet-top.leaflet-right { top: calc(var(--topbar-h) + 24px); right: 12px; }
.leaflet-bar { border: 1px solid var(--panel-border) !important; box-shadow: var(--shadow-sm) !important; border-radius: 10px !important; overflow: hidden; }
.leaflet-bar a { background: var(--panel) !important; color: var(--text) !important; border-bottom-color: var(--panel-border) !important; backdrop-filter: blur(10px); width: 32px !important; height: 32px !important; line-height: 32px !important; }
.leaflet-bar a:hover { background: var(--hover) !important; }
.leaflet-control-attribution { background: var(--panel) !important; color: var(--text-3) !important; font-size: 10px !important; border-radius: 6px 0 0 0; }
.leaflet-control-attribution a { color: var(--text-2) !important; }
.leaflet-control-scale-line { background: var(--panel) !important; color: var(--text-2) !important; border-color: var(--text-3) !important; font-size: 10px; }
.leaflet-popup-content-wrapper { background: var(--panel-solid); color: var(--text); border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--panel-border); }
.leaflet-popup-tip { background: var(--panel-solid); }
.leaflet-popup-content { margin: 12px 14px; line-height: 1.5; font-size: 13px; }
.popup-title { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.popup-meta { font-size: 12px; color: var(--text-2); font-family: var(--mono); }
.popup-desc { font-size: 12px; color: var(--text-2); margin-top: 4px; max-height: 120px; overflow: auto; }
.popup-desc img { max-width: 100%; }
.popup-btn { margin-top: 8px; display: inline-block; padding: 4px 10px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12px; cursor: pointer; }
.leaflet-tooltip { background: var(--panel-solid); color: var(--text); border: 1px solid var(--panel-border); border-radius: 7px; box-shadow: var(--shadow-sm); font-size: 12px; font-weight: 600; padding: 3px 8px; }
.leaflet-tooltip.label { background: rgba(255, 255, 255, 0.85); border: none; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); font-weight: 600; font-size: 11.5px; color: #222; padding: 2px 6px; }
[data-theme="dark"] .leaflet-tooltip.label { background: rgba(20, 22, 30, 0.85); color: #eee; }
.leaflet-tooltip-top:before, .leaflet-tooltip-bottom:before, .leaflet-tooltip-left:before, .leaflet-tooltip-right:before { display: none; }
[data-theme="dark"] .leaflet-layer.dimmable { filter: brightness(.85); }
.leaflet-layer.tiles-dark { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.75); }

/* markers */
.pin { position: relative; width: 24px; height: 32px; }
.pin .pin-body {
  position: absolute; left: 3px; top: 0; width: 18px; height: 18px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  border: 2.5px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}
.pin .pin-body::after { content: ""; position: absolute; left: 4px; top: 4px; width: 5px; height: 5px; border-radius: 50%; background: rgba(255, 255, 255, .85); }
.pin.selected .pin-body { transform: rotate(-45deg) scale(1.25); }
.wp-marker { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-grad); color: #fff; font-weight: 700; font-size: 12.5px; display: grid; place-items: center; border: 2.5px solid #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .35); cursor: grab; }
.wp-marker.start { background: #10b981; }
.wp-marker.end { background: #ef4444; }
.endpoint { padding: 2px 8px; border-radius: 6px; color: #fff; font-weight: 700; font-size: 11px; white-space: nowrap; box-shadow: 0 2px 6px rgba(0, 0, 0, .35); border: 1.5px solid #fff; }
.endpoint.start { background: #10b981; }
.endpoint.end { background: #ef4444; }
.car { font-size: 26px; line-height: 1; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .4)); transition: transform .1s linear; transform-origin: center; }
.elev-cursor { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); box-shadow: 0 0 0 4px rgba(255, 106, 61, .3); }

/* animated flow on selected route */
.route-flow { stroke-dasharray: 4 16; animation: flow 1.2s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -20; } }
.route-glow { filter: blur(3px); }

/* responsive */
@media (max-width: 860px) {
  :root { --sidebar-w: min(320px, calc(100vw - 24px)); }
  .brand .sub { display: none; }
  .bottom-panel { left: 12px; }
  .topbar-actions .btn span.txt { display: none; }
}
