/* ============================================================
   THEME VARIABLES (Dark Mode Only)
   ============================================================ */
:root {
  --bg: #0b0f14;
  --surface: #0f141a;
  --text: #e7ecf3;
  --muted: #9aa6b2;
  --line: #1f2a36;
  --chip: #16202b;
  --primary: #4f8cff;

  --ok: #0ea05a;
  --warn: #f59f00;
  --bad: #f04438;

  --radius: 14px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* ============================================================
   GLOBAL
   ============================================================ */
* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu,
    Helvetica, Arial, sans-serif;
}

/* Utility */
.hidden {
  display: none !important;
}

.sep {
  height: 1px;
  background: var(--line);
  margin: 16px 0;
}

/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: saturate(140%) blur(10px);
  background: color-mix(in oklab, var(--bg) 70%, transparent);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 100%;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "IBM Plex Mono", "IBM Plex Mono Fallback", monospace;
  font-size: 30px;
  font-weight: 700;
}

.brand img {
  height: 50px;
  opacity: 0.9;
}

/* ============================================================
   MAIN LAYOUT - Two Column
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  height: calc(100vh - 76px);
  padding: 16px;
  overflow: hidden;
}

@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
}

/* ============================================================
   PANELS
   ============================================================ */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.panel-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.panel-left {
  overflow-y: auto;
}

.panel-right {
  min-height: 0;
}

.map-body {
  padding: 0;
  position: relative;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover {
  background: var(--chip);
  border-color: var(--muted);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: color-mix(in oklab, var(--primary) 85%, black);
}

.btn-success {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.btn-success:hover {
  background: color-mix(in oklab, var(--ok) 85%, black);
}

/* ============================================================
   UPLOAD AREA
   ============================================================ */
.upload-area {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--primary);
  background: color-mix(in oklab, var(--primary) 10%, transparent);
}

.upload-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.upload-area p {
  margin: 4px 0;
  color: var(--text);
}

.upload-hint {
  font-size: 13px;
  color: var(--muted) !important;
}

/* ============================================================
   FILE INFO
   ============================================================ */
.file-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--chip);
  border-radius: 8px;
  margin-bottom: 16px;
}

.file-name {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

/* ============================================================
   CONTROLS
   ============================================================ */
.controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.control-group input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.control-group span {
  font-size: 13px;
  color: var(--text);
}

.slider-buttons {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.btn-slider {
  width: 28px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--chip);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-slider.btn-reset {
  width: auto;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 500;
}

.btn-slider:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.btn-slider:active {
  transform: scale(0.95);
}

.checkbox-group {
  margin: 2px 0;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
}

.checkbox-label input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--primary);
  cursor: pointer;
}

.position-info,
.bounds-info {
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--muted);
}

.position-info {
  display: flex;
  gap: 16px;
}

.bounds-info div {
  margin-bottom: 4px;
}

/* ============================================================
   EXPORT SECTION
   ============================================================ */
.export-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.download-link {
  margin-top: 8px;
}

.download-link a {
  width: 100%;
}

.download-links {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.download-links a {
  flex: 1;
  text-align: center;
}

.status-message {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  text-align: center;
}

.status-message.loading {
  background: color-mix(in oklab, var(--primary) 15%, transparent);
  color: var(--primary);
}

.status-message.success {
  background: color-mix(in oklab, var(--ok) 15%, transparent);
  color: var(--ok);
}

.status-message.error {
  background: color-mix(in oklab, var(--bad) 15%, transparent);
  color: var(--bad);
}

/* ============================================================
   MAP
   ============================================================ */
#map {
  width: 100%;
  height: 100%;
  background: #1a1a2e;
  border-radius: 0 0 var(--radius) var(--radius);
}

.map-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  pointer-events: none;
  z-index: 1000;
}

.map-controls {
  display: flex;
  gap: 8px;
}

/* Leaflet dark theme overrides */
.leaflet-container {
  background: #1a1a2e;
}

.leaflet-control-zoom {
  border: 1px solid var(--line) !important;
  border-radius: 8px !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-bottom: 1px solid var(--line) !important;
}

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

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

/* Layer control styling */
.leaflet-control-layers {
  border: 1px solid var(--line) !important;
  border-radius: 8px !important;
  background: var(--surface) !important;
}

.leaflet-control-layers-toggle {
  background-color: var(--surface) !important;
  width: 36px !important;
  height: 36px !important;
}

.leaflet-control-layers-expanded {
  padding: 8px 12px !important;
  background: var(--surface) !important;
  color: var(--text) !important;
}

.leaflet-control-layers-base label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.leaflet-control-layers-base label:hover {
  color: var(--primary);
}

.leaflet-control-layers-selector {
  accent-color: var(--primary);
}

/* PDF overlay styling */
.pdf-overlay {
  cursor: move;
  pointer-events: auto !important;
  user-select: none;
  -webkit-user-drag: none;
}

.pdf-overlay img {
  pointer-events: auto !important;
  user-select: none;
  -webkit-user-drag: none;
  draggable: false;
}

/* Overlay handle controls */
.overlay-handles {
  position: absolute;
  pointer-events: none;
  z-index: 1000;
}

.overlay-handle {
  position: absolute;
  width: 32px;
  height: 32px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  color: #fff;
  pointer-events: auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transform: translate(-50%, -50%);
  transition: transform 0.1s ease, background 0.2s ease;
  user-select: none;
}

.overlay-handle:hover {
  transform: translate(-50%, -50%) scale(1.15);
  background: var(--accent-hover);
}

.handle-move {
  cursor: move;
  background: #3b82f6;
}

.handle-move:hover {
  background: #2563eb;
}

.handle-resize {
  cursor: nwse-resize;
  background: #10b981;
}

.handle-resize:hover {
  background: #059669;
}

.handle-rotate {
  cursor: grab;
  background: #f59e0b;
}

.handle-rotate:hover {
  background: #d97706;
}

.handle-rotate:active {
  cursor: grabbing;
}

/* ============================================================
   FIXED FEATURE
   ============================================================ */
.fixed-feature-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fixed-feature-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ok);
}

.fixed-feature-status .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
}

.btn-danger {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}

.btn-danger:hover {
  background: color-mix(in oklab, var(--bad) 85%, black);
}

/* ============================================================
   MODAL
   ============================================================ */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none !important;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

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

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

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

.modal-instructions {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--chip);
  border-radius: 8px;
}

.modal-instructions p {
  margin: 4px 0;
  font-size: 14px;
  color: var(--muted);
}

.modal-instructions strong {
  color: var(--text);
}

.overlay-map-container {
  width: 100%;
  height: 400px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--line);
}

/* Style the leaflet map in modal */
.overlay-map-container .leaflet-container {
  background: var(--bg);
}

.overlay-map-container .leaflet-control-zoom {
  border: 1px solid var(--line);
}

.overlay-map-container .leaflet-control-zoom a {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.overlay-map-container .leaflet-control-zoom a:hover {
  background: var(--chip);
}

/* Fixed feature pin marker */
.fixed-feature-pin-container {
  background: none !important;
  border: none !important;
}

.fixed-feature-pin {
  width: 24px;
  height: 24px;
  background: var(--bad);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.fixed-feature-pin-map {
  width: 24px;
  height: 24px;
  background: var(--primary);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
