:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #e5e7eb;
  --text: #1f2328;
  --muted: #6b7280;
  --accent: #2f6fed;
  --danger: #d93a3a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .06);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", "Noto Sans KR", sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
code { background: #f1f3f5; padding: 1px 5px; border-radius: 4px; font-size: .9em; }

.app { display: grid; grid-template-columns: 420px 1fr; height: 100vh; }

/* ---------- 사이드바 ---------- */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--line);
}
.trip-header { padding: 18px 18px 10px; }
.trip-title {
  width: 100%; border: 0; outline: 0; font-size: 22px; font-weight: 700; padding: 4px 0;
  border-bottom: 2px solid transparent;
}
.trip-title:focus { border-bottom-color: var(--accent); }
.title-row { display: flex; align-items: center; gap: 6px; }
.title-row .trip-title { flex: 1; min-width: 0; }
.share-btn {
  flex: none; border: 1px solid var(--accent); color: var(--accent); background: #fff;
  font-weight: 600; font-size: 13px; padding: 5px 12px; border-radius: 999px;
}
.share-btn:hover { background: color-mix(in srgb, var(--accent) 8%, #fff); }
.trip-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.sync-status { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.sync-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #c2c8d0; }
.sync-status[data-state="saved"]::before { background: #1f9d63; }
.sync-status[data-state="pending"]::before,
.sync-status[data-state="saving"]::before,
.sync-status[data-state="loading"]::before { background: #f08c00; }
.sync-status[data-state="offline"] { color: var(--danger); }
.sync-status[data-state="offline"]::before { background: var(--danger); }
.sync-status[data-state="readonly"]::before { background: var(--accent); }
.banner { background: #fff4e5; color: #8a4b00; font-size: 13px; padding: 10px 18px; border-bottom: 1px solid #f5d9b0; }

/* 보기 전용 */
body.readonly .add-form,
body.readonly .day-head-actions,
body.readonly .day-tab.add,
body.readonly .grip { display: none !important; }
body.readonly .drag-handle { cursor: default; }
body.readonly .place-body input:hover, body.readonly .place-body textarea:hover,
body.readonly .day-title:hover { border-color: transparent; }
body.readonly .p-time:disabled { color: var(--muted); opacity: 1; }
body.readonly .p-memo:placeholder-shown { display: none; }

/* 공유 창 */
.share-points { padding-left: 18px; font-size: 14px; line-height: 1.8; color: #374151; }
.share-points b { margin-right: 6px; }
.link-row { margin: 14px 0; }
.link-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; font-size: 14px; }
.link-box { display: flex; gap: 6px; }
.dialog .link-box input { flex: 1; min-width: 0; margin: 0; font-size: 12.5px; color: var(--muted); }
.start-date { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.start-date input { border: 1px solid var(--line); border-radius: 8px; padding: 3px 6px; font-size: 13px; }

.icon-btn {
  border: 0; background: transparent; width: 30px; height: 30px; border-radius: 8px;
  font-size: 16px; color: var(--muted); display: inline-grid; place-items: center;
}
.icon-btn:hover { background: #f0f2f5; color: var(--text); }
.text-btn { border: 0; background: transparent; color: var(--muted); font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.text-btn:hover { background: #f0f2f5; color: var(--text); }
.text-btn.danger:hover { color: var(--danger); }
.primary-btn {
  border: 0; background: var(--accent); color: #fff; font-weight: 600;
  padding: 8px 14px; border-radius: 8px; white-space: nowrap;
}
.primary-btn:hover { filter: brightness(1.07); }
.primary-btn:disabled { opacity: .55; cursor: wait; }

/* 일자 탭 */
.day-tabs {
  position: relative; display: flex; gap: 6px; padding: 4px 18px 10px; overflow-x: auto;
  scrollbar-width: thin; border-bottom: 1px solid var(--line);
}
.day-tab {
  flex: none; display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px;
}
.day-tab small { color: var(--muted); }
.day-tab .count { background: #f0f2f5; border-radius: 999px; padding: 0 7px; font-size: 11px; color: var(--muted); }
.day-tab.active { border-color: var(--c); background: color-mix(in srgb, var(--c) 9%, #fff); }
.day-tab.active .count { background: var(--c); color: #fff; }
.day-tab.add { color: var(--muted); padding: 6px 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); display: inline-block; flex: none; }

.day-head { padding: 12px 18px 4px; }
.day-head-top { display: flex; justify-content: space-between; align-items: center; }
.day-label { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.day-title {
  width: 100%; margin-top: 4px; border: 0; outline: 0; padding: 4px 0; font-size: 14px; color: var(--muted);
  border-bottom: 1px dashed transparent;
}
.day-title:hover { border-bottom-color: var(--line); }
.day-title:focus { border-bottom-color: var(--accent); color: var(--text); }

/* 장소 추가 */
.add-form { padding: 8px 18px 12px; display: flex; flex-direction: column; gap: 6px; position: relative; }
.add-form input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 14px; outline: 0; background: #fff;
}
.add-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }
.add-row { display: flex; gap: 6px; }
.add-status { font-size: 12.5px; min-height: 0; color: var(--muted); }
.add-status.error { color: var(--danger); }
.add-status.ok { color: #1f9d63; }
.candidates {
  list-style: none; margin: 0; padding: 4px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; box-shadow: var(--shadow); max-height: 300px; overflow: auto;
}
.cand-head { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--muted); padding: 4px 8px; }
.cand { width: 100%; text-align: left; border: 0; background: transparent; padding: 8px; border-radius: 8px; display: flex; flex-direction: column; gap: 2px; }
.cand:hover { background: #f3f6ff; }
.cand small { color: var(--muted); font-size: 12px; }

/* 장소 목록 */
.place-list { list-style: none; margin: 0; padding: 4px 12px 40px; overflow-y: auto; flex: 1; min-height: 0; }
.place { margin: 0 0 2px; }
.place-card {
  display: flex; gap: 8px; align-items: flex-start; padding: 10px 6px 10px 4px;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff; transition: border-color .15s, box-shadow .15s;
  cursor: pointer;
}
.place-card:hover { border-color: #cfd6e0; }
.place.selected .place-card { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }
.place.ghost .place-card { opacity: .4; border-style: dashed; }
.drag-handle { display: flex; align-items: center; gap: 2px; cursor: grab; padding: 2px 0 0 2px; touch-action: none; user-select: none; }
.drag-handle:active { cursor: grabbing; }
.grip { color: #c2c8d0; font-size: 12px; letter-spacing: -2px; }
.num {
  width: 26px; height: 26px; border-radius: 50%; background: var(--c); color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 700; flex: none;
}
.place-body { flex: 1; min-width: 0; }
.place-row { display: flex; align-items: center; gap: 6px; }
.place-body input, .place-body textarea {
  border: 1px solid transparent; background: transparent; border-radius: 6px; outline: 0; padding: 2px 4px;
}
.place-body input:hover, .place-body textarea:hover { border-color: var(--line); }
.place-body input:focus, .place-body textarea:focus { border-color: var(--accent); background: #fff; }
.p-time { width: 104px; flex: none; font-size: 13px; color: var(--muted); }
.p-time:invalid, .p-time[value=""] { color: #b0b6bf; }
.p-title { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; }
.p-sub { font-size: 12px; color: var(--muted); padding: 1px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-warn { font-size: 12px; color: #b26a00; padding: 1px 4px; }
.p-memo { display: block; width: 100%; resize: none; font-size: 13.5px; line-height: 1.45; margin-top: 2px; overflow: hidden; color: #374151; }
.place-actions { display: flex; flex-direction: column; }
.leg { font-size: 11.5px; color: var(--muted); padding: 3px 0 3px 46px; }
.empty-hint { padding: 30px 24px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.7; }

/* ---------- 지도 ---------- */
.map-area { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #e8eaed; z-index: 0; }
.map-toolbar {
  position: absolute; top: 12px; left: 12px; display: flex; background: #fff; border-radius: 10px;
  box-shadow: var(--shadow); padding: 3px; z-index: 2;
}
.seg { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.seg.active { background: var(--accent); color: #fff; font-weight: 600; }

.pin {
  --c: #e5484d;
  width: 30px; height: 30px; border-radius: 50%; background: var(--c); color: #fff;
  border: 2.5px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  display: grid; place-items: center; font-weight: 800; font-size: 13px;
  transition: transform .15s; cursor: pointer;
}
.pin.selected { transform: scale(1.35); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 35%, transparent), 0 3px 10px rgba(0, 0, 0, .4); }
/* 구글 고급 마커는 아래쪽 가운데가 기준점이라 원 중심을 좌표에 맞추려고 내림 */
.pin.g { transform: translateY(50%); }
.pin.g.selected { transform: translateY(50%) scale(1.35); }
/* Leaflet */
.pin-wrap, .arrow-wrap { background: none; border: 0; }
.arrow {
  width: 16px; height: 16px; display: grid; place-items: center;
}
.arrow::before {
  content: ""; border-left: 11px solid var(--c); border-top: 7px solid transparent; border-bottom: 7px solid transparent;
  filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 0 1px #fff);
}
.leaflet-container { font: inherit; }
.block-btn { display: block; text-align: center; text-decoration: none; margin-top: 8px; padding: 10px 14px; }

.map-notice {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 3;
  background: #fff; padding: 22px 26px; border-radius: 14px; box-shadow: var(--shadow);
  max-width: 440px; text-align: center; line-height: 1.6; font-size: 14px;
}
.map-notice button { margin-top: 12px; }

/* 상세 패널 */
.detail {
  position: absolute; top: 12px; right: 12px; bottom: 12px; width: 380px; z-index: 4;
  background: #fff; border-radius: 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, .18);
  overflow-y: auto; animation: slideIn .18s ease-out;
}
@keyframes slideIn { from { transform: translateX(16px); opacity: 0; } }
.detail-head {
  position: sticky; top: 0; background: #fff; z-index: 1;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 16px 14px 10px 18px;
  border-bottom: 1px solid var(--line);
}
.detail-head h2 { margin: 0; font-size: 18px; }
.detail-orig { font-size: 13px; color: var(--muted); margin-top: 2px; }
.my-note { margin: 12px 18px 0; padding: 10px 12px; background: #fff8e6; border-radius: 10px; font-size: 13.5px; }
.my-note p { margin: 4px 0 0; white-space: pre-wrap; }
.photos { display: flex; gap: 6px; overflow-x: auto; padding: 12px 18px 0; scroll-snap-type: x mandatory; }
.photos figure { margin: 0; flex: none; position: relative; scroll-snap-align: start; }
.photos img { height: 150px; width: auto; max-width: 260px; object-fit: cover; border-radius: 10px; display: block; background: #eee; }
.photos figcaption { position: absolute; left: 6px; bottom: 6px; font-size: 10px; }
.photos figcaption a { color: #fff; text-shadow: 0 1px 3px #000; text-decoration: none; }
.detail-section { padding: 14px 18px; border-bottom: 1px solid #f0f2f5; font-size: 14px; }
.detail-section h3 { margin: 0 0 10px; font-size: 15px; }
.detail-section.error { color: var(--danger); }
.g-name { font-weight: 700; font-size: 16px; }
.g-type { font-weight: 400; font-size: 12px; color: var(--muted); background: #f0f2f5; padding: 1px 7px; border-radius: 999px; margin-left: 4px; }
.rating { display: flex; align-items: center; gap: 6px; margin: 6px 0 8px; }
.rating b { font-size: 16px; }
.stars { --pct: calc(var(--r) / 5 * 100%); display: inline-block; font-size: 14px; letter-spacing: 1px;
  background: linear-gradient(90deg, #fbbc04 var(--pct), #dadce0 var(--pct)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stars::before { content: "★★★★★"; }
.info-row { margin: 5px 0; color: #374151; word-break: break-all; }
.info-row a { color: var(--accent); }
.hours summary { cursor: pointer; margin-top: 6px; color: #374151; }
.hours ul { margin: 6px 0 0; padding-left: 22px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.muted { color: var(--muted); font-size: 13px; }
.review { padding: 10px 0; border-top: 1px solid #f0f2f5; }
.review:first-of-type { border-top: 0; padding-top: 0; }
.review-head { display: flex; gap: 10px; align-items: center; }
.review-head img, .avatar { width: 32px; height: 32px; border-radius: 50%; background: #e5e7eb; flex: none; }
.review-head a { font-weight: 600; font-size: 13.5px; color: var(--text); text-decoration: none; }
.review-meta { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.review-meta .stars { font-size: 12px; }
.review-text {
  margin: 6px 0 0; font-size: 13.5px; line-height: 1.55; color: #374151; white-space: pre-wrap; cursor: pointer;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.review-text.open { -webkit-line-clamp: unset; display: block; }
.gmaps-link { display: block; text-align: center; padding: 14px; color: var(--accent); font-weight: 600; text-decoration: none; }
.spinner { width: 26px; height: 26px; margin: 20px auto; border: 3px solid #e5e7eb; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 팝오버 */
.popover {
  position: fixed; z-index: 50; min-width: 200px; max-width: 300px; background: #fff; border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .16); padding: 5px; border: 1px solid var(--line);
}
.popover button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 7px; font-size: 13.5px; }
.popover button:hover { background: #f3f4f6; }
.popover button.danger { color: var(--danger); }
.popover hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.pop-label { font-size: 11.5px; color: var(--muted); padding: 4px 10px 2px; }

/* 다이얼로그 */
.dialog { border: 0; border-radius: 16px; padding: 24px; max-width: 480px; width: calc(100% - 32px); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.dialog::backdrop { background: rgba(15, 23, 42, .35); }
.dialog h2 { margin: 0 0 6px; font-size: 19px; }
.dialog p { margin: 6px 0; font-size: 14px; color: #374151; }
.key-steps { font-size: 13.5px; line-height: 1.7; padding-left: 20px; color: #374151; }
.dialog input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font-family: ui-monospace, monospace; margin-top: 6px; }
.dialog .hint { font-size: 12px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ---------- 모바일 ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; }
  .map-area { order: -1; height: 50vh; position: sticky; top: 0; z-index: 5; }
  .sidebar { border-right: 0; }
  .place-list { overflow: visible; }
  .detail { left: 8px; right: 8px; width: auto; top: 8px; bottom: 8px; }
}
