/* ───────────────────────── 기본 토큰 ───────────────────────── */
:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --accent: #0ea5e9;
  --accent-strong: #0284c7;
  --reservoir: #dc2626;
  --weir: #2563eb;
  --danger: #ef4444;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: 16px; /* iOS Safari: 16px 미만은 focus 시 자동 줌 */
  color: var(--text);
}

/* ───────────────────────── 로그인 페이지 ───────────────────────── */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 0% 0%, rgba(14, 165, 233, 0.15), transparent 60%),
    radial-gradient(1000px 500px at 100% 100%, rgba(37, 99, 235, 0.12), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 36px 28px 28px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-card .logo {
  font-size: 36px;
  line-height: 1;
  margin-bottom: 16px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.login-card p.subtitle {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 13px;
}

.login-form { display: flex; flex-direction: column; gap: 12px; }

.login-form input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #f8fafc;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.login-form input[type="password"]:focus {
  border-color: var(--accent);
  background: #fff;
}

.login-form button {
  padding: 12px 14px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s, transform 0.05s;
}

.login-form button:hover { background: var(--accent-strong); }
.login-form button:active { transform: translateY(1px); }
.login-form button:disabled { background: #cbd5e1; cursor: not-allowed; }

.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-top: 4px;
}

.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ───────────────────────── 지도 페이지 레이아웃 ───────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* iOS Safari: 동적 viewport */
}

.topbar {
  height: 52px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 1000;
  flex: 0 0 auto;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.topbar .brand .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--reservoir), var(--weir));
}

.topbar .logout-btn {
  font-size: 13px;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.topbar .logout-btn:hover { background: #f1f5f9; color: var(--text); }

.map-area {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map { width: 100%; height: 100%; }

/* ───────────────────────── 검색 + 필터 패널 ───────────────────────── */
.search-wrap {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 500;
  width: 320px;
  max-width: calc(100% - 28px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-box {
  background: var(--card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  padding: 6px 4px 6px 36px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.35-4.35'/></svg>");
  background-repeat: no-repeat;
  background-position: 12px center;
}

.search-box input {
  flex: 1;
  border: none;
  outline: none;
  padding: 6px 4px;
  background: transparent;
  min-width: 0;
}

.search-box .filter-toggle {
  flex: 0 0 auto;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.search-box .filter-toggle:hover { background: #f1f5f9; color: var(--text); }
.search-box .filter-toggle.active { color: var(--accent-strong); background: #e0f2fe; }
.search-box .filter-toggle .arrow { transition: transform 0.2s; }
.search-box .filter-toggle.active .arrow { transform: rotate(180deg); }

.filter-panel {
  background: var(--card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  display: none;
  flex-direction: column;
  overflow: hidden;
  max-height: 70vh;
}

.filter-panel.open { display: flex; }

.filter-controls {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 0 0 auto;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.filter-row label.col {
  width: 56px;
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.filter-row .chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}

.chip {
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.chip:hover { background: #f1f5f9; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.filter-row select {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  outline: none;
}

.filter-row select:focus { border-color: var(--accent); }

.filter-result-head {
  padding: 8px 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
}

.filter-result-head .reset-btn {
  font-size: 12px;
  color: var(--accent-strong);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.filter-result-head .reset-btn:hover { background: #e0f2fe; }

.result-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.result-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
}

.result-item:hover { background: #f1f5f9; }

.result-item .swatch-sm {
  width: 8px; height: 8px; border-radius: 50%;
  flex: 0 0 auto;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.15);
}

.result-item .name {
  font-size: 13.5px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-item .meta {
  font-size: 11.5px;
  color: var(--text-muted);
  flex: 0 0 auto;
}

.result-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 18px;
}

/* ───────────────────────── GPS 버튼 ───────────────────────── */
.gps-btn {
  position: absolute;
  right: 14px;
  bottom: 28px;
  z-index: 500;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.12s, transform 0.05s;
}

.gps-btn:hover { background: #f1f5f9; }
.gps-btn:active { transform: scale(0.95); }
.gps-btn.active { background: var(--accent); color: #fff; }

.gps-btn svg { width: 22px; height: 22px; }

.gps-btn.locating svg { animation: spin 1.2s linear infinite; }
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* 사용자 위치 마커 (Leaflet circleMarker) */
.user-location-pulse {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.2), 0 0 8px rgba(14, 165, 233, 0.5);
}

/* ───────────────────────── 범례 ───────────────────────── */
.legend {
  position: absolute;
  left: 14px;
  bottom: 28px;
  z-index: 500;
  background: var(--card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 12px 14px;
  min-width: 168px;
}

.legend h3 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.legend label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.legend label input { accent-color: var(--accent); margin: 0; }

.legend .swatch {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.15);
  flex: 0 0 auto;
}

.legend .swatch.reservoir { background: var(--reservoir); }
.legend .swatch.weir { background: var(--weir); }

.legend .count { margin-left: auto; color: var(--text-muted); font-size: 12px; }

/* ───────────────────────── 사이드 패널 ───────────────────────── */
.side-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 400px;
  max-width: 100%;
  background: var(--card);
  box-shadow: -8px 0 24px rgba(15, 23, 42, 0.08);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 600;
  display: flex;
  flex-direction: column;
}

.side-panel.open { transform: translateX(0); }

.panel-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
}

.panel-header .title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.panel-header .badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  margin-top: 4px;
}

.panel-header .badge.reservoir { background: #fee2e2; color: #b91c1c; }
.panel-header .badge.weir { background: #dbeafe; color: #1d4ed8; }

.panel-close {
  font-size: 22px;
  color: var(--text-muted);
  padding: 0 4px;
  line-height: 1;
}

.panel-close:hover { color: var(--text); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 18px 18px;
}

.panel-section { margin-top: 18px; }

.panel-section h4 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.info-grid {
  display: grid;
  grid-template-columns: minmax(90px, auto) 1fr;
  gap: 6px 14px;
  font-size: 13.5px;
}

.info-grid dt {
  color: var(--text-muted);
  font-weight: 500;
  margin: 0;
}

.info-grid dd {
  margin: 0;
  word-break: break-word;
}

/* ───────────────────────── 메모 ───────────────────────── */
.memo-list { display: flex; flex-direction: column; gap: 10px; }

.memo-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 13.5px;
}

.memo-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.memo-author {
  font-weight: 700;
  color: var(--text);
}

.memo-time { margin-left: auto; }

.memo-content { white-space: pre-wrap; word-break: break-word; line-height: 1.5; }

.memo-actions { display: flex; gap: 8px; margin-top: 8px; }

.memo-actions button {
  font-size: 13px;
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  min-height: 32px; /* 터치 타깃 최소 크기 */
}

.memo-actions button:hover { background: #f1f5f9; color: var(--text); }
.memo-actions button.delete:hover { background: #fee2e2; color: var(--danger); border-color: #fecaca; }

.memo-edit {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.memo-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-top: 10px;
}

.memo-form .row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.memo-form select,
.memo-form textarea,
.memo-edit textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  outline: none;
  font-size: 13.5px;
}

.memo-form select:focus,
.memo-form textarea:focus,
.memo-edit textarea:focus { border-color: var(--accent); }

.memo-form textarea,
.memo-edit textarea {
  resize: vertical;
  min-height: 70px;
  line-height: 1.5;
}

.memo-form .actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:disabled { background: #cbd5e1; cursor: not-allowed; }

.btn-secondary {
  background: #fff;
  color: var(--text);
  font-size: 13px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: #f1f5f9; }

.empty-state {
  color: var(--text-muted);
  font-size: 13px;
  padding: 10px 0;
  text-align: center;
}

/* ───────────────────────── 모바일 ───────────────────────── */
@media (max-width: 640px) {
  .search-box { width: calc(100% - 28px); }
  .side-panel {
    width: 100%;
    top: auto;
    height: 75%;
    border-left: none;
    border-top: 1px solid var(--border);
    transform: translateY(100%);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .side-panel.open { transform: translateY(0); }
  .legend { left: 10px; bottom: 14px; min-width: 150px; }
}

/* Leaflet 마커 커스텀 */
.marker-reservoir, .marker-weir {
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.35);
}

/* ───────────────────────── 답글 ───────────────────────── */
.memo-replies {
  margin-top: 10px;
  padding-left: 14px;
  border-left: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.memo-card.reply {
  background: #ffffff;
  border: 1px solid var(--border);
  padding: 8px 10px;
  font-size: 13px;
}

.memo-card.reply .memo-content { font-size: 13px; }

.reply-form {
  margin-top: 8px;
  padding-left: 14px;
  border-left: 2px solid var(--accent);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.reply-form .row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.reply-form select,
.reply-form textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  outline: none;
  font-size: 13px;
}

.reply-form textarea { resize: vertical; min-height: 50px; line-height: 1.45; }
.reply-form select:focus,
.reply-form textarea:focus { border-color: var(--accent); }

.reply-form .actions { display: flex; justify-content: flex-end; gap: 6px; }

.reply-form .btn-primary,
.reply-form .btn-secondary {
  padding: 6px 12px;
  font-size: 12px;
}

/* ───────────────────────── 모아보기 모달 ───────────────────────── */
.topbar .overview-btn {
  font-size: 13px;
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  margin-right: 6px;
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.topbar .overview-btn:hover { background: #f1f5f9; }

.topbar .topbar-actions { display: flex; align-items: center; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 24px;
  backdrop-filter: blur(2px);
}

.modal-overlay.open { display: flex; }

.modal {
  width: 100%;
  max-width: 760px;
  max-height: 100%;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-header .title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }

.modal-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 20px 0;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  background: #fff;
}

.modal-tabs button {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.modal-tabs button:hover { color: var(--text); }
.modal-tabs button.active { color: var(--accent-strong); border-bottom-color: var(--accent-strong); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 20px;
  background: #f8fafc;
}

.modal-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 12px;
  font-size: 14px;
}

.facility-group {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  overflow: hidden;
}

.facility-header {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

.facility-header:hover { background: #f1f5f9; }

.facility-header .swatch-sm {
  width: 8px; height: 8px; border-radius: 50%;
  flex: 0 0 auto;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.15);
}

.facility-header .name { font-weight: 700; font-size: 14px; }
.facility-header .type-label { font-size: 11px; color: var(--text-muted); }
.facility-header .memo-count-pill {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.facility-memos {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.facility-memos .memo-card { background: #f8fafc; }

@media (max-width: 640px) {
  .modal-overlay { padding: 0; }
  .modal { border-radius: 0; max-height: 100vh; height: 100vh; }
}
