* { box-sizing: border-box; margin: 0; padding: 0; }
body { display: flex; flex-direction: column; height: 100vh; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; overflow: hidden; }

/* ── 지도 로딩 오버레이 ── */
#map-loader {
  position: fixed; inset: 0; background: rgba(255,255,255,0.75);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  z-index: 9000; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  transition: opacity 0.3s ease;
}
#map-loader.fade-out { opacity: 0; pointer-events: none; }
#map-loader .loader-spinner {
  width: 38px; height: 38px;
  border: 3px solid #e5e7eb; border-top-color: #16a34a;
  border-radius: 50%; animation: loader-spin 0.75s linear infinite;
}
#map-loader .loader-text { font-size: 13px; color: #94a3b8; font-weight: 500; }
@keyframes loader-spin { to { transform: rotate(360deg); } }

/* ── 메인 헤더 ── */
#main-header {
  height: 56px; flex-shrink: 0;
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  display: flex; align-items: center;
  gap: 8px; padding: 0 16px;
  position: relative; z-index: 4000;
}
#mh-logo {
  font-size: 20px; font-weight: 800;
  color: #16a34a; text-decoration: none;
  white-space: nowrap; flex-shrink: 0;
  padding: 5px 8px; border-radius: 6px;
  transition: background 0.15s;
  display: inline-flex; align-items: center; gap: 6px;
}
#mh-logo:hover { background: #f0fdf4; }
.mh-logo-icon { width: 22px; height: 22px; border-radius: 5px; flex-shrink: 0; }
/* 서브페이지 nav 링크 (about, marathon 등) */
.mh-nav { display: flex; gap: 2px; flex-shrink: 0; margin-left: auto; }
.mh-link {
  padding: 6px 12px;
  color: #4b5563; font-size: 14px; font-weight: 500;
  text-decoration: none; border-radius: 6px; white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.mh-link:hover { background: #f3f4f6; color: #111827; }
.mh-search-wrap {
  flex: 1; max-width: 480px;
  margin-left: 8px; position: relative;
}

/* ── 앱 바디 ── */
#app-body { display: flex; flex: 1; overflow: hidden; min-height: 0; }

/* ── 서브페이지 푸터 ── */
#main-footer {
  flex-shrink: 0; height: 40px;
  background: #ffffff; border-top: 1px solid #e5e7eb;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
}
.mf-copy { font-size: 12px; color: #9ca3af; }
.mf-links { display: flex; gap: 16px; }
.mf-link { font-size: 12px; color: #6b7280; text-decoration: none; transition: color 0.15s; }
.mf-link:hover { color: #111827; }

/* ── 사이드바: 전 화면 바텀 시트 ── */
#sidebar {
  position: fixed;
  bottom: calc(56px + env(safe-area-inset-bottom));
  left: 0; right: 0;
  height: 0;
  background: #ffffff;
  border-radius: 10px 10px 0 0;
  z-index: 2000;
  transition: height 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.14);
}
#sidebar.sb-expanded { height: calc(100vh - 168px); }
#sidebar.sb-peek    { height: calc((100vh - 112px) / 2); }
#sidebar.sb-min     { height: 76px; }

.sidebar-drag-handle {
  display: flex;
  height: 28px;
  align-items: center;
  cursor: grab;
  justify-content: center;
  cursor: grab;
  flex-shrink: 0;
  touch-action: none;
}
.sidebar-drag-handle::after {
  content: '';
  display: block;
  width: 40px; height: 4px;
  background: #d1d5db;
  border-radius: 2px;
}

/* ── 사이드바 필터 바 ── */
.sb-filter-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}
#sb-filter-trigger {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 10px; border: 1.5px solid #e2e8f0;
  border-radius: 99px; background: white;
  font-size: 12px; font-weight: 600; color: #374151;
  cursor: pointer; flex-shrink: 0; white-space: nowrap;
  transition: all 0.15s;
}
#sb-filter-trigger.has-filter { border-color: #16a34a; color: #16a34a; }
#sb-filter-chips {
  display: flex; gap: 5px; flex: 1; overflow-x: auto; scrollbar-width: none;
}
#sb-filter-chips::-webkit-scrollbar { display: none; }
.sb-active-chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 4px 8px; border-radius: 99px;
  background: #fff1f0; color: #e11d48;
  font-size: 11px; font-weight: 600; cursor: pointer;
  white-space: nowrap; flex-shrink: 0;
  border: 1px solid #fecdd3;
}
.sb-chip-x { font-size: 13px; line-height: 1; color: #f43f5e; }
#sb-filter-right {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0; margin-left: auto;
}
#sb-count-label { font-size: 11px; color: #9ca3af; white-space: nowrap; }
.upload-btn {
  padding: 5px 10px; background: #16a34a; color: white;
  border: none; border-radius: 6px; font-size: 12px; font-weight: 700;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.upload-btn:hover { background: #15803d; }

/* ── 코스 필터 팝업 ── */
#cf-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 4000; opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
#cf-backdrop.visible { opacity: 1; pointer-events: auto; }
#cf-popup {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #fff; border-radius: 20px 20px 0 0;
  z-index: 4100; display: flex; flex-direction: column;
  max-height: 75vh;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
#cf-popup.visible { transform: translateY(0); }
.cf-handle-bar { padding: 10px 0 4px; display: flex; justify-content: center; }
.cf-handle { width: 36px; height: 4px; background: #d1d5db; border-radius: 2px; }
.cf-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 16px 12px;
}
.cf-title { font-size: 16px; font-weight: 700; color: #0f172a; }
.cf-reset {
  font-size: 13px; color: #64748b; border: none; background: none;
  cursor: pointer; text-decoration: underline; padding: 0;
}
.cf-body { overflow-y: auto; flex: 1; padding: 0 16px 8px; }
.cf-section { margin-bottom: 20px; }
.cf-section-title {
  font-size: 12px; font-weight: 700; color: #94a3b8;
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px;
}
.cf-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.cf-chip {
  padding: 7px 14px; border: 1.5px solid #e2e8f0;
  border-radius: 99px; background: white;
  font-size: 13px; font-weight: 500; color: #475569;
  cursor: pointer; transition: all 0.15s;
}
.cf-chip.active {
  background: #f0fdf4; color: #16a34a;
  border-color: #16a34a; font-weight: 700;
}
.cf-footer {
  padding: 12px 16px; border-top: 1px solid #f1f5f9;
}
.cf-apply-btn {
  width: 100%; padding: 14px;
  background: #16a34a; color: white;
  border: none; border-radius: 12px;
  font-size: 15px; font-weight: 700; cursor: pointer;
}
.cf-apply-btn:active { background: #15803d; }
.region-btn { flex: none !important; }

#course-list {
  flex: 1; min-height: 0; overflow-y: auto; padding: 8px 8px 24px;
  display: flex; flex-direction: column; gap: 6px;
  overscroll-behavior: none;
}
#course-list::-webkit-scrollbar { width: 4px; }
#course-list::-webkit-scrollbar-track { background: transparent; }
#course-list::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 2px; }

.loading-msg { font-size: 12px; color: #9ca3af; padding: 16px 4px; text-align: center; }
.loading-msg.err { color: #dc2626; }
.area-filter-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; font-size: 12px; color: #6b7280;
  border-bottom: 1px solid #e5e7eb;
}
.area-filter-bar button {
  background: none; border: 1px solid #e5e7eb; border-radius: 6px;
  color: #2563eb; font-size: 11px; padding: 2px 8px; cursor: pointer;
}
.area-filter-bar button:hover { background: #f3f4f6; }

.course-item {
  display: flex; align-items: stretch; border-radius: 8px; overflow: hidden;
  cursor: pointer; background: #f9fafb; border: 1px solid #f1f5f9;
  transition: background 0.15s; flex-shrink: 0;
}
.course-item:hover { background: #f1f5f9; border-color: #e2e8f0; }
.ci-accent { width: 48px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.ci-thumb { padding: 0; overflow: hidden; }
.ci-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ci-body { flex: 1; padding: 8px 8px 8px 4px; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ci-badge { display: inline-block; padding: 1px 6px; border-radius: 99px; font-size: 10px; font-weight: 700; width: fit-content; }
.ci-name { font-size: 13px; font-weight: 600; color: #111827; line-height: 1.3; word-break: keep-all; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-stats { display: flex; gap: 8px; font-size: 11px; color: #6b7280; }

.sidebar-bottom {
  flex-shrink: 0; padding: 10px 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
  border-top: 1px solid #e5e7eb;
}
.section-label { font-size: 11px; color: #9ca3af; }
.toggle-wrap { display: flex; gap: 4px; flex-wrap: wrap; }
.toggle-btn {
  padding: 4px 10px; border: 1px solid #e5e7eb; border-radius: 12px;
  background: #ffffff; color: #6b7280; cursor: pointer; font-size: 11px; white-space: nowrap;
}
.toggle-btn.on { background: #16a34a; border-color: #16a34a; color: white; }
.side-btn {
  padding: 8px; border: 1px solid #e5e7eb; border-radius: 6px;
  cursor: pointer; font-size: 13px; width: 100%;
  background: #f9fafb; color: #374151; text-align: left;
}
.side-btn:hover { background: #f3f4f6; }
#btn-edit-toggle.active { background: #16a34a; border-color: #16a34a; color: white; }
.divider { border: none; border-top: 1px solid #e5e7eb; }

/* ── 지도 ── */
#map { flex: 1; position: relative; }
#map.edit-mode { cursor: crosshair; }

.map-fab {
  position: absolute; z-index: 1000;
  width: 40px; height: 40px; background: white; border: none; border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3); cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.map-fab:hover { background: #f0f0f0; }
.lb-hidden { display: none !important; }
#locate-btn { bottom: 144px; right: 12px; } /* JS가 시트 실측 위치를 매 프레임 추적해서 bottom 갱신 (main.css 참고: rAF 트래킹, transition 없음) */
.locate-status {
  position: absolute; z-index: 1000; right: 58px; bottom: 144px;
  background: white; padding: 5px 10px; border-radius: 99px;
  font-size: 11px; color: #374151; white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  display: none;
}
.locate-status.visible { display: block; }
#locate-btn svg { width: 22px; height: 22px; }

/* 헤더 검색 바 */
.map-search-inner {
  display: flex; align-items: center; gap: 8px;
  background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 8px;
  padding: 0 12px; height: 38px;
}
.map-search-icon { font-size: 15px; flex-shrink: 0; color: #9ca3af; }
#map-search-input { flex: 1; border: none; outline: none; font-size: 14px; color: #111827; background: transparent; }
#map-search-input::placeholder { color: #9ca3af; }
.map-search-clear { background: none; border: none; cursor: pointer; color: #9ca3af; font-size: 16px; padding: 0; display: flex; align-items: center; }
.map-search-clear:hover { color: #374151; }
.map-search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 300;
  background: white; border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.10); overflow: hidden;
}
.msr-item { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid #f1f5f9; }
.msr-item:last-child { border-bottom: none; }
.msr-item:hover { background: #f8fafc; }
.msr-course-item { background: #f0fdf4; }
.msr-course-item:hover { background: #dcfce7; }
.msr-name { font-size: 13px; font-weight: 600; color: #0f172a; }
.msr-addr { font-size: 11px; color: #94a3b8; }

#search-here-btn {
  position: absolute; z-index: 1000;
  top: 12px; left: 50%; transform: translateX(-50%);
  padding: 8px 16px; background: white; color: #111;
  border: 1.5px solid #d1d5db; border-radius: 20px;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15); cursor: pointer; white-space: nowrap;
  transition: box-shadow 0.15s;
}
#search-here-btn:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.2); }

/* ── 모달 ── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 9999;
  align-items: center; justify-content: center;
}
.modal-backdrop.visible { display: flex; }
.modal-box {
  background: white; border-radius: 12px; padding: 24px;
  width: 340px; display: flex; flex-direction: column; gap: 10px;
  max-height: 90vh; overflow-y: auto;
}
.modal-box h2 { font-size: 16px; color: #111; }
.label-opt { font-size: 11px; color: #94a3b8; font-weight: 400; }
.modal-box label { font-size: 13px; color: #444; margin-top: 2px; }
.modal-box input[type="text"] { padding: 8px 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 14px; width: 100%; outline: none; }
.modal-box input[type="text"]:focus { border-color: #2563eb; }
.modal-box textarea { padding: 8px 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 13px; width: 100%; resize: vertical; outline: none; font-family: inherit; line-height: 1.5; }
.modal-box textarea:focus { border-color: #2563eb; }
.modal-box .file-name { font-size: 12px; color: #888; background: #f3f4f6; padding: 6px 10px; border-radius: 6px; }
.replace-area { border: 2px dashed #ddd; border-radius: 6px; padding: 10px; text-align: center; font-size: 12px; color: #888; cursor: pointer; }
.replace-area:hover { border-color: #2563eb; color: #2563eb; }
.replace-area.selected { border-color: #16a34a; color: #16a34a; }
.modal-btns { display: flex; gap: 8px; margin-top: 4px; }
.modal-btns button { flex: 1; padding: 8px; border: none; border-radius: 6px; cursor: pointer; font-size: 14px; }
.btn-confirm { background: #2563eb; color: white; }
.btn-confirm:hover { background: #1d4ed8; }
.btn-cancel { background: #e5e7eb; color: #333; }

/* ── 멀티 이미지 업로드 프리뷰 ── */
.multi-photo-label { font-size: 13px; color: #444; margin-top: 2px; }
.multi-photo-row { display: flex; flex-wrap: wrap; gap: 8px; min-height: 72px; align-items: flex-start; }
.photo-preview-item { position: relative; width: 64px; height: 64px; border-radius: 6px; overflow: hidden; flex-shrink: 0; }
.photo-preview-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-preview-item button { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%; border: none; background: rgba(0,0,0,0.55); color: white; font-size: 12px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.photo-preview-add { width: 64px; height: 64px; border-radius: 6px; border: 2px dashed #d1d5db; background: #f9fafb; display: flex; align-items: center; justify-content: center; font-size: 22px; color: #94a3b8; cursor: pointer; flex-shrink: 0; }
.photo-preview-add:hover { border-color: #2563eb; color: #2563eb; }

/* ── 캐러셀 (코스 상세 페이지에서 재사용) ── */
.carousel-btn { position: absolute; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; border-radius: 50%; border: none; background: rgba(0,0,0,0.45); color: white; font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 3; }
.carousel-btn:hover { background: rgba(0,0,0,0.7); }
.carousel-prev { left: 8px; }
.carousel-next { right: 8px; }
.carousel-dots { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); display: flex; gap: 5px; z-index: 3; }
.cdot { width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,0.5); cursor: pointer; transition: background 0.2s; }
.cdot.active { background: white; }

/* ── 커스텀 마커 팝업 ── */
.add-popup { background: white; border-radius: 8px; padding: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.25); display: flex; flex-direction: column; gap: 6px; }
.add-popup input { padding: 4px 8px; border-radius: 4px; border: 1px solid #ccc; font-size: 13px; }
.place-result { padding: 6px 8px; cursor: pointer; border-bottom: 1px solid #f0f0f0; }
.place-result:hover { background: #f3f4f6; }
.place-result:last-child { border-bottom: none; }

/* ── 하단 네비게이션 ── */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 56px; z-index: 3000;
  background: #ffffff; border-top: 1px solid #e5e7eb;
  display: flex; align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom);
}
.bn-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: #6b7280;
  font-size: 10px; font-weight: 500;
  cursor: pointer; background: none; border: none; padding: 0;
  transition: color 0.15s; -webkit-tap-highlight-color: transparent;
}
.bn-item:hover, .bn-item.active { color: #16a34a; }
.bn-icon { font-size: 20px; line-height: 1; }
.bn-label { font-size: 10px; }

/* ── 모바일 ── */
@media (max-width: 640px) {
  #main-header { padding: 0 12px; }
  .mh-search-wrap { max-width: none; }
  .modal-box { width: calc(100vw - 32px); }
}
