:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e3e6ea;
  --text: #1c2126;
  --muted: #7b848e;
  --primary: #2f6fed;
  --primary-dark: #2559c7;
  --danger: #e4483c;
  --accent: #f5493d;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(20, 30, 45, .10);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
               "Malgun Gothic", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ---------- 키 입력 게이트 ---------- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, #eef2f8, #e2e8f2);
  padding: 20px;
}
.gate-card {
  width: min(520px, 100%);
  background: var(--panel);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(20, 30, 45, .16);
  padding: 32px;
}
.gate-card h1 { margin: 0 0 12px; font-size: 22px; }
.gate-desc { margin: 0 0 18px; font-size: 14px; line-height: 1.65; color: #4a545e; }
.gate-desc a { color: var(--primary); }
.gate-steps {
  margin: 0 0 22px; padding-left: 20px;
  font-size: 13px; line-height: 1.9; color: #4a545e;
}
.gate-steps code {
  background: #eef1f5; padding: 2px 6px; border-radius: 5px;
  font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.gate-row { display: flex; gap: 8px; }
.gate-row input { flex: 1; }
.gate-error { margin: 14px 0 0; color: var(--danger); font-size: 13px; }

/* ---------- 공통 폼 ---------- */
input[type="text"] {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, .13);
}

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 11px 16px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: #fff; border-color: var(--line); color: #4a545e; }
.btn.ghost:hover { border-color: #c6ccd4; background: #f8f9fb; }
.btn.wide { width: 100%; }
.btn.sm { padding: 7px 11px; font-size: 12.5px; }
.link-btn {
  background: none; border: none; color: var(--primary);
  font: inherit; font-size: 13px; cursor: pointer; text-decoration: underline;
}
.icon-btn {
  background: none; border: none; font-size: 17px; cursor: pointer;
  color: var(--muted); padding: 4px 6px; border-radius: 8px;
}
.icon-btn:hover { background: #eef1f5; }

/* ---------- 레이아웃 ---------- */
.app { display: flex; height: 100%; }

.sidebar {
  width: 340px;
  flex: 0 0 340px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}
.side-head h1 { margin: 0; font-size: 17px; letter-spacing: -.3px; }

.panel { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.panel.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; border-bottom: none; }
.panel-title {
  margin: 0 0 12px; font-size: 12px; font-weight: 700;
  color: var(--muted); letter-spacing: .3px;
  display: flex; align-items: center; gap: 6px;
}
.panel-hint { margin-left: auto; font-weight: 500; font-size: 11px; color: #a3abb4; }
.badge {
  background: #eef1f5; color: #56606a; border-radius: 20px;
  padding: 1px 8px; font-size: 11px;
}

#addForm { display: flex; flex-direction: column; gap: 8px; }
#addForm .row { display: flex; gap: 6px; }
#addForm .row input { flex: 1; }
#addForm .row .btn { padding: 11px 12px; }

.msg { margin: 10px 0 0; font-size: 12.5px; line-height: 1.5; }
.msg.ok { color: #1a7f47; }
.msg.err { color: var(--danger); }

/* ---------- 병원 목록 ---------- */
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s;
}
.list-item:hover { background: #f4f6f9; }
.list-item.nearest { background: #fff2f1; }
.list-item.active { background: #e9f0fe; }
.li-rank {
  flex: 0 0 22px; height: 22px; border-radius: 50%;
  background: #eef1f5; color: #56606a;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin-top: 2px;
}
.list-item.nearest .li-rank { background: var(--accent); color: #fff; }
.li-body { flex: 1; min-width: 0; }
.li-name { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.li-addr {
  font-size: 12px; color: var(--muted); line-height: 1.45;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.li-memo { font-size: 12px; color: #8b939c; margin-top: 2px; }
.li-dist {
  font-size: 11.5px; font-weight: 700; color: var(--primary);
  margin-top: 3px;
}
.list-item.nearest .li-dist { color: var(--accent); }
.li-del {
  flex: 0 0 auto; background: none; border: none;
  color: #c3cad2; font-size: 15px; cursor: pointer;
  padding: 2px 4px; border-radius: 6px;
}
.li-del:hover { color: var(--danger); background: #fdeceb; }

.empty {
  margin: 20px 4px; font-size: 13px; line-height: 1.7;
  color: #a3abb4; text-align: center;
}

.side-foot {
  padding: 12px 18px; border-top: 1px solid var(--line);
  display: flex; gap: 8px;
}
.side-foot .btn { flex: 1; }

/* ---------- 지도 ---------- */
.map-wrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; background: #dfe3e8; }

.search-results {
  margin: 8px 0 0; max-height: 260px; overflow-y: auto;
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px;
}
.sr-item { padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.sr-item:hover { background: #f4f6f9; }
.sr-title { font-size: 13.5px; font-weight: 600; }
.sr-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.sr-empty { padding: 12px; font-size: 13px; color: var(--muted); }


.nearest-card {
  position: absolute; left: 14px; bottom: 20px; z-index: 20;
  background: #fff; border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
  max-width: calc(100% - 28px);
}
.nearest-label {
  font-size: 10.5px; color: var(--muted); font-weight: 600;
  border-right: 1px solid var(--line); padding-right: 12px;
  line-height: 1.4; width: 62px; flex: none;
}
.nearest-card strong { font-size: 15px; }
.nearest-dist {
  font-size: 13px; font-weight: 700; color: var(--accent);
  background: #fff1f0; padding: 3px 9px; border-radius: 20px;
}

.pick-banner {
  position: absolute; top: 70px; left: 50%; transform: translateX(-50%);
  z-index: 22;
  background: #1c2126; color: #fff;
  padding: 9px 16px; border-radius: 30px;
  font-size: 13px; box-shadow: var(--shadow);
}
.pick-banner .link-btn { color: #8fb6ff; margin-left: 6px; }

.zoom-ctrl {
  position: absolute; right: 14px; bottom: 20px; z-index: 20;
  display: flex; flex-direction: column;
  background: #fff; border-radius: 10px; box-shadow: var(--shadow); overflow: hidden;
}
.zoom-ctrl button {
  width: 38px; height: 38px; border: none; background: #fff;
  font-size: 16px; cursor: pointer; color: #4a545e;
  border-bottom: 1px solid var(--line);
}
.zoom-ctrl button:last-child { border-bottom: none; }
.zoom-ctrl button:hover { background: #f4f6f9; }

/* 지도 위 마커 라벨 */
.pin-label {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(20, 30, 45, .18);
  transform: translateY(2px);
}
.pin-label.is-nearest {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

@media (max-width: 820px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; flex: 0 0 auto; max-height: 46vh;
    border-right: none; border-bottom: 1px solid var(--line);
  }
  .map-wrap { flex: 1; min-height: 54vh; }
  .nearest-label { display: none; }
}

/* ===== 지역 필터 / 프리셋 ===== */
.filter-row {
  display: flex; gap: 6px; align-items: center;
  margin: 0 0 10px;
}
.filter-row select {
  flex: 1; min-width: 0;
  padding: 8px 10px;
  font-size: 13px; font-family: inherit; color: #2b333b;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer;
}
.filter-row select:focus { outline: none; border-color: var(--primary); }
.filter-row .btn { white-space: nowrap; }

.list-more {
  margin: 8px 0 0; padding: 8px 10px;
  font-size: 11.5px; line-height: 1.5; color: #8b939c;
  background: #f4f6f9; border-radius: 8px;
}

.li-tag {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  font-size: 10.5px; font-weight: 700; letter-spacing: -.2px;
  border-radius: 999px; vertical-align: 1px;
}
.li-tag.closed { background: #e6e9ed; color: #6d757e; }
.list-item.closed .li-name { color: #8b939c; }
.list-item.closed .li-rank { background: #e6e9ed; color: #8b939c; }

.pin-label.is-closed {
  background: #eceff3; color: #6d757e; border-color: #cfd5dc;
  text-decoration: line-through;
}

.side-foot { flex-wrap: wrap; }
.side-foot .btn { flex: 1 1 calc(50% - 4px); }

/* ===== 탭 (찾기 / 관리) ===== */
.tabs {
  display: flex; gap: 4px; padding: 8px 12px 0;
  border-bottom: 1px solid var(--line); background: #fff;
}
.tab {
  flex: 1; padding: 11px 8px;
  font: 600 13.5px/1 inherit; color: var(--muted);
  background: none; border: none; border-bottom: 2px solid transparent;
  cursor: pointer; transition: color .12s, border-color .12s;
}
.tab:hover { color: #4a545e; }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ===== 찾기: 검색 · 기준 위치 ===== */
.search-row { display: flex; gap: 6px; }
.search-row input { flex: 1; min-width: 0; }

.origin-row {
  display: flex; align-items: center; gap: 10px;
  margin-top: 12px; padding: 10px 12px;
  background: #eef3fe; border: 1px solid #d8e3fb; border-radius: var(--radius);
}
.origin-pin { color: var(--primary); font-size: 15px; line-height: 1; }
.origin-body { flex: 1; min-width: 0; }
.origin-label { display: block; font-size: 10.5px; font-weight: 700; color: #6c86bd; letter-spacing: .2px; }
.origin-body strong {
  display: block; font-size: 13px; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.toggle {
  display: flex; align-items: center; gap: 7px;
  margin-top: 10px; font-size: 12.5px; color: #4a545e; cursor: pointer;
  user-select: none;
}
.toggle input { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }

/* 지도 위 기준 위치 점 */
.origin-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary); border: 3px solid #fff;
  box-shadow: 0 0 0 3px rgba(47, 111, 237, .28), 0 2px 6px rgba(0, 0, 0, .25);
}

.refind-btn {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 22;
  padding: 10px 18px; border: none; border-radius: 30px;
  background: var(--primary); color: #fff;
  font: 600 13px/1 inherit; cursor: pointer;
  box-shadow: 0 3px 12px rgba(47, 111, 237, .38);
}
.refind-btn:hover { background: var(--primary-dark); }

/* ===== 관리: 지역 필터 / 목록 검색 ===== */
.filter-row { display: flex; gap: 6px; align-items: center; margin: 0 0 8px; }
.filter-row select {
  flex: 1; min-width: 0;
  padding: 8px 10px;
  font-size: 13px; font-family: inherit; color: #2b333b;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer;
}
.filter-row select:focus { outline: none; border-color: var(--primary); }
.filter-row .btn { white-space: nowrap; }

.m-search { width: 100%; margin-bottom: 10px; padding: 9px 12px; font-size: 13px; }

.list-more {
  margin: 8px 0 0; padding: 8px 10px;
  font-size: 11.5px; line-height: 1.5; color: #8b939c;
  background: #f4f6f9; border-radius: 8px;
}

/* ===== 폐업 표시 ===== */
.li-tag {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  font-size: 10.5px; font-weight: 700; letter-spacing: -.2px;
  border-radius: 999px; vertical-align: 1px;
}
.li-tag.closed { background: #e6e9ed; color: #6d757e; }
.list-item.closed .li-name { color: #8b939c; }
.list-item.closed .li-rank { background: #e6e9ed; color: #8b939c; }
.pin-label.is-closed {
  background: #eceff3; color: #6d757e; border-color: #cfd5dc;
  text-decoration: line-through;
}

.side-foot { flex-wrap: wrap; }
.side-foot .btn { flex: 1 1 calc(50% - 4px); }

/* 관리 탭: 접히는 등록 폼 */
.add-box { border: none; }
.add-summary {
  list-style: none; cursor: pointer;
  font-size: 13.5px; font-weight: 700; color: var(--primary);
  padding: 4px 0;
}
.add-summary::-webkit-details-marker { display: none; }
.add-box[open] .add-summary { margin-bottom: 10px; color: #4a545e; }

.sr-kind {
  display: inline-block; margin-right: 6px; padding: 1px 6px;
  font-size: 10.5px; font-weight: 700;
  background: #eef3fe; color: var(--primary); border-radius: 999px;
}
.sr-hint { display: block; margin-top: 6px; font-size: 11px; color: #a3abb4; }

/* ---------- 회송 메시지 ---------- */
.li-refer {
  flex: 0 0 auto; align-self: center;
  background: #fff; border: 1px solid var(--line); color: var(--primary);
  font-size: 11.5px; font-weight: 700; font-family: inherit;
  padding: 5px 9px; border-radius: 8px; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.li-refer:hover { background: #eef3fe; border-color: #b9cdfa; }
.list-item.closed .li-refer { display: none; }

.modal {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(20, 30, 45, .38);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-card {
  width: min(620px, 100%); max-height: 100%;
  background: #fff; border-radius: 14px;
  box-shadow: 0 12px 44px rgba(20, 30, 45, .28);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.modal-headings { flex: 1; min-width: 0; }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-sub {
  margin: 4px 0 0; font-size: 13px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.modal-sub b { color: var(--text); font-size: 14px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-body .panel-title { margin-top: 18px; }
.modal-body .panel-title:first-child { margin-top: 0; }

.dx-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px;
  max-height: 210px; overflow-y: auto; padding-right: 2px;
}
.dx-btn {
  text-align: left; background: #fff; cursor: pointer;
  border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 10px; font-family: inherit; color: var(--text);
  transition: background .12s, border-color .12s;
}
.dx-btn:hover { background: #f4f6f9; border-color: #c6ccd4; }
.dx-btn.is-on { background: #eef3fe; border-color: var(--primary); }
.dx-name { display: block; font-size: 13px; font-weight: 600; }
.dx-name .dx-no { color: var(--muted); font-weight: 700; margin-right: 4px; }
.dx-note { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.dx-btn.is-on .dx-note { color: #5b7fd4; }

.refer-text {
  width: 100%; margin-top: 4px;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 13px; font-family: inherit; font-size: 13.5px; line-height: 1.7;
  resize: vertical; outline: none; background: #fff; color: var(--text);
}
.refer-text:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,111,237,.13); }

.modal-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-top: 1px solid var(--line); background: #fafbfc;
}
.modal-foot .toggle { margin: 0; font-size: 12.5px; }
.modal-foot .btn { margin-left: auto; }
.copied { font-size: 12.5px; font-weight: 600; color: #1a7f47; }

@media (max-width: 820px) {
  .modal { position: fixed; padding: 12px; }
  .dx-grid { grid-template-columns: 1fr; max-height: 160px; }
}
