:root {
  --primary-color: #1a3ea7;
  --light-grey: #f7f7f7;
  --grey: #f0f0f0;
  --dark-grey: #666;
  --text-color: #333;
  --headings-color: #303030;
  --warning: #cf4861;
}

/* Global Styles */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--text-color);
  background-color: #fff;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

/* Typography */
h1,
h2,
h3 {
  font-weight: 600;
  color: var(--headings-color);
  margin: 0;
}

h1 {
  margin-bottom: 10px;
}

h1 span {
  font-weight: 300;
}

/* Layout Containers */
#header-container {
  padding: 10px;
}

#control-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

#icon-container {
  position: relative;
  margin-left: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#map {
  width: 100%;
  height: calc(100vh - 150px);
}

/* Tabs Styling */
#tabs {
  display: flex;
  gap: 4px;
}

.tab {
  background-color: var(--grey);
  border-radius: 20px;
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  color: var(--text-color);
  font-size: 12px;
  border: none;
}

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

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

/* Icon Styling */
#error-icon,
#sync-icon,
#search-icon,
#legend-icon {
  height: 20px;
  width: auto;
  cursor: pointer;
  transition: opacity 0.2s ease-in-out;
}

#error-icon path,
#sync-icon path,
#search-icon path,
#legend-icon path {
  fill: var(--dark-grey);
}

#error-icon.in-error path {
  fill: var(--warning);
}

#error-icon:hover svg path,
#sync-icon:hover svg path,
#search-icon:hover svg path,
#legend-icon:hover svg path {
  fill: var(--primary-color);
}

/* Keyframes and Sync Icon Animation */
@keyframes rotateSync {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulseGreen {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

#sync-icon.syncing svg {
  animation: rotateSync 2s linear infinite;
}

#sync-icon.syncing svg path {
  fill: green;
}

#sync-icon.synced svg {
  animation: pulseGreen 0.5s ease-in-out;
}

#sync-icon.synced svg path {
  fill: green;
}

#search-icon svg,
#error-icon svg,
#sync-icon svg,
#legend-icon svg {
  height: 100%;
  width: auto;
  display: block;
}

/* Error Popup Styling */
#error-popup {
  position: absolute;
  top: 30px; /* Adjust as needed */
  right: 0;
  background-color: #ffffff;
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  width: 250px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 1000;
  font-size: 13px;
  display: flex;
  flex-direction: column;
}

.popup-header {
  font-size: 12px;
  font-weight: bold;
  border-bottom: 1px solid var(--light-grey);
  padding-bottom: 8px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
}

.popup-header span {
  align-self: center;
}

#error-popup.hidden {
  display: none;
}

/* Close error popup button styling */
#close-search-popup,
#close-error-popup {
  display: inline-block;
  align-self: flex-end;
  padding: 2px 2px 3px;
  cursor: pointer;
  color: var(--primary-color);
}

/* Map Specific Adjustments */
#map {
  touch-action: manipulation;
}

#map .gm-style-iw-d p {
  margin: 0.6em 0;
}

#map .gm-style-iw-d p:last-of-type {
  margin: 1em 0 0.6em;
}

#map .gm-style-iw-d p a {
  padding: 4px 8px;
  text-decoration: none;
  background-color: var(--grey);
  border-radius: 10px;
  color: var(--primary-color);
  font-weight: 500;
}
#map .gm-style-iw-d p a:hover {
  background-color: var(--primary-color);
  color: var(--grey);
}

#map .gm-style h3 {
  margin: 0 0 10px 0;
}

#map .gm-style-iw button {
  display: none !important;
}

#map .gm-style-iw {
  z-index: 10000 !important;
}

#map .legend-property-details {
  padding-left: 0;
}

#search-box {
  width: 100%;
  padding: 8px;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
}

#search-popup {
  position: absolute;
  top: 30px; /* Matches error popup */
  right: 0;
  background-color: #ffffff;
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  width: 250px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 1000;
  font-size: 13px;
  display: flex;
  flex-direction: column;
}

#search-popup.hidden {
  display: none;
}

/* Mobile-first styles already applied */

/* Tablet & Desktop Breakpoint */
@media (min-width: 768px) {
  #header-container {
    padding: 20px;
  }
  .tab {
    font-size: 14px; /* Larger font on tablet & desktop */
  }
}

/* Legend Sidebar Styling */
#legend-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  background-color: #ffffff;
  padding: 16px;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
  width: 280px;
  height: 100vh;
  overflow-y: auto;
  z-index: 1000;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease-in-out;
  transform: translateX(0);
}

#legend-sidebar.hidden {
  transform: translateX(100%);
  display: block; /* Don't use display: none to allow for animation */
}

/* Dark overlay when sidebar is open */
#sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.3);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}

#sidebar-overlay.hidden {
  display: none;
}

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

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: bold;
  border-bottom: 1px solid var(--light-grey);
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.sidebar-header span {
  align-self: center;
}

#close-legend-sidebar {
  display: inline-block;
  align-self: flex-end;
  padding: 2px 2px 3px;
  cursor: pointer;
  color: var(--primary-color);
}

.legend-group {
  margin-bottom: 16px;
}

.legend-group-header {
  display: flex;
  align-items: center;
  padding: 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.legend-group-header:hover {
  background-color: var(--light-grey);
}

.legend-toggle-icon {
  margin-left: 4px;
  transition: transform 0.3s ease;
}

.legend-toggle-icon.rotated svg {
  transform: rotate(180deg);
}

.legend-group-content {
  margin-left: 24px;
  padding-left: 8px;
  border-left: 1px solid var(--light-grey);
  margin-top: 4px;
}

.legend-group-content.hidden {
  display: none;
}

.legend-property-item {
  margin-bottom: 12px;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.legend-property-item:hover {
  background-color: var(--light-grey);
}

.legend-property-name {
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--primary-color);
  font-size: 13px;
}

.legend-property-details {
  font-size: 12px;
  padding-left: 4px;
}

.legend-property-details p {
  margin: 3px 0;
}

.legend-property-details p a {
  padding: 4px 8px;
  text-decoration: none;
  background-color: var(--grey);
  border-radius: 10px;
  color: var(--primary-color);
  font-weight: 500;
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
}

.legend-property-details p a:hover {
  background-color: var(--primary-color);
  color: var(--grey);
}

.legend-group-title {
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 14px;
}

.legend-section-title {
  font-weight: 700;
  margin-bottom: 12px;
  font-size: 15px;
  color: var(--primary-color);
  border-bottom: 1px solid var(--light-grey);
  padding-bottom: 6px;
}

.legend-item,
.legend-group-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.legend-item:hover,
.legend-group-header:hover {
  background-color: var(--light-grey);
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  margin-right: 8px;
  flex-shrink: 0;
}

.legend-label {
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-count {
  margin-left: 8px;
  background-color: var(--grey);
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
}

.legend-summary {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--light-grey);
  font-size: 12px;
  color: var(--dark-grey);
  text-align: center;
}

/* Property Window Styling */
.property-name {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--primary-color);
    font-size: 13px;
}

.property-details {
    font-size: 12px;
    padding-left: 4px;
}

.property-details p {
    margin: 3px 0;
}

.property-details p a {
    padding: 4px 8px;
    text-decoration: none;
    background-color: var(--grey);
    border-radius: 10px;
    color: var(--primary-color);
    font-weight: 500;
    display: inline-block;
    margin-top: 4px;
    font-size: 11px;
}

.property-details p a:hover {
    background-color: var(--primary-color);
    color: var(--grey);
}

/* Legend Styling */
.legend-property-name {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--primary-color);
    font-size: 13px;
}

.legend-property-details {
    font-size: 12px;
    padding-left: 4px;
}

.legend-property-details p {
    margin: 3px 0;
}

.legend-property-details p a {
    padding: 4px 8px;
    text-decoration: none;
    background-color: var(--grey);
    border-radius: 10px;
    color: var(--primary-color);
    font-weight: 500;
    display: inline-block;
    margin-top: 4px;
    font-size: 11px;
}

.legend-property-details p a:hover {
    background-color: var(--primary-color);
    color: var(--grey);
}
