:root {
  --bg: #0f1720;
  --panel: #16212c;
  --panel-2: #1c2a37;
  --border: #2a3a48;
  --text: #e7edf2;
  --report-text: #000000;
  --text-dim: #65768a;
  --accent: #677e93;
  --accent-2: #2b7fd6;
  --red: #ef4444;
  --orange: #f59e0b;
  --yellow: #eab308;
  --blue: #3b82f6;
  --green: #22c55e;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* 페이지 자체의 핀치/더블탭 확대를 막는다. 지도는 Leaflet이 .leaflet-container에
     touch-action: none을 설정하고 핀치 줌을 직접 처리하므로 영향받지 않는다. */
  touch-action: pan-x pan-y;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

textarea,
.field textarea,
.mobile-report-form textarea {
  color: var(--report-text);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-pin { font-size: 28px; }
.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--text-dim); }

.header-actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: #223141; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #08131e; }
.btn-primary:hover { background: var(--accent-2); }
.btn-secondary { background: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); font-weight: 600; }
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; }

.app-body {
  display: grid;
  grid-template-columns: 280px 1fr;
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}

.mobile-report-panel { display: none; }

.filter-panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
}

.filter-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.filter-panel-header h2 { margin: 0; font-size: 15px; }
.filter-panel-header-actions { display: flex; align-items: center; gap: 8px; }

/* 모바일 드로어 전용 닫기 버튼 (데스크톱에서는 숨김) */
.filter-close-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

/* 모바일에서 필터 드로어가 열렸을 때 바깥 영역 탭으로 닫기 위한 배경 */
.filter-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 540;
}
.filter-backdrop.open { display: block; }

.filter-group { margin-bottom: 16px; }
.filter-group-title { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.03em; }
.filter-chip-list { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #08131e; font-weight: 700; }

.filter-summary { font-size: 12px; color: var(--text-dim); margin-top: 8px; }

.filter-toggle-btn {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 500;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}

.mobile-congestion-toggle-btn {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* z-index: 0 으로 스태킹 컨텍스트를 만들어 Leaflet 내부 컨트롤(z-index 1000)이
   제보 페이지·모달 등 바깥 오버레이 위로 떠오르지 않게 가둔다. */
.map-area { position: relative; height: 100%; z-index: 0; }
#map { height: 100%; width: 100%; background: #0b1017; }

.legend {
  position: absolute;
  bottom: 16px;
  left: 16px;
  background: rgba(22, 33, 44, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 400;
}
.legend > div { display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.red { background: var(--red); }
.dot.orange { background: var(--orange); }
.dot.yellow { background: var(--yellow); }
.dot.blue { background: var(--blue); }
.dot.green { background: var(--green); }

.detail-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 380px;
  max-width: 92vw;
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.2s ease;
  z-index: 600;
  overflow-y: auto;
  padding: 18px;
}
.detail-panel.open { transform: translateX(0); }
.detail-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
}

.detail-title { font-size: 16px; font-weight: 700; margin: 0 0 4px; }
.detail-sub { font-size: 12px; color: var(--text-dim); margin: 0 0 16px; }
.detail-section { margin-bottom: 16px; }
.detail-section h4 { margin: 0 0 6px; font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em; }
.detail-section p, .detail-section pre { margin: 0; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.badge { padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; background: var(--panel-2); border: 1px solid var(--border); }
.badge.risk-매우\ 높음, .badge.risk-높음 { background: rgba(239,68,68,0.18); color: #ff8080; border-color: rgba(239,68,68,0.4); }
.badge.risk-보통 { background: rgba(245,158,11,0.18); color: #ffc266; border-color: rgba(245,158,11,0.4); }
.badge.risk-낮음 { background: rgba(34,197,94,0.18); color: #7cf0a8; border-color: rgba(34,197,94,0.4); }

.report-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 8px;
  background: var(--panel-2);
  font-size: 13px;
  color: var(--report-text);
}
.report-card img { max-width: 100%; border-radius: 6px; margin-top: 6px; }
.report-card .meta { color: var(--text-dim); font-size: 11px; margin-top: 4px; }

.official-report-box {
  background: #0d1621;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 13px;
  max-height: 260px;
  overflow-y: auto;
}

.channel-buttons { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.complaint-form { display: flex; gap: 6px; margin-top: 10px; }
.complaint-form input { flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); }
.complaint-form select { padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); }

.status-select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); }

.escalation-banner {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #ff9f9f;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  margin-bottom: 12px;
  font-weight: 600;
}

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 900;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 560px;
  max-width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-sm { width: 420px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 22px; cursor: pointer; }

.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.field select, .field textarea, .field input[type="file"], .field input[type="text"] {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.field span { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

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

.other-input { margin-top: 4px; }
.hidden { display: none !important; }

.hint { font-size: 13px; color: var(--accent); background: rgba(58,160,255,0.1); padding: 8px 10px; border-radius: 8px; margin: 0; }
.hint-inline { font-size: 12px; margin-bottom: 8px; }

.gradient-bar {
  display: flex;
  height: 38px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  gap: 2px;
  background: var(--panel-2);
}
.gradient-segment {
  flex: 1;
  border: none;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.15s, transform 0.1s;
}
.gradient-segment:hover { opacity: 0.75; }
.gradient-segment.active {
  opacity: 1;
  transform: scaleY(1.08);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.7);
}
.gradient-bar-caption { font-size: 12px; color: var(--text-dim); text-align: center; }

.filter-search-input {
  width: 100%;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  margin-bottom: 6px;
}

.ai-preview-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; background: var(--panel-2); }
.ai-preview-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.ai-preview-result { font-size: 13px; line-height: 1.5; color: var(--text-dim); white-space: pre-wrap; }

.error-text { color: #ff8080; font-size: 13px; margin: 0; min-height: 16px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #101c27;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1000;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.leaflet-popup-content-wrapper { background: var(--panel); color: var(--text); }
.leaflet-popup-tip { background: var(--panel); }

/* 모바일 빠른 제보 패널 (화면 하단 절반) — 버튼 1개만 노출 */
.mobile-report-panel {
  flex-direction: column;
  background: var(--panel);
  border-top: 1px solid var(--border);
  overflow-y: auto;
}

.mobile-cta-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  padding: 20px;
  text-align: center;
}
.mobile-cta-area > span { font-size: 14px; color: var(--text-dim); }

.mobile-cta-btn {
  width: 100%;
  max-width: 320px;
  padding: 18px;
  font-size: 18px;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(58, 160, 255, 0.25);
}
.mobile-cta-btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

/* 모바일 제보 폼 전체화면 페이지 (제보하기 버튼 클릭 시 다음 화면으로 전환) */
.mobile-report-page {
  display: none;
  position: absolute;
  inset: 0;
  background: var(--panel);
  z-index: 700;
  flex-direction: column;
}
.mobile-report-page.open { display: flex; }

.mobile-report-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.mobile-report-page-header strong { font-size: 15px; }
.mobile-report-page-header-spacer { width: 40px; }

.mobile-report-page form.mobile-report-form {
  flex: 1 1 auto;
  overflow-y: auto;
}

.mobile-location-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  flex: 0 0 auto;
}
.mobile-location-bar.location-error { color: #ff9f9f; }
.mobile-location-bar.location-ok { color: #7cf0a8; }

.mobile-report-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px 16px;
}

.mobile-photo-row { display: flex; align-items: center; gap: 10px; }
.mobile-photo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px dashed var(--accent);
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  background: rgba(58, 160, 255, 0.08);
}
.mobile-photo-preview { height: 44px; width: 44px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.photo-preview {
  display: block;
  margin-top: 8px;
  max-width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
}

.mobile-optional-fields {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.mobile-optional-fields summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
}
.mobile-optional-fields .field,
.mobile-optional-fields .field-row {
  margin-top: 10px;
}

.mobile-submit-btn { width: 100%; padding: 12px; font-size: 15px; }
.mobile-submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 860px) {
  .app-body { grid-template-columns: 1fr; display: flex; flex-direction: column; }
  .filter-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 280px;
    max-width: 85vw;
    height: 100%;
    z-index: 550;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .filter-panel.open { transform: translateX(0); }
  .filter-toggle-btn { display: block; }
  .filter-close-btn { display: block; }
  .field-row { grid-template-columns: 1fr; }

  .app-header { padding: 8px 12px; }
  .brand p { display: none; }
  .header-actions { display: none; }
  .map-area { flex: 1 1 0; min-height: 0; }
  .mobile-report-panel { display: flex; flex: 1 1 0; min-height: 0; }
  .mobile-congestion-toggle-btn { display: block; }

  /* 모바일은 핀치 줌이 가능하므로 +/- 버튼을 숨겨 필터 버튼과의 겹침과 지도 가림을 없앤다. */
  .leaflet-control-zoom { display: none; }
  /* 화면이 좁을 때 범례가 지도를 덜 가리도록 축소 */
  .legend { font-size: 11px; padding: 6px 8px; gap: 2px; }

  /* iOS는 16px 미만 입력창에 포커스하면 화면을 강제 확대하므로 모바일에서는 16px로 맞춘다. */
  .field select,
  .field textarea,
  .field input[type="text"],
  .mobile-report-form textarea,
  .other-input,
  .filter-search-input,
  .complaint-form input,
  .complaint-form select {
    font-size: 16px;
  }
}
