:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface-soft: #f7faf8;
  --text: #15231b;
  --muted: #68746d;
  --line: #dce5df;
  --green: #0a714c;
  --green-dark: #075a3d;
  --green-soft: #e3f4ec;
  --lime: #8ac926;
  --orange: #f39c3d;
  --red: #d95555;
  --blue: #3277c8;
  --shadow: 0 12px 36px rgba(30, 55, 42, 0.09);
  --radius: 20px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Pretendard, "Noto Sans KR", "Apple SD Gothic Neo", system-ui, sans-serif;
  line-height: 1.5;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px max(24px, calc((100vw - 1440px) / 2));
  background: rgba(243, 246, 244, 0.88);
  border-bottom: 1px solid rgba(220, 229, 223, 0.9);
  backdrop-filter: blur(14px);
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(23px, 3vw, 32px); letter-spacing: -0.04em; }
h2 { margin-bottom: 4px; font-size: 20px; letter-spacing: -0.03em; }
h3 { margin-bottom: 5px; font-size: 17px; letter-spacing: -0.025em; }

.eyebrow {
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.mode-badge {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 9px 13px;
  color: #68500f;
  background: #fff7d7;
  border: 1px solid #eadb93;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 750;
}
.mode-dot { width: 8px; height: 8px; background: #d6a20a; border-radius: 50%; }
.mode-badge.live { color: var(--green-dark); background: var(--green-soft); border-color: #b8dfce; }
.mode-badge.live .mode-dot { background: var(--green); box-shadow: 0 0 0 4px rgba(10, 113, 76, 0.12); }

main {
  width: min(1440px, calc(100% - 36px));
  margin: 24px auto 64px;
}

.search-panel {
  display: grid;
  grid-template-columns: 1.4fr 0.75fr 1.25fr 0.75fr auto;
  gap: 12px;
  align-items: end;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.field { display: grid; gap: 6px; }
.field label { color: var(--muted); font-size: 12px; font-weight: 750; }
.field select, .field input, #sortSelect {
  width: 100%;
  min-height: 45px;
  padding: 0 13px;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}
.field select:focus, .field input:focus, #sortSelect:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(10, 113, 76, 0.12); }

.primary-button {
  min-height: 45px;
  padding: 0 22px;
  color: white;
  background: var(--green);
  border: 0;
  border-radius: 12px;
  font-weight: 800;
}
.primary-button:hover { background: var(--green-dark); }

.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 2px 4px;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip {
  flex: 0 0 auto;
  padding: 8px 13px;
  color: var(--muted);
  background: rgba(255,255,255,.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 750;
}
.filter-chip.active { color: white; background: var(--green); border-color: var(--green); }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}
.summary-card {
  display: grid;
  gap: 2px;
  min-height: 88px;
  align-content: center;
  padding: 15px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.summary-card span { color: var(--muted); font-size: 12px; font-weight: 700; }
.summary-card strong { overflow: hidden; font-size: 19px; text-overflow: ellipsis; white-space: nowrap; }
.warning-card { background: #fffaf1; border-color: #f0dec1; }
.warning-card strong { color: #8b5a16; font-size: 16px; }

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, .75fr);
  gap: 14px;
  min-height: 670px;
}

.map-card, .results-card, .route-card, .notice-card {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.card-heading p { margin-bottom: 0; color: var(--muted); font-size: 13px; }

#map { width: 100%; height: 610px; background: #e7eee9; }
.map-fallback { padding: 18px; color: #805c23; background: #fff5df; font-size: 13px; }

.legend { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; color: var(--muted); font-size: 11px; }
.legend span { display: inline-flex; gap: 5px; align-items: center; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }
.legend-dot.available { background: var(--green); }
.legend-dot.crowded { background: var(--red); }
.legend-line { width: 18px; border-top: 4px solid; }
.legend-line.roadside { border-color: #7658c9; }

.results-card { position: relative; max-height: 670px; overflow: auto; }
.sticky-heading { position: sticky; top: 0; z-index: 10; background: rgba(255,255,255,.96); backdrop-filter: blur(9px); }
#sortSelect { width: 105px; min-height: 38px; font-size: 12px; }
.results-list { display: grid; gap: 10px; padding: 12px; }

.parking-item {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.parking-item:hover { transform: translateY(-2px); border-color: #a9caba; box-shadow: 0 8px 24px rgba(30,55,42,.08); }
.parking-item.highlight { border-color: var(--green); box-shadow: 0 0 0 3px rgba(10,113,76,.12); }
.parking-item-top { display: flex; justify-content: space-between; gap: 14px; }
.parking-address { margin-bottom: 0; color: var(--muted); font-size: 12px; }
.badge-row { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 7px; }
.badge { padding: 3px 7px; border-radius: 999px; background: #edf1ee; color: #5b675f; font-size: 10px; font-weight: 800; }
.badge.public { color: var(--green-dark); background: var(--green-soft); }
.badge.free { color: #1a5ca4; background: #e9f3ff; }
.badge.live { color: #8d4c10; background: #fff0de; }
.badge.roadside { color: #5b399f; background: #eee8ff; }

.availability-block { min-width: 76px; text-align: right; }
.availability-value { display: block; color: var(--green); font-size: 22px; }
.availability-block.crowded .availability-value { color: var(--red); }
.availability-label { color: var(--muted); font-size: 11px; }

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.metric-row div { min-width: 0; }
.metric-row span { display: block; color: var(--muted); font-size: 10px; }
.metric-row strong { display: block; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.item-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.confidence-text { color: var(--muted); font-size: 10px; }
.map-focus-button { padding: 6px 9px; color: var(--green-dark); background: transparent; border: 0; font-size: 11px; font-weight: 800; }

.empty-state { padding: 60px 24px; color: var(--muted); text-align: center; }
.empty-state strong { display: block; margin-bottom: 5px; color: var(--text); font-size: 17px; }

.route-card { margin-top: 14px; }
.quick-station-card {
  margin: 0 0 14px;
  border-color: #b8d8c8;
  box-shadow: 0 10px 30px rgba(10, 113, 76, 0.10);
}
.quick-station-card .card-heading {
  padding-bottom: 12px;
  background: linear-gradient(135deg, #f8fffb 0%, #eef8f2 100%);
}
.section-kicker {
  margin-bottom: 3px;
  color: var(--green);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .04em;
}
.quick-station-card .station-rail {
  padding-top: 18px;
  padding-bottom: 22px;
}
.station-rail {
  display: flex;
  align-items: flex-start;
  gap: 0;
  overflow-x: auto;
  padding: 24px 22px 28px;
  scrollbar-color: #b6c9bd transparent;
}
.station-button {
  position: relative;
  flex: 0 0 92px;
  padding: 30px 5px 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 12px;
  font-weight: 750;
  text-align: center;
}
.station-button::before {
  position: absolute;
  top: 7px;
  left: 50%;
  z-index: 2;
  width: 15px;
  height: 15px;
  background: white;
  border: 4px solid var(--green);
  border-radius: 50%;
  content: "";
  transform: translateX(-50%);
}
.station-button::after {
  position: absolute;
  top: 14px;
  left: 50%;
  width: 100%;
  height: 4px;
  background: var(--green);
  content: "";
}
.station-button:last-child::after { display: none; }
.station-button.active { color: var(--green-dark); }
.station-button.active::before { background: var(--green); box-shadow: 0 0 0 5px rgba(10,113,76,.15); }

.notice-card { margin-top: 14px; padding: 20px 22px; box-shadow: none; }
.notice-card h2 { font-size: 15px; }
.notice-card p { margin-bottom: 0; color: var(--muted); font-size: 12px; }

dialog { max-width: 480px; padding: 0; border: 0; border-radius: 20px; box-shadow: 0 20px 80px rgba(12,30,20,.28); }
dialog::backdrop { background: rgba(8, 20, 13, .46); backdrop-filter: blur(3px); }
.dialog-card { display: grid; gap: 20px; padding: 26px; }
.dialog-card p { margin-bottom: 0; color: var(--muted); }

.leaflet-popup-content-wrapper { border-radius: 14px; }
.leaflet-popup-content { margin: 13px 15px; }
.popup-title { margin-bottom: 4px; font-weight: 850; }
.popup-meta { color: var(--muted); font-size: 12px; }
.station-marker { display: grid; place-items: center; width: 34px !important; height: 34px !important; color: white; background: var(--green); border: 4px solid white; border-radius: 50%; box-shadow: 0 4px 14px rgba(8,55,34,.3); font-weight: 900; }
.parking-marker { display: grid; place-items: center; width: 30px !important; height: 30px !important; color: white; background: var(--green); border: 3px solid white; border-radius: 10px; box-shadow: 0 3px 10px rgba(8,55,34,.25); font-size: 12px; font-weight: 900; }
.parking-marker.crowded { background: var(--red); }
.parking-marker.unknown { background: var(--blue); }

@media (max-width: 1060px) {
  .search-panel { grid-template-columns: repeat(4, 1fr); }
  .search-panel .primary-button { grid-column: 1 / -1; }
  .content-grid { grid-template-columns: 1fr; }
  .results-card { max-height: none; }
  #map { height: 480px; }
}

@media (max-width: 720px) {
  .topbar { padding: 14px 18px; }
  .eyebrow { font-size: 9px; }
  .mode-badge { padding: 8px 10px; font-size: 11px; }
  main { width: min(100% - 20px, 1440px); margin-top: 12px; }
  .search-panel { grid-template-columns: 1fr 1fr; padding: 13px; }
  .station-field, .search-panel .primary-button { grid-column: 1 / -1; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-card { min-height: 75px; padding: 12px; }
  .summary-card strong { font-size: 16px; }
  .card-heading { align-items: flex-start; padding: 15px; }
  .legend { display: none; }
  #map { height: 410px; }
  .results-list { padding: 9px; }
  .parking-item { padding: 14px; }
  .route-card .card-heading { padding-bottom: 10px; }
  .quick-station-card { margin-bottom: 10px; }
  .quick-station-card .station-rail { padding: 16px 12px 20px; }
  .station-button { flex-basis: 78px; }
}

.mode-badge.error {
  border-color: #d97706;
  background: #fff7ed;
  color: #9a3412;
}
.mode-badge.error .mode-dot {
  background: #f59e0b;
}


/* 데이터 로딩 및 오류 상태 */
.mode-badge.loading .mode-dot { animation: modePulse 1s ease-in-out infinite; }
@keyframes modePulse { 0%, 100% { opacity: .35; transform: scale(.85); } 50% { opacity: 1; transform: scale(1.15); } }
.loading-state { min-height: 220px; }
.loading-spinner { width: 30px; height: 30px; border: 3px solid rgba(10, 113, 76, .18); border-top-color: #0a714c; border-radius: 50%; animation: loadingSpin .8s linear infinite; }
@keyframes loadingSpin { to { transform: rotate(360deg); } }
.error-state { gap: 12px; }
.retry-button { border: 0; border-radius: 10px; padding: 10px 16px; background: #0a714c; color: white; font-weight: 700; cursor: pointer; }
.notice-card code { padding: 2px 6px; border-radius: 6px; background: rgba(10, 113, 76, .08); }
