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

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #64748b;
  --background: #ffffff;
  --sidebar-bg: #f8f9fa;
  --border: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --success: #10b981;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --canvas-grid: #f1f5f9;
  --lot-fill: #e8f4e8;
  --lot-stroke: #2d5a2d;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text-primary);
  background: var(--background);
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

/* Header */
.header {
  background: #2c3e50;
  color: white;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  flex-shrink: 0;
}

.app-title {
  font-size: 16px;
  font-weight: 600;
  color: white;
  margin-right: 8px;
}

.lot-chips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
}

.lot-chip {
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.3);
  background: transparent;
  color: rgba(255,255,255,0.8);
  transition: all 0.2s;
}

.lot-chip:hover {
  background: rgba(255,255,255,0.1);
  color: white;
}

.lot-chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.btn-primary.header-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn-primary.header-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

/* Main layout */
.main {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100%;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section { }

.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.side-count {
  font-weight: 400;
  color: var(--text-secondary);
}

.label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 4px;
}

.input, .select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-primary);
  background: white;
  outline: none;
  transition: border-color 0.2s;
}

.input:focus, .select:focus {
  border-color: var(--primary);
}

/* Tech description */
.tech-desc {
  width: 100%;
  min-height: 100px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

.tech-desc:focus { border-color: var(--primary); }

.extract-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.extract-status {
  font-size: 11px;
  color: var(--text-secondary);
}

/* Survey Data Display */
.survey-data-display {
  max-height: 250px;
  overflow-y: auto;
}

.survey-sides-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.survey-side-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.4rem;
  transition: all 0.2s ease;
}

.survey-side-item:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.survey-side-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 0.6rem;
  flex-shrink: 0;
}

.survey-side-bearing {
  flex: 1;
  font-family: 'SF Mono', Monaco, monospace;
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.survey-side-distance {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--primary);
  flex-shrink: 0;
}

.survey-side-adjacent {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

.survey-summary {
  margin-top: 0.6rem;
  padding: 0.6rem;
  background: #f0fdf4;
  border-radius: 6px;
  border: 1px solid rgba(22, 163, 74, 0.2);
}

.survey-summary-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.survey-summary-item + .survey-summary-item {
  margin-top: 0.35rem;
}

.survey-summary-label {
  font-weight: 500;
}

.survey-summary-value {
  font-weight: 600;
  color: #16a34a;
}

/* Sides table */
.sides-table {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: white;
}

.side-row {
  display: grid;
  grid-template-columns: 24px 110px 70px 1fr 32px;
  gap: 6px;
  align-items: center;
  padding: 6px;
  border-bottom: 1px solid var(--border);
}

.side-row:last-child {
  border-bottom: none;
}

.side-num {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  font-weight: 600;
}

.side-row .input {
  padding: 6px 8px;
  font-size: 12px;
}

.side-remove {
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.side-remove:hover { background: var(--danger-hover); }

/* Buttons */
.btn {
  padding: 6px 14px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-small {
  width: 100%;
  padding: 6px;
  background: white;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
  margin-top: 6px;
}

.btn-small:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-danger {
  width: 100%;
  padding: 6px;
  background: white;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
  margin-top: 8px;
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

/* Background image controls */
.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.slider {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
}

.input-file {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
}

/* Toggles */
.toggles-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 12px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
}

.toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  margin: 0;
}

/* Export */
.export-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.export-row .select {
  width: auto;
  flex: 1;
}

.kml-row { margin-top: 6px; }

/* Canvas area */
.canvas-area {
  display: flex;
  flex-direction: column;
  background: white;
  overflow: hidden;
}

.toolbar {
  height: 48px;
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
}

.tool-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  color: var(--text-primary);
}

.tool-btn:hover {
  background: var(--sidebar-bg);
  border-color: var(--primary);
}

.zoom-indicator {
  font-size: 13px;
  color: var(--text-secondary);
  font-family: 'SF Mono', Monaco, monospace;
  padding: 0 4px;
}

#mainSvg {
  flex: 1;
  width: 100%;
  cursor: grab;
  background: white;
}

#mainSvg.dragging { cursor: grabbing; }
#mainSvg.dragging-lot { cursor: move; }
#mainSvg.dragging-vertex { cursor: crosshair; }

/* Vertex popup */
.popup {
  position: absolute;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  z-index: 100;
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
}

.popup label { display: flex; align-items: center; gap: 3px; }
.popup input {
  width: 70px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
}

/* SVG lot styling */
.lot-group { cursor: pointer; }
.lot-group.active .lot-polygon { stroke-dasharray: none; }
.lot-group:not(.active) .lot-polygon { opacity: 0.6; }

.vertex-handle {
  cursor: crosshair;
  transition: r 0.1s;
}

.vertex-handle:hover { r: 7; }

/* Responsive */
@media (max-width: 1200px) {
  .main {
    grid-template-columns: 350px 1fr;
  }
}

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

  .sidebar {
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  header {
    padding: 12px;
  }
}

@media (max-width: 600px) {
  .section-title {
    font-size: 11px;
  }

  .input, .select {
    font-size: 14px;
  }

  .sidebar {
    padding: 12px;
  }

  .side-row {
    gap: 4px;
  }

  .toggle {
    font-size: 12px;
  }
}
