:root {
  --ink: #172b3a;
  --muted: #64748b;
  --line: #d7dfeb;
  --line-strong: #b7c4d6;
  --surface: #ffffff;
  --soft: #f5f8fc;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #dbeafe;
  --panel-width: 312px;
}

* { box-sizing: border-box; }
html, body, #map { width: 100%; height: 100%; margin: 0; }
body {
  overflow: hidden;
  color: var(--ink);
  background: #dbe5f0;
  font-family: Arial, "Noto Sans KR", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button { color: inherit; }
#map { position: fixed; inset: 0; }

.explorer {
  position: fixed;
  z-index: 4;
  inset: 0 auto 0 0;
  display: grid;
  width: var(--panel-width);
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  border-right: 1px solid var(--line-strong);
  background: var(--surface);
  transition: transform .2s ease;
}
.explorer.collapsed { transform: translateX(-100%); }

.explorer-head { padding: 14px 16px 11px; border-bottom: 1px solid var(--line); background: var(--soft); }
.eyebrow { margin: 0 0 5px; color: var(--accent); font: 700 10px/1.2 Consolas, monospace; letter-spacing: .12em; }
h1 { margin: 0; font-size: 18px; line-height: 1.25; letter-spacing: -.02em; }
.summary { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.metrics { display: flex; gap: 14px; margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.metrics strong { margin-right: 3px; color: var(--ink); font-size: 12px; font-variant-numeric: tabular-nums; }

.controls { display: grid; gap: 8px; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.search-field { display: grid; gap: 4px; color: #425466; font-size: 10px; font-weight: 600; }
.search-field input {
  width: 100%; height: 32px; padding: 0 9px;
  border: 1px solid var(--line-strong); border-radius: 4px; background: #fff; color: var(--ink); font-size: 12px;
}
.search-field input:focus { border-color: var(--accent); outline: 3px solid rgba(37, 99, 235, .14); }
.layer-toggles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.layer-toggles label {
  display: flex; min-width: 0; flex: 1; align-items: center; gap: 5px; min-height: 30px; padding: 5px 7px;
  border: 1px solid var(--line); border-radius: 4px; color: #425466; font-size: 10px; cursor: pointer;
}
.layer-toggles input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); }
.legend { width: 9px; height: 9px; flex: none; border-radius: 2px; }
.legend.group { border: 2px solid var(--accent-dark); background: rgba(37, 99, 235, .14); }
.legend.code { border: 1px solid #64748b; background: rgba(100, 116, 139, .12); }
.legend.berth { border: 1px solid #d43f57; border-radius: 50%; background: rgba(228, 76, 96, .16); }
.legend.anchorage { border: 1px solid #c77a00; border-radius: 50%; background: rgba(215, 137, 8, .16); }
.secondary-button {
  min-height: 30px; border: 1px solid var(--line-strong); border-radius: 4px; background: #fff; color: #334155; font-size: 10px; font-weight: 600; cursor: pointer;
}
.secondary-button:hover { border-color: #93b4ee; background: #eff6ff; }

.selection { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 8px; padding: 10px 16px; border-bottom: 1px solid var(--line-strong); background: #eff6ff; }
.selection h2 { margin: 1px 0 0; font-size: 15px; line-height: 1.25; }
.selected-rank, .selected-country, .selected-evidence, .selected-stays { margin: 0; }
.selected-rank { color: var(--accent); font-size: 9px; font-weight: 700; }
.selected-country, .selected-evidence, .selected-stays { color: var(--muted); font-size: 10px; line-height: 1.45; }
#clear-selection { width: 26px; height: 26px; border: 0; border-radius: 3px; background: transparent; color: #526577; font-size: 18px; cursor: pointer; }
#clear-selection:hover { background: #dbeafe; }
.code-controls { display: grid; grid-column: 1 / -1; gap: 4px; margin-top: 5px; }
.code-controls-title { margin: 0 0 2px; color: #425466; font-size: 10px; font-weight: 600; }
.code-control {
  display: grid; grid-template-columns: 14px 8px minmax(0, 1fr) auto; align-items: center; gap: 6px; min-height: 28px; padding: 4px 7px;
  border: 1px solid #bfdbfe; border-radius: 3px; background: #fff; color: #334155; cursor: pointer;
}
.code-control:hover { border-color: #93b4ee; background: #f8fbff; }
.code-control input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); }
.code-control strong { font: 600 10px/1.2 Consolas, monospace; }
.code-control span { color: var(--muted); font-size: 9px; font-variant-numeric: tabular-nums; }
.code-dot { width: 7px; height: 7px; border-radius: 50%; }
.selected-stays { grid-column: 1 / -1; color: #425466; }
.selected-evidence { grid-column: 1 / -1; }
.edit-tools { display: grid; grid-column: 1 / -1; gap: 5px; padding-top: 2px; }
.edit-mode-button {
  min-height: 29px; padding: 5px 8px; border: 1px solid #93b4ee; border-radius: 4px;
  background: #fff; color: #1d4ed8; font-size: 10px; font-weight: 700; cursor: pointer;
}
.edit-mode-button:hover:not(:disabled), .edit-mode-button[aria-pressed="true"] { background: #dbeafe; }
.edit-mode-button:disabled { border-color: var(--line); color: #94a3b8; cursor: not-allowed; }
.edit-session, .edit-guide, .edit-coordinates, .edit-message { margin: 0; font-size: 9px; line-height: 1.4; }
.edit-session, .edit-guide, .edit-coordinates { color: var(--muted); }
.point-editor { display: grid; gap: 6px; padding: 8px; border: 1px solid #93b4ee; border-radius: 4px; background: #fff; }
.edit-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.edit-fields label { display: grid; gap: 3px; color: #425466; font-size: 9px; font-weight: 600; }
.edit-fields select { min-width: 0; height: 28px; padding: 0 6px; border: 1px solid var(--line-strong); border-radius: 3px; background: #fff; color: var(--ink); font-size: 10px; }
.edit-coordinates { padding: 5px 6px; border-radius: 3px; background: var(--soft); font-family: Consolas, monospace; }
.edit-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
.edit-actions button, .popup-delete {
  min-height: 28px; padding: 5px 8px; border: 1px solid var(--line-strong); border-radius: 3px; background: #fff; font-size: 9px; font-weight: 600; cursor: pointer;
}
#edit-save { border-color: var(--accent); background: var(--accent); color: #fff; }
#edit-save:disabled { border-color: #bfdbfe; background: #bfdbfe; cursor: not-allowed; }
.edit-message { min-height: 13px; color: #1d4ed8; }
.edit-message.error { color: #b91c1c; }
.popup-delete { width: 100%; margin-top: 8px; border-color: #fecaca; color: #b91c1c; }
.popup-delete:hover { background: #fff1f2; }

.port-list { min-height: 0; overflow: auto; scrollbar-width: thin; }
.port-row {
  display: grid; width: 100%; grid-template-columns: 28px minmax(0, 1fr); gap: 7px; padding: 8px 16px;
  border: 0; border-bottom: 1px solid var(--line); background: #fff; text-align: left; cursor: pointer;
}
.port-row:hover { background: #f8fafc; }
.port-row.active { background: #eff6ff; box-shadow: inset 3px 0 var(--accent); }
.rank { padding-top: 1px; color: var(--muted); font: 600 10px/1.3 Consolas, monospace; font-variant-numeric: tabular-nums; }
.port-copy { min-width: 0; }
.port-title { display: flex; min-width: 0; align-items: baseline; justify-content: space-between; gap: 8px; }
.port-title strong { overflow: hidden; font-size: 11px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.port-title span { flex: none; color: var(--muted); font-size: 9px; }
.port-codes { margin: 3px 0 0; overflow: hidden; color: #496174; font: 9px/1.35 Consolas, monospace; text-overflow: ellipsis; white-space: nowrap; }
.empty-state { margin: 18px 16px; color: var(--muted); font-size: 11px; text-align: center; }

.panel-toggle {
  position: fixed; z-index: 5; left: calc(var(--panel-width) + 10px); bottom: 12px; min-height: 30px; padding: 5px 9px;
  border: 1px solid var(--line-strong); border-radius: 4px; background: rgba(255,255,255,.96); color: #334155; font-size: 10px; cursor: pointer; transition: left .2s ease;
}
.explorer.collapsed + .panel-toggle { left: 10px; }
.map-status { position: fixed; z-index: 3; top: 10px; right: 10px; padding: 7px 9px; border: 1px solid var(--line-strong); border-radius: 4px; background: rgba(255,255,255,.96); color: #425466; font-size: 10px; }
.warning { position: fixed; z-index: 6; right: 10px; bottom: 10px; max-width: 340px; padding: 9px 11px; border: 1px solid #fecaca; border-radius: 4px; background: #fff7f7; color: #991b1b; font-size: 11px; }

.maplibregl-ctrl-top-right { top: 44px; }
.maplibregl-ctrl-group { border-radius: 4px !important; box-shadow: none !important; }
.maplibregl-popup-content { padding: 11px 12px; border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 8px 24px rgba(15, 23, 42, .14); }
.popup-title { margin: 0; color: var(--ink); font-size: 13px; }
.popup-meta { margin: 4px 0 0; color: var(--muted); font-size: 10px; }

button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(37, 99, 235, .28); outline-offset: 1px; }

@media (max-width: 700px) {
  :root { --panel-width: 100%; }
  .explorer { top: auto; width: 100%; height: min(58dvh, 540px); border-top: 1px solid var(--line-strong); border-right: 0; }
  .explorer.collapsed { transform: translateY(100%); }
  .panel-toggle { left: 10px; bottom: calc(min(58dvh, 540px) + 10px); }
  .explorer.collapsed + .panel-toggle { left: 10px; bottom: 10px; }
  .map-status { top: 8px; right: 8px; }
  .maplibregl-ctrl-top-right { top: 40px; }
}
