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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: 300px;
  min-width: 300px;
  height: 100vh;
  overflow-y: auto;
  background: #f8f9fa;
  border-right: 1px solid #dee2e6;
  padding: 16px;
  z-index: 10;
}

#sidebar h2 {
  font-size: 18px;
  margin-bottom: 12px;
  color: #333;
}

#sidebar h3 {
  font-size: 14px;
  margin-bottom: 8px;
  color: #555;
}

.section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e9ecef;
}

/* ── Stats ── */
#stats {
  font-size: 14px;
  color: #666;
}

/* ── Readonly banner ── */
.banner {
  background: #fff3cd;
  color: #856404;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ── Buttons ── */
.btn-primary {
  width: 100%;
  padding: 10px 16px;
  background: #B8860B;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { background: #9a7209; }

.btn-secondary {
  width: 100%;
  padding: 6px 12px;
  background: white;
  color: #666;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
}
.btn-secondary:hover { background: #f0f0f0; }

/* ── Search ── */
#search-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  background: white;
  outline: none;
}
#search-input:focus {
  border-color: #B8860B;
  box-shadow: 0 0 0 2px rgba(184,134,11,0.15);
}
#search-results {
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  margin-top: 4px;
}
#search-results:empty {
  display: none;
}
#search-results li {
  padding: 6px 8px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  line-height: 1.4;
}
#search-results li:hover {
  background: #fff8e1;
}
#search-results li .search-name {
  font-weight: 600;
  color: #333;
}
#search-results li .search-addr {
  font-size: 12px;
  color: #888;
}
#search-results li .search-status {
  font-size: 11px;
  font-weight: 600;
  margin-left: 6px;
}

/* ── Filter panel ── */
#filter-panel label {
  display: block;
  font-size: 12px;
  color: #888;
  margin: 8px 0 4px;
}

#filter-panel select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  background: white;
  min-height: 60px;
}

#filter-count {
  font-size: 12px;
  color: #888;
  margin-top: 6px;
}

/* ── Geocode failed list ── */
#geocode-failed-list {
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
}

#geocode-failed-list li {
  padding: 4px 0;
  font-size: 13px;
  color: #dc3545;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
}
#geocode-failed-list li:hover {
  background: #fff5f5;
}

/* ── Map ── */
#map {
  flex: 1;
  height: 100vh;
}

/* ── InfoWindow ── */
.info-window {
  min-width: 250px;
  font-size: 13px;
  line-height: 1.6;
}
.info-window h4 {
  font-size: 15px;
  margin-bottom: 6px;
  color: #333;
}
.info-window .field {
  color: #666;
}
.info-window .field span {
  color: #333;
  font-weight: 500;
}
.info-window .status-control {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #eee;
}
.info-window select {
  width: 100%;
  padding: 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
}
.info-window .error {
  color: #dc3545;
  font-size: 12px;
  margin-top: 4px;
}
.info-window .success {
  color: #28a745;
  font-size: 12px;
  margin-top: 4px;
}

/* ── Modal ── */
.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  padding: 24px;
  border-radius: 8px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-content h3 {
  margin-bottom: 16px;
  font-size: 16px;
}

#import-result {
  font-size: 14px;
  line-height: 1.8;
  margin-bottom: 16px;
}

/* ── Loading ── */
.loading {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(255,255,255,0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e9ecef;
  border-top: 4px solid #B8860B;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

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

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 6px;
  color: white;
  font-size: 14px;
  z-index: 3000;
  animation: fadeIn 0.3s;
}
.toast.error { background: #dc3545; }
.toast.success { background: #28a745; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Visit Modal ── */
.visit-modal-content {
  max-width: 520px;
}
.visit-modal-content label {
  display: block;
  font-size: 12px;
  color: #888;
  margin: 10px 0 4px;
}
.visit-modal-content .required {
  color: #dc3545;
}
.visit-modal-content select,
.visit-modal-content input[type="text"],
.visit-modal-content input[type="date"],
.visit-modal-content textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: white;
}
.visit-modal-content textarea {
  resize: vertical;
}
.visit-group {
  margin-top: 4px;
  transition: opacity 0.2s;
}
.visit-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  margin-top: 10px;
}
.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 6px;
  font-size: 13px !important;
  color: #333 !important;
  white-space: nowrap;
  margin: 0 !important;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: auto;
}
.revisit-date-wrap {
  flex: 1;
}
.revisit-date-wrap label {
  margin-top: 0 !important;
}
.visit-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.visit-actions .btn-secondary {
  margin-top: 0;
}

/* ── Sidebar toggle (mobile only) ── */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 20;
  width: 44px;
  height: 44px;
  background: white;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  line-height: 1;
}

/* ── Mobile responsive ── */
@media (max-width: 768px) {
  body {
    flex-direction: column;
  }

  .sidebar-toggle {
    display: block;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: 85%;
    max-width: 320px;
    height: 100vh;
    transition: left 0.3s ease;
    z-index: 100;
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  }

  #sidebar.open {
    left: 0;
  }

  .sidebar-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 90;
  }

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

  /* Touch-friendly inputs (prevent iOS zoom) */
  #search-input,
  #filter-panel select,
  .visit-modal-content select,
  .visit-modal-content input[type="text"],
  .visit-modal-content input[type="date"],
  .visit-modal-content textarea {
    font-size: 16px;
  }

  /* Larger tap targets */
  .btn-primary, .btn-secondary {
    padding: 12px 16px;
    font-size: 15px;
  }

  /* Toast position for mobile */
  .toast {
    left: 16px;
    right: 16px;
    bottom: 16px;
    text-align: center;
  }

  /* InfoWindow mobile-friendly */
  .info-window {
    min-width: 200px;
    max-width: 280px;
  }

  /* Visit modal fullscreen on mobile */
  .visit-modal-content {
    width: 95%;
    max-height: 90vh;
  }
}

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

/* ── Marker legend ── */
.legend {
  font-size: 12px;
  color: #666;
  margin-top: 4px;
}
.legend span {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.legend .red { background: #dc3545; }
.legend .orange { background: #fd7e14; }
.legend .green { background: #28a745; }
.legend .gray { background: #999; }
