/* =============================================
   디자인 토큰
   ============================================= */
:root {
  --bg:           #2c2c2c;
  --bg-dark:      #242424;
  --bg-card:      #ffffff;
  --accent:       #1D9E75;
  --accent-dark:  #0d3322;
  --accent-border:#1a6644;
  --accent-text:  #5dcaa5;
  --text-primary: #1a1a1a;
  --text-secondary:#999;
  --text-muted:   #ccc;
  --text-light:   #f0f0f0;
  --text-dim:     #666;
  --border:       #484848;
  --border-card:  #f0f0f0;
  --btn-inactive: #aaa;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 16px;
}

/* =============================================
   리셋 + 기본
   ============================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { overscroll-behavior: none; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-light);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; }
ul { list-style: none; }

/* =============================================
   앱 레이아웃
   ============================================= */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
}

/* =============================================
   탑바
   ============================================= */
.topbar {
  flex-shrink: 0;
  padding: 20px 20px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 7px;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}
.appname {
  font-size: 17px;
  font-weight: 500;
  color: var(--text-light);
  letter-spacing: -0.3px;
}
.location-text {
  font-size: 11px;
  color: var(--text-dim);
}

/* =============================================
   입력 카드 (유종 / 주유량 / 반경)
   ============================================= */
.inputs {
  flex-shrink: 0;
  background: var(--bg-card);
  margin: 0 16px;
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
}
.inp-seg {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.inp-seg + .inp-seg {
  border-left: 0.5px solid #e8e8e8;
  padding-left: 14px;
}
.inp-label { font-size: 10px; color: var(--text-secondary); letter-spacing: 0.3px; }
.inp-val   { font-size: 15px; font-weight: 500; color: var(--text-primary); }
.inp-unit  { font-size: 12px; font-weight: 400; color: var(--text-secondary); }

/* =============================================
   컨트롤 바 (정렬 + 뷰 토글)
   ============================================= */
.controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
}
.sort-row {
  display: flex;
  gap: 5px;
}
.sort-btn {
  font-size: 11px;
  padding: 5px 9px;
  border-radius: 20px;
  border: 0.5px solid var(--border);
  background: transparent;
  color: var(--btn-inactive);
  white-space: nowrap;
  transition: all 0.15s;
}
.sort-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.sort-btn:hover:not(.active) { color: var(--text-light); }

.view-btns { display: flex; gap: 6px; }
.vt-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: transparent;
  color: #888;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.vt-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* =============================================
   메인 콘텐츠
   ============================================= */
.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.view-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.view-panel[hidden] { display: none; }

/* =============================================
   추천 토글 행
   ============================================= */
.rec-row {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 16px 10px;
}
.rec-label { font-size: 11px; color: var(--btn-inactive); }

/* 토글 스위치 */
.toggle {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: #444;
  border: none;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle.on { background: var(--accent); }
.toggle-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: left 0.2s;
  pointer-events: none;
}
.toggle.on .toggle-thumb { left: 18px; }

/* =============================================
   추천 카드 (다크 그린)
   ============================================= */
.rec-card {
  background: var(--accent-dark);
  border-radius: var(--radius);
  margin: 0 16px 10px;
  padding: 14px 16px;
  border: 1px solid var(--accent-border);
  cursor: pointer;
  flex-shrink: 0;
}
.rec-tag {
  font-size: 10px;
  font-weight: 500;
  color: var(--accent-text);
  margin-bottom: 6px;
  letter-spacing: 0.05em;
}
.rec-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-light);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rec-reason {
  font-size: 11px;
  color: #7ab89a;
  line-height: 1.5;
  margin-bottom: 12px;
}
.rec-nums { display: flex; gap: 14px; }
.rec-num  { display: flex; flex-direction: column; gap: 2px; }
.rec-val  { font-size: 14px; font-weight: 500; color: var(--text-light); }
.rec-lbl  { font-size: 10px; color: #5a8a70; }

/* =============================================
   주유소 카드
   ============================================= */
.cards {
  padding: 0 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: transform 0.1s;
}
.card:active { transform: scale(0.99); }
.card.best   { outline: 1.5px solid var(--accent); }

.best-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 500;
  background: #E1F5EE;
  color: #0F6E56;
  padding: 3px 8px;
  border-radius: 20px;
  margin-bottom: 8px;
}

.station-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.station-name.closed { color: var(--text-muted); }

/* 배지 */
.badges {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.badge      { font-size: 10px; padding: 2px 7px; border-radius: 10px; }
.badge.self { background: #E6F1FB; color: #185FA5; }
.badge.open { background: #E1F5EE; color: #0F6E56; }
.badge.h24  { background: #f0f0ee; color: #5F5E5A; }
.badge.closed-badge { background: #FCEBEB; color: #A32D2D; }

/* 히어로 값 */
.hero-wrap {
  display: flex;
  align-items: baseline;
  margin-bottom: 2px;
}
.hero-val {
  font-size: 26px;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  line-height: 1;
}
.hero-val.closed { color: var(--text-muted); }
.hero-unit {
  font-size: 13px;
  color: var(--text-secondary);
  margin-left: 4px;
}

/* 구분선 */
.divider {
  height: 0.5px;
  background: var(--border-card);
  margin: 10px 0;
}

/* 메타 정보 */
.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.meta-items { display: flex; gap: 12px; }
.meta-item  { display: flex; flex-direction: column; gap: 1px; }
.meta-val   { font-size: 13px; font-weight: 500; color: #333; }
.meta-val.muted { color: var(--text-muted); }
.meta-label { font-size: 10px; color: var(--text-secondary); }

/* 카드 내 길안내 버튼 */
.card-nav-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #f5f5f5;
  border: 0.5px solid #e8e8e8;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.card-nav-btn:hover { background: #efefef; }
.card-nav-btn.disabled { opacity: 0.3; pointer-events: none; }

.update-time {
  font-size: 10px;
  color: #bbb;
  margin-top: 8px;
}

/* =============================================
   바텀 탭바
   ============================================= */
.tab-bar {
  flex-shrink: 0;
  background: var(--bg-dark);
  border-top: 0.5px solid #3a3a3a;
  padding: 10px 0 max(6px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-around;
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  color: #555;
  padding: 4px 24px;
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.tab.active { color: var(--accent); }

/* =============================================
   지도 뷰
   ============================================= */
#map-view-root {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 지도 캔버스 래퍼 */
.map-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map-canvas {
  position: absolute;
  inset: 0;
}

/* 지도 내 팝업 (마커 클릭 시, 지도 하단에 겹쳐 표시) */
.map-popup {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  background: var(--bg-card);
  border-radius: 14px;
  padding: 13px 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 10;
}
.popup-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}
.popup-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}
.popup-close {
  font-size: 16px;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
  background: none;
  border: none;
  padding: 0 0 0 8px;
}
.popup-badges {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}
.popup-nums {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}
.pn { display: flex; flex-direction: column; gap: 2px; }
.pn-val { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.pn-lbl { font-size: 10px; color: var(--text-secondary); }
.nav-apps { display: flex; gap: 6px; }
.nav-app {
  flex: 1;
  padding: 7px;
  border-radius: 9px;
  border: 0.5px solid #e0e0e0;
  font-size: 11px;
  font-weight: 500;
  color: #333;
  text-align: center;
  cursor: pointer;
  background: #f8f8f8;
  font-family: inherit;
  transition: background 0.15s;
}
.nav-app:hover { background: #efefef; }

/* 지도 하단 추천 배너 */
.map-rec-banner {
  flex-shrink: 0;
  background: var(--accent-dark);
  border: 1px solid var(--accent-border);
  border-radius: 14px;
  margin: 10px 16px;
  padding: 12px 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.map-rec-tag    { font-size: 10px; color: var(--accent-text); margin-bottom: 3px; }
.map-rec-name   { font-size: 13px; font-weight: 500; color: var(--text-light); margin-bottom: 3px; }
.map-rec-reason { font-size: 11px; color: #7ab89a; }

/* =============================================
   카카오맵 마커
   ============================================= */
.map-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.4));
  user-select: none;
}
.marker-bubble {
  background: #2c2c2c;
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  padding: 5px 9px;
  border-radius: 10px;
  white-space: nowrap;
  border: 1.5px solid #484848;
  position: relative;
}
.marker-bubble .rec-tag-marker {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
}
.marker-bubble.closed-marker { background: #888; border-color: #888; }
.marker-tail {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #2c2c2c;
}
.marker-tail.closed { border-top-color: #888; }
.map-marker.selected .marker-bubble { outline: 2px solid #fff; }

/* 내 위치 마커 */
.map-marker-me {
  position: relative;
  width: 28px;
  height: 28px;
}
.map-marker-me-dot {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 14px; height: 14px;
  background: #4A90D9;
  border-radius: 50%;
  border: 2.5px solid #fff;
  z-index: 1;
}
.map-marker-me-ring {
  position: absolute;
  inset: 0;
  background: rgba(74, 144, 217, 0.2);
  border-radius: 50%;
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  0%   { transform: scale(0.8); opacity: 0.8; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* =============================================
   설정 패널 (바텀시트)
   ============================================= */
.settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0);
  transition: background 0.25s;
}
.settings-backdrop.open { background: rgba(0,0,0,0.5); }

.settings-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 201;
  background: #fff;
  border-radius: 20px 20px 0 0;
  max-height: 85dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(.22,.68,0,1.1);
  max-width: 480px;
  margin: 0 auto;
}
.settings-sheet.open { transform: translateY(0); }

.settings-handle {
  width: 40px; height: 4px;
  background: #ddd;
  border-radius: 2px;
  margin: 12px auto 0;
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 10px;
  border-bottom: 1px solid #f0f0f0;
}
.settings-title { font-size: 17px; font-weight: 700; color: var(--text-primary); }
.settings-close {
  font-size: 16px; color: #999; padding: 4px 6px;
  cursor: pointer; background: none; border: none; font-family: inherit;
}
.settings-close:hover { color: #333; }
.settings-body { padding: 8px 20px 36px; }
.settings-section {
  padding: 16px 0;
  border-bottom: 1px solid #f5f5f5;
}
.settings-section:last-child { border-bottom: none; }
.settings-label {
  font-size: 13px; font-weight: 700; color: #888;
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px;
}
.settings-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 16px; border-radius: 20px; font-size: 14px; font-weight: 600;
  font-family: inherit; border: 1.5px solid #e0e0e0; background: none;
  color: #555; cursor: pointer; transition: all 0.15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip--active { background: var(--accent); color: #fff; border-color: var(--accent); }
.settings-row { display: flex; align-items: center; gap: 8px; }
.settings-input {
  width: 100px; height: 42px; border: 1.5px solid #ddd; border-radius: 10px;
  padding: 0 12px; font-size: 16px; font-family: inherit; color: var(--text-primary);
  outline: none; transition: border-color 0.15s; -moz-appearance: textfield;
}
.settings-input::-webkit-outer-spin-button,
.settings-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.settings-input:focus { border-color: var(--accent); }
.settings-unit { font-size: 14px; color: #888; }
.settings-hint { font-size: 12px; color: #aaa; margin-top: 6px; }

/* =============================================
   로딩 오버레이
   ============================================= */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(44,44,44,0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-light);
  font-size: 14px;
}
.loading-overlay[hidden] { display: none; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid #444;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================
   토스트
   ============================================= */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #333;
  color: #fff;
  font-size: 13px;
  padding: 10px 20px;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 1000;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* =============================================
   반응형
   ============================================= */
@media (min-width: 480px) {
  #app {
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
}
