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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #fafafa;
  color: #333;
  line-height: 1.6;
}

a {
  color: #555;
  text-decoration: none;
}

a:hover {
  color: #000;
}

/* Layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.header {
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.nav {
  display: flex;
  gap: 24px;
}

.nav a {
  font-size: 14px;
  padding: 8px 0;
  border-bottom: 2px solid transparent;
}

.nav a:hover,
.nav a.active {
  color: #333;
  border-bottom-color: #333;
}

/* Page Title */
.page-title {
  padding: 32px 0 24px;
}

.page-title h1 {
  font-size: 24px;
  font-weight: 600;
  color: #222;
}

.page-title p {
  color: #666;
  font-size: 14px;
  margin-top: 4px;
}

/* Cards */
.card {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 24px;
}

.card-header {
  font-size: 14px;
  font-weight: 500;
  color: #666;
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 20px;
}

.stat-label {
  font-size: 12px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 32px;
  font-weight: 600;
  color: #222;
  margin-top: 4px;
}

.stat-sub {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
}

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 24px;
  margin-bottom: 32px;
}

.chart-container {
  position: relative;
  height: 300px;
}

/* Map */
.map-container {
  height: calc(100vh - 140px);
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  overflow: hidden;
}

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

/* Map Controls */
.map-controls {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.filter-group label {
  font-size: 13px;
  color: #666;
}

.checkbox-group {
  display: flex;
  gap: 12px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

.checkbox-item input {
  cursor: pointer;
}

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

/* Upload */
.upload-area {
  border: 2px dashed #ddd;
  border-radius: 8px;
  padding: 48px;
  text-align: center;
  background: #fff;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
}

.upload-area:hover,
.upload-area.dragover {
  border-color: #999;
  background: #f9f9f9;
}

.upload-area input[type="file"] {
  display: none;
}

.upload-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  color: #ccc;
}

.upload-text {
  font-size: 16px;
  color: #666;
  margin-bottom: 8px;
}

.upload-hint {
  font-size: 13px;
  color: #999;
}

/* Form */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #555;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  transition: border-color 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: #999;
}

select.form-control {
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: #333;
  color: #fff;
  border-color: #333;
}

.btn-primary:hover {
  background: #222;
}

.btn-primary:disabled {
  background: #ccc;
  border-color: #ccc;
  cursor: not-allowed;
}

.btn-secondary {
  background: #fff;
  color: #333;
  border-color: #ddd;
}

.btn-secondary:hover {
  background: #f5f5f5;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}

/* Table */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #eee;
}

th {
  font-size: 12px;
  font-weight: 500;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

td {
  font-size: 14px;
}

tr:hover {
  background: #fafafa;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-d00 { background: #dbeafe; color: #1e40af; }
.badge-d10 { background: #dcfce7; color: #166534; }
.badge-d20 { background: #ffedd5; color: #c2410c; }
.badge-d40 { background: #fee2e2; color: #b91c1c; }
.badge-rut { background: #ede9fe; color: #6b21a8; }

.badge-low { background: #f3f4f6; color: #6b7280; }
.badge-medium { background: #fef3c7; color: #92400e; }
.badge-high { background: #fee2e2; color: #b91c1c; }

/* Results */
.results-section {
  margin-top: 32px;
}

.result-item {
  display: flex;
  gap: 16px;
  padding: 16px;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  margin-bottom: 12px;
}

.result-image {
  width: 120px;
  height: 90px;
  object-fit: cover;
  border-radius: 4px;
  background: #f0f0f0;
}

.result-info {
  flex: 1;
}

.result-info h4 {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
}

.result-meta {
  font-size: 13px;
  color: #666;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: #999;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid #eee;
  border-top-color: #666;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 12px;
}

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

/* Progress */
.progress-bar {
  width: 100%;
  height: 4px;
  background: #eee;
  border-radius: 2px;
  overflow: hidden;
  margin-top: 16px;
}

.progress-fill {
  height: 100%;
  background: #333;
  transition: width 0.3s;
}

/* Alert */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 16px;
}

.alert-success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.alert-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.alert-info {
  background: #f8fafc;
  color: #475569;
  border: 1px solid #e2e8f0;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: #fff;
  border-radius: 8px;
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #999;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: #333;
}

.modal-body {
  padding: 24px;
}

/* Popup (Map) */
.leaflet-popup-content-wrapper {
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.leaflet-popup-content {
  margin: 12px 16px;
  font-size: 13px;
  line-height: 1.5;
}

.popup-title {
  font-weight: 600;
  margin-bottom: 8px;
}

.popup-image {
  width: 100%;
  max-width: 200px;
  border-radius: 4px;
  margin-top: 8px;
}

/* BBox Canvas */
.bbox-canvas-container {
  margin-bottom: 16px;
  border-radius: 4px;
  overflow: hidden;
}

.bbox-canvas {
  width: 100%;
  height: auto;
  display: block;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: #999;
}

.empty-state h3 {
  font-size: 16px;
  color: #666;
  margin-bottom: 8px;
}

/* Grid Layouts */
.two-col {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
}

@media (max-width: 768px) {
  .two-col {
    grid-template-columns: 1fr;
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .nav {
    gap: 16px;
  }

  .map-container {
    height: calc(100vh - 200px);
  }
}

/* Utilities */
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mb-32 { margin-bottom: 32px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: #999; }
.text-small { font-size: 13px; }

/* Location Picker */
.modal-lg {
  max-width: 800px;
}

.location-methods {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.location-method-btn {
  font-size: 13px;
  padding: 10px 8px;
}

.address-result-item {
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}

.address-result-item:hover {
  background: #f5f5f5;
}

.address-result-item:last-child {
  border-bottom: none;
}

/* Range Slider */
.slider {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: #e5e5e5;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: #3B82F6;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s;
}

.slider::-webkit-slider-thumb:hover {
  background: #2563EB;
}

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #3B82F6;
  border-radius: 50%;
  cursor: pointer;
  border: none;
  transition: background 0.15s;
}

.slider::-moz-range-thumb:hover {
  background: #2563EB;
}

@media (max-width: 768px) {
  .modal-lg {
    width: 95%;
  }
}
