/* ========================================
   公開型GIS - メインスタイル
   ======================================== */

:root {
  --primary: #1a56db;
  --primary-dark: #1e429f;
  --primary-light: #e8f0fe;
  --secondary: #057a55;
  --danger: #c81e1e;
  --warning: #b45309;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --sidebar-width: 320px;
  --header-height: 52px;
  --toolbar-height: 44px;
  --font: 'Hiragino Kaku Gothic ProN', 'Meiryo', 'Yu Gothic', sans-serif;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--gray-900);
  overflow: hidden;
}

/* ========================================
   Header
   ======================================== */
#header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 1000;
  box-shadow: var(--shadow);
}

#header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}

#header-title .subtitle {
  font-weight: 400;
  font-size: 12px;
  opacity: 0.8;
  display: none;
}

@media (min-width: 600px) {
  #header-title .subtitle { display: inline; }
}

#header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: background 0.15s;
  font-family: var(--font);
}
.header-btn:hover { background: rgba(255,255,255,0.25); }
.header-btn .label { display: none; }
@media (min-width: 640px) { .header-btn .label { display: inline; } }

/* ========================================
   Layout
   ======================================== */
#app {
  position: fixed;
  top: var(--header-height);
  left: 0; right: 0; bottom: 0;
  display: flex;
}

/* ========================================
   Sidebar
   ======================================== */
#sidebar {
  width: var(--sidebar-width);
  background: #fff;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--gray-200);
  z-index: 500;
  transition: transform 0.25s ease;
  position: relative;
  flex-shrink: 0;
}

#sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-width)));
  position: absolute;
  top: 0; bottom: 0;
}

#sidebar-toggle {
  position: absolute;
  right: -32px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 52px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  box-shadow: 2px 0 4px rgba(0,0,0,0.08);
  z-index: 501;
}
#sidebar-toggle:hover { background: var(--gray-50); }

#sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 10px 4px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 11px;
  color: var(--gray-500);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  font-family: var(--font);
  position: relative;
}
.sidebar-tab:hover { background: var(--gray-50); color: var(--primary); }
.sidebar-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--primary-light);
}
.sidebar-tab .badge {
  position: absolute;
  top: 5px;
  right: 10px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  border-radius: 8px;
  padding: 1px 4px;
  min-width: 16px;
  text-align: center;
}

#sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ========================================
   Layers Panel
   ======================================== */
#panel-layers {
  padding: 0;
}

.layer-category {
  border-bottom: 1px solid var(--gray-200);
}

.layer-category-header {
  padding: 8px 12px;
  background: var(--gray-50);
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.layer-category-header:hover { background: var(--gray-100); }

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer;
  transition: background 0.1s;
}
.layer-item:hover { background: var(--gray-50); }
.layer-item:last-child { border-bottom: none; }

.layer-visibility {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 2px solid var(--gray-300);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.15s;
}
.layer-visibility.checked {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.layer-color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(0,0,0,0.15);
}
.layer-color-line {
  width: 20px;
  height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
}

.layer-name {
  flex: 1;
  font-size: 13px;
  color: var(--gray-700);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-count {
  font-size: 11px;
  color: var(--gray-400);
  flex-shrink: 0;
}

.layer-opacity-btn {
  background: none;
  border: none;
  padding: 2px 4px;
  cursor: pointer;
  color: var(--gray-400);
  font-size: 13px;
  flex-shrink: 0;
  border-radius: 4px;
  line-height: 1;
}
.layer-opacity-btn:hover { color: var(--primary); background: var(--primary-light); }

.layer-opacity-row {
  padding: 4px 12px 10px 44px;
  display: none;
  align-items: center;
  gap: 8px;
}
.layer-opacity-row.open { display: flex; }
.layer-opacity-row label { font-size: 11px; color: var(--gray-500); flex-shrink: 0; }
.layer-opacity-row input[type=range] { flex: 1; height: 4px; }

/* ========================================
   Legend Panel
   ======================================== */
#panel-legend { padding: 12px; }
.legend-section { margin-bottom: 16px; }
.legend-title { font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 8px; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.legend-symbol { width: 20px; flex-shrink: 0; }
.legend-symbol.circle {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.2);
}
.legend-symbol.line { height: 3px; border-radius: 2px; }
.legend-symbol.polygon { height: 14px; border-radius: 2px; border: 1.5px solid rgba(0,0,0,0.2); }
.legend-label { font-size: 12px; color: var(--gray-700); }

/* ========================================
   Search Panel
   ======================================== */
#panel-search { padding: 12px; }
.search-group { margin-bottom: 16px; }

/* 検索パネル内の各セクションをカード形式で区別 */
#panel-search .search-group {
  background: var(--gray-50, #f9fafb);
  border: 1px solid var(--gray-200, #e5e7eb);
  border-radius: var(--radius, 8px);
  padding: 10px 12px 12px;
  margin-bottom: 10px;
}
#panel-search .search-group:last-child { margin-bottom: 0; }

.search-group-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary, #1a56db);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--gray-200, #e5e7eb);
  letter-spacing: 0.02em;
}
.search-input-row {
  display: flex;
  gap: 6px;
}
.search-input-row input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border 0.15s;
}
.search-input-row input:focus { border-color: var(--primary); }
.search-results { margin-top: 8px; }
.search-result-item {
  padding: 8px 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s;
}
.search-result-item:hover { background: var(--primary-light); border-color: var(--primary); }
.search-result-item .name { font-weight: 500; color: var(--gray-900); }
.search-result-item .address { font-size: 11px; color: var(--gray-500); margin-top: 2px; }

.latlng-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 6px;
}
.latlng-row input {
  padding: 8px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
}
.latlng-row input:focus { border-color: var(--primary); }

/* ========================================
   Notices Panel
   ======================================== */
#panel-notices { padding: 12px; }
.notice-item {
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.1s;
}
.notice-item:hover { background: var(--gray-50); }
.notice-item.important { border-left: 3px solid var(--danger); }
.notice-item .notice-date { font-size: 11px; color: var(--gray-400); margin-bottom: 3px; }
.notice-item .notice-title { font-size: 13px; font-weight: 600; color: var(--gray-900); }
.notice-item .notice-body { font-size: 12px; color: var(--gray-500); margin-top: 4px; line-height: 1.5; }
.notice-important-badge {
  display: inline-block;
  font-size: 10px;
  background: var(--danger);
  color: #fff;
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
}

/* ========================================
   Map Container
   ======================================== */
#map-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  overflow: hidden;
}

#map, #map2 {
  flex: 1;
  height: 100%;
}

/* Leaflet のデフォルト grab カーソルを上書き — JS inline style で管理するため CSS 側は無効化のみ */
.leaflet-grab,
.leaflet-dragging .leaflet-grab {
  cursor: inherit;
}
/* 作図モード: 頂点マーカーを計測と同サイズの小さな丸に統一 */
#map .leaflet-div-icon,
#map .leaflet-editing-icon {
  width: 8px !important;
  height: 8px !important;
  margin-left: -4px !important;
  margin-top: -4px !important;
  border-radius: 50% !important;
  background: #fff !important;
  border: 2px solid #c53030 !important;
  box-sizing: border-box !important;
}
/* タッチ用の大きなアイコンも縮小 */
#map .leaflet-touch-icon {
  width: 12px !important;
  height: 12px !important;
  margin-left: -6px !important;
  margin-top: -6px !important;
  border-radius: 50% !important;
  background: #fff !important;
  border: 2px solid #c53030 !important;
  box-sizing: border-box !important;
}

/* 作図モード: Leaflet.Draw の .leaflet-mouse-marker カーソルを黒い十字に固定 */
.leaflet-mouse-marker {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cline x1='12' y1='1' x2='12' y2='23' stroke='%23000' stroke-width='1.5'/%3E%3Cline x1='1' y1='12' x2='23' y2='12' stroke='%23000' stroke-width='1.5'/%3E%3Ccircle cx='12' cy='12' r='2' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3C/svg%3E") 12 12, crosshair !important;
}
/* ローディング中は砂時計（inline style より優先するため !important） */
body.map-loading #map .leaflet-container,
body.map-loading #map {
  cursor: wait !important;
}

#map2 { display: none; }
#map2.active { display: flex; }

#map-divider {
  width: 4px;
  background: var(--primary);
  cursor: col-resize;
  display: none;
  flex-shrink: 0;
  position: relative;
}
#map-divider.active { display: block; }
#map-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 40px;
  background: var(--primary);
  border-radius: 2px;
  opacity: 0.7;
}

/* ========================================
   Toolbar (floating on map)
   ======================================== */
#toolbar {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  z-index: 1200;
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  flex-wrap: wrap;
  max-width: calc(100vw - 24px);
}

.tool-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: none;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-700);
  font-size: 14px;
  transition: all 0.15s;
  position: relative;
}
.tool-btn:hover { background: var(--gray-100); color: var(--primary); }
.tool-btn.active { background: var(--primary-light); color: var(--primary); }
.tool-btn[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
}
.tool-btn[data-tooltip]:hover::after { opacity: 1; }

.tool-separator {
  width: 1px;
  background: var(--gray-200);
  margin: 4px 2px;
}

/* ========================================
   Map Info Bar
   ======================================== */
#map-info-bar {
  position: absolute;
  bottom: 28px;
  left: 10px;
  background: rgba(255,255,255,0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 4px 10px;
  font-size: 12px;
  color: var(--gray-700);
  z-index: 1200;
  cursor: pointer;
  user-select: none;
}
#map-info-bar:hover { background: #fff; }
#coord-display { display: inline; }

/* ========================================
   Center Mark
   ======================================== */
#center-mark, #center-mark-2 {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1200;
  pointer-events: none;
  display: none;
}
#center-mark.visible, #center-mark-2.visible { display: block; }
#center-mark svg, #center-mark-2 svg {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
}

/* ========================================
   Basemap Switcher (floating)
   ======================================== */
#basemap-switcher {
  position: absolute;
  bottom: 28px;
  right: 10px;
  z-index: 1200;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: none;
}
#basemap-switcher.visible { display: block; }
.basemap-option {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--gray-100);
  transition: background 0.1s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.basemap-option:last-child { border-bottom: none; }
.basemap-option:hover { background: var(--gray-50); }
.basemap-option.active { color: var(--primary); font-weight: 600; }
.basemap-option::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid var(--gray-300);
  flex-shrink: 0;
}
.basemap-option.active::before {
  background: var(--primary);
  border-color: var(--primary);
}

/* ========================================
   Buttons (general)
   ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #9b1c1c; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* ========================================
   Modals
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-overlay.hidden { display: none; }

.modal {
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.modal-header h2 { font-size: 16px; font-weight: 700; color: var(--gray-900); }
.modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--gray-100);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  font-size: 14px;
}
.modal-close:hover { background: var(--gray-200); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-body p { line-height: 1.7; font-size: 14px; color: var(--gray-700); margin-bottom: 12px; }
.modal-body pre {
  white-space: pre-wrap;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.7;
  color: var(--gray-700);
  background: var(--gray-50);
  border-radius: var(--radius);
  padding: 12px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

/* Terms modal */
#terms-modal .modal { max-width: 580px; }
.terms-agree-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px;
  background: var(--gray-50);
  border-radius: var(--radius);
  margin-top: 16px;
}
.terms-agree-row input[type=checkbox] { margin-top: 2px; flex-shrink: 0; width: 16px; height: 16px; }
.terms-agree-row label { font-size: 13px; cursor: pointer; line-height: 1.5; }

/* Attribute modal */
#attribute-modal .modal { max-width: 460px; }
.attribute-table { width: 100%; border-collapse: collapse; }
.attribute-table th, .attribute-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--gray-100);
  font-size: 13px;
  vertical-align: top;
}
.attribute-table th {
  width: 35%;
  color: var(--gray-500);
  font-weight: 500;
  background: var(--gray-50);
}
.attribute-table td { color: var(--gray-900); }
.attribute-table a { color: var(--primary); }
.attribute-table img { max-width: 100%; border-radius: 4px; margin-top: 4px; }

/* Share modal */
#share-modal .modal { max-width: 420px; }
.share-url-box {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}
.share-url-box input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: monospace;
  outline: none;
  color: var(--gray-700);
  background: var(--gray-50);
}
#qr-code { text-align: center; margin-top: 8px; }
#qr-code canvas { border-radius: 4px; }

/* Attribute list modal */
#attr-list-modal .modal { max-width: 720px; }
.attr-list-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.attr-list-controls input {
  flex: 1;
  min-width: 160px;
  padding: 7px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
}
.attr-list-controls input:focus { border-color: var(--primary); }
.attr-list-table-wrap { overflow-x: auto; max-height: 400px; overflow-y: auto; }
.attr-list-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.attr-list-table th {
  background: var(--gray-50);
  padding: 8px;
  text-align: left;
  border-bottom: 2px solid var(--gray-200);
  position: sticky;
  top: 0;
  font-weight: 600;
  color: var(--gray-700);
  white-space: nowrap;
  cursor: pointer;
}
.attr-list-table th:hover { background: var(--gray-100); }
.attr-list-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-900);
}
.attr-list-table tr:hover td { background: var(--primary-light); cursor: pointer; }
.attr-list-table tr.selected td { background: #dbeafe; }
.no-results { text-align: center; color: var(--gray-400); padding: 24px; font-size: 13px; }

/* Measure result */
#draw-color-panel {
  position: absolute;
  top: 80px;
  right: 10px;
  z-index: 1200;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 10px 12px;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#draw-color-panel.hidden { display: none; }
.draw-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.draw-color-label {
  font-size: 12px;
  color: var(--gray-600);
  min-width: 56px;
}
#draw-color-panel input[type="color"] {
  width: 32px;
  height: 24px;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  padding: 1px;
  cursor: pointer;
}

#measure-result {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 1200;
  display: none;
  white-space: nowrap;
}
#measure-result.visible { display: flex; align-items: center; gap: 10px; }

/* Loading overlay */
#loading {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
#loading.hidden { display: none; }
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading p { color: var(--gray-500); font-size: 14px; }

/* ========================================
   Print styles
   ======================================== */
.leaflet-control-attribution { font-size: 10px !important; }

#print-info-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255,255,255,0.95);
  padding: 8px 12px;
  font-size: 12px;
  display: none;
  z-index: 400;
  border-top: 1px solid var(--gray-200);
}

@media print {
  #header, #sidebar, #toolbar, #map-info-bar, #basemap-switcher,
  .leaflet-control-container { display: none !important; }
  #app { top: 0 !important; }
  #map-wrapper { position: fixed; inset: 0; }
  #print-info-panel { display: block !important; }
}

/* ========================================
   Mobile menu button (hamburger)
   ======================================== */
#mobile-menu-btn {
  display: none;
}

@media (max-width: 640px) {
  #mobile-menu-btn {
    display: flex;
    position: fixed;
    top: calc(var(--header-height) + 10px);
    left: 10px;
    z-index: 700;
    width: 40px;
    height: 40px;
    background: #fff;
    border: none;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--primary);
    cursor: pointer;
  }
  #mobile-menu-btn:hover { background: var(--gray-50); }
}

/* Sidebar overlay – lives inside #map-wrapper so it only covers the map area,
   not the sidebar itself. Tapping it closes the sidebar on mobile. */
#sidebar-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 300;
}
#sidebar-overlay.visible { display: block; }

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 640px) {
  :root { --sidebar-width: 88vw; }

  /* Sidebar hidden by default on mobile; shown with .open */
  #sidebar {
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: calc(-1 * var(--sidebar-width));
    z-index: 600;
    transition: left 0.25s ease;
    box-shadow: var(--shadow-lg);
  }
  #sidebar.open { left: 0; }

  /* Hide the desktop toggle tab on mobile */
  #sidebar-toggle { display: none; }

  #toolbar {
    top: auto;
    bottom: 36px;
    left: 8px;
    right: 8px;
    transform: none;
    justify-content: center;
  }

  #map-info-bar { bottom: 30px; font-size: 11px; }
}

/* ========================================
   Scrollbar
   ======================================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ========================================
   Custom Leaflet styles
   ======================================== */
.leaflet-popup-content-wrapper {
  border-radius: 8px !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 0 !important;
}
.leaflet-popup-content { margin: 0 !important; min-width: 200px; }
.popup-header {
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px 8px 0 0;
  font-size: 14px;
  font-weight: 600;
}
.popup-body { padding: 10px 14px; }
.popup-row { margin-bottom: 6px; font-size: 13px; }
.popup-row .popup-label { color: var(--gray-500); font-size: 11px; margin-bottom: 1px; }
.popup-row .popup-value { color: var(--gray-900); }
.popup-actions {
  padding: 8px 14px;
  border-top: 1px solid var(--gray-100);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.leaflet-popup-close-button {
  color: rgba(255,255,255,0.8) !important;
  font-size: 18px !important;
  top: 8px !important;
  right: 10px !important;
}
.leaflet-popup-close-button:hover { color: #fff !important; }

/* Custom marker */
.custom-marker {
  display: flex;
  align-items: center;
  justify-content: center;
}
.marker-pin {
  width: 28px;
  height: 28px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}
.marker-pin i {
  transform: rotate(45deg);
  font-size: 12px;
  color: #fff;
}

/* Drawing hint */
.leaflet-draw-tooltip {
  font-family: var(--font) !important;
  font-size: 12px !important;
}

/* ========================================
   Route Search
   ======================================== */
.route-mode-btns {
  display: flex;
  gap: 6px;
}
.route-mode-btn {
  flex: 1;
  padding: 6px 4px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  color: var(--gray-700);
  text-align: center;
  transition: all 0.15s;
}
.route-mode-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.route-addr-row {
  display: flex;
  gap: 4px;
  align-items: center;
}
.route-addr-input {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
}
.route-addr-input:focus { border-color: var(--primary); }
.route-addr-results {
  margin-top: 4px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  display: none;
}
.route-addr-results.open { display: block; }
.route-addr-result-item {
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}
.route-addr-result-item:last-child { border-bottom: none; }
.route-addr-result-item:hover { background: var(--primary-light); color: var(--primary); }
.route-point-status {
  font-size: 11px;
  color: var(--gray-500);
  margin-top: 3px;
  min-height: 16px;
}
.route-point-status.set { color: var(--secondary); }
.route-point-status.picking { color: var(--primary); }
.route-result {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--gray-50);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  font-size: 13px;
  display: none;
}
.route-result.visible { display: block; }
.route-result-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.route-result-row:last-child { margin-bottom: 0; }

/* ========================================
   Help Modal
   ======================================== */
.help-modal { max-width: 640px; }
.help-modal-body {
  padding: 0;
  max-height: 70vh;
  overflow-y: auto;
}
.help-section {
  border-bottom: 1px solid var(--gray-200);
}
.help-section:last-child { border-bottom: none; }
.help-section-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-900);
  font-family: var(--font);
  text-align: left;
  transition: background 0.15s;
}
.help-section-toggle:hover { background: var(--gray-50); }
.help-section-toggle span { display: flex; align-items: center; }
.help-chevron {
  font-size: 12px;
  color: var(--gray-400);
  transition: transform 0.2s ease;
}
.help-section.open .help-chevron { transform: rotate(180deg); }
.help-section-body {
  display: none;
  padding: 0 20px 16px;
}
.help-section.open .help-section-body { display: block; }
.help-dl { margin: 0; }
.help-dl dt {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-800);
  margin-top: 12px;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.help-dl dt:first-child { margin-top: 0; }
.help-dl dd {
  margin: 0 0 0 0;
  font-size: 13px;
  color: var(--gray-600);
  line-height: 1.65;
  padding-left: 20px;
}
kbd {
  display: inline-block;
  padding: 1px 5px;
  font-size: 11px;
  font-family: monospace;
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
  border-bottom-width: 2px;
  border-radius: 3px;
  color: var(--gray-700);
}
.help-btn-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}
