:root {
  --red: #c1121f;
  --red-soft: #fdecee;
  --ink: #16181d;
  --ink-2: #575d68;
  --ink-3: #8b929e;
  --line: #e4e7ec;
  --bg: #ffffff;
  --bg-2: #f7f8fa;
  --panel-w: 372px;
  --head-h: 0px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
    "Malgun Gothic", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

#app {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  height: 100%;
  height: 100dvh;
}

/* ---------- 패널 ---------- */

#panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--bg);
}

.panel-head {
  position: relative;
  padding: 22px 22px 15px;
  border-bottom: 1px solid var(--line);
}

.panel-head::before {
  content: '';
  position: absolute;
  top: 24px;
  left: 0;
  width: 3px;
  height: 21px;
  border-radius: 0 3px 3px 0;
  background: var(--red);
}

.panel-head h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.panel-head .sub {
  margin: 5px 0 0;
  font-size: 13px;
  color: var(--ink-2);
}

.panel-head strong { color: var(--red); }

.controls {
  padding: 15px 22px 13px;
  border-bottom: 1px solid var(--line);
}

.search-wrap { position: relative; }

#search {
  width: 100%;
  padding: 10px 34px 10px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-2);
  outline: none;
}

#search:focus {
  border-color: var(--red);
  background: var(--bg);
  box-shadow: 0 0 0 3px var(--red-soft);
}

#search::-webkit-search-cancel-button { display: none; }

#search-clear {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  font-size: 18px;
  line-height: 1;
  color: var(--ink-3);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

#search-clear:hover { background: var(--bg-2); color: var(--ink); }

.filter { margin-top: 12px; }

.filter-label em {
  font-style: normal;
  font-weight: 600;
  opacity: 0.72;
}

.filter-label {
  display: block;
  margin-bottom: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink-3);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 6px 11px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--ink-2);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.chip:hover:not(:disabled) { border-color: var(--ink-3); }

.chip:disabled { opacity: 0.38; cursor: default; }

.chip[aria-pressed="true"] {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
  font-weight: 600;
}

.chip .n { opacity: 0.65; margin-left: 3px; font-variant-numeric: tabular-nums; }

.toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
}

.toggle input { accent-color: var(--red); width: 15px; height: 15px; }

.result-count {
  margin: 0;
  padding: 11px 22px 6px;
  font-size: 12px;
  color: var(--ink-3);
}

.result-count span { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink-2); }

/* ---------- 목록 ---------- */

.list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0 12px 10px;
  scrollbar-width: thin;
  scrollbar-color: #d5d9e0 transparent;
  overflow-y: auto;
  list-style: none;
  overscroll-behavior: contain;
}

.item {
  padding: 10px 10px;
  border-radius: 9px;
  cursor: pointer;
}

.list::-webkit-scrollbar { width: 8px; }
.list::-webkit-scrollbar-thumb { background: #dde1e7; border: 2px solid #fff; border-radius: 99px; }
.list::-webkit-scrollbar-thumb:hover { background: #c9cfd8; }

.item { transition: background 0.12s ease; }
.item:hover { background: var(--bg-2); }

.item[aria-current="true"] { background: var(--red-soft); }

.item-top {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.item-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.item-code {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.item-closed {
  margin-left: auto;
  padding: 1px 6px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--line);
  border-radius: 4px;
}

.item-addr {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--ink-2);
  line-height: 1.45;
}

.empty {
  padding: 28px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-3);
}

/* ---------- 푸터 / 안내 팝업 ---------- */

.panel-foot {
  padding: 10px 20px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.panel-foot button {
  padding: 0;
  font-size: 11.5px;
  font-family: inherit;
  color: var(--ink-3);
  background: none;
  border: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.panel-foot button:hover { color: var(--ink-2); }

:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
  border-radius: 6px;
}

.chip:focus-visible { outline-offset: 1px; }

#info {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  color: var(--ink);
  background: #fff;
  border: 0;
  border-radius: 18px;
  box-shadow: 0 18px 60px rgba(12, 18, 28, 0.28);
}

#info::backdrop { background: rgba(12, 18, 28, 0.42); }

#info .sheet { padding: 22px 24px 26px; }

.sheet-head {
  display: flex;
  align-items: center;
  margin-bottom: 14px;
}

.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }

.sheet-head button {
  margin-left: auto;
  width: 30px;
  height: 30px;
  font-size: 21px;
  line-height: 1;
  color: var(--ink-3);
  background: var(--bg-2);
  border: 0;
  border-radius: 9px;
  cursor: pointer;
}

.sheet-head button:hover { color: var(--ink); }

#info section + section { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
#info h3 { margin: 0 0 6px; font-size: 12px; font-weight: 700; color: var(--ink-3); }
#info p { margin: 0 0 5px; font-size: 13px; line-height: 1.6; color: var(--ink-2); }
#info a { color: var(--red); }
#info ul { margin: 7px 0 0; padding-left: 17px; font-size: 13px; line-height: 1.7; color: var(--ink-2); }
#info li a { color: var(--ink-2); }

/* ---------- 지도 ---------- */

#map-wrap { position: relative; min-width: 0; }
#map { width: 100%; height: 100%; background: var(--bg-2); }

#sheet-handle {
  display: none;
  width: 100%;
  padding: 10px 0 6px;
  background: none;
  border: 0;
  cursor: grab;
}

#sheet-handle .grip {
  display: block;
  width: 38px;
  height: 4px;
  margin: 0 auto;
  border-radius: 99px;
  background: #d8dce3;
}

.map-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 32px;
  text-align: center;
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink-2);
  background: var(--bg-2);
}

.map-error strong { display: block; font-size: 15px; color: var(--ink); }
.map-error code {
  padding: 2px 6px;
  font-size: 12.5px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
}

/* ---------- 말풍선 ---------- */

.pop {
  width: 276px;
  max-width: calc(100vw - 28px);
  padding: 14px 15px 13px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 6px 26px rgba(0, 0, 0, 0.2);
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
}

.pop-head { display: flex; align-items: baseline; gap: 6px; padding-right: 20px; }
.pop-name { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.pop-code { font-size: 11px; font-weight: 600; color: var(--ink-3); }

.pop-addr { margin: 7px 0 0; font-size: 12.5px; color: var(--ink-2); }
.pop-meta { margin: 5px 0 0; font-size: 12px; color: var(--ink-3); }

.pop-route {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
}

.pop-route-label {
  flex: 0 0 auto;
  padding-right: 2px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-3);
}

.pop-route a {
  flex: 1;
  padding: 7px 0;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.pop-route a:hover { border-color: var(--ink-3); background: #fff; }

.pop-links { display: flex; gap: 6px; margin-top: 6px; }

.pop-links a,
.pop-links button {
  flex: 1;
  padding: 7px 0;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  text-align: center;
  text-decoration: none;
  color: var(--ink-2);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}

.pop-links a:hover,
.pop-links button:hover { border-color: var(--ink-3); color: var(--ink); }

.pop-close {
  position: absolute;
  top: 8px;
  right: 9px;
  width: 24px;
  height: 24px;
  font-size: 17px;
  line-height: 1;
  color: var(--ink-3);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.pop-close:hover { background: var(--bg-2); color: var(--ink); }

/* ---------- 구분 색상 ---------- */

.chip-dot::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  vertical-align: 1px;
  border-radius: 50%;
  background: var(--dot);
}

.chip[aria-pressed="true"].chip-dot::before { background: #fff; }

.tag {
  padding: 1px 6px 2px;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.5;
  color: #fff;
  background: var(--dot);
  border-radius: 4px;
}



/* ---------- 모바일 (바텀시트) ---------- */

/* 태블릿: 사이드바를 좁혀 지도를 넓게 쓴다 */
@media (min-width: 781px) and (max-width: 1100px) {
  :root { --panel-w: 306px; }
  .panel-head { padding: 18px 16px 12px; }
  .panel-head h1 { font-size: 17px; }
  .controls { padding: 13px 16px 11px; }
  .result-count { padding: 10px 16px 5px; }
  .list { padding: 0 8px 10px; }
  .panel-foot { padding-left: 16px; padding-right: 16px; }
  .chip { padding: 5px 9px; font-size: 12px; }
}

/* 큰 화면: 목록을 넉넉하게 */
@media (min-width: 1700px) {
  :root { --panel-w: 420px; }
}

/* 가로로 눕힌 폰: 세로 공간이 없으므로 여백을 줄인다 */
@media (max-width: 1100px) and (max-height: 520px) and (orientation: landscape) {
  .panel-head { padding: 12px 16px 8px; }
  .panel-head h1 { font-size: 16px; }
  .panel-head .sub { font-size: 12px; }
  .controls { padding: 10px 16px 8px; }
  .filter { margin-top: 8px; }
  .item { padding: 8px 10px; }
}

@media (max-width: 780px) {
  :root { --sheet-peek: 150px; }

  #app { grid-template-columns: 1fr; grid-template-rows: 1fr; }

  #map-wrap { grid-row: 1; }

  #sheet-handle { display: block; }

  #panel {
    position: fixed;
    left: 0;
    right: 0;
    /* iOS 키보드가 올라오면 visualViewport 가 줄어든다. 그만큼 시트를 띄워야
       입력창이 키보드에 가리지 않는다. */
    bottom: var(--kb, 0px);
    z-index: 10;
    /* 키보드가 올라오면 --vvh 가 줄어든다. 그 안에 들어가야 검색창이 안 잘린다. */
    height: min(86dvh, calc(var(--vvh, 100dvh) - 44px));
    border-right: 0;
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -2px 28px rgba(16, 22, 32, 0.16);
    transform: translateY(calc(100% - var(--sheet-peek)));
    transition: transform 0.34s cubic-bezier(0.22, 0.61, 0.36, 1);
    will-change: transform;
  }

  #panel.open { transform: translateY(0); }

  .panel-head { padding: 2px 20px 12px; border-bottom: 0; }
  .panel-head h1 { font-size: 18px; }
  .panel-head .sub { font-size: 13px; }

  .controls { padding: 0 20px 14px; }

  /* 접힌 상태에서는 검색창까지만 보인다 */
  .filter, .toggle, .result-count { display: none; }

  /* 검색 중에는 필터를 접어 결과에 자리를 내준다 */
  #panel.open.searching .filter,
  #panel.open.searching .toggle { display: none; }
  #panel.open .filter { display: block; }
  #panel.open .toggle { display: flex; }
  #panel.open .result-count { display: block; }

  #search {
    padding: 13px 38px 13px 14px;
    font-size: 15px;
    border-radius: 12px;
  }

  /* 손가락으로 누를 만하되 시트를 덜 차지하게 둔다 */
  .chip {
    padding: 6px 11px;
    font-size: 12.5px;
    border-radius: 999px;
  }

  .chips { gap: 5px; }

  .filter { margin-top: 10px; }

  .filter-label { margin-bottom: 4px; font-size: 10.5px; }

  .toggle { margin-top: 10px; font-size: 12.5px; }

  .result-count { padding: 12px 20px 4px; }

  .list { padding: 0 12px 8px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

  .item { padding: 13px 10px; border-radius: 12px; }
  .item-name { font-size: 15px; }
  .item-addr { margin-top: 4px; font-size: 13px; }

  .item + .item { border-top: 1px solid #f1f3f6; }

  .pending, .panel-foot { padding-left: 20px; padding-right: 20px; }
  .panel-foot { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }

  .pop { width: min(300px, calc(100vw - 40px)); border-radius: 16px; }

  /* 센터가 셋 이상이면 말풍선이 길어져 위가 잘린다. 넘치면 목록 안에서 굴린다. */
  #map .pop-list { max-height: 128px; }
  #info { width: min(440px, calc(100vw - 24px)); border-radius: 16px; }
  .pop-route a, .pop-links button { padding: 10px 0; font-size: 13px; }
}

@media (max-width: 780px) and (prefers-reduced-motion: reduce) {
  #panel { transition: none; }
}


/* ---------- 말풍선 안 센터 목록 ---------- */

.pop-list {
  margin: 9px 0 0;
  padding: 0;
  list-style: none;
  max-height: 190px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.pop-item {
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
}

.pop-item:hover { background: var(--bg-2); }

.pop-item.active { background: var(--red-soft); }

.pop-item-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.pop-item-name {
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pop-item-code {
  flex: 0 0 auto;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-3);
}

.pop-item-link {
  flex: 0 0 auto;
  margin-left: auto;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--red);
  text-decoration: none;
  white-space: nowrap;
}

.pop-item-link:hover { text-decoration: underline; }

.pop-item-meta {
  margin-top: 2px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--ink-3);
}
