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

html, body, #app {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  background: #1a1a2e;
  color: #e0e0e0;
  overflow: hidden;
}

/* ── Header ── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 46px;
  background: #0f0f1a;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
  gap: 8px;
  z-index: 1000;
  position: relative;
}
#header-left { display: flex; align-items: center; gap: 8px; }
#header-right { display: flex; align-items: center; gap: 6px; }
#brand { font-size: 17px; font-weight: 700; color: #7eb8f7; white-space: nowrap; margin-right: 8px; }
#free-link {
  font-size: 11px; font-weight: 600; text-decoration: none;
  color: #9fd8c7; background: #14302a;
  border: 1px solid #1f4a40; border-radius: 4px;
  padding: 4px 8px; white-space: nowrap; margin-right: 8px;
}
#free-link:hover { background: #1a4038; color: #c4ecdd; }
#search-input {
  width: 260px; padding: 5px 9px;
  background: #2a2a4a; border: 1px solid #3a3a5a;
  color: #e0e0e0; border-radius: 4px; font-size: 13px;
}
#search-input:focus { outline: none; border-color: #7eb8f7; }
#search-btn { padding: 5px 12px; }

/* ── Buttons ── */
.btn {
  padding: 5px 12px;
  border: none; border-radius: 4px;
  cursor: pointer; font-size: 12px; font-weight: 600;
  white-space: nowrap; transition: filter 0.15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { filter: brightness(0.9); }
.btn-green  { background: #2d7a3a; color: #fff; }
.btn-blue   { background: #1e5fa8; color: #fff; }
.btn-red    { background: #8b2020; color: #fff; }
.btn-gray   { background: #444; color: #ddd; }
.btn-full   { width: 100%; margin-top: 6px; padding: 7px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Main layout ── */
#main {
  display: flex;
  height: calc(100% - 46px);
  overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: 240px;
  min-width: 220px;
  background: #1a1a2e;
  border-right: 1px solid #2a2a4a;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

#tabs {
  display: flex;
  background: #0f0f1a;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
}
.tab {
  flex: 1; padding: 9px 2px;
  background: none; border: none;
  color: #888; font-size: 11px; font-weight: 600;
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: #bbb; }
.tab.active { color: #7eb8f7; border-bottom-color: #7eb8f7; }

.panel {
  display: none;
  overflow-y: auto;
  flex: 1;
  padding: 8px;
  gap: 0;
}
.panel.active { display: block; }

.group {
  border: 1px solid #2a2a4a;
  border-radius: 5px;
  padding: 8px;
  margin-bottom: 8px;
}
.group-title {
  font-size: 11px; font-weight: 700;
  color: #7eb8f7; text-transform: uppercase;
  letter-spacing: 0.05em; margin-bottom: 6px;
}

.group label {
  display: block;
  padding: 2px 0;
  cursor: pointer;
  color: #ccc;
}
.group label:hover { color: #fff; }
.group input[type="checkbox"] { margin-right: 5px; accent-color: #7eb8f7; }

.row-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #aaa;
  font-size: 12px;
  margin-top: 6px;
  margin-bottom: 2px;
}
.row-label input[type="color"] {
  width: 36px; height: 22px;
  border: 1px solid #3a3a5a; border-radius: 3px;
  background: none; cursor: pointer;
}
.row-label span { color: #7eb8f7; font-weight: 700; }

input[type="range"] {
  width: 100%; height: 4px;
  accent-color: #7eb8f7;
  margin: 4px 0;
}

select {
  width: 100%; padding: 4px 6px;
  background: #2a2a4a; border: 1px solid #3a3a5a;
  color: #e0e0e0; border-radius: 4px; font-size: 12px;
  margin: 2px 0;
}

.hint {
  font-size: 11px; color: #666;
  line-height: 1.4; margin: 4px 0;
}

/* Road control rows */
.road-row {
  border: 1px solid #2a2a4a; border-radius: 4px;
  padding: 6px 8px; margin-bottom: 6px;
}
.road-row-title {
  font-size: 11px; font-weight: 700; color: #ccc;
  margin-bottom: 4px; display: flex; align-items: center; gap: 6px;
}
.road-swatch {
  display: inline-block; width: 20px; height: 8px;
  border-radius: 2px; border: 1px solid rgba(255,255,255,0.2);
}
.road-sub { display: flex; gap: 6px; align-items: center; margin-top: 3px; }
.road-sub label { font-size: 11px; color: #888; white-space: nowrap; }
.road-sub input[type="range"] { flex: 1; }
.road-sub input[type="color"] {
  width: 28px; height: 20px;
  border: 1px solid #3a3a5a; border-radius: 3px;
  background: none; cursor: pointer;
}

/* Annotation list */
#annotation-list { max-height: 160px; overflow-y: auto; }
.ann-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 3px 5px; border-radius: 3px; cursor: pointer;
  font-size: 11px; color: #ccc;
}
.ann-item:hover { background: #2a2a4a; }
.ann-item.selected { background: #1e3a5f; color: #7eb8f7; }
.ann-item-del {
  background: none; border: none; color: #666; cursor: pointer;
  font-size: 14px; line-height: 1;
}
.ann-item-del:hover { color: #e05; }

/* ── Map container ── */
#map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#map {
  width: 100%; height: 100%;
}
#map-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 500; /* above Leaflet tile/overlay panes, below controls (800) */
}
#map-svg.annotate-mode,
#map-svg.bbox-mode {
  pointer-events: all;
  cursor: crosshair;
}

/* Hide leaflet attribution (still legally attributing via OSM data) */
.leaflet-control-attribution { font-size: 9px; opacity: 0.6; }

/* ── Loading overlay ── */
#loading {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(15,15,26,0.88);
  border: 1px solid #2a2a4a;
  border-radius: 8px;
  padding: 20px 32px;
  text-align: center;
  color: #ccc;
  z-index: 2000;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
#loading.hidden { display: none; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid #333; border-top-color: #7eb8f7;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Status bar ── */
#statusbar {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(15,15,26,0.75);
  display: flex; gap: 16px; padding: 3px 10px;
  font-size: 11px; color: #888; z-index: 500;
}
#status-msg { margin-left: auto; color: #7eb8f7; }

/* ── Edit modal ── */
#edit-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 9000;
}
#edit-modal.hidden { display: none; }
#edit-box {
  background: #1a1a2e; border: 1px solid #3a3a5a;
  border-radius: 8px; padding: 20px; min-width: 300px;
}
.modal-title { font-size: 14px; font-weight: 700; color: #7eb8f7; margin-bottom: 10px; }
#edit-text {
  width: 100%; padding: 8px;
  background: #2a2a4a; border: 1px solid #3a3a5a;
  color: #e0e0e0; border-radius: 4px; font-size: 14px;
  resize: vertical;
}
.modal-row { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; }

/* Annotation drag cursor */
.draggable-ann { cursor: move; }

/* ── Icon library ── */
.hidden-file { display: none; }
#icon-library {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 8px 0 4px;
}
#icon-library:empty { margin: 0; }
.icon-thumb {
  position: relative;
  aspect-ratio: 1;
  border: 2px solid #2a2a4a;
  border-radius: 5px;
  background: #2a2a4a;
  cursor: pointer;
  overflow: hidden;
}
.icon-thumb:hover { border-color: #4a4a7a; }
.icon-thumb.armed { border-color: #7eb8f7; box-shadow: 0 0 0 1px #7eb8f7; }
.icon-thumb img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  padding: 3px;
}
.icon-thumb-del {
  position: absolute; top: -1px; right: -1px;
  width: 15px; height: 15px;
  background: rgba(15,15,26,0.85);
  border: none; border-radius: 0 0 0 5px;
  color: #888; cursor: pointer;
  font-size: 11px; line-height: 1;
  display: none;
}
.icon-thumb:hover .icon-thumb-del { display: block; }
.icon-thumb-del:hover { color: #e05; }
