:root {
  --bg: #12151b;
  --panel: #1b1f27;
  --panel-2: #232833;
  --line: #303645;
  --text: #e8ebf0;
  --muted: #9aa3b2;
  --accent: #4fd1c5;
  --accent-2: #38a89d;
  --danger: #ff5c5c;
  --ok: #3ddc84;
  --warn: #ffb020;
  --radius: 10px;
  --side-w: 360px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); min-height: 100vh; }
a { color: var(--accent); }
h2 { margin: 0; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }
button, input, select { font: inherit; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); padding: 8px 16px; border-radius: 999px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #062421; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-ghost { background: transparent; }
.btn-danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn-sm { padding: 4px 12px; font-size: 13px; }
input[type=text], input[type=search], select { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; min-width: 0; }
input[type=text]:focus, input[type=search]:focus, select:focus { outline: none; border-color: var(--accent); }

/* ---------- app shell ---------- */
.app-body { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel); z-index: 1000; flex: none; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.brand .muted { font-weight: 400; font-size: 13px; }
.top-right { display: flex; align-items: center; gap: 12px; }
.user { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.user img { width: 28px; height: 28px; border-radius: 50%; }
.side-toggle { display: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 4px 12px; cursor: pointer; font-size: 13px; }
.seg button[aria-pressed=true] { background: var(--accent); color: #062421; font-weight: 600; }

.app { flex: 1; display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 0; }
.side { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; border-right: 1px solid var(--line); background: var(--bg); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }

.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px 14px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop:focus-visible, .drop.over { border-color: var(--accent); background: rgba(79, 209, 197, .06); outline: none; }
.drop-inner { display: grid; gap: 4px; }
.drop-inner .muted { font-size: 13px; }

/* ---------- detail ---------- */
.detail-head { display: flex; align-items: center; gap: 8px; }
.detail-head .name-input { flex: 1; font-weight: 600; background: transparent; border-color: transparent; padding: 4px 6px; }
.detail-head .name-input:hover { border-color: var(--line); }
.detail-head .name-input:focus { border-color: var(--accent); background: var(--panel-2); }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; flex: none; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.stat b { display: block; font-size: 18px; font-weight: 650; }
.stat span { font-size: 12px; color: var(--muted); }
#detail-sub { margin: 0; }

/* ---------- library ---------- */
.lib-panel { flex: 1; align-content: start; }
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lib-head select { font-size: 13px; padding: 4px 8px; }
.lib { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.lib li { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.lib li.selected { border-color: var(--accent); }
.lib li .main { min-width: 0; cursor: pointer; }
.lib li .title { display: block; font-size: 14px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib li .meta { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib li .acts { display: flex; gap: 4px; }
.lib li .acts button { padding: 2px 8px; font-size: 12px; }
.lib li .vis { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 0; }
.lib li .local-tag { font-size: 11px; color: var(--warn); margin-left: 6px; font-weight: 400; }
.lib li.confirming { border-color: var(--danger); }

/* ---------- map ---------- */
.mapwrap { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
#map { flex: 1; min-height: 0; background: #0d1015; }
.drop-overlay { position: absolute; inset: 0; z-index: 900; display: grid; place-items: center; background: rgba(18, 21, 27, .7); border: 3px dashed var(--accent); pointer-events: none; }
.drop-overlay span { background: var(--panel); padding: 14px 22px; border-radius: var(--radius); font-weight: 600; }
.leaflet-container { font: 13px/1.4 var(--font); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.leaflet-popup-content { margin: 10px 14px; }
.leaflet-popup-content b { display: block; margin-bottom: 2px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-control-layers, .leaflet-bar a, .leaflet-control-zoom a { background: var(--panel); color: var(--text); border-color: var(--line) !important; }
.leaflet-control-layers-expanded { color: var(--text); }
.leaflet-bar a:hover { background: var(--panel-2); }
.leaflet-control-attribution { background: rgba(27, 31, 39, .8) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--accent); }
.map-btn { width: 30px; height: 30px; line-height: 30px; text-align: center; font-size: 16px; cursor: pointer; display: block; }
.pin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .5); }
.pin.start { background: var(--ok); }
.pin.end { background: var(--danger); }
.pin.hover { background: #fff; border-color: #111; width: 12px; height: 12px; }

/* ---------- elevation profile ---------- */
.profile { flex: none; height: 190px; border-top: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
.profile-head { display: flex; align-items: center; gap: 12px; padding: 6px 12px 0; }
.profile-head .muted { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-body { position: relative; flex: 1; min-height: 0; }
#profile-canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.profile-tip { position: absolute; top: 6px; pointer-events: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 12px; white-space: nowrap; }
.profile-empty { margin: 0; padding: 30px; text-align: center; }
.profile-show { position: absolute; left: 12px; bottom: 28px; z-index: 800; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 2000; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; max-width: min(560px, calc(100vw - 32px)); box-shadow: 0 10px 30px rgba(0, 0, 0, .4); }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; }
.login { padding: 24px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px; max-width: 420px; text-align: center; display: grid; gap: 14px; justify-items: center; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-status { margin: 0; color: var(--muted); }
.login-status.error { color: var(--danger); }
.gsi { min-height: 44px; }

/* ---------- cookie notice ---------- */
.consent { position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 3000; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); max-width: 900px; margin: 0 auto; }
.consent p { margin: 0; font-size: 14px; color: var(--muted); flex: 1 1 380px; }
.consent-actions { display: flex; gap: 8px; }

/* ---------- phones / narrow ---------- */
@media (max-width: 820px) {
  .top { padding: 8px 12px; }
  .brand .muted, .brand img, .user span { display: none; }
  .side-toggle { display: inline-flex; }
  .app { grid-template-columns: 1fr; position: relative; }
  .side { position: absolute; inset: 0 auto 0 0; width: min(var(--side-w), 92vw); z-index: 950; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 10px 0 30px rgba(0, 0, 0, .5); }
  .profile { height: 150px; }
}
@media (max-width: 420px) {
  .top-right { gap: 8px; }
  .user { display: none; }
}
