/* =============================================
   주유소 앱 — 메인 스타일시트
   ============================================= */

/* ---------- CSS 변수 ---------- */
:root {
  --bg:           #2c2c2c;
  --bg-card:      #ffffff;
  --bg-surface:   #383838;
  --accent:       #1D9E75;
  --accent-light: #25c791;
  --accent-dark:  #157a5a;
  --text-primary:   #f0f0f0;
  --text-secondary: #aaaaaa;
  --text-dark:      #1a1a1a;
  --text-muted:     #666666;
  --border:       #444444;
  --radius-card:  12px;
  --radius-btn:   8px;
  --shadow-card:  0 2px 12px rgba(0,0,0,0.18);
  --font:         system-ui, -apple-system, 'Segoe UI', sans-serif;
  --header-h:     112px;
}

/* ---------- 리셋 ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100dvh;
  -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;        /* 정확히 화면 높이. min-height이면 sticky 오작동 */
  overflow: hidden;      /* 자식의 스크롤이 body로 새지 않게 */
}

/* =============================================
   HEADER
   ============================================= */
.app-header {
  flex-shrink: 0;        /* 헤더가 줄어들지 않게 */
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px 8px;
  /* sticky 제거: main-content가 내부 스크롤하므로 불필요하고 flex에서 오작동 */
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.title-icon { font-size: 22px; }

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--border); }

/* =============================================
   검색바 (SearchBar 컴포넌트가 마운트될 영역)
   ============================================= */
#search-bar-root { width: 100%; }

.search-bar {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 0 12px;
  gap: 8px;
}

.search-bar input {
  flex: 1;
  height: 40px;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
}

.search-bar input::placeholder { color: var(--text-secondary); }

.search-bar button {
  color: var(--text-secondary);
  font-size: 18px;
  line-height: 1;
}
.search-bar button:hover { color: var(--accent); }

/* =============================================
   연료 탭
   ============================================= */
.fuel-tabs {
  flex-shrink: 0;        /* 탭도 줄어들지 않게 */
  display: flex;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  gap: 0;
}

.fuel-tab {
  flex: 1;
  padding: 12px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  text-align: center;
}

.fuel-tab.active,
.fuel-tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.fuel-tab:hover:not(.active) { color: var(--text-primary); }

/* =============================================
   메인 콘텐츠
   ============================================= */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding-bottom: 24px;
}

/* =============================================
   추천 섹션
   ============================================= */
.recommend-section {
  padding: 16px 16px 0;
}

/* =============================================
   추천 카드 (RecommendCard)
   ============================================= */
.recommend-card {
  background: var(--accent);
  border-radius: var(--radius-card);
  padding: 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.recommend-card .label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.75);
  margin-bottom: 4px;
}

.recommend-card .station-name {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
}

.recommend-card .station-meta {
  font-size: 12px;
  color: rgba(255,255,255,0.8);
  margin-top: 2px;
}

.recommend-card .price-block {
  text-align: right;
  white-space: nowrap;
}

.recommend-card .total-amount {
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  line-height: 1;
}

.recommend-card .unit-price {
  font-size: 12px;
  color: rgba(255,255,255,0.75);
  margin-top: 2px;
}

/* =============================================
   뷰 전환 (목록 / 지도)
   ============================================= */
.view-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 16px 0;
}

.view-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.view-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 16px;
  border-radius: var(--radius-btn);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  transition: all 0.15s;
}

.view-btn.active,
.view-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.view-btn:hover:not(.active) { color: var(--text-primary); }

.btn-icon { font-size: 15px; }

.view-panel { display: flex; flex-direction: column; }
.view-panel:not(.active) { display: none; }

/* =============================================
   주유소 카드 (StationCard)
   ============================================= */
.station-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.station-card {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.station-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
}

.station-card:active { transform: translateY(0); }

.station-card .card-left { flex: 1; min-width: 0; }

.station-card .stn-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-card .stn-brand {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.station-card .stn-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.station-card .stn-dist {
  font-size: 12px;
  color: var(--text-muted);
}

.station-card .stn-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: #e8f7f1;
  color: var(--accent-dark);
}

.station-card .card-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
  white-space: nowrap;
}

/* 총금액 — 카드에서 가장 크게 */
.station-card .total-amount {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-dark);
  line-height: 1;
}

.station-card .unit-price {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.station-card .price-diff {
  font-size: 11px;
  font-weight: 600;
  margin-top: 2px;
}
.station-card .price-diff.cheaper { color: var(--accent); }
.station-card .price-diff.pricier  { color: #e05656; }

/* =============================================
   지도 뷰
   ============================================= */
#map-view-root {
  width: 100%;
  height: 55dvh;
  min-height: 300px;
  border-radius: var(--radius-card);
  overflow: hidden;
  background: var(--bg-surface);
}

.map-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 14px;
}

/* =============================================
   로딩 오버레이
   ============================================= */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(44,44,44,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-primary);
  font-size: 14px;
}

.loading-overlay[hidden] { display: none; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

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

.toast.show { transform: translateX(-50%) translateY(0); }

/* =============================================
   빈 상태
   ============================================= */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; line-height: 1.6; }

/* =============================================
   정렬 바 (ListView)
   ============================================= */
.sort-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.sort-bar::-webkit-scrollbar { display: none; }

.sort-tab {
  flex-shrink: 0;
  padding: 5px 13px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  background: none;
  transition: all 0.15s;
}
.sort-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.sort-tab:hover:not(.active) { color: var(--text-primary); }

.favs-toggle {
  flex-shrink: 0;
  margin-left: auto;
  padding: 5px 13px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  background: none;
  transition: all 0.15s;
}
.favs-toggle.active {
  color: #e05656;
  border-color: #e05656;
}

/* =============================================
   배지
   ============================================= */
.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
  line-height: 1.3;
}
.badge--self   { background: #e8f0fe; color: #3c74e0; }
.badge--24h    { background: #fff3cd; color: #856404; }
.badge--open   { background: #e8f7f1; color: var(--accent-dark); }
.badge--closed { background: #fdecea; color: #c62828; }

/* =============================================
   StationCard 추가 스타일
   ============================================= */
.station-card--closed { opacity: 0.4; }

.stn-sep { color: var(--text-muted); font-size: 11px; }

.stn-time { font-size: 12px; color: var(--text-muted); }

.stn-update {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* 정렬 기준 강조 */
.field--active {
  color: var(--accent) !important;
  font-weight: 700;
}

/* 찜 버튼 */
.fav-btn {
  font-size: 18px;
  color: #ccc;
  line-height: 1;
  padding: 0;
  margin-bottom: 4px;
  transition: color 0.15s, transform 0.1s;
  background: none;
  border: none;
  cursor: pointer;
}
.fav-btn--on   { color: #e05656; }
.fav-btn:hover { transform: scale(1.15); }

/* =============================================
   추천 카드 (RecommendCard) — 업데이트
   ============================================= */
.recommend-card {
  background: var(--accent);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.rec-left { flex: 1; min-width: 0; }

.rec-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.7);
  margin-bottom: 3px;
}

.rec-name {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rec-reason {
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  margin-top: 3px;
}

.rec-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  font-size: 12px;
  color: rgba(255,255,255,0.75);
}
.rec-sep { opacity: 0.6; }

.rec-right {
  text-align: right;
  white-space: nowrap;
  position: relative;
  padding-top: 4px;
}

.rec-off-btn {
  position: absolute;
  top: -4px;
  right: -4px;
  font-size: 12px;
  color: rgba(255,255,255,0.6);
  padding: 2px 4px;
  line-height: 1;
  cursor: pointer;
}
.rec-off-btn:hover { color: #fff; }

.rec-total {
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  line-height: 1;
  margin-top: 16px;
}

.rec-unit {
  font-size: 12px;
  color: rgba(255,255,255,0.75);
  margin-top: 2px;
}

/* 추천 꺼짐 바 */
.rec-off-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.rec-on-btn {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  padding: 4px 10px;
  border: 1.5px solid var(--accent);
  border-radius: 12px;
  cursor: pointer;
  background: none;
  font-family: inherit;
}

/* =============================================
   리스트↔지도 FAB (우측 상단 고정)
   ============================================= */
.fab-view {
  position: fixed;
  /* 헤더(112px) + 연료탭(~45px) + 여백 */
  top: 170px;
  right: 16px;
  z-index: 50;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  transition: background 0.15s, transform 0.1s;
}
.fab-view:hover  { background: var(--accent-light); }
.fab-view:active { transform: scale(0.93); }

/* =============================================
   카카오맵 — 일반 마커
   ============================================= */
.map-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25));
  user-select: none;
}

.map-marker-label {
  background: #fff;
  color: var(--text-dark);
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font);
  padding: 4px 8px;
  border-radius: 20px;
  white-space: nowrap;
  border: 1.5px solid #ddd;
  line-height: 1;
}

.map-marker-pin {
  width: 8px;
  height: 8px;
  background: #555;
  border-radius: 50%;
  margin-top: 3px;
}

/* 추천 마커 */
.map-marker--recommend .map-marker-label {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-dark);
}

.map-marker--recommend .map-marker-pin {
  background: var(--accent);
}

.map-marker-badge {
  background: #fff;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  font-family: var(--font);
  padding: 2px 6px;
  border-radius: 10px;
  margin-bottom: 3px;
  border: 1.5px solid var(--accent);
  line-height: 1;
}

/* 내 위치 마커 */
.map-marker-me {
  position: relative;
  width: 16px;
  height: 16px;
}

.map-marker-me-dot {
  position: absolute;
  inset: 3px;
  background: #4285f4;
  border-radius: 50%;
  border: 2px solid #fff;
  z-index: 1;
}

.map-marker-me-ring {
  position: absolute;
  inset: -6px;
  background: rgba(66, 133, 244, 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.6); opacity: 0; }
}

/* =============================================
   카카오맵 — 팝업
   ============================================= */
.map-popup {
  display: flex;
  flex-direction: column;
  align-items: center;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.22));
  font-family: var(--font);
}

.map-popup-inner {
  position: relative;
  background: #fff;
  border-radius: 12px;
  padding: 14px 16px 12px;
  min-width: 220px;
  max-width: 280px;
}

.map-popup-close {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 13px;
  color: #999;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}
.map-popup-close:hover { color: #333; }

.map-popup-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-dark);
  padding-right: 20px;
  line-height: 1.3;
}

.map-popup-meta {
  font-size: 11px;
  color: #888;
  margin-top: 3px;
}

.map-popup-price {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-dark);
  margin: 8px 0;
  line-height: 1;
}

.map-popup-price span {
  font-size: 13px;
  font-weight: 500;
  color: #888;
  margin-left: 2px;
}

.map-popup-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.nav-btn {
  padding: 7px 4px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: opacity 0.15s;
}
.nav-btn:hover { opacity: 0.85; }

.nav-btn--kakao  { background: #fee500; color: #3c1e1e; border-color: #e5ce00; }
.nav-btn--tmap   { background: #e8240a; color: #fff; border-color: #c81f08; }
.nav-btn--naver  { background: #03c75a; color: #fff; border-color: #02a84b; }
.nav-btn--google { background: #4285f4; color: #fff; border-color: #3070d6; }

/* 팝업 꼬리 삼각형 */
.map-popup-arrow {
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 10px solid #fff;
  margin-top: -1px;
}

/* =============================================
   반응형
   ============================================= */
@media (min-width: 480px) {
  .station-card .total-amount { font-size: 26px; }
  .recommend-card .total-amount { font-size: 28px; }
}

@media (min-width: 768px) {
  #app {
    max-width: 600px;
    margin: 0 auto;
    box-shadow: 0 0 40px rgba(0,0,0,0.4);
  }
}
