html, body { margin: 0; padding: 0; width: 100%; height: 100%; font-family: -apple-system, "Segoe UI", "Malgun Gothic", sans-serif; }
#map { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: #0b1622; }

:root {
  --navy-900: #0b1726;
  --navy-800: #0f1f33;
  --navy-700: #16273f;
  --accent: #2b7de9;
  --text-dim: rgba(255,255,255,0.6);
}

/* --- 상단 헤더 --- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 50px; z-index: 1100;
  background: var(--navy-900); display: flex; align-items: center;
  padding: 0 18px; box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
#topbar-title { color: #fff; font-size: 17px; font-weight: 700; letter-spacing: 0.3px; }
.topbar-spacer { flex: 1; }

#topbar-regions { display: flex; gap: 8px; }
.region-btn {
  background: var(--navy-700); border: none; color: var(--text-dim);
  padding: 7px 18px; border-radius: 16px; font-size: 13px; cursor: pointer;
  white-space: nowrap;
}
.region-btn:hover { color: #fff; }
.region-btn.active { background: var(--accent); color: #fff; font-weight: 600; }
#topbar-logo { height: 26px; }

/* --- 좌측 사이드바 --- */
#sidebar {
  position: absolute; top: 50px; left: 0; bottom: 0; width: 230px; z-index: 1000;
  background: var(--navy-800); color: #fff; overflow-y: auto;
  box-shadow: 2px 0 8px rgba(0,0,0,0.35);
  padding: 14px 0; display: flex; flex-direction: column;
}
.sidebar-bottom { margin-top: auto; padding-bottom: 6px; }
.sidebar-section-title {
  font-size: 13px; font-weight: 700; color: var(--text-dim);
  padding: 8px 16px; display: flex; align-items: center; justify-content: space-between;
}
.sidebar-divider { height: 1px; background: rgba(255,255,255,0.08); margin: 10px 0; }

.layer-toggle {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; font-size: 14px;
}
.layer-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.layer-label { flex: 1; }

.switch { position: relative; display: inline-block; width: 36px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer; inset: 0; background: rgba(255,255,255,0.2);
  border-radius: 20px; transition: 0.15s;
}
.switch-slider::before {
  content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: 0.15s;
}
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(16px); }

/* --- 하단 메테오그램 (윈디 스타일 시간/기상 테이블) --- */
#meteogram {
  position: absolute; left: 230px; right: 0; bottom: 0; height: 214px; z-index: 1000;
  background: var(--navy-800); box-shadow: 0 -2px 10px rgba(0,0,0,0.4);
  display: flex; flex-direction: column; align-items: stretch;
}
#meteogram-tabs {
  display: flex; gap: 4px; padding: 4px 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08); flex-shrink: 0; height: 28px; box-sizing: border-box;
}
.meteo-tab {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 12px; padding: 4px 14px; cursor: pointer; border-radius: 6px 6px 0 0;
  border-bottom: 2px solid transparent;
}
.meteo-tab:hover { color: #fff; }
.meteo-tab.active { color: #fff; border-bottom: 2px solid var(--accent); font-weight: 600; }
#meteogram-scroll { flex: 1; overflow-x: auto; overflow-y: auto;
  scrollbar-width: thin;
}
#meteo-chart { flex: 1; display: block; overflow: hidden; cursor: pointer; }
#play-btn {
  background: var(--accent); border: none; color: #fff; width: 24px; height: 24px;
  border-radius: 50%; cursor: pointer; font-size: 11px; flex-shrink: 0;
}
#play-btn:hover { background: #3d8cf5; }
#play-btn.playing { background: #e9532b; }

#meteogram-scroll {
  flex: 1; overflow-x: auto; overflow-y: auto;
  scrollbar-width: thin; /* Firefox: 얇은 스크롤바로 행 공간을 덜 차지하게 */
}
#meteogram-scroll::-webkit-scrollbar { height: 10px; width: 10px; }
#meteogram-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.25); border-radius: 5px; }
#meteogram-table { border-collapse: collapse; font-size: 11px; color: #fff; white-space: nowrap; }
#meteogram-table th, #meteogram-table td {
  padding: 3px 4px; text-align: center; min-width: 28px;
  border-right: 1px solid rgba(255,255,255,0.05);
}
#meteogram-table thead th {
  position: sticky; top: 0; background: var(--navy-800);
}
#meteogram-table tbody th, #meteogram-table thead th.meteo-corner {
  position: sticky; left: 0; background: var(--navy-800); z-index: 3;
  text-align: left; color: var(--text-dim); font-weight: 600;
  box-shadow: 2px 0 4px rgba(0,0,0,0.3);
}
#meteo-day-row th { font-weight: 700; border-bottom: 1px solid rgba(255,255,255,0.1); }
#meteo-day-row th.meteo-corner { background: var(--navy-800); }
.meteo-col { cursor: pointer; }
.meteo-col:hover { background: rgba(255,255,255,0.06); }
.meteo-col.active-col { background: var(--accent) !important; font-weight: 700; }
.meteo-col.meteo-past { background: rgba(255,255,255,0.04); color: rgba(255,255,255,0.35); }
.meteo-arrow { display: inline-block; }
.meteo-empty { opacity: 0.3; }

/* --- 우상단 베이스맵 전환 --- */
#basemap-switch {
  position: absolute; top: 62px; right: 16px; z-index: 1000;
  background: var(--navy-800); border-radius: 8px; overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4); display: flex; flex-direction: column;
}
.basemap-btn {
  background: transparent; border: none; color: var(--text-dim);
  padding: 9px 16px; font-size: 13px; cursor: pointer; text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.basemap-btn:last-child { border-bottom: none; }
.basemap-btn:hover { color: #fff; background: rgba(255,255,255,0.05); }
.basemap-btn.active { color: #fff; background: var(--accent); font-weight: 600; }

.leaflet-control-zoom { margin-top: 140px !important; }

/* --- 범례 (우하단) --- */
#legend {
  position: absolute; right: 16px; bottom: 230px; z-index: 1000;
  background: var(--navy-800); color: #fff; padding: 10px 14px;
  border-radius: 8px; font-size: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
#legend-title { font-weight: 600; margin-bottom: 6px; }
#legend-bar {
  width: 180px; height: 10px; border-radius: 4px;
  background: linear-gradient(to right, #30123b, #4669d6, #1ea6a6, #7ad151, #fde725, #d23105);
}
#legend-labels { display: flex; justify-content: space-between; margin-top: 4px; opacity: 0.85; }

/* --- 클릭 정보 패널: Leaflet popup이 아니라 직접 위치를 잡는 div ---
   클릭 지점의 화면 좌표를 구해서 그 "오른쪽"에, 패널의 "상단"이 지점과 같은 높이가 되도록
   배치한다 (Leaflet 기본 Popup은 박스 하단이 지점에 닿는 구조라 상단 기준 배치가 불가능). */
#click-info-panel {
  position: absolute; z-index: 1200;
  background: var(--navy-800); color: #fff; border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
  padding: 12px 14px 12px 14px; font-size: 13px; min-width: 160px;
}
#click-info-panel.hidden { display: none; }
#click-info-close {
  position: absolute; top: 0; right: 0;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; padding: 0; margin: 0;
  color: rgba(255,255,255,0.6); font-size: 18px; line-height: 1;
  cursor: pointer; border-radius: 0 8px 0 4px;
  box-sizing: border-box;
}
#click-info-close:hover { color: #fff; background: rgba(255,255,255,0.1); }
.wave-popup-coords { opacity: 0.6; font-size: 11px; margin-bottom: 8px; padding-right: 20px; }
.wave-popup-row { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,0.08); gap: 16px; }
.wave-popup-row .label { opacity: 0.7; }
.wave-popup-row .value { font-weight: 600; }
.wave-popup-divider { height: 1px; background: rgba(255,255,255,0.12); margin: 8px 0; }

.dir-arrow { pointer-events: none; }

/* 조위 관측소 마커 툴팁 */
.tidal-station-tooltip {
  background: rgba(15, 31, 51, 0.92); border: 1px solid #ffd166;
  color: #ffd166; font-size: 12px; font-weight: 600;
  padding: 3px 8px; border-radius: 6px; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.tidal-station-tooltip::before { border-top-color: #ffd166 !important; }

/* --- 추가정보 사이드바 그룹 --- */
.sidebar-group-header {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px 6px 10px; cursor: default;
}
.grp-collapse-btn {
  background: rgba(255,255,255,0.1); border: none; color: rgba(255,255,255,0.7);
  width: 18px; height: 18px; border-radius: 4px; font-size: 14px; line-height: 1;
  cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.grp-collapse-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }
.grp-label { flex: 1; font-size: 13px; font-weight: 600; color: rgba(255,255,255,0.85); }
.sidebar-group-items { overflow: hidden; transition: max-height 0.2s ease; max-height: 200px; }
.sidebar-group-items.collapsed { max-height: 0 !important; }
.layer-sub { padding-left: 30px !important; }
.layer-sub.grp-disabled { opacity: 0.4; pointer-events: none; }

/* --- 관측소 정보 패널 (마커 클릭 시 우측) --- */
#obs-info-panel {
  position: absolute; z-index: 1200;
  top: 62px; right: 16px;
  background: var(--navy-800); color: #fff; border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
  padding: 12px 14px 12px 14px; font-size: 13px; min-width: 200px; max-width: 260px;
}
#obs-info-panel.hidden { display: none; }
#obs-info-close {
  position: absolute; top: 0; right: 0;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; padding: 0; margin: 0;
  color: rgba(255,255,255,0.6); font-size: 18px; line-height: 1;
  cursor: pointer; border-radius: 0 8px 0 4px; box-sizing: border-box;
}
#obs-info-close:hover { color: #fff; background: rgba(255,255,255,0.1); }
.obs-panel-title {
  font-size: 12px; font-weight: 700; color: var(--text-dim);
  margin-bottom: 6px; padding-right: 20px; display: flex; align-items: center; gap: 6px;
}
.obs-panel-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.obs-panel-name { font-size: 14px; font-weight: 700; color: #fff; margin-bottom: 4px; padding-right: 20px; }
.obs-panel-coords { font-size: 11px; opacity: 0.55; margin-bottom: 10px; }
.obs-panel-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.07); gap: 12px;
}
.obs-panel-row:last-child { border-bottom: none; }
.obs-panel-row .label { opacity: 0.65; font-size: 12px; }
.obs-panel-row .value { font-weight: 600; font-size: 13px; }
.obs-panel-pending {
  font-size: 12px; color: rgba(255,255,255,0.4);
  text-align: center; padding: 10px 0;
  border: 1px dashed rgba(255,255,255,0.15); border-radius: 6px; margin-top: 4px;
}

/* 관측소/부이 마커 팝업 */
.obs-marker-tooltip {
  background: rgba(15,31,51,0.92); border: 1px solid rgba(255,255,255,0.3);
  color: #fff; font-size: 11px; font-weight: 600;
  padding: 2px 7px; border-radius: 5px; white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
}

/* --- 선택 지점 마커 (우클릭 시) --- */
.selection-marker {
  filter: drop-shadow(0 0 4px rgba(0,0,0,0.6)) drop-shadow(0 0 8px rgba(255,90,54,0.7));
  animation: selection-pulse 1.4s ease-in-out infinite;
}
@keyframes selection-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
