@import url('theme.css');

/* ========================================
   OV Map — Main Styles (test.html design)
   ======================================== */

body {
  font-family: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overflow: hidden;
  height: 100vh;
  display: flex;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Sidebar ──────────────────────────── */
#sidebar {
  width: 280px;
  background: var(--sidebar-bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  box-shadow: var(--shadow-md);
  transition: width 0.3s ease, min-width 0.3s ease, background-color 0.25s ease, color 0.25s ease;
  position: relative;
  min-width: 280px;
  overflow: visible;
  border-right: 1px solid var(--border);
}

#sidebar.collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
}

.sidebar-collapse-btn {
  position: fixed;
  left: 280px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 60px;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
  z-index: 1001;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left 0.3s ease, background 0.2s, color 0.2s, border-color 0.2s;
}

.sidebar-collapse-btn svg {
  stroke: currentColor;
  fill: none;
}

.sidebar-collapse-btn:hover {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}

#sidebar.collapsed ~ .sidebar-collapse-btn {
  left: 0;
}

/* ── Brand ────────────────────────────── */
.sidebar-header {
  padding: 12px 16px;
  background: var(--sidebar-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  background: var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Theme Toggle (in sidebar header) ─── */
.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.theme-toggle svg {
  stroke: currentColor;
  fill: none;
}

.theme-toggle:hover {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}

.theme-toggle:active {
  transform: scale(0.93);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  transition: opacity 0.2s ease;
}

[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ── Search ───────────────────────────── */
.search-box {
  padding: 10px;
  background: var(--sidebar-header);
  border-bottom: 1px solid var(--border);
}

.search-mode-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.search-mode-btn {
  flex: 1;
  padding: 5px 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  font-weight: 500;
}

.search-mode-btn.active {
  background: var(--accent);
  color: var(--text-on-accent);
}

.search-mode-btn:hover:not(.active) {
  background: var(--hover);
  color: var(--text-secondary);
}

.search-scope-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.search-scope-btn {
  flex: 1;
  padding: 4px 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  font-weight: 500;
}

.search-scope-btn.active {
  background: var(--accent);
  color: var(--text-on-accent);
}

.search-scope-btn:hover:not(.active) {
  background: var(--hover);
  color: var(--text-secondary);
}

.search-input-wrap {
  display: flex;
  gap: 4px;
}

.search-input-wrap input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.search-input-wrap input:focus {
  border-color: var(--border-focus);
}

.search-input-wrap input::placeholder {
  color: var(--text-muted);
}

.search-btn {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.search-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.search-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
}

.search-btn.primary:hover {
  background: var(--accent-hover);
}

.api-key-box {
  margin-top: 8px;
  padding: 10px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.api-key-label {
  font-size: 11px;
  color: var(--text-accent);
  margin-bottom: 6px;
  font-weight: 500;
}

.api-key-row {
  display: flex;
  gap: 4px;
}

.api-key-row input {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  font-size: 12px;
  outline: none;
  font-family: inherit;
}

.api-key-row input:focus {
  border-color: var(--border-focus);
}

.api-key-hint {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

.search-results {
  max-height: 250px;
  overflow-y: auto;
  margin-top: 6px;
  display: none;
}

.search-results.has-items { display: block; }

.search-result-item {
  padding: 8px 10px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  cursor: pointer;
  transition: background 0.15s;
  border-left: 3px solid var(--accent);
}

.search-result-item:hover { background: var(--hover); }

.search-result-item .result-name {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

.search-result-item .result-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-item.layer-match {
  border-left-color: var(--warning);
}

.search-hint {
  padding: 8px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.search-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Map Controls ─────────────────────── */
.locate-btn {
  width: 36px;
  height: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.locate-btn svg {
  stroke: currentColor;
  fill: none;
}

.locate-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.locating { animation: pulse 1s infinite; }

.sidebar-btn {
  display: none;
  width: 36px;
  height: 36px;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
}

.sidebar-btn svg {
  stroke: currentColor;
  fill: none;
}

.sidebar-btn:hover { background: var(--hover); color: var(--text); }

.sidebar-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Sidebar Content ──────────────────── */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
  transition: scrollbar-color 0.3s;
}

.sidebar-content:hover,
.sidebar-content.scrolling {
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.sidebar-content::-webkit-scrollbar { width: 5px; }
.sidebar-content::-webkit-scrollbar-track { background: transparent; }
.sidebar-content::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 3px;
}
.sidebar-content:hover::-webkit-scrollbar-thumb,
.sidebar-content.scrolling::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
}

/* ── Layer Sections ───────────────────── */
.layer-section {
  margin-bottom: 10px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px;
  border: 1px solid var(--border);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.section-header h4 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.section-header h4 svg {
  color: var(--text-muted);
}

/* ── Layer List (custom radio) ────────── */
.layer-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
  color: var(--text);
}

.layer-item:hover { background: var(--hover); }

.layer-item input[type="radio"],
.layer-item input[type="checkbox"] {
  display: none;
}

.layer-radio {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  position: relative;
  transition: border-color 0.2s;
}

.layer-item input[type="radio"]:checked ~ .layer-radio {
  border-color: var(--accent);
}

.layer-item input[type="radio"]:checked ~ .layer-radio::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.layer-item input[type="checkbox"] {
  display: block;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

/* ── Import Buttons ───────────────────── */
.import-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.btn-dot.kml { background: #3b82f6; }
.btn-dot.geojson { background: #22c55e; }
.btn-dot.gpx { background: #f59e0b; }

/* ── Tool Links ───────────────────────── */
.tool-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tool-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
}

.tool-link:hover {
  border-color: var(--accent-border);
  background: var(--accent-subtle);
}

.tool-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.tool-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tool-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.tool-desc {
  font-size: 11px;
  color: var(--text-muted);
}

.tool-link svg:last-child {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.2s;
}

.tool-link:hover svg:last-child {
  transform: translateX(2px);
  color: var(--accent);
}

/* ── Buttons ──────────────────────────── */
.btn {
  padding: 8px 14px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s;
  flex: 1;
  min-width: 70px;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:active { transform: scale(0.97); }

.btn-accent, .btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
}
.btn-accent:hover, .btn-primary:hover { background: var(--accent-hover); }

.btn-import {
  background: var(--surface-alt);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  flex: 1;
}
.btn-import:hover {
  background: var(--hover);
  color: var(--text);
  border-color: var(--accent-border);
}

.btn-danger {
  background: var(--danger);
  color: var(--text-on-accent);
}
.btn-danger:hover { opacity: 0.9; }

.btn-outline-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger-border);
  font-size: 12px;
  padding: 5px 10px;
}
.btn-outline-danger:hover {
  background: var(--danger-subtle);
}

.btn-warn {
  background: var(--warning);
  color: var(--text-on-accent);
}
.btn-warn:hover { opacity: 0.9; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--hover); color: var(--text); }

.btn-inline {
  background: none;
  border: none;
  color: var(--text-accent);
  font-size: 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  font-family: inherit;
  font-weight: 500;
  white-space: nowrap;
}

.btn-inline:hover {
  background: var(--accent-subtle);
  color: var(--accent-hover);
}

/* ── Map ──────────────────────────────── */
#map {
  flex: 1;
  height: 100vh;
}

/* ── Coordinates Bar ──────────────────── */
#coordinates {
  position: absolute;
  bottom: 30px;
  left: 290px;
  background: var(--coord-bg);
  color: var(--coord-text);
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  z-index: 1000;
  display: flex;
  gap: 16px;
  transition: left 0.3s ease;
  border: 1px solid var(--coord-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#sidebar.collapsed ~ #coordinates {
  left: 10px;
}

.coord-left,
.coord-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.coord-left svg,
.coord-right svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Imported Layer Items ─────────────── */
.empty-hint {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 8px;
}

.layer-item-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1;
}

.layer-item-name {
  font-size: 12px;
  word-break: break-all;
  flex: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  transition: background 0.15s;
}

.layer-item-name:hover { background: var(--accent-subtle); }

.layer-item-name input {
  background: var(--input-bg);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 12px;
  padding: 1px 4px;
  border-radius: 3px;
  outline: none;
  width: 100%;
  font-family: inherit;
}

.layer-actions {
  display: flex;
  gap: 2px;
  margin-left: 4px;
}

.layer-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 3px;
  line-height: 1;
  transition: all 0.15s;
}

.layer-actions button:hover {
  background: var(--hover);
  color: var(--text);
}

/* ── Measure ──────────────────────────── */
.measure-result {
  background: var(--surface-alt);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 12px;
  border: 1px solid var(--border);
}

.measure-result .label {
  color: var(--text-accent);
  font-weight: 600;
}

.measure-result .value {
  color: var(--text);
  margin-top: 4px;
}

/* ── Modals ───────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 10002;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 420px;
  max-width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-header);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
}

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

.modal-body {
  padding: 14px 18px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

/* ── Cloud Sync ───────────────────────── */
.cloud-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin: -14px -18px 14px;
}

.cloud-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.cloud-tab:hover {
  color: var(--text);
  background: var(--accent-subtle);
}

.cloud-tab.active {
  color: var(--text-accent);
  border-bottom-color: var(--accent);
}

.cloud-tab-content { display: none; }
.cloud-tab-content.active { display: block; }

.cloud-api-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.cloud-api-bar input {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  outline: none;
  font-family: inherit;
}

.cloud-api-bar input:focus { border-color: var(--border-focus); }

.cloud-api-bar button {
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent);
  color: var(--text-on-accent);
  white-space: nowrap;
  transition: background 0.2s;
  font-family: inherit;
}

.cloud-api-bar button:hover { background: var(--accent-hover); }

#cloudApiStatus {
  font-size: 11px;
  margin-bottom: 8px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

#cloudApiStatus.ok { color: var(--success); background: var(--success-subtle); }
#cloudApiStatus.err { color: var(--danger); background: var(--danger-subtle); }

.cloud-file-list { display: flex; flex-direction: column; gap: 8px; }

.cloud-file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}

.cloud-file-item:hover { background: var(--hover); }

.cloud-file-item.selected {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.cloud-file-item input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.cloud-file-info { flex: 1; min-width: 0; }
.cloud-file-name { font-size: 13px; color: var(--text); word-break: break-all; }
.cloud-file-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.cloud-file-item.imported { opacity: 0.5; cursor: default; }

.cloud-sync-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 30px 10px;
}

/* ── Context Menu ─────────────────────── */
.context-menu {
  display: none;
  position: fixed;
  z-index: 10001;
  background: var(--ctx-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 220px;
  overflow: hidden;
  font-size: 13px;
  border: 1px solid var(--border);
}

.context-menu.show { display: block; }

.context-title {
  padding: 8px 14px;
  background: var(--ctx-header);
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

.context-coord {
  padding: 10px 14px;
  font-family: 'SF Mono', 'Consolas', 'Courier New', monospace;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--ctx-border);
  line-height: 1.6;
  word-break: break-all;
}

.context-actions { display: flex; flex-direction: column; }

.context-actions button {
  padding: 8px 14px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background 0.12s;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
}

.context-actions button:hover { background: var(--ctx-hover); }

@keyframes ctx-pulse {
  0% { transform: scale(0.6); opacity: 0.9; }
  60% { transform: scale(1.5); opacity: 0; }
  100% { transform: scale(1.5); opacity: 0; }
}

.leaflet-marker-icon.ctx-indicator {
  background: none;
  border: none;
}

/* ── Loading ──────────────────────────── */
#loadingOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 10000;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.loading-text { color: var(--text); font-size: 14px; }

/* ── Overlay (mobile) ─────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 999;
}

/* ── Popup ────────────────────────────── */
.leaflet-popup-content {
  margin: 8px 12px;
  max-height: 300px;
  overflow-y: auto;
  min-width: 180px;
  max-width: calc(100vw - 60px);
  width: auto;
  -webkit-user-select: text;
  user-select: text;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-width: calc(100vw - 40px);
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
  background: var(--popup-bg);
  color: var(--popup-text);
}

.leaflet-popup-content-wrapper.layer-popup { max-width: none; }
.layer-popup .leaflet-popup-content { min-width: 200px; max-width: 800px; width: auto; max-height: 400px; }

.popup-layer-tag {
  font-size: 11px;
  color: var(--text-accent);
  background: var(--accent-subtle);
  padding: 3px 8px;
  border-radius: 3px;
  margin-bottom: 8px;
  font-weight: 500;
  word-break: break-all;
  border-left: 3px solid var(--accent);
}

.popup-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--accent);
}

.popup-table { width: 100%; border-collapse: collapse; font-size: 12px; }

.popup-table td {
  padding: 4px 8px;
  border: 1px solid var(--popup-border);
  vertical-align: top;
}

.popup-table tr:nth-child(even) { background: var(--popup-row-even); }
.popup-table tr:hover { background: var(--popup-row-hover); }

.popup-key { font-weight: 600; color: var(--popup-key); white-space: nowrap; width: 35%; }
.popup-val { color: var(--popup-val); word-break: break-all; }

.popup-body { font-size: 13px; color: var(--text); line-height: 1.8; }
.popup-body strong { color: var(--danger); }

.measure-popup .leaflet-popup-content { min-width: auto; max-width: 280px; }

.leaflet-draw-tooltip {
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  border: none;
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12px;
}

.leaflet-draw-tooltip:before { border-right-color: var(--tooltip-bg); }

.layer-color-indicator { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

/* ── Leaflet Zoom Control ─────────────── */
.leaflet-control-zoom {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  overflow: hidden;
  box-shadow: var(--shadow-md) !important;
}

.leaflet-control-zoom a {
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  font-size: 20px !important;
  color: var(--text) !important;
  background: var(--surface) !important;
  border-bottom: 1px solid var(--border) !important;
  transition: background 0.15s, color 0.15s;
}

.leaflet-control-zoom a:last-child {
  border-bottom: none !important;
}

.leaflet-control-zoom a:hover {
  background: var(--hover) !important;
  color: var(--accent) !important;
}

.leaflet-control-zoom a:active {
  background: var(--accent-subtle) !important;
}

/* ── Leaflet Draw Control ─────────────── */
.leaflet-draw {
  border: none !important;
  box-shadow: none !important;
}

.leaflet-draw-toolbar {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  overflow: hidden;
  box-shadow: var(--shadow-md) !important;
}

.leaflet-draw-toolbar a {
  width: 36px !important;
  height: 36px !important;
  background-color: var(--surface) !important;
  border-bottom: 1px solid var(--border) !important;
  transition: background 0.15s;
}

.leaflet-draw-toolbar a:last-child {
  border-bottom: none !important;
}

.leaflet-draw-toolbar a:hover {
  background-color: var(--hover) !important;
}

.leaflet-draw-toolbar a:active {
  background-color: var(--accent-subtle) !important;
}

.leaflet-draw-actions {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  overflow: hidden;
  box-shadow: var(--shadow-md) !important;
  margin-top: 4px !important;
}

.leaflet-draw-actions a {
  width: auto !important;
  padding: 0 10px !important;
  height: 32px !important;
  line-height: 32px !important;
  background-color: var(--surface) !important;
  color: var(--text) !important;
  border-bottom: 1px solid var(--border) !important;
  transition: background 0.15s;
  font-size: 12px;
}

.leaflet-draw-actions a:last-child {
  border-bottom: none !important;
}

.leaflet-draw-actions a:hover {
  background-color: var(--hover) !important;
}

/* ── Leaflet Draw Toolbar Icons (hollow) ── */
.leaflet-draw-toolbar a {
  background-size: 20px 20px !important;
  background-position: center center !important;
  background-repeat: no-repeat !important;
}

.leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-draw-polyline {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2'%3E%3Cpath d='M4 20L20 4'/%3E%3Ccircle cx='4' cy='20' r='2'/%3E%3Ccircle cx='20' cy='4' r='2'/%3E%3C/svg%3E") !important;
}

.leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-draw-polygon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2'%3E%3Cpath d='M12 3L3 12l4 8h10l4-8z'/%3E%3C/svg%3E") !important;
}

.leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-draw-rectangle {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2'%3E%3Crect x='3' y='5' width='18' height='14' rx='1'/%3E%3C/svg%3E") !important;
}

.leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-draw-circle {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Ccircle cx='12' cy='12' r='2'/%3E%3C/svg%3E") !important;
}

.leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-draw-marker {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2'%3E%3Cpath d='M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z'/%3E%3Ccircle cx='12' cy='10' r='3'/%3E%3C/svg%3E") !important;
}

.leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-edit-edit {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2'%3E%3Cpath d='M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7'/%3E%3Cpath d='M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z'/%3E%3C/svg%3E") !important;
}

.leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-edit-remove {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2'%3E%3Cpolyline points='3 6 5 6 21 6'/%3E%3Cpath d='M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'/%3E%3C/svg%3E") !important;
}

/* ── Leaflet Draw icons (dark theme) ── */
[data-theme="dark"] .leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-draw-polyline {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M4 20L20 4'/%3E%3Ccircle cx='4' cy='20' r='2'/%3E%3Ccircle cx='20' cy='4' r='2'/%3E%3C/svg%3E") !important;
}

[data-theme="dark"] .leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-draw-polygon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M12 3L3 12l4 8h10l4-8z'/%3E%3C/svg%3E") !important;
}

[data-theme="dark"] .leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-draw-rectangle {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Crect x='3' y='5' width='18' height='14' rx='1'/%3E%3C/svg%3E") !important;
}

[data-theme="dark"] .leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-draw-circle {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Ccircle cx='12' cy='12' r='2'/%3E%3C/svg%3E") !important;
}

[data-theme="dark"] .leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-draw-marker {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z'/%3E%3Ccircle cx='12' cy='10' r='3'/%3E%3C/svg%3E") !important;
}

[data-theme="dark"] .leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-edit-edit {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7'/%3E%3Cpath d='M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z'/%3E%3C/svg%3E") !important;
}

[data-theme="dark"] .leaflet-draw .leaflet-draw-toolbar a.leaflet-draw-edit-remove {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='3 6 5 6 21 6'/%3E%3Cpath d='M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'/%3E%3C/svg%3E") !important;
}

.marker-delete-btn {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 10px;
  background: var(--danger);
  color: var(--text-on-accent);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.6;
  font-family: inherit;
}

.marker-delete-btn:hover { opacity: 0.85; }

/* ── Responsive ───────────────────────── */
@media (max-width: 768px) {
  body { flex-direction: column; }

  .sidebar-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    transition: left 0.3s ease;
    z-index: 1050;
    min-width: 280px;
    overflow: hidden;
  }

  .sidebar-collapse-btn { display: none; }

  #sidebar.open { left: 0; }
  .sidebar-overlay.show { display: block; }

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

  #coordinates {
    left: 10px;
    bottom: 10px;
    padding: 5px 10px;
    font-size: 11px;
    border-radius: var(--radius-sm);
    flex-direction: column;
    gap: 2px;
  }

  .context-menu { min-width: 180px; }

  .layer-popup .leaflet-popup-content {
    min-width: 140px;
    max-width: calc(100vw - 40px);
  }

  .popup-key { width: auto; white-space: normal; }

  .popup-table td { display: block; width: 100%; padding: 3px 6px; }
}

@media (max-width: 480px) {
  #sidebar {
    width: 260px;
    left: -260px;
    min-width: 260px;
  }

  .search-input-wrap input { font-size: 16px; }
  .layer-item { padding: 8px; }

  .btn {
    padding: 10px 12px;
    min-width: 60px;
  }

  .import-buttons { flex-direction: column; }
  .import-buttons .btn { width: 100%; }
}
