/* Base styles and reset */
* { 
  box-sizing: border-box; 
}

html, body { 
  height: 100%; 
  margin: 0; 
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; 
}

/* Layout components */
.container { 
  display: flex; 
  height: 100vh; 
}

.sidebar { 
  width: 380px; 
  background: #1f2937; 
  color: #f9fafb; 
  display: flex; 
  flex-direction: column; 
  box-shadow: 2px 0 8px rgba(0,0,0,0.1); 
  z-index: 1000; 
}

.main-content { 
  flex: 1; 
  position: relative; 
}

#map { 
  height: 100%; 
}

/* Mobile sidebar toggle button */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 1002;
  background: #1f2937;
  color: #f9fafb;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: all 0.2s ease;
}

.sidebar-toggle:hover {
  background: #374151;
  transform: scale(1.05);
}

.sidebar-toggle:active {
  transform: scale(0.95);
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.show {
  opacity: 1;
}

/* Loading */
.loader { 
  position: fixed; 
  top: 0; 
  left: 0; 
  right: 0; 
  background: #1f2937; 
  color: white; 
  padding: 16px; 
  text-align: center; 
  z-index: 9999; 
}

.loader-bar { 
  height: 4px; 
  background: #374151; 
  border-radius: 2px; 
  overflow: hidden; 
  margin-top: 8px; 
}

.loader-progress { 
  height: 100%; 
  background: linear-gradient(90deg, #3b82f6, #06b6d4); 
  transition: width 0.3s; 
}

/* Header */
.header { 
  padding: 20px 24px; 
  border-bottom: 1px solid #374151; 
}

.header h1 { 
  margin: 0; 
  font-size: 18px; 
  font-weight: 600; 
  color: #f9fafb; 
}

.header p { 
  margin: 4px 0 0; 
  font-size: 13px; 
  color: #9ca3af; 
}

/* Controls Section */
.controls { 
  flex: 1; 
  overflow-y: auto; 
  padding: 20px 24px; 
}

.section { 
  margin-bottom: 32px; 
}

.section-title { 
  font-size: 14px; 
  font-weight: 600; 
  color: #f3f4f6; 
  margin-bottom: 12px; 
  display: flex; 
  align-items: center; 
}

.section-title i { 
  margin-right: 8px; 
}

/* Category Toggles */
.category-toggles { 
  display: grid; 
  grid-template-columns: 1fr 1fr; 
  gap: 8px; 
  margin-bottom: 16px; 
}

.category-toggles .wide { 
  grid-column: 1 / -1; 
}

.toggle-btn { 
  padding: 10px 12px; 
  border: 1px solid #4b5563; 
  background: transparent; 
  color: #d1d5db; 
  border-radius: 8px; 
  cursor: pointer; 
  transition: all 0.2s; 
  font-size: 12px; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  min-height: 44px; /* Touch-friendly minimum */
}

.toggle-btn:hover { 
  background: #374151; 
}

.toggle-btn.active { 
  background: #3b82f6; 
  border-color: #3b82f6; 
  color: white; 
}

.toggle-btn i { 
  margin-right: 6px; 
}

/* Search */
.search-group { 
  margin-bottom: 16px; 
}

.search-input { 
  width: 100%; 
  padding: 10px 12px; 
  border: 1px solid #4b5563; 
  background: #374151; 
  color: #f9fafb; 
  border-radius: 8px; 
  font-size: 14px; 
  min-height: 44px; /* Touch-friendly */
}

.search-input::placeholder { 
  color: #9ca3af; 
}

.search-input:focus { 
  outline: none; 
  border-color: #3b82f6; 
}

/* Advanced Filters */
.filters { 
  display: none; 
}

.filters.show { 
  display: block; 
}

.filter-row { 
  display: grid; 
  grid-template-columns: 1fr auto 1fr; 
  gap: 8px; 
  align-items: center; 
  margin-bottom: 12px; 
}

.filter-label { 
  font-size: 12px; 
  color: #d1d5db; 
  margin-bottom: 4px; 
}

.filter-input { 
  padding: 8px; /* Increased for touch */
  border: 1px solid #4b5563; 
  background: #374151; 
  color: #f9fafb; 
  border-radius: 6px; 
  font-size: 12px; 
  width: 100%; 
  min-height: 40px; /* Touch-friendly */
}

.filter-operator { 
  font-size: 12px; 
  color: #9ca3af; 
  text-align: center; 
}

.expand-btn { 
  background: transparent; 
  border: 1px solid #4b5563; 
  color: #9ca3af; 
  padding: 10px 12px; /* Increased for touch */
  border-radius: 6px; 
  cursor: pointer; 
  font-size: 12px; 
  transition: all 0.2s; 
  margin-top: 8px; 
  min-height: 44px; /* Touch-friendly */
  display: flex;
  align-items: center;
  justify-content: center;
}

.expand-btn:hover { 
  background: #374151; 
  color: #f9fafb; 
}

/* Results */
.results-header { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  margin-bottom: 8px; 
}

.results-count { 
  font-size: 12px; 
  color: #9ca3af; 
}

.results-list { 
  max-height: 200px; 
  overflow-y: auto; 
}

.result-item { 
  padding: 12px; /* Increased for touch */
  border: 1px solid #374151; 
  border-radius: 8px; 
  margin-bottom: 6px; 
  cursor: pointer; 
  transition: all 0.2s; 
  min-height: 44px; /* Touch-friendly */
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.result-item:hover { 
  background: #374151; 
  border-color: #4b5563; 
}

.result-item:active {
  background: #4b5563;
  transform: scale(0.98);
}

.result-name { 
  font-weight: 500; 
  color: #f9fafb; 
  font-size: 13px; 
}

.result-location { 
  font-size: 11px; 
  color: #9ca3af; 
  margin-top: 2px; 
}

/* Analysis Panel */
.analysis-panel { 
  border-top: 1px solid #374151; 
  padding: 20px 24px; 
  background: #111827; 
  transition: padding 0.3s ease; 
}

.analysis-panel.show { 
  display: block; 
}

.analysis-panel.hide { 
  display: none; 
}

.analysis-panel.collapsed { 
  padding: 12px 24px; 
}

.analysis-header { 
  cursor: pointer; 
  user-select: none; 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  margin-bottom: 16px; 
  min-height: 44px; /* Touch-friendly */
  padding: 4px 0;
}

.analysis-header:hover { 
  color: #3b82f6; 
}

.analysis-title-content { 
  display: flex; 
  align-items: center; 
}

.analysis-title-content i { 
  margin-right: 8px; 
}

.collapse-arrow { 
  font-size: 12px; 
  transition: transform 0.3s ease, color 0.2s ease; 
  color: #9ca3af; 
}

.analysis-header:hover .collapse-arrow { 
  color: #3b82f6; 
}

.collapse-arrow.collapsed { 
  transform: rotate(180deg); 
}

.analysis-content { 
  transition: max-height 0.3s ease, opacity 0.3s ease; 
  overflow: hidden; 
  max-height: 400px; 
  opacity: 1; 
}

.analysis-content.collapsed { 
  max-height: 0; 
  opacity: 0; 
  margin: 0; 
}

.radius-controls { 
  margin-bottom: 16px; 
}

.radius-input { 
  width: 80px; 
  min-height: 40px; /* Touch-friendly */
}

.nearby-list { 
  max-height: 180px; 
  overflow-y: auto; 
}

/* Fixed nearby items styling - added missing interactive properties */
.nearby-item { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  padding: 10px 12px; /* Increased for touch */
  border-bottom: 1px solid #374151; 
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 6px;
  margin-bottom: 2px;
  min-height: 44px; /* Touch-friendly */
}

.nearby-item:hover { 
  background: #374151; 
  border-color: #4b5563;
  transform: translateX(4px);
}

.nearby-item:active {
  background: #4b5563;
  transform: translateX(2px) scale(0.98);
}

.nearby-item:last-child { 
  border-bottom: 1px solid #374151; 
}

.nearby-name { 
  color: #f9fafb; 
  font-size: 12px; 
}

.nearby-distance { 
  color: #9ca3af; 
  font-size: 11px; 
}

/* Details Modal */
.details-modal { 
  position: fixed; 
  top: 20px; 
  right: 20px; 
  width: 420px; 
  background: white; 
  border-radius: 12px; 
  box-shadow: 0 20px 25px rgba(0,0,0,0.15); 
  z-index: 1001; 
  max-height: calc(100vh - 40px); 
  overflow: hidden; 
  transform: translateX(100%); 
  transition: transform 0.3s ease; 
}

.details-modal.show { 
  transform: translateX(0); 
}

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

.modal-title { 
  font-size: 16px; 
  font-weight: 600; 
  color: #1f2937; 
}

.close-btn { 
  background: none; 
  border: none; 
  font-size: 18px; 
  color: #6b7280; 
  cursor: pointer; 
  padding: 8px; /* Increased for touch */
  min-width: 44px; /* Touch-friendly */
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.close-btn:hover { 
  color: #1f2937; 
  background: #f3f4f6;
}

.close-btn:active {
  background: #e5e7eb;
  transform: scale(0.95);
}

.modal-content { 
  overflow-y: auto; 
  max-height: calc(100vh - 120px); 
}

.data-section { 
  padding: 20px 24px; 
  border-bottom: 1px solid #f3f4f6; 
}

.data-section:last-child { 
  border-bottom: none; 
}

.section-header { 
  font-size: 14px; 
  font-weight: 600; 
  color: #374151; 
  margin-bottom: 12px; 
  display: flex; 
  align-items: center; 
}

.section-header i { 
  margin-right: 8px; 
  color: #3b82f6; 
}

.data-grid { 
  display: grid; 
  grid-template-columns: 1fr 1fr; 
  gap: 12px; 
}

.data-item { 
}

.data-label { 
  font-size: 11px; 
  color: #6b7280; 
  text-transform: uppercase; 
  letter-spacing: 0.5px; 
  margin-bottom: 2px; 
}

.data-value { 
  font-size: 13px; 
  color: #1f2937; 
  font-weight: 500; 
}

/* Map legend */
.legend { 
  position: absolute; 
  bottom: 20px; 
  left: 20px; 
  background: rgba(255,255,255,0.95); 
  padding: 16px; 
  border-radius: 8px; 
  font-size: 12px; 
  box-shadow: 0 2px 8px rgba(0,0,0,0.1); 
}

.legend-item { 
  display: flex; 
  align-items: center; 
  margin-bottom: 6px; 
}

.legend-item:last-child { 
  margin-bottom: 0; 
}

.legend-dot { 
  width: 12px; 
  height: 12px; 
  border-radius: 50%; 
  margin-right: 8px; 
  border: 2px solid rgba(0,0,0,0.3); 
}

/* Small, muted explanatory note under section header */
.section-note {
  font-size: 12px;
  line-height: 1.3;
  color: #9ca3af;      /* muted gray */
  margin: 6px 0 12px;  /* spacing between header and grid */
  max-width: 840px;    /* keep lines readable */
  word-break: break-word;
}

/* Trends styles for the Google Trends integration */
.trend-grid { 
  display:grid; 
  grid-template-columns: 1fr 1fr; 
  gap: 12px; 
}

.trend-card { 
  display:flex; 
  align-items:center; 
  justify-content:space-between; 
  padding:12px 14px; 
  border:1px solid #e5e7eb; 
  border-radius:10px; 
  background:#fff; 
  box-shadow: 0 1px 2px rgba(0,0,0,0.03); 
  min-height: 44px; /* Touch-friendly */
}

.trend-keyword { 
  font-size:13px; 
  color:#111827; 
  font-weight:500; 
  letter-spacing: .2px; 
}

.trend-value { 
  min-width:46px; 
  text-align:center; 
  padding:6px 8px; 
  border-radius:8px; 
  color:#fff; 
  font-weight:700; 
  line-height:1; 
  text-shadow: 0 1px 2px rgba(0,0,0,0.6); 
}

.trend-value.na { 
  background:#9ca3af; 
  color:#111827; 
  text-shadow:none; 
  font-weight:600; 
}

/* ========================================
   MOBILE RESPONSIVE STYLES
   ======================================== */

/* Large tablets and small desktops */
@media (max-width: 1024px) {
  .sidebar {
    width: 340px;
  }
  
  .details-modal {
    width: 380px;
  }
}

/* Tablets */
@media (max-width: 768px) {
  .container {
    flex-direction: column;
  }
  
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 100%;
    max-width: 400px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1001;
  }
  
  .sidebar.show {
    transform: translateX(0);
  }
  
  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .sidebar-overlay {
    display: block;
  }
  
  .main-content {
    width: 100%;
    height: 100vh;
  }
  
  .details-modal {
    top: 10px;
    right: 10px;
    left: 10px;
    width: auto;
    max-height: calc(100vh - 20px);
    border-radius: 8px;
  }
  
  .legend {
    bottom: 80px;
    left: 10px;
    right: 10px;
    font-size: 10px;
    padding: 12px;
  }
  
  .legend-item {
    margin-bottom: 4px;
  }
  
  .legend-dot {
    width: 10px;
    height: 10px;
    margin-right: 6px;
  }
  
  /* Tablet-specific adjustments */
  .header h1 {
    font-size: 16px;
  }
  
  .header p {
    font-size: 12px;
  }
  
  .controls {
    padding: 16px 20px;
  }
  
  .section {
    margin-bottom: 28px;
  }
  
  .section-title {
    font-size: 13px;
  }
  
  .data-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .trend-grid {
    grid-template-columns: 1fr;
  }
}

/* Mobile phones */
@media (max-width: 480px) {
  .sidebar {
    width: 100%;
    max-width: none;
  }
  
  .sidebar-toggle {
    top: 15px;
    left: 15px;
    padding: 10px;
    font-size: 14px;
  }
  
  .header {
    padding: 16px 20px;
  }
  
  .header h1 {
    font-size: 15px;
  }
  
  .header p {
    font-size: 11px;
  }
  
  .controls {
    padding: 14px 18px;
  }
  
  .section {
    margin-bottom: 24px;
  }
  
  .section-title {
    font-size: 12px;
    margin-bottom: 10px;
  }
  
  .section-title i {
    margin-right: 6px;
  }
  
  /* Single column category toggles on mobile */
  .category-toggles {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  
  .category-toggles .wide {
    grid-column: 1;
  }
  
  .toggle-btn {
    font-size: 11px;
    padding: 12px 10px;
    min-height: 48px; /* Larger for mobile */
  }
  
  .toggle-btn i {
    margin-right: 4px;
  }
  
  .search-input {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 12px 14px;
    min-height: 48px;
  }
  
  .filter-input {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 10px 12px;
    min-height: 48px;
  }
  
  .filter-row {
    grid-template-columns: 1fr;
    gap: 4px;
    margin-bottom: 16px;
  }
  
  .filter-operator {
    display: none; /* Hide "até" text on mobile */
  }
  
  .expand-btn {
    font-size: 11px;
    padding: 12px 14px;
    min-height: 48px;
  }
  
  .results-list {
    max-height: 150px;
  }
  
  .result-item {
    padding: 14px 12px;
    min-height: 48px;
  }
  
  .result-name {
    font-size: 12px;
  }
  
  .result-location {
    font-size: 10px;
  }
  
  .analysis-panel {
    padding: 16px 18px;
  }
  
  .analysis-panel.collapsed {
    padding: 10px 18px;
  }
  
  .analysis-header {
    min-height: 48px;
  }
  
  .nearby-item {
    padding: 12px 10px;
    min-height: 48px;
  }
  
  .nearby-name {
    font-size: 11px;
  }
  
  .nearby-distance {
    font-size: 10px;
  }
  
  .radius-input {
    width: 100px;
    min-height: 48px;
    font-size: 16px; /* Prevent zoom on iOS */
  }
  
  .details-modal {
    top: 5px;
    right: 5px;
    left: 5px;
    border-radius: 6px;
  }
  
  .modal-header {
    padding: 16px 18px;
  }
  
  .modal-title {
    font-size: 14px;
  }
  
  .close-btn {
    font-size: 20px;
    padding: 10px;
    min-width: 48px;
    min-height: 48px;
  }
  
  .data-section {
    padding: 16px 18px;
  }
  
  .section-header {
    font-size: 13px;
    margin-bottom: 10px;
  }
  
  .section-header i {
    margin-right: 6px;
  }
  
  .data-label {
    font-size: 10px;
  }
  
  .data-value {
    font-size: 12px;
  }
  
  .section-note {
    font-size: 11px;
    margin: 4px 0 10px;
  }
  
  .trend-card {
    padding: 10px 12px;
    min-height: 48px;
  }
  
  .trend-keyword {
    font-size: 12px;
  }
  
  .legend {
    bottom: 20px;
    left: 5px;
    right: 5px;
    font-size: 9px;
    padding: 10px;
  }
  
  .legend-item {
    margin-bottom: 3px;
  }
  
  .legend-dot {
    width: 8px;
    height: 8px;
    margin-right: 4px;
  }
}

/* Extra small phones */
@media (max-width: 360px) {
  .sidebar-toggle {
    top: 10px;
    left: 10px;
    padding: 8px;
    font-size: 13px;
  }
  
  .header {
    padding: 14px 16px;
  }
  
  .header h1 {
    font-size: 14px;
  }
  
  .controls {
    padding: 12px 16px;
  }
  
  .section {
    margin-bottom: 20px;
  }
  
  .toggle-btn {
    font-size: 10px;
    padding: 10px 8px;
  }
  
  .search-input,
  .filter-input,
  .radius-input {
    font-size: 16px;
    padding: 10px 12px;
  }
  
  .expand-btn {
    font-size: 10px;
    padding: 10px 12px;
  }
  
  .result-item {
    padding: 12px 10px;
  }
  
  .result-name {
    font-size: 11px;
  }
  
  .result-location {
    font-size: 9px;
  }
  
  .analysis-panel {
    padding: 14px 16px;
  }
  
  .nearby-item {
    padding: 10px 8px;
  }
  
  .nearby-name {
    font-size: 10px;
  }
  
  .nearby-distance {
    font-size: 9px;
  }
  
  .details-modal {
    top: 0;
    right: 0;
    left: 0;
    border-radius: 0;
    max-height: 100vh;
  }
  
  .modal-header {
    padding: 14px 16px;
  }
  
  .modal-title {
    font-size: 13px;
  }
  
  .data-section {
    padding: 14px 16px;
  }
  
  .section-header {
    font-size: 12px;
  }
  
  .trend-keyword {
    font-size: 11px;
  }
}

/* Landscape orientation adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  .sidebar {
    width: 50%;
    max-width: 350px;
  }
  
  .results-list {
    max-height: 120px;
  }
  
  .nearby-list {
    max-height: 120px;
  }
  
  .analysis-panel {
    padding: 12px 18px;
  }
  
  .controls {
    padding: 12px 18px;
  }
  
  .section {
    margin-bottom: 20px;
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .legend-dot {
    border-width: 1px;
  }
  
  .toggle-btn,
  .expand-btn,
  .result-item,
  .nearby-item {
    border-width: 1px;
  }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar-overlay,
  .details-modal,
  .toggle-btn,
  .expand-btn,
  .result-item,
  .nearby-item,
  .close-btn,
  .analysis-content,
  .collapse-arrow {
    transition: none;
  }
  
  .nearby-item:hover {
    transform: none;
  }
  
  .result-item:active,
  .nearby-item:active,
  .close-btn:active {
    transform: none;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .details-modal {
    background: #1f2937;
    color: #f9fafb;
  }
  
  .modal-header {
    background: #111827;
    border-bottom-color: #374151;
  }
  
  .modal-title {
    color: #f9fafb;
  }
  
  .close-btn {
    color: #9ca3af;
  }
  
  .close-btn:hover {
    color: #f9fafb;
    background: #374151;
  }
  
  .close-btn:active {
    background: #4b5563;
  }
  
  .data-section {
    border-bottom-color: #374151;
  }
  
  .section-header {
    color: #f3f4f6;
  }
  
  .data-label {
    color: #9ca3af;
  }
  
  .data-value {
    color: #f9fafb;
  }
  
  .trend-card {
    background: #374151;
    border-color: #4b5563;
  }
  
  .trend-keyword {
    color: #f9fafb;
  }
}
