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

:root {
  --primary: #2D6A4F;
  --primary-light: #40916C;
  --primary-dark: #1B4332;
  --accent: #B7E4C7;
  --bg: #F8FAF9;
  --surface: #FFFFFF;
  --border: #E2EBE6;
  --text: #1A2E23;
  --text-muted: #6B8F78;
  --danger: #C0392B;
  --shadow: 0 4px 24px rgba(0,0,0,0.12);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --radius: 20px;
  --radius-sm: 12px;
  font-family: 'Noto Sans KR', -apple-system, sans-serif;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }

/* ── 로그인 페이지 ── */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100dvh;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 60%, var(--primary-light) 100%);
}
.login-container {
  background: var(--surface); border-radius: 24px; padding: 48px 40px;
  width: 100%; max-width: 380px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 32px;
}
.login-logo { text-align: center; }
.logo-icon { font-size: 48px; margin-bottom: 12px; }
.login-logo h1 { font-size: 24px; font-weight: 600; color: var(--primary-dark); }
.login-logo p  { font-size: 14px; color: var(--text-muted); margin-top: 4px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.input-group input {
  width: 100%; padding: 14px 16px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 15px; font-family: inherit;
  outline: none; transition: border-color .2s;
}
.input-group input:focus { border-color: var(--primary); }
.error-msg { color: var(--danger); font-size: 13px; min-height: 18px; text-align: center; }

/* ── 공통 버튼 ── */
.btn-primary {
  background: var(--primary); color: #fff; border: none;
  border-radius: var(--radius-sm); padding: 14px 20px;
  font-size: 15px; font-weight: 500; font-family: inherit;
  cursor: pointer; transition: background .2s, transform .1s;
}
.btn-primary:hover  { background: var(--primary-light); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary {
  background: var(--bg); color: var(--primary); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 16px;
  font-size: 14px; font-weight: 500; font-family: inherit;
  cursor: pointer; transition: background .2s;
}
.btn-secondary:hover { background: var(--accent); }
.btn-sm  { padding: 8px 12px; font-size: 13px; }
.btn-full { width: 100%; }
.btn-icon-sm {
  background: none; border: none; font-size: 16px; cursor: pointer;
  padding: 6px; border-radius: 8px; color: var(--text-muted);
  transition: background .15s, color .15s; line-height: 1;
}
.btn-icon-sm:hover { background: var(--bg); color: var(--text); }

/* ── 지도 전체화면 ── */
.map-page { height: 100dvh; overflow: hidden; }
#map { position: fixed; inset: 0; }

/* ── 플로팅 버튼 (FAB) ── */
.fab {
  position: fixed; z-index: 100; border: none; cursor: pointer;
  font-weight: 700; font-family: inherit; transition: transform .15s, box-shadow .15s;
  box-shadow: var(--shadow);
}
.fab:hover  { transform: scale(1.07); }
.fab:active { transform: scale(0.95); }

.fab-list {
  top: max(20px, env(safe-area-inset-top, 20px));
  right: 20px;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--surface); color: var(--text); font-size: 18px;
}
.fab-add {
  bottom: max(32px, env(safe-area-inset-bottom, 32px));
  right: 20px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 26px;
}

/* ── 목록 드로어 ── */
.drawer-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.3); z-index: 200;
}
.drawer-backdrop.show { display: block; }
.drawer {
  position: fixed; top: 0; right: -320px; bottom: 0; width: 320px;
  background: var(--surface); z-index: 210;
  display: flex; flex-direction: column;
  transition: right .3s cubic-bezier(.4,0,.2,1);
  box-shadow: -4px 0 24px rgba(0,0,0,0.12);
}
.drawer.open { right: 0; }
.drawer-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 24px 20px 12px;
}
.drawer-header h2 { font-size: 18px; font-weight: 600; }
.building-count {
  font-size: 12px; color: var(--text-muted);
  background: var(--bg); padding: 3px 10px; border-radius: 20px;
  margin-top: 4px; display: inline-block;
}
.drawer-close {
  background: none; border: none; font-size: 18px; cursor: pointer;
  color: var(--text-muted); padding: 4px; border-radius: 8px;
  transition: background .15s;
}
.drawer-close:hover { background: var(--bg); }
.drawer-search { padding: 0 16px 12px; }
.drawer-search input {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; font-family: inherit;
  outline: none; background: var(--bg); transition: border-color .2s;
}
.drawer-search input:focus { border-color: var(--primary); }
.building-list { flex: 1; overflow-y: auto; list-style: none; padding: 0 12px 12px; }
.building-item {
  padding: 14px 12px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .15s; margin-bottom: 4px;
}
.building-item:hover { background: var(--bg); }
.building-item-name { font-size: 15px; font-weight: 500; margin-bottom: 3px; }
.building-item-addr { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.building-item-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.meta-tag {
  font-size: 11px; color: var(--primary); background: var(--accent);
  padding: 2px 8px; border-radius: 20px;
}

/* ── 바텀시트 공통 ── */
.sheet-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.35); z-index: 300;
}
.sheet-backdrop.show { display: block; }
.sheet {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 310;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  max-height: 85dvh;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.14);
}
.sheet.open { transform: translateY(0); }
.sheet-sm { max-height: 70dvh; }

.sheet-handle {
  width: 40px; height: 4px; background: var(--border);
  border-radius: 2px; margin: 12px auto 0; flex-shrink: 0;
}
.sheet-header { padding: 12px 20px 0; flex-shrink: 0; }
.sheet-title-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
}
.sheet-title { font-size: 19px; font-weight: 600; line-height: 1.3; }
.sheet-address { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.sheet-header-actions { display: flex; gap: 2px; flex-shrink: 0; }
.sheet-close-btn { font-size: 18px; }

/* 요약 통계 */
.sheet-stats {
  display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap;
}
.stat-chip {
  background: var(--bg); border-radius: 20px;
  padding: 5px 12px; font-size: 12px; color: var(--text-muted);
  display: flex; align-items: center; gap: 4px;
}
.stat-chip strong { color: var(--primary); font-weight: 600; }

/* ── 탭 ── */
.sheet-tabs {
  display: flex; gap: 4px; margin: 14px 20px 0;
  background: var(--bg); border-radius: var(--radius-sm); padding: 4px;
  flex-shrink: 0;
}
.tab-btn {
  flex: 1; padding: 9px; background: none; border: none;
  border-radius: 10px; font-size: 13px; font-weight: 500;
  font-family: inherit; cursor: pointer; color: var(--text-muted);
  transition: all .2s;
}
.tab-btn.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.tab-content { display: none; }
.tab-content.active { display: block; }

.sheet-body {
  flex: 1; overflow-y: auto; padding: 16px 20px 40px;
}

/* ── 임장 기록 ── */
.inspection-list { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.inspection-card {
  background: var(--bg); border-radius: var(--radius-sm); padding: 16px;
  border-left: 4px solid var(--primary);
}
.inspection-card-header {
  display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px;
}
.inspection-date  { font-size: 13px; font-weight: 600; color: var(--primary); }
.inspection-price { font-size: 15px; font-weight: 600; }
.inspection-review { font-size: 14px; margin-bottom: 5px; }
.inspection-notes  { font-size: 13px; color: var(--text-muted); white-space: pre-wrap; }
.inspection-actions { display: flex; gap: 8px; margin-top: 10px; }
.btn-tiny {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 10px; font-size: 12px; cursor: pointer;
  font-family: inherit; color: var(--text-muted); transition: all .15s;
}
.btn-tiny:hover { background: var(--surface); }
.btn-tiny.danger { color: var(--danger); border-color: var(--danger); }

/* ── 사진 ── */
.photo-upload-area {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 18px; border: 2px dashed var(--border); border-radius: var(--radius-sm);
  cursor: pointer; margin-bottom: 14px; color: var(--text-muted);
  transition: all .2s; font-size: 14px;
}
.photo-upload-area:hover { border-color: var(--primary); color: var(--primary); background: var(--accent); }
.upload-hint { display: flex; align-items: center; gap: 8px; }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo-thumb {
  aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden;
  cursor: pointer; background: var(--bg);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s; }
.photo-thumb:hover img { transform: scale(1.05); }

/* ── 건물 추가 폼 ── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 12px; color: var(--text-muted);
  font-weight: 500; margin-bottom: 6px;
}
.form-group input, .form-group textarea {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; font-family: inherit;
  outline: none; transition: border-color .2s; background: var(--bg);
}
.form-group input:focus, .form-group textarea:focus {
  border-color: var(--primary); background: var(--surface);
}
.form-group textarea { resize: vertical; }
.address-row { display: flex; gap: 8px; }
.address-row input { flex: 1; }
.add-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.6; }
.coord-display {
  display: flex; align-items: center; gap: 8px;
  background: var(--accent); border-radius: var(--radius-sm);
  padding: 10px 14px; margin-bottom: 14px; font-size: 13px; color: var(--primary-dark);
}

/* ── 지도 pick 모드 ── */
.map-pick-mode #map { cursor: crosshair; }
.pick-toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--primary-dark); color: #fff; padding: 12px 24px;
  border-radius: 24px; font-size: 14px; z-index: 400; box-shadow: var(--shadow);
  animation: fadeUp .3s ease; white-space: nowrap;
}
@keyframes fadeUp {
  from { opacity:0; transform: translate(-50%, 10px); }
  to   { opacity:1; transform: translate(-50%, 0); }
}

/* ── 라이트박스 ── */
.lightbox {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.92); z-index: 500;
  flex-direction: column; align-items: center; justify-content: center;
}
.lightbox.open { display: flex; }
.lightbox-img { max-width: 90vw; max-height: 80dvh; object-fit: contain; border-radius: 8px; }
.lightbox-close {
  position: absolute; top: 20px; right: 20px;
  background: rgba(255,255,255,0.15); border: none; color: #fff;
  font-size: 18px; width: 44px; height: 44px; border-radius: 50%;
  cursor: pointer; transition: background .15s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.25); }
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,0.15); border: none; color: #fff;
  font-size: 36px; width: 52px; height: 52px; border-radius: 50%;
  cursor: pointer; transition: background .15s;
}
.lightbox-nav:hover  { background: rgba(255,255,255,0.25); }
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }
.lightbox-delete {
  position: absolute; bottom: 24px;
  background: rgba(192,57,43,0.8); border: none; color: #fff;
  padding: 10px 20px; border-radius: 20px; cursor: pointer;
  font-size: 14px; transition: background .15s;
}
.lightbox-delete:hover { background: var(--danger); }

/* ── 네이버 지도 커스텀 마커 ── */
.custom-marker {
  background: var(--surface); color: var(--primary-dark);
  padding: 6px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;
  white-space: nowrap; box-shadow: var(--shadow-sm);
  border: 2px solid var(--primary); cursor: pointer;
  transition: transform .15s, background .15s;
  font-family: 'Noto Sans KR', sans-serif;
}
.custom-marker:hover   { transform: scale(1.08); background: var(--accent); }
.custom-marker.visited { background: var(--primary); color: #fff; }

/* ── 스크롤바 ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── 태블릿/데스크톱 ── */
@media (min-width: 768px) {
  .sheet { max-width: 480px; left: 50%; right: auto; transform: translateX(-50%) translateY(100%); }
  .sheet.open { transform: translateX(-50%) translateY(0); }
  .drawer { width: 360px; }
}
