/* ================================
   BUTTON STYLES
   ================================
   
   Modular button styling system using color palette variables.
   Import color_palette.css before this file.
   
   ================================ */

/* Import color palette */
@import url("color_palette.css");

/* ================================
   BASE BUTTON STYLES
   ================================ */

.btn,
.action-button,
button[type="submit"],
button[type="button"] {
  /* Layout */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);

  /* Spacing */
  padding: 5px 10px;
  margin: 0;

  /* Typography: regular weight, as the rest of the panel */
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-normal);
  line-height: 1.4;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: 0.02em;

  /* Appearance: square, quiet, one thin rim on the panel surface (the .btn-ask look) */
  border-radius: var(--gd-r);
  border: 1px solid var(--gd-rim);
  cursor: pointer;
  user-select: none;
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast);
  background-color: var(--gd-surface);
  color: var(--gd-text-hi);
}

/* Hover state - lighter variant */
.btn:hover,
.action-button:hover,
button[type="submit"]:hover,
button[type="button"]:hover {
  background-color: var(--gd-elevated);
  border-color: var(--gd-text-mid);
}

/* Active state - darker variant */
.btn:active,
.action-button:active,
button[type="submit"]:active,
button[type="button"]:active {
  background-color: var(--gd-elevated);
  border-color: var(--gd-text-hi);
}

/* Focus state */
.btn:focus,
.action-button:focus,
button[type="submit"]:focus,
button[type="button"]:focus {
  outline: none;
  box-shadow: var(--focus-ring-shadow);
}

/* Disabled state - applies to ALL buttons */
button:disabled,
button.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: auto;
  position: relative;
}

/* Disabled tooltip - rendered via JS onto document.body to escape panel overflow */
/* See button_styles.css disabled tooltip JS in DOMContentLoaded below */

/* Prevent hover effects on disabled buttons */
button:disabled:hover,
button.disabled:hover {
  transform: none !important;
  box-shadow: none !important;
}

/* ================================
   BUTTON IMPORTANCE HIERARCHY
   ================================ */

/* Primary - Standard dark theme */
.btn-primary {
  background-color: var(--color-primary-dark);
  color: var(--text-on-primary);
  border-color: var(--color-accent-orange);
}

.btn-primary:hover {
  background-color: var(--color-primary-lighter);
  border-color: var(--color-accent-orange-light);
  box-shadow: 0 2px 8px rgba(204, 102, 0, 0.3);
}

.btn-primary:active {
  background-color: var(--color-primary-darker);
  border-color: var(--color-accent-orange-dark);
}

/* Secondary - Slightly lighter variant */
.btn-secondary {
  background-color: var(--color-primary-lighter);
  color: var(--text-on-primary);
  border-color: var(--color-accent-orange);
}

.btn-secondary:hover {
  background-color: var(--color-primary-dark);
  border-color: var(--color-accent-orange-light);
}

.btn-secondary:active {
  background-color: var(--color-primary-darker);
  border-color: var(--color-accent-orange-dark);
}

/* Ghost - Transparent with border only */
.btn-ghost {
  background-color: transparent;
  color: var(--color-primary-dark);
  border-color: var(--color-accent-orange);
}

.btn-ghost:hover {
  background-color: var(--color-primary-dark);
  color: var(--text-on-primary);
  border-color: var(--color-accent-orange-light);
}

.btn-ghost:active {
  background-color: var(--color-primary-darker);
  border-color: var(--color-accent-orange-dark);
}

/* ================================
   SEMANTIC BUTTON STATES
   ================================ */

/* Success state - for confirmations */
.btn-success,
.action-button.success {
  background-color: var(--color-green-600);
  color: var(--text-on-primary);
  border-color: var(--color-green-600);
}

.btn-success:hover,
.action-button.success:hover {
  background-color: var(--color-green-700);
  border-color: var(--color-green-700);
}

/* Danger state - for destructive actions */
.btn-danger,
.action-button.danger {
  background-color: var(--color-red-600);
  color: var(--text-on-primary);
  border-color: var(--color-red-600);
}

.btn-danger:hover,
.action-button.danger:hover {
  background-color: var(--color-red-700);
  border-color: var(--color-red-700);
}

/* Warning state - for caution actions */
.btn-warning,
.action-button.warning {
  background-color: var(--color-yellow-600);
  color: var(--color-gray-900);
  border-color: var(--color-yellow-600);
}

.btn-warning:hover,
.action-button.warning:hover {
  background-color: var(--color-yellow-700);
  border-color: var(--color-yellow-700);
}

/* ================================
   BUTTON SIZES (3 SIZES ONLY)
   ================================ */

/* SMALL - Compact buttons */
.btn-small,
.btn-sm {
  padding: 4px 8px;
  font-size: var(--font-size-md);
  border-radius: 4px;
}

/* MEDIUM - Default size (base styles) */
.btn-medium,
.btn-md {
  padding: 6px 12px;
  font-size: var(--font-size-lg);
  border-radius: 5px;
}

/* LARGE - Prominent buttons */
.btn-large,
.btn-lg {
  padding: 8px 16px;
  font-size: var(--font-size-xl);
  border-radius: 6px;
  font-weight: var(--font-weight-semibold);
}

/* Full width */
.btn-block,
.action-button.full-width {
  width: 100%;
  display: flex;
}

/* ================================
   BUTTON GROUPS
   ================================ */

.btn-group,
.action-button-group {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.action-button-group .action-button {
  flex: 1;
  min-width: 120px;
}

.btn-group-vertical,
.button-group {
  flex-direction: column;
  width: 100%;
  gap: 8px;
}

.btn-group-vertical .btn,
.btn-group-vertical .action-button {
  width: 100%;
}

/* Button row layout helpers */
.button-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.button-row.with-config {
  display: flex;
  align-items: stretch;
}

.button-row.with-config .action-button {
  flex: 1;
  margin: 0;
}

/* ================================
   ICON BUTTONS
   ================================ */

.btn-icon,
.icon-btn {
  padding: var(--spacing-sm);
  aspect-ratio: 1;
  min-width: 36px;
  min-height: 36px;
}

.btn-icon.small,
.icon-btn.small {
  padding: var(--spacing-xs);
  min-width: 28px;
  min-height: 28px;
}

.btn-icon.large,
.icon-btn.large {
  padding: var(--spacing-md);
  min-width: 44px;
  min-height: 44px;
}

/* Icon inside button */
.btn i,
.action-button i,
.btn .icon,
.action-button .icon {
  font-size: 1.1em;
  line-height: 1;
}

/* ================================
   SPECIAL BUTTONS
   ================================ */

/* Popup action buttons - clean, minimal style for map popups */
.popup-action-btn {
  padding: 6px 10px;
  font-size: var(--font-size-md);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #f8f9fa;
  color: #374151;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex: 0 0 auto;
}

.popup-action-btn:hover {
  background: #3b82f6;
  color: white;
  border-color: #3b82f6;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}

.popup-action-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

/* Close button */
.close-btn,
.btn-close {
  background: transparent !important;
  border: none !important;
  color: var(--text-muted) !important;
  font-size: var(--font-size-2xl) !important;
  cursor: pointer !important;
  padding: var(--spacing-xs) var(--spacing-sm) !important;
  line-height: 1;
  transition: all var(--transition-fast);
  border-radius: var(--radius-sm);
}

.close-btn:hover,
.btn-close:hover {
  color: var(--text-primary) !important;
  background: var(--bg-secondary) !important;
}

/* Ask button - compact text button for contextual AI questions */
.btn-ask {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: auto !important;
  height: 26px !important;
  min-width: unset !important;
  padding: 0 8px !important;
  margin: 0 4px !important;
  font-size: var(--font-size-xs) !important;
  font-weight: 500 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  color: var(--gd-text-hi) !important;
  background: transparent !important;
  border: 1px solid var(--gd-rim) !important;
  border-radius: var(--gd-r) !important;
  cursor: pointer !important;
  transform: none !important;
  backdrop-filter: none !important;
  flex: 0 0 auto !important;
}

.btn-ask:hover {
  color: var(--gd-text-hi) !important;
  background: var(--gd-elevated) !important;
  border-color: var(--gd-text-mid) !important;
  transform: none !important;
}

/* Configuration Button (gear icon) - Consistent sizing */
.filter-config-btn {
  background: #f8f9fa !important;
  border: 1px solid #d4d7dc !important;
  width: 32px !important;
  height: 38px !important;
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: var(--font-size-2xl) !important;
  border-radius: 6px !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  flex-shrink: 0 !important;
  margin-left: 8px !important;
}

.filter-config-btn:hover {
  background: #e9ecef !important;
  border-color: #b8bcc3 !important;
  color: #2c3e50 !important;
}

/* ================================
   FLOATING BUTTONS (MAP OVERLAYS)
   ================================
   Buttons that float over the map and reposition dynamically
   when drawers open/close. Managed by drawer.js updateMapElementPositions()
   ================================ */

.floating-btn {
  position: fixed;
  right: 20px; /* Default position, overridden by JS when drawer opens */
  z-index: 999; /* Below panels (1000+) but above map */
  transition: right 0.3s ease; /* Smooth slide when drawer opens/closes */
  box-shadow: var(--shadow-lg);
}

/* Floating quick controls (grid search stacked above draw + location search) */
.floating-quick-controls {
  position: fixed;
  right: 20px;
  bottom: 70px;
  z-index: 999;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.quick-controls-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* The map search box doubles as the grid search; while the typed value looks
   like a grid reference the Places suggestion dropdown is suppressed. */
.pac-suppressed .pac-container {
  display: none !important;
}

.floating-tool-btn {
  background: var(--color-white);
  border: 1px solid var(--border-gray-300);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
}

.floating-tool-btn:hover {
  background: var(--bg-gray-50);
  transform: scale(1.05);
}

.floating-tool-btn.active {
  background: var(--color-accent-orange);
  color: var(--text-on-dark);
  border-color: var(--color-accent-orange);
}

/* Measure tool markers */
.measure-point {
  width: 10px;
  height: 10px;
  background: var(--color-accent-orange);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: pointer;
  position: relative;
}

.measure-label {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-primary-dark, #1a1a2e);
  color: #fff;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: var(--font-size-xs);
  font-family: var(--gd-font-mono);
  white-space: nowrap;
  pointer-events: none;
  border: 1px solid var(--color-accent-orange);
}

.measure-cursor-label {
  background: var(--color-primary-dark, #1a1a2e);
  color: var(--color-accent-orange);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: var(--font-size-xs);
  font-family: var(--gd-font-mono);
  white-space: nowrap;
  pointer-events: none;
  border: 1px solid var(--color-accent-orange);
}

.floating-search-box {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--color-white);
  border: 1px solid var(--border-gray-300);
  border-radius: var(--radius-md);
  padding: 4px;
  box-shadow: var(--shadow-lg);
}

/* Explicit width, not min-width, so the box keeps a stable size. */
.floating-search-box input {
  border: none;
  outline: none;
  padding: 6px 10px;
  font-size: var(--font-size-md);
  background: transparent;
  color: var(--text-primary);
  width: 180px;
  box-sizing: content-box;
}

.floating-search-box input::placeholder {
  color: var(--text-placeholder);
  font-style: italic;
}

/* Google Places Autocomplete — scrollable drop-up */
.pac-container {
  max-height: 40vh;
  overflow-y: auto;
}

.floating-search-box button {
  background: var(--color-accent-orange);
  color: var(--text-on-dark);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.floating-search-box button:hover {
  background: var(--color-accent-orange-light);
  transform: scale(1.05);
}

/* Floating button variants */
.floating-btn.action {
  /* Action button styling (orange, for primary actions like "Back") */
  background: var(--color-accent-orange);
  color: var(--text-on-dark);
  border: 1px solid var(--color-accent-orange);
  padding: var(--spacing-sm) var(--spacing-lg);
  border-radius: var(--radius-md);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-height: 40px;
}

.floating-btn.action:hover {
  background: var(--color-primary-lighter);
  border-color: var(--color-accent-orange);
  transform: translateY(-1px);
  box-shadow: var(--shadow-xl);
}

.floating-btn.info {
  /* Info display styling (for status/coordinate displays) */
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: var(--spacing-sm);
  font-size: var(--font-size-md);
  color: var(--text-primary);
}

/* Legacy support - old float-btn class */
.float-btn {
  position: fixed;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-round);
  background-color: var(--interactive-primary);
  color: var(--text-on-primary);
  border: none;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-base);
  z-index: 100;
}

.float-btn:hover {
  background-color: var(--interactive-primary-hover);
  box-shadow: var(--shadow-xl);
  transform: scale(1.05);
}

/* Sidebar buttons - dark blue theme */
.sidebar-btn {
  width: 60px;
  height: 60px;
  background-color: var(--color-primary-dark); /* Dark blue instead of gray */
  color: var(--text-on-dark);
  border: 1px solid var(--color-accent-orange); /* Add orange border */
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin: var(--spacing-sm);
  font-size: var(--font-size-md);
  transition: all var(--transition-base);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
}

.sidebar-btn:hover {
  background-color: var(--color-primary-lighter); /* Lighter blue on hover */
  border-color: var(--color-accent-orange-light);
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(204, 102, 0, 0.3); /* Orange glow */
}

.sidebar-btn .sidebar-icon {
  font-size: 20px;
}

/* ================================
   LEGACY SUPPORT
   ================================ */

/* Map existing action-button classes to new system */
.action-button {
  @extend .btn-primary;
  width: 100%;
  margin-top: var(--spacing-sm) !important;
}

.action-button.common-button {
  @extend .btn-primary;
}

/* ================================
   RESPONSIVE
   ================================ */

@media (max-width: 768px) {
  .btn,
  .action-button {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-md);
  }

  .btn-lg,
  .action-button.large {
    padding: var(--spacing-md) var(--spacing-lg);
    font-size: var(--font-size-lg);
  }
}

@media (max-width: 480px) {
  .btn-group:not(.btn-group-vertical) {
    flex-direction: column;
    width: 100%;
  }

  .btn-group:not(.btn-group-vertical) .btn,
  .btn-group:not(.btn-group-vertical) .action-button {
    width: 100%;
  }
}

/* ================================
   CRITICAL OVERRIDES FOR LEGACY STYLES.CSS
   These override conflicting styles from styles.css
   ================================ */

/* Override styles.css line 700 - .action-button base styles */
.action-button {
  font-size: var(--font-size-md) !important;
  padding: 6px 12px !important;
  font-weight: var(--font-weight-medium) !important;
}

/* Override styles.css line 1914 - #clear-all-button .action-button */
#clear-all-button .action-button {
  font-size: var(--font-size-md) !important;
  padding: 6px 12px !important;
}

/* Override any other action-button instances from styles.css */
button.action-button,
.action-button.common-button,
#network-controls .action-button,
#general-layer-toggles button.action-button,
.filter-panel .action-button {
  font-size: var(--font-size-md) !important;
  padding: 6px 12px !important;
}
