/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1a1a1a;
  color: #fff;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ========== Main View ========== */
#main-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
}

#main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: #2a2a2a;
  border-bottom: 1px solid #444;
  flex-shrink: 0;
  z-index: 10;
}

#main-header h1 {
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#pdf-buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.pdf-btn {
  display: inline-block;
  padding: 6px 14px;
  background: #c8a040;
  color: #1a1a1a;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  text-decoration: none;
}

.pdf-btn:hover {
  background: #dab550;
}

/* Map Container */
#map-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
  touch-action: none;
}

#map-container .map-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

#main-map {
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

#grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Grid Square Overlays */
.grid-square {
  position: absolute;
  cursor: pointer;
  pointer-events: auto;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  z-index: 5;
}

.grid-square:hover {
  background: rgba(218, 165, 32, 0.35);
  border-color: rgba(218, 165, 32, 0.8);
}

.grid-square .tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 4px 8px;
  border-radius: 3px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 20;
}

.grid-square:hover .tooltip {
  display: block;
}

/* ========== Detail View (Image Viewer) ========== */
#detail-view {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #111;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

#detail-header {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  z-index: 1010;
  flex-shrink: 0;
  gap: 12px;
}

#detail-title {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
}

#zoom-controls {
  display: flex;
  gap: 4px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.back-btn .back-arrow {
  display: inline-block;
  font-size: 18px;
  line-height: 1;
  margin-top: -1px;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.zoom-btn {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.zoom-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

#detail-content {
  flex: 1;
  overflow: hidden;
  position: relative;
  cursor: grab;
  touch-action: none;
}

#detail-content.grabbing {
  cursor: grabbing;
}

#detail-image {
  display: block;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-drag: none;
}


/* ========== Loading Indicator ========== */
.loading-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #c8a040;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ========== Responsive ========== */
@media (max-width: 600px) {
  #main-header {
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 10px;
  }

  #main-header h1 {
    font-size: 13px;
    width: 100%;
  }

  .pdf-btn {
    padding: 5px 10px;
    font-size: 12px;
  }

  .back-btn {
    padding: 5px 10px;
    font-size: 13px;
  }

  #detail-title, #pdf-title {
    font-size: 13px;
  }

  .zoom-btn {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  #map-container {
    cursor: grab;
  }
}
