/* ═══════════════════════════════════════════════════════════════════
   Maritime Situational Awareness Dashboard — Styles
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg-base:    #0a0e1a;
  --bg-panel:   #0d1420;
  --bg-card:    #111827;
  --bg-hover:   #1a2235;
  --border:     #1e2d45;
  --border-lit: #2a3f60;

  --text-1: #e2eaf5;
  --text-2: #8fa4c0;
  --text-3: #4d6480;

  --accent:   #1e88e5;
  --accent-2: #0d47a1;
  --ok:       #00c853;
  --warn:     #ffd600;
  --danger:   #f44336;
  --info:     #29b6f6;
  --purple:   #9c27b0;

  --panel-w:      310px;
  --header-h:     52px;
  --statusbar-h:  36px;

  --font-mono: 'Courier New', Courier, monospace;
  --font-ui:   -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg-base);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: 13px;
}

/* ── HEADER ─────────────────────────────────────────────────────── */
#header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--header-h);
  display: flex; align-items: center; gap: 16px;
  background: linear-gradient(90deg, #060c18 0%, #0b1525 40%, #060c18 100%);
  border-bottom: 1px solid var(--border-lit);
  padding: 0 16px;
}
.hdr-logo {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; letter-spacing: 0.05em;
  color: var(--info); white-space: nowrap;
}
.hdr-logo .logo-icon {
  width: 28px; height: 28px; background: var(--accent);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.hdr-title {
  flex: 1; text-align: center;
  font-size: 14px; color: var(--text-2); letter-spacing: 0.08em;
}
.hdr-status {
  display: flex; align-items: center; gap: 16px;
}
.status-item {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--text-2);
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-3); flex-shrink: 0;
}
.dot.ok   { background: var(--ok);     box-shadow: 0 0 6px var(--ok); }
.dot.warn { background: var(--warn);   box-shadow: 0 0 6px var(--warn); }
.dot.err  { background: var(--danger); }
.dot.pulse { animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
#clock { font-family: var(--font-mono); font-size: 12px; color: var(--text-2); min-width: 80px; text-align: right; }

/* ── LAYOUT ─────────────────────────────────────────────────────── */
#layout {
  position: fixed;
  top: var(--header-h); bottom: var(--statusbar-h); left: 0; right: 0;
  display: flex;
}

/* ── PANELS ─────────────────────────────────────────────────────── */
.panel {
  width: var(--panel-w); min-width: var(--panel-w);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.panel.right { border-right: none; border-left: 1px solid var(--border); }

.panel-section { border-bottom: 1px solid var(--border); flex-shrink: 0; }
.panel-section.grow { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

.section-hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  cursor: default; user-select: none;
}
.section-title {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-2);
}
.section-badge {
  font-size: 10px; padding: 1px 6px; border-radius: 10px;
  background: var(--bg-base); color: var(--text-3); border: 1px solid var(--border);
}
.section-badge.active { background: var(--accent-2); color: var(--info); border-color: var(--accent); }
.section-body { padding: 8px 12px; overflow-y: auto; }
.section-body.no-pad { padding: 0; }

/* ── GROUP TOGGLE BUTTONS ───────────────────────────────────────── */
.grp-toggle-wrap { display: flex; gap: 4px; }
.grp-btn {
  font-size: 9px; padding: 2px 7px; border-radius: 10px;
  border: 1px solid var(--border); cursor: pointer;
  background: var(--bg-base); color: var(--text-3);
  font-family: var(--font-main); letter-spacing: 0.03em;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap; user-select: none;
}
.grp-btn::before { content: '○ '; }
.grp-btn.active {
  background: rgba(0,200,83,.15); color: #a5d6a7;
  border-color: var(--ok);
}
.grp-btn.active::before { content: '● '; }

/* ── VESSEL SEARCH INPUT ────────────────────────────────────────── */
.vessel-search-input {
  flex: 1; min-width: 0; max-width: 110px;
  padding: 2px 6px; margin: 0 6px;
  background: var(--bg-base); color: var(--text-1);
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 10px; font-family: var(--font-main);
  outline: none;
}
.vessel-search-input::placeholder { color: var(--text-3); }
.vessel-search-input:focus { border-color: var(--accent); }

/* ── DB SOURCE TOGGLE ───────────────────────────────────────────── */
.db-source-toggle-wrap {
  display: flex; gap: 6px; margin-bottom: 6px;
}
.db-src-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 7px 4px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer; transition: all .18s;
  color: var(--text-3);
}
.db-src-btn:hover { background: var(--bg-hover); border-color: var(--border-lit); color: var(--text-2); }
.db-src-btn.active {
  background: rgba(30,136,229,.15);
  border-color: var(--accent); color: var(--info);
}
.db-src-icon { font-size: 16px; line-height: 1; }
.db-src-label { font-size: 12px; font-weight: 600; }
.db-src-sub   { font-size: 10px; color: inherit; opacity: .7; }
#db-source-status {
  font-size: 10px; color: var(--text-3); min-height: 14px;
  text-align: center; transition: color .3s;
}
#db-source-status.ok   { color: var(--ok); }
#db-source-status.warn { color: var(--warn); }
#db-source-status.err  { color: var(--danger); }

/* ── MAP ────────────────────────────────────────────────────────── */
#map-container { flex: 1; position: relative; overflow: hidden; }
/* 기상 레이어(weatherPane z=100)가 타일 아래에 배치됨
   → map 배경색이 바다 영역의 '베이스' 색으로 보임 */
#map { width: 100%; height: 100%; background: #0d1420; }

.leaflet-control-zoom a {
  background: var(--bg-card) !important; color: var(--text-1) !important;
  border-color: var(--border-lit) !important;
}
.leaflet-control-zoom a:hover { background: var(--bg-hover) !important; }
.leaflet-control-attribution {
  background: rgba(10,14,26,.75) !important; color: var(--text-3) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--text-3) !important; }

#map-toolbar {
  position: absolute; top: 10px; left: 10px; z-index: 500;
  display: flex; flex-direction: column; gap: 4px;
}
.map-btn {
  padding: 5px 10px;
  background: rgba(13,20,32,.9); border: 1px solid var(--border-lit);
  border-radius: 4px; color: var(--text-2); font-size: 11px;
  cursor: pointer; white-space: nowrap; transition: all .15s;
}
.map-btn:hover { background: var(--bg-hover); color: var(--text-1); }
.map-btn.active { background: var(--accent-2); color: var(--info); border-color: var(--accent); }
#btn-clear-alert { color: #f44336; border-color: rgba(244,67,54,.35); }
#btn-clear-alert:hover { background: rgba(244,67,54,.15); color: #ff6f60; }

/* ── 연근해 구역도 레이어 패널 (지도 우하단, 예보 슬라이더 바로 위) ──
   bottom 은 슬라이더 높이 — initZonePanel 이 열 때 실측값으로 덮어쓴다. */
#zone-panel {
  position: absolute; bottom: 57px; right: 10px; z-index: 700;
  width: 240px; max-height: calc(100% - 57px - 84px);
  display: none; flex-direction: column;
  background: rgba(13,20,32,.94); border: 1px solid var(--border-lit);
  border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.45);
}
#zone-panel.visible { display: flex; }
.zp-hdr {
  display: flex; align-items: center; gap: 4px;
  padding: 7px 8px; border-bottom: 1px solid var(--border);
}
.zp-title { flex: 1; font-size: 12px; font-weight: 600; color: var(--text-1); }
.zp-btn {
  padding: 2px 6px; font-size: 10px; cursor: pointer;
  background: transparent; border: 1px solid var(--border-lit);
  border-radius: 3px; color: var(--text-2);
}
.zp-btn:hover { background: var(--bg-hover); color: var(--text-1); }
.zp-body { overflow-y: auto; padding: 4px 0 6px; }
.zp-group {
  padding: 6px 10px 2px; font-size: 10px; font-weight: 600;
  color: var(--text-3); letter-spacing: .4px;
}
.zp-row {
  display: flex; align-items: center; gap: 7px;
  padding: 3px 10px; font-size: 11px; color: var(--text-2); cursor: pointer;
}
.zp-row:hover { background: var(--bg-hover); color: var(--text-1); }
.zp-row input { margin: 0; accent-color: var(--accent); cursor: pointer; }
.zp-row.error .zp-name { color: #f44336; text-decoration: line-through; }
.zp-swatch { width: 16px; height: 10px; flex-shrink: 0; border-radius: 2px; box-sizing: border-box; }
.zp-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zp-cnt { font-family: var(--font-mono); font-size: 10px; color: var(--text-3); }
.zp-empty { padding: 10px; font-size: 11px; color: var(--text-3); }

#map-coords {
  position: absolute; bottom: 78px; left: 50%; transform: translateX(-50%); z-index: 500;
  background: rgba(10,14,26,.82); border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 10px;
  font-family: var(--font-mono); font-size: 11px; color: var(--text-2);
  white-space: nowrap; pointer-events: none;
}

/* ── FORECAST TIME SLIDER ───────────────────────────────────────── */
#forecast-slider-panel {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 800;
  background: rgba(8,12,22,0.90);
  border-top: 1px solid var(--border-lit);
  padding: 6px 12px 8px;
  display: flex; flex-direction: column; gap: 4px;
  backdrop-filter: blur(4px);
}
#fcs-header {
  display: flex; align-items: center; justify-content: space-between;
}
#fcs-label-title {
  font-size: 10px; font-weight: 600; color: var(--text-3);
  letter-spacing: 0.4px; text-transform: uppercase;
}
#fcs-time-display {
  font-size: 12px; font-weight: 600; color: var(--info);
  font-family: var(--font-mono);
}
#fcs-controls {
  display: flex; align-items: center; gap: 6px;
}
.fcs-btn {
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-2); border-radius: 4px;
  width: 28px; height: 24px; cursor: pointer; font-size: 10px;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s; flex-shrink: 0;
}
.fcs-btn:hover { background: var(--bg-hover); color: var(--text-1); border-color: var(--border-lit); }
.fcs-btn.fcs-play.playing { background: rgba(0,200,83,0.15); color: #00c853; border-color: #00c853; }
#fcs-slider-wrap {
  flex: 1; padding: 0 4px;
}
#fcs-slider {
  width: 100%; height: 4px;
  -webkit-appearance: none; appearance: none;
  background: var(--bg-card);
  border-radius: 2px; outline: none; cursor: pointer;
  accent-color: var(--info);
}
#fcs-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--info); cursor: pointer;
  box-shadow: 0 0 6px rgba(41,182,246,0.5);
}
#fcs-step-info {
  font-size: 10px; color: var(--text-3); font-family: var(--font-mono);
  white-space: nowrap; flex-shrink: 0;
}
#fcs-now {
  font-size: 9px; font-weight: 700; letter-spacing: 0.3px;
  color: var(--ok); border-color: var(--ok);
  width: auto; padding: 0 6px;
}
#fcs-now:hover { background: rgba(0,200,83,0.15); }

/* ── LAYER TOGGLE ───────────────────────────────────────────────── */
.layer-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 0; border-bottom: 1px solid var(--border);
}
.layer-row:last-child { border-bottom: none; }
.layer-info { display: flex; align-items: center; gap: 8px; }
.layer-dot  { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.layer-name { font-size: 12px; color: var(--text-1); }
.layer-count{ font-size: 10px; color: var(--text-3); font-family: var(--font-mono); }
/* 표출에서 제외된 건수 — 배지 옆에 작게 붙여 '없음' 과 구분되게 한다 */
.layer-note{ font-size: 9px; color: #ffb74d; margin-left: 4px; white-space: nowrap; }
/* 상위 레이어의 내역 행 — 들여쓰기와 세로선으로 종속 관계를 보인다.
   기본은 접힘. 상위 행의 caret 을 눌러야 펼쳐진다 — 하위까지 모두 펴면
   레이어 목록이 16행이 되어 패널에서 기상 항목이 스크롤 밖으로 밀린다. */
.layer-sub{ display: none; }
.layer-sub.open{ display: flex; }
.layer-sub .layer-info{ padding-left: 12px; border-left: 1px solid var(--border-lit); margin-left: 4px; }
.layer-sub .layer-name{ font-size: 11px; color: var(--text-2); }

/* 펼침 표시 — 하위 레이어가 있는 행에만 붙는다 */
.layer-caret{
  display: inline-block; width: 12px; margin-right: 2px;
  color: var(--text-3); font-size: 9px; cursor: pointer;
  transition: transform .15s; user-select: none; flex-shrink: 0;
}
.layer-caret:hover{ color: var(--text-1); }
.layer-caret.open{ transform: rotate(90deg); }
.layer-row.has-sub .layer-info{ cursor: pointer; }

.toggle { position: relative; width: 32px; height: 18px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--bg-base); border: 1px solid var(--border-lit);
  border-radius: 18px; cursor: pointer; transition: .2s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 12px; height: 12px; left: 2px; top: 2px;
  background: var(--text-3); border-radius: 50%; transition: .2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent-2); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::before { background: var(--info); transform: translateX(14px); }

/* ── VESSEL LIST ────────────────────────────────────────────────── */
#vessel-list { overflow-y: auto; flex: 1; }
.vessel-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .1s;
}
.vessel-item:hover    { background: var(--bg-hover); }
.vessel-item.selected { background: var(--accent-2); }
.vessel-flag { font-size: 14px; flex-shrink: 0; }
.vessel-info { flex: 1; min-width: 0; }
.vessel-name {
  font-size: 12px; color: var(--text-1); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.vessel-meta { font-size: 10px; color: var(--text-3); font-family: var(--font-mono); }
.vessel-tag {
  font-size: 9px; padding: 1px 5px; border-radius: 3px; flex-shrink: 0;
}
.vessel-tag.ais    { background: rgba(30,136,229,.2);  color: var(--info);  border: 1px solid var(--accent); }
.vessel-tag.sat    { background: rgba(156,39,176,.2);  color: #ce93d8;     border: 1px solid var(--purple); }
.vessel-tag.dark   { background: rgba(244,67,54,.2);   color: #ef9a9a;     border: 1px solid var(--danger); }
.vessel-tag.merged { background: rgba(0,200,83,.15);   color: #a5d6a7;     border: 1px solid var(--ok); }

/* ── ALERTS ─────────────────────────────────────────────────────── */
#alert-list { overflow-y: auto; flex: 1; }
.alert-item {
  display: flex; gap: 8px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s;
}
.alert-item:hover { background: var(--bg-hover); }
.alert-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }
.alert-body { flex: 1; min-width: 0; }
.alert-title { font-size: 11px; font-weight: 600; color: var(--text-1); margin-bottom: 2px; }
.alert-desc  { font-size: 10px; color: var(--text-2); line-height: 1.4; }
.alert-time  { font-size: 9px; color: var(--text-3); font-family: var(--font-mono); margin-top: 2px; }
.alert-meta  { font-size: 9px; color: var(--text-3); font-family: var(--font-mono); margin-top: 2px; }
.alert-meta b { color: #4fc3f7; font-weight: 600; }
.alert-sev   { font-size: 9px; padding: 1px 5px; border-radius: 3px; flex-shrink: 0; align-self: flex-start; }
.alert-sev.high { background: rgba(244,67,54,.2);  color: #ef9a9a; border: 1px solid var(--danger); }
.alert-sev.med  { background: rgba(255,214,0,.15); color: #ffe57f; border: 1px solid var(--warn); }
.alert-sev.low  { background: rgba(41,182,246,.15);color: #81d4fa; border: 1px solid var(--info); }

/* ── WEATHER ────────────────────────────────────────────────────── */
.weather-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px 12px;
}
.weather-cell {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.weather-icon { font-size: 20px; }
.weather-val  { font-size: 14px; font-weight: 700; color: var(--text-1); font-family: var(--font-mono); }
.weather-lbl  { font-size: 9px; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }

/* ── CONGESTION INDEX ───────────────────────────────────────────── */
.congestion-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px; border-bottom: 1px solid var(--border);
}
.cong-zone { flex: 1; font-size: 11px; color: var(--text-1); }
.cong-bar-wrap { width: 80px; height: 8px; background: var(--bg-base); border-radius: 4px; overflow: hidden; }
.cong-bar  { height: 100%; border-radius: 4px; transition: width .5s; }
.cong-val  { font-family: var(--font-mono); font-size: 11px; color: var(--text-2); width: 36px; text-align: right; }

/* ── AI CHAT ────────────────────────────────────────────────────── */
#chat-section { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
#chat-messages {
  flex: 1; overflow-y: auto; padding: 8px;
  display: flex; flex-direction: column; gap: 6px;
}
.chat-msg {
  max-width: 90%; padding: 6px 10px; border-radius: 8px;
  font-size: 11px; line-height: 1.5;
}
.chat-msg.user  { align-self: flex-end; background: var(--accent-2); color: var(--info); border-bottom-right-radius: 2px; }
.chat-msg.agent { align-self: flex-start; background: var(--bg-card); color: var(--text-1); border: 1px solid var(--border); border-bottom-left-radius: 2px; }
.chat-msg.system{ align-self: center; background: none; color: var(--text-3); font-style: italic; font-size: 10px; }
#chat-input-row { display: flex; gap: 4px; padding: 6px 8px; border-top: 1px solid var(--border); }
#chat-input {
  flex: 1; background: var(--bg-base); border: 1px solid var(--border-lit);
  border-radius: 4px; color: var(--text-1); font-size: 11px;
  padding: 5px 8px; outline: none; resize: none; font-family: var(--font-ui);
}
#chat-input:focus { border-color: var(--accent); }
#chat-send {
  padding: 5px 10px; background: var(--accent-2); border: 1px solid var(--accent);
  color: var(--info); border-radius: 4px; cursor: pointer; font-size: 12px; transition: background .15s;
}
#chat-send:hover    { background: var(--accent); }
#chat-send:disabled { opacity: .4; cursor: not-allowed; }

/* ── STATUS BAR ──────────────────────────────────────────────────── */
#statusbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
  height: var(--statusbar-h);
  display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--bg-card); border-top: 1px solid var(--border-lit);
}
.sb-item { display: flex; align-items: center; gap: 5px; font-size: 10px; color: var(--text-3); font-family: var(--font-mono); }
.sb-item span.val { color: var(--text-2); }
.sb-sep { width: 1px; height: 16px; background: var(--border-lit); }

/* ── DETAIL POPUP ────────────────────────────────────────────────── */
#detail-panel {
  position: fixed; bottom: calc(var(--statusbar-h) + 10px); right: calc(var(--panel-w) + 10px);
  z-index: 800; width: 280px; max-height: 88vh;
  background: var(--bg-panel); border: 1px solid var(--border-lit);
  border-radius: 8px; box-shadow: 0 8px 32px rgba(0,0,0,.6);
  display: none; overflow: hidden;
  flex-direction: column;
}
#detail-panel.visible { display: flex; }
.detail-hdr { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.detail-title { font-size: 13px; font-weight: 700; color: var(--text-1); }
.detail-close { cursor: pointer; color: var(--text-3); font-size: 16px; transition: color .15s; }
.detail-close:hover { color: var(--text-1); }
.detail-body { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.detail-row { display: flex; justify-content: space-between; font-size: 10px; }
.detail-row .lbl { color: var(--text-3); }
.detail-row .val { color: var(--text-1); font-family: var(--font-mono); }

/* ── 항로위험도 차트 ─────────────────────────────────────────────── */
.risk-chart-wrap {
  margin-top: 1px; border-radius: 4px; overflow: hidden;
  border: 1px solid var(--border); background: #080d18;
}
.risk-chart-wrap canvas {
  display: block; width: 100%; height: auto;
}

/* ── LOADING OVERLAY ─────────────────────────────────────────────── */
#loading {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-base);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px;
  /* NO transition here — JS removes display:none directly */
}
.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border-lit); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--text-2); font-size: 13px; }

/* ── SCROLLBAR ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-lit); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ── LEAFLET POPUP ───────────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: var(--bg-panel) !important; border: 1px solid var(--border-lit) !important;
  border-radius: 6px !important; box-shadow: 0 4px 20px rgba(0,0,0,.6) !important;
}
.leaflet-popup-content { color: var(--text-1) !important; font-size: 12px !important; }

/* ── MARKER CLUSTER ──────────────────────────────────────────────── */
/* 줌 레벨에 따라 자동 클러스터링 되는 선박 집합 아이콘 */
.mc-sm, .mc-md, .mc-lg {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  color: #fff;
  border: 2px solid;
  box-shadow: 0 2px 10px rgba(0,0,0,.5);
  pointer-events: all;
}
/* 소형 클러스터 (< 50척) — AIS 파란계열 */
.mc-sm {
  width: 32px; height: 32px;
  font-size: 11px;
  background: rgba(30, 136, 229, .82);
  border-color: #29b6f6;
}
/* 중형 클러스터 (50–299척) */
.mc-md {
  width: 40px; height: 40px;
  font-size: 12px;
  background: rgba(0, 172, 193, .85);
  border-color: #00e5ff;
}
/* 대형 클러스터 (300척 이상) */
.mc-lg {
  width: 52px; height: 52px;
  font-size: 13px;
  background: rgba(230, 74, 25, .85);
  border-color: #ff6d00;
  animation: cluster-pulse 2s ease-in-out infinite;
}
@keyframes cluster-pulse {
  0%,100% { box-shadow: 0 2px 10px rgba(0,0,0,.5); }
  50%      { box-shadow: 0 0 20px rgba(255,109,0,.6); }
}

/* ── PAST TRACK (2H 항적 얇은 점선) ─────────────────────────────── */
.past-track-line {
  stroke: #7ec8e3;
  stroke-width: 1;
  stroke-dasharray: 2 5;
  stroke-opacity: 0.70;
}

/* ── PREDICTED ROUTE ─────────────────────────────────────────────── */
/* Marching-ants animated dashed line */
.route-predicted {
  stroke-dasharray: 10 7;
  animation: route-march 0.7s linear infinite;
}
@keyframes route-march { to { stroke-dashoffset: -17; } }

/* Destination port marker (⚓ icon) */
.dest-marker {
  width: 28px; height: 28px;
  background: rgba(0,229,255,0.15);
  border: 2px solid #00e5ff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: #00e5ff;
  animation: dest-pulse 2s ease-in-out infinite;
}
@keyframes dest-pulse {
  0%,100% { box-shadow: 0 0 8px rgba(0,229,255,.3); }
  50%      { box-shadow: 0 0 18px rgba(0,229,255,.7); }
}

/* Route midpoint ETA/distance label */
.route-mid-label {
  background: rgba(0,10,20,.88);
  border: 1px solid rgba(0,229,255,.5);
  border-radius: 4px;
  padding: 3px 8px;
  color: #00e5ff;
  font-size: 10px;
  font-family: var(--font-mono);
  white-space: nowrap;
  transform: translate(-50%, -160%);
  position: relative;
  pointer-events: none;
}

/* Destination tooltip override */
.dest-tooltip {
  background: rgba(0,10,20,.9) !important;
  border: 1px solid #00e5ff !important;
  color: #00e5ff !important;
  font-size: 11px !important;
  font-family: var(--font-mono) !important;
  border-radius: 4px !important;
}
.dest-tooltip::before { display: none !important; }

/* Detail panel route section */
.detail-divider { height: 1px; background: var(--border-lit); margin: 3px 0; }
.dest-val { color: #00e5ff !important; }
.route-eta { color: var(--text-3); font-size: 10px; }
.detail-fit-btn {
  width: 100%; margin-top: 8px; padding: 6px;
  background: rgba(0,229,255,.1);
  border: 1px solid rgba(0,229,255,.4);
  color: #00e5ff;
  border-radius: 4px; cursor: pointer;
  font-size: 11px;
  transition: background .15s;
}
.detail-fit-btn:hover { background: rgba(0,229,255,.2); }
.leaflet-popup-tip { background: var(--bg-panel) !important; }

/* ── CPA 충돌위험 연결선 ───────────────────────────────────────────── */
.cpa-line { animation: cpa-blink 1.4s ease-in-out infinite; }
@keyframes cpa-blink {
  0%,100% { opacity: 0.85; }
  50%      { opacity: 0.35; }
}

/* ── 알림 클릭 시 선박 깜박임 링 ──────────────────────────────────── */
@keyframes alert-blink {
  0%,100% { opacity: 0.9; transform: scale(1);   }
  50%      { opacity: 0.15; transform: scale(1.7); }
}
.alert-blink-ring {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2.5px solid currentColor;
  animation: alert-blink 0.75s ease-in-out infinite;
}
.alert-blink-ring-lg {
  width: 46px; height: 46px; border-radius: 50%;
  border: 2px solid currentColor; opacity: 0.45;
  animation: alert-blink 0.75s ease-in-out infinite;
  animation-delay: 0.2s;
}

/* ── WEATHER OVERLAY ────────────────────────────────────────────── */
/* ── MAP LEGEND ─────────────────────────────────────────────────── */
#map-legend {
  position: absolute;
  bottom: 82px;
  left: 10px;
  z-index: 800;
  display: flex;
  flex-direction: column;
  gap: 5px;
  pointer-events: none;
}
.lgd-item {
  background: rgba(10,14,26,0.84);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 4px;
  padding: 5px 9px 4px;
  min-width: 190px;
  transition: opacity 0.3s;
  backdrop-filter: blur(4px);
}
.lgd-title {
  font-size: 10px;
  color: #8fa4c0;
  font-weight: 600;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}
.lgd-bar {
  height: 7px;
  border-radius: 3px;
  margin-bottom: 3px;
}
.lgd-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: #4d6480;
}
.lgd-cats {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}
.lgd-cat {
  font-size: 9px;
  color: #8fa4c0;
  display: flex;
  align-items: center;
  gap: 3px;
}
.lgd-cat i {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 2px;
  font-style: normal;
}

/* ── ROUTE SAFETY ZONE ROWS ──────────────────────────────────────── */
.risk-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px; border-bottom: 1px solid var(--border);
}
.risk-zone-name { flex: 1; font-size: 12px; color: var(--text-1); }
.risk-badge {
  font-size: 10px; font-weight: 700; padding: 2px 6px;
  border-radius: 3px; letter-spacing: 0.3px;
}
.risk-badge.r0 { background: rgba(0,200,83,.2);   color: #00c853; border: 1px solid #00c853; }
.risk-badge.r1 { background: rgba(100,221,23,.2);  color: #64dd17; border: 1px solid #64dd17; }
.risk-badge.r2 { background: rgba(255,214,0,.2);   color: #ffd600; border: 1px solid #ffd600; }
.risk-badge.r3 { background: rgba(255,109,0,.2);   color: #ff6d00; border: 1px solid #ff6d00; }
.risk-badge.r4 { background: rgba(244,67,54,.2);   color: #f44336; border: 1px solid #f44336; }
.risk-meta { font-size: 10px; color: var(--text-3); white-space: nowrap; }

/* ── SELECTED VESSEL HIGHLIGHT ──────────────────────────────────── */
.vessel-highlight-ring {
  border-radius: 50%;
  border: 2px solid #fff176;
  box-shadow: 0 0 0 3px rgba(255, 241, 118, 0.35);
  animation: highlight-ring 1.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes highlight-ring {
  0%,100% { box-shadow: 0 0 0 3px rgba(255,241,118,.35), 0 0 12px rgba(255,241,118,.4); }
  50%      { box-shadow: 0 0 0 6px rgba(255,241,118,.15), 0 0 24px rgba(255,241,118,.7); }
}
.vessel-icon-selected {
  filter: drop-shadow(0 0 5px #fff176) drop-shadow(0 0 10px #fff176);
  transform: scale(1.6);
  transform-origin: center;
}

/* =================================================================
   X-band SAR 선박탐지 마커 · 팝업
   Dark vessel 은 한눈에 들어와야 하므로 맥동 링 + 경고 표식을 준다.
   ================================================================= */
.sar-match-marker {
  position: relative; width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
}
.sar-match-core {
  color: #4dd0e1; font-size: 12px; line-height: 1;
  text-shadow: 0 0 5px #4dd0e1, 0 0 10px #4dd0e199;
}

.sar-dark-marker {
  position: relative; width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
}
.sar-dark-core {
  color: #ff1744; font-size: 10px; line-height: 1; z-index: 2;
  text-shadow: 0 0 4px #ff1744, 0 0 9px #ff174499;
}
/* 맥동 링 — 정지 상태에서도 눈에 걸리도록 크기와 투명도를 함께 준다 */
.sar-dark-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 1.5px solid #ff1744; z-index: 1;
  animation: sar-dark-pulse 1.8s ease-out infinite;
}
.sar-dark-bang {
  position: absolute; top: -4px; right: -3px; z-index: 3;
  font: 700 6px/1 system-ui, sans-serif; color: #fff;
  background: #ff1744; border-radius: 50%;
  width: 8px; height: 8px; text-align: center; line-height: 8px;
  box-shadow: 0 0 4px #ff1744;
}
@keyframes sar-dark-pulse {
  0%   { transform: scale(0.55); opacity: 1;   }
  70%  { transform: scale(1.35); opacity: 0.12;}
  100% { transform: scale(1.5);  opacity: 0;   }
}
/* 애니메이션 민감 사용자 배려 — 링은 남기고 움직임만 멈춘다 */
@media (prefers-reduced-motion: reduce) {
  .sar-dark-ring { animation: none; opacity: 0.65; }
}

.sar-popup-wrap .leaflet-popup-content-wrapper {
  background: #10161f; color: #e3f2fd;
  border: 1px solid #37474f; border-radius: 6px;
}
.sar-popup-wrap .leaflet-popup-tip { background: #10161f; }
.sar-popup { font: 12px/1.45 system-ui, sans-serif; min-width: 260px; }
.sar-popup-head {
  display: flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 13px;
  padding-bottom: 6px; margin-bottom: 6px;
  border-bottom: 1px solid #2a3542;
}
.sar-popup-head > span:last-child {
  /* flex 항목은 기본 min-width:auto 라 긴 이름이 팝업 폭을 밀고 나간다 */
  min-width: 0; overflow-wrap: anywhere;
}
/* 장면 파일명 — NISAR 는 90자 남짓이라 13px 굵게는 세 줄이 된다.
   Sentinel-1(67자 안팎)과 같이 두 줄에 들도록 조금 줄인다. */
.sar-popup-head .scene-id { font-size: 11.5px; font-weight: 600; }
.sar-popup-dark .sar-popup-head { color: #ff8a80; }
.sar-badge {
  font: 700 10px/1 system-ui, sans-serif; padding: 3px 6px;
  border-radius: 3px; letter-spacing: .04em; white-space: nowrap;
}
.sar-badge-dark  { background: #ff1744; color: #fff; }
.sar-badge-match { background: #00838f; color: #e0f7fa; }
.sar-popup-table { width: 100%; border-collapse: collapse; }
.sar-popup-table th {
  text-align: left; font-weight: 500; color: #90a4ae;
  padding: 3px 10px 3px 0; white-space: nowrap; vertical-align: top;
}
.sar-popup-table td { padding: 3px 0; vertical-align: top; }
.sar-sub { color: #78909c; font-size: 11px; }

/* AIS 대조 불가 (GRD 범위 밖) — dark 와 혼동되지 않게 주황 외곽선 */
.sar-unver-marker {
  position: relative; width: 15px; height: 15px;
  display: flex; align-items: center; justify-content: center;
}
.sar-unver-core {
  color: #ffb74d; font-size: 12px; line-height: 1;
  text-shadow: 0 0 4px #ffb74d99;
}
.sar-badge-unver { background: #ef6c00; color: #fff3e0; }

/* ── 위성 장면 표식 ─────────────────────────────────────────────────
   촬영폭 한가운데 놓는 작은 위성 아이콘. 테두리는 비대화(interactive
   false)로 두고 이 아이콘만 클릭 대상이라, 선 위를 정확히 맞출 필요가
   없고 겹친 장면도 어느 것을 눌렀는지 분명하다. */
.scene-marker {
  width: 18px; height: 18px; line-height: 18px;
  text-align: center; font-size: 12px;
  border-radius: 50%; cursor: pointer;
  background: rgba(10,14,26,.82);
  transition: transform .12s, box-shadow .12s;
}
.scene-marker:hover { transform: scale(1.35); }
/* 레이어별 색 — 범례(테두리 색)와 맞춘다 */
.scene-sar { color:#b39ddb; border:1px solid #b39ddb; box-shadow:0 0 5px #b39ddb66; }
.scene-eo  { color:#80deea; border:1px solid #80deea; box-shadow:0 0 5px #80deea66; }
.scene-env { color:#80cbc4; border:1px solid #80cbc4; box-shadow:0 0 5px #80cbc466; }


/* =================================================================
   반응형 — 좁은 데스크톱 · 태블릿 · 모바일
   ≤1280px : 패널 폭을 줄이고 헤더 부제를 뺀다.
   ≤900px  : 좌·우 패널을 지도 위 전체화면 화면으로 바꾸고
             하단 탭(#mobile-tabbar)으로 전환한다. 어느 화면을 보일지는
             body[data-mview] 가 정한다 (initMobileUI).
   ================================================================= */
#mobile-tabbar, .m-only { display: none; }

@media (max-width: 1280px) {
  :root { --panel-w: 270px; }
  .hdr-title { display: none; }
  .hdr-logo { flex: 1; }
}

@media (max-width: 900px) {
  :root {
    --header-h: 44px;
    --tabbar-h: 56px;
    --safe-b: env(safe-area-inset-bottom, 0px);
  }

  /* ── 헤더 ── */
  #header { gap: 8px; padding: 0 10px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .hdr-logo { font-size: 13px; min-width: 0; overflow: hidden; }
  .hdr-logo .logo-icon { width: 24px; height: 24px; font-size: 14px; flex-shrink: 0; }
  .hdr-status { gap: 10px; flex-shrink: 0; }
  #clock { font-size: 11px; min-width: 0; }

  /* ── 상태바 대신 하단 탭 ── */
  #statusbar { display: none; }
  #layout { bottom: calc(var(--tabbar-h) + var(--safe-b)); }

  #mobile-tabbar {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
    height: calc(var(--tabbar-h) + var(--safe-b));
    padding-bottom: var(--safe-b);
    background: var(--bg-card); border-top: 1px solid var(--border-lit);
  }
  .mtab {
    flex: 1; position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    background: none; border: none; color: var(--text-3);
    font-family: var(--font-ui); font-size: 10px; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .mtab-ico { font-size: 18px; line-height: 1; filter: grayscale(1); opacity: .7; }
  .mtab.active { color: var(--info); }
  .mtab.active .mtab-ico { filter: none; opacity: 1; }
  .mtab.active::before {
    content: ''; position: absolute; top: 0; left: 25%; right: 25%;
    height: 2px; background: var(--info); border-radius: 0 0 2px 2px;
  }
  .mtab-badge {
    position: absolute; top: 5px; left: calc(50% + 6px);
    min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
    font-size: 9px; font-weight: 700; line-height: 16px; text-align: center;
    background: var(--accent-2); color: var(--info); border: 1px solid var(--accent);
  }
  .mtab-badge.alert { background: var(--danger); color: #fff; border-color: var(--danger); }
  .mtab-badge:empty { display: none; }

  /* ── 패널 → 지도 위를 덮는 전체화면 화면 ── */
  .panel {
    position: absolute; inset: 0; z-index: 1100;
    width: auto; min-width: 0; border: none;
    display: none; overflow-y: auto; -webkit-overflow-scrolling: touch;
  }
  body[data-mview="layers"]  #left-panel,
  body[data-mview="vessels"] #left-panel,
  body[data-mview="status"]  #right-panel,
  body[data-mview="chat"]    #right-panel { display: flex; }

  /* 레이어 화면: 레이어 제어 + 데이터 소스 / 선박 화면: 목록만 */
  body[data-mview="layers"]  #left-panel .panel-section.grow { display: none; }
  body[data-mview="vessels"] #left-panel .panel-section:not(.grow) { display: none; }
  /* 경보·기상 화면: 채팅 제외 / AI 화면: 채팅만 */
  body[data-mview="status"] #chat-section { display: none; }
  /* 경보 섹션은 인라인 display:flex 라 !important 가 필요하다 */
  body[data-mview="chat"]   #right-panel .panel-section:not(#chat-section) { display: none !important; }
  body[data-mview="chat"]   #right-panel { overflow: hidden; }

  /* 경보 목록은 인라인 max-height(380px) 를 화면 비율로 바꾼다 */
  #right-panel > .panel-section:first-child { max-height: 50vh !important; }
  .weather-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

  /* ── 터치 대상 키우기 ── */
  .section-hdr { padding: 10px 12px; }
  .section-title { font-size: 12px; }
  .grp-btn { font-size: 11px; padding: 4px 9px; }
  .layer-row { padding: 9px 0; }
  .layer-name { font-size: 14px; }
  .layer-sub .layer-name { font-size: 13px; }
  .layer-caret { width: 20px; font-size: 11px; }
  .toggle { width: 42px; height: 24px; }
  .toggle-slider { border-radius: 24px; }
  .toggle-slider::before { width: 18px; height: 18px; }
  .toggle input:checked + .toggle-slider::before { transform: translateX(18px); }
  .vessel-item { padding: 10px 12px; }
  .vessel-name { font-size: 14px; }
  .vessel-meta { font-size: 11px; }
  .alert-item { padding: 11px 12px; }
  .alert-title { font-size: 13px; }
  .alert-desc { font-size: 12px; }
  .alert-time, .alert-meta { font-size: 10px; }
  .cong-zone, .risk-zone-name { font-size: 13px; }
  .congestion-row, .risk-row { padding: 8px 12px; }
  .db-src-btn { padding: 10px 4px; }

  /* iOS 는 16px 미만 입력창에 포커스하면 화면을 확대한다 */
  .vessel-search-input { max-width: none; font-size: 16px; padding: 5px 8px; }
  #chat-input { font-size: 16px; }
  #chat-send { padding: 5px 16px; font-size: 16px; }
  .chat-msg { font-size: 13px; }
  .chat-msg.system { font-size: 12px; }

  /* ── 지도 위 도구 ── */
  .m-only { display: block; }
  #map-toolbar { top: 8px; left: 8px; }
  .map-btn { padding: 7px 10px; font-size: 12px; }
  #map-coords { display: none; }             /* 마우스 좌표 — 터치 기기에서는 의미 없음 */
  #map-legend { display: none; bottom: 104px; left: 8px; max-height: calc(100% - 260px); overflow: hidden; }
  body.m-legend #map-legend { display: flex; }
  .lgd-item { min-width: 160px; }

  #zone-panel { left: 8px; right: 8px; width: auto; }
  .zp-row { padding: 7px 12px; font-size: 13px; }
  .zp-btn { padding: 5px 9px; font-size: 11px; }

  /* 예보 슬라이더 — 슬라이더를 버튼 아래 한 줄로 내린다 */
  #forecast-slider-panel { padding: 6px 10px 8px; }
  #fcs-controls { flex-wrap: wrap; row-gap: 8px; }
  #fcs-slider-wrap { order: 10; flex-basis: 100%; padding: 4px 6px; }
  #fcs-step-info { margin-left: auto; }
  .fcs-btn { width: 38px; height: 32px; font-size: 12px; }
  #fcs-now { padding: 0 10px; font-size: 11px; }
  #fcs-slider::-webkit-slider-thumb { width: 22px; height: 22px; }
  #fcs-slider::-moz-range-thumb { width: 22px; height: 22px; }

  /* ── 선박 상세 → 하단 시트 ── */
  #detail-panel {
    left: 8px; right: 8px; width: auto;
    bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px);
    max-height: 55vh; z-index: 1050;
  }
  body[data-mview]:not([data-mview="map"]) #detail-panel { display: none; }
  .detail-hdr { padding: 8px 12px; }
  .detail-close { font-size: 26px; line-height: 1; padding: 0 4px; }
  .detail-row { font-size: 12px; gap: 12px; }
  .detail-row .val { text-align: right; overflow-wrap: anywhere; }

  .leaflet-popup-content { max-width: calc(100vw - 60px); }
  .sar-popup { min-width: 0; }
}

@media (max-width: 600px) {
  .hdr-sub { display: none; }
  .status-item > span:not(.dot) { display: none; }   /* 점만 남긴다 — 설명은 title */
  .hdr-status { gap: 7px; }
  .clk-utc { display: none; }
}

/* 가로 모드 휴대폰 — 세로 공간이 좁으니 탭을 낮춘다 */
@media (max-width: 900px) and (max-height: 500px) {
  :root { --tabbar-h: 40px; --header-h: 38px; }
  .mtab { flex-direction: row; gap: 5px; font-size: 11px; }
  .mtab-ico { font-size: 15px; }
  .mtab-badge { top: 3px; }
  #detail-panel { max-height: calc(100vh - var(--header-h) - var(--tabbar-h) - 16px); }
  /* 슬라이더를 버튼과 한 줄로 되돌리고 제목 줄은 뺀다 */
  #fcs-header { display: none; }
  #forecast-slider-panel { padding: 4px 10px; }
  #fcs-controls { flex-wrap: nowrap; }
  #fcs-slider-wrap { order: 0; flex-basis: auto; }
  #fcs-step-info { margin-left: 0; }
  .fcs-btn { width: 34px; height: 28px; }
  #map-legend { bottom: 48px; max-height: calc(100% - 60px); }
  #map-toolbar { flex-direction: row; flex-wrap: wrap; right: 60px; }
}
