/**
 * Material Style CSS - Maptoolkit MapMaker
 * 
 * Systematically organized Material Design styles for the MapMaker application.
 * Features comprehensive design tokens, logical component organization, and
 * consolidated application-specific styles.
 * 
 * Structure:
 * 1. Design Tokens (CSS Variables) - Colors, typography, spacing, motion
 * 2. Base Styles - Global styles and resets
 * 3. Layout Components - App bar, sidebar, tabs, navigation
 * 4. Content Components - Expansion panels, form controls, interactive elements
 * 5. Map Components - Map controls, popups, overlays
 * 6. Utilities & Overrides - Helper classes and specific fixes
 */

/* =============================================================================
   1. DESIGN TOKENS
   Core design decisions as reusable CSS variables
   ============================================================================= */

:root {
  /* Color Palette - Neutral Gray/Black Theme */
  
  /* Surface Colors - Pure neutral hierarchy */
  
  
  /* MD3 role tokens (authoritative values) */
  --md-sys-color-primary: #888888;
  --md-sys-color-primary-container: #4E4E4E;
  --md-sys-color-on-primary: #FFFFFF;
  --md-sys-color-on-primary-container: #E0E0E0;
  --md-sys-color-surface: #2D2D2D;
  --md-sys-color-surface-dim: #1A1A1A;
  --md-sys-color-surface-bright: #3A3A3A;
  --md-sys-color-surface-container-lowest: #000000;
  --md-sys-color-surface-container-low: #1E1E1E;
  --md-sys-color-surface-container: #2D2D2D;
  --md-sys-color-surface-container-high: #363636;
  --md-sys-color-surface-container-highest: #444444;
  --md-sys-color-on-surface: #E0E0E0;
  --md-sys-color-on-surface-variant: #A0A0A0;
  --md-sys-color-outline: #888888;
  --md-sys-color-error: #ec5e57;
  --md-sys-color-on-error: #601410;
  /* Accent roles mapped to MD3 */
  --md-sys-color-secondary: #f18383; /* active accent */
  --md-sys-color-tertiary: #c8b9ecff; /* master accent */
  /* MD3 state layer opacities */
  --md-sys-state-hover-opacity: 8%;
  --md-sys-state-focus-opacity: 12%;
  --md-sys-state-pressed-opacity: 12%;
  --md-sys-state-dragged-opacity: 16%;
  
  /* Container surfaces - Neutral gray progression */
  --md-sys-color-surface-container-lower: color-mix(in srgb, var(--md-sys-color-surface-container-lowest) 50%, var(--md-sys-color-surface-container-low));    /* Dark overlays */
  --md-sys-color-surface-container-higher: color-mix(in srgb, var(--md-sys-color-surface-container-high) 50%, var(--md-sys-color-surface-container-highest));   /* Cards, panels */
  --md-sys-color-surface-container-lighter: color-mix(in srgb, var(--md-sys-color-surface-container-highest) 50%, var(--md-sys-color-surface-bright));  /* Active elements */
  --md-sys-color-surface-container-lightest: color-mix(in srgb, var(--md-sys-color-surface-bright) 70%, white); /* Brightest accents */
  
  /* Text colors - Neutral, high contrast */
  
  /* Tinted surfaces - for state-aware components */
  
  --md-sys-state-layer-accent: color-mix(in srgb, var(--md-sys-color-accent) var(--md-sys-state-hover-opacity), transparent);  /* State color tint */
  
  /* Reusable interaction colors - Master state (neutral) */
  --md-sys-state-focus-halo-primary: rgba(136, 136, 136, 0.2);    /* Neutral focus ring shadow */
  --md-sys-color-accent-master: var(--md-sys-color-tertiary);
  --md-sys-color-accent-active: var(--md-sys-color-secondary);
  --md-sys-color-accent: var(--md-sys-color-accent-master);
  
  /* Reusable interaction colors - State accent (dynamic) */
  --md-sys-state-focus-halo-accent: color-mix(in srgb, var(--md-sys-color-accent) 20%, transparent);
  --md-sys-state-hover-layer-accent: color-mix(in srgb, var(--md-sys-color-accent) 15%, transparent);
  
  /* Typography */
  --font-family: 'Mulish', 'Helvetica Neue', Arial, sans-serif;
  
  /* Type Scale */
  --md-sys-typescale-title-small: 400 14px/20px var(--font-family);
  --md-sys-typescale-label-large: 500 14px/20px var(--font-family);
  --md-sys-typescale-label-medium: 500 12px/16px var(--font-family);
  --md-sys-typescale-label-small: 500 11px/16px var(--font-family);
  --md-sys-typescale-body-medium: 400 12px/16px var(--font-family);
  --md-sys-typescale-body-small: 400 11px/16px var(--font-family);
  
  /* Spacing (4px base unit) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  
  /* Border colors — surface hierarchy */
  --md-sys-color-surface-border: rgba(255, 255, 255, 0.08);
  --md-sys-color-surface-container-border: rgba(255, 255, 255, 0.12);
  --md-sys-color-input-border: rgba(255, 255, 255, 0.20);

  /* Borders & Shapes */
  --radius-extra-small: 2px;
  --radius-small: 4px;
  --radius-medium: 8px;
  --radius-large: 12px;
  --radius-full: 9999px;
  --shape-segmented-control-radius: 20px;
  --border-width-1: 1px;
  --border-width-1_5: 1.5px;
  --border-width-2: 2px;
  --border-width-3: 3px;
  
  
  /* Elevation (Material Design shadows) */
  --elevation-1: 0 1px 2px 0 rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.15);
  --elevation-2: 0 1px 2px 0 rgba(0, 0, 0, 0.3), 0 2px 6px 2px rgba(0, 0, 0, 0.15);
  --elevation-3: 0 4px 8px 3px rgba(0, 0, 0, 0.15), 0 1px 3px 0 rgba(0, 0, 0, 0.3);
  --elevation-4: 0 8px 16px 4px rgba(0, 0, 0, 0.15), 0 3px 6px 2px rgba(0, 0, 0, 0.3);
  
  
  
  /* Common Sizes */
  --size-icon-small: 16px;
  --size-icon-medium: 20px;
  --size-icon-large: 24px;

  /* Panel indentation (aligns body content with header text, past icon) */
  --md-comp-panel-indent-outer: 44px;
  --md-comp-panel-indent-nested: 60px;

  --size-control-width: 40px;
  --size-toggle-width: 32px;
  --size-toggle-height: 64px;
  --size-switch-handle: 14px;
  
  /* Motion (MD3) */
  --md-sys-motion-duration-fast: 200ms;
  --md-sys-motion-duration-quick: 150ms;
  --md-sys-motion-duration-medium: 300ms;
  
  /* Tooltip Component Token */
  --md-comp-tooltip-background: var(--md-sys-color-surface-container-higher);
  --md-comp-tooltip-text-color: var(--md-sys-color-on-surface);
  --md-comp-tooltip-border-color: var(--md-sys-color-surface-border);
  --md-comp-tooltip-border-width: var(--border-width-1);
  --md-comp-tooltip-border-radius: var(--radius-small);
  --md-comp-tooltip-padding: var(--space-2) var(--space-3);
  --md-comp-tooltip-font: var(--md-sys-typescale-body-small);
  --md-comp-tooltip-max-width: 220px;
  --md-comp-tooltip-z-index: 1100;
  --md-comp-tooltip-offset: var(--space-2);
  --md-sys-motion-duration-slow: 500ms;
  --md-sys-motion-easing-standard: cubic-bezier(0.2, 0, 0, 1);
  --md-sys-motion-easing-emphasized: cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Z-Index Layers */
  --z-dropdown: 50;
  --z-overlay: 100;
  --z-modal: 200;
  --z-toast: 1000;
  --z-fixed: 999;
  
  /* Common Opacities */
  --opacity-disabled: 0.4;
  --opacity-hidden: 0;
  --opacity-visible: 1;
  
  /* Common Dimensions */
  --size-scrollbar: 10px;
  --size-scrollbar-small: 8px;
  --size-slider-thumb: 18px;
  --size-form-switch-width: 32px;
  --size-form-switch-height: 18px;
  --size-number-input: 25px;
  
  /* Component Tokens (Common Colors) */
  --md-comp-scrollbar-track: var(--md-sys-color-surface-container-high);
  --md-comp-scrollbar-thumb: var(--md-sys-color-surface-container);
  --md-comp-scrollbar-thumb-hover: var(--md-sys-color-surface-container-higher);
  --md-comp-accent-layer-08: 8%;
  --md-comp-accent-layer-15: 15%;
  --md-comp-accent-layer-20: 20%;
  --md-comp-accent-layer-25: 25%;
  --md-comp-accent-layer-30: 30%;
  --md-comp-accent-layer-50: 50%;
  --md-comp-switch-track-hover-bg: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container-low));
  --md-comp-switch-handle-color: oklch(from var(--md-sys-color-accent) calc(l - 0.3) c h);
  --md-comp-disabled-container: rgba(230, 225, 229, 0.12);
  --md-comp-disabled-content: rgba(230, 225, 229, 0.38);
  /* Focus Primitives (MD3) */
  --focus-outline-width: 2px;
  --focus-inset-width: 2px;
  --focus-halo-width: 6px;
  --focus-outline-offset: 2px;
}

body[data-master-state="true"] {
  --md-sys-color-accent: var(--md-sys-color-accent-master);
}

body[data-master-state="false"] {
  --md-sys-color-accent: var(--md-sys-color-accent-active);
}

/* =============================================================================
   2. BASE STYLES
   ============================================================================= */

body {
  display: flex;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background-color: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: var(--font-family);
}

/* Main container - Map viewport */
main {
  z-index: 2;
  flex: 1 1 auto;
  position: relative; /* For absolute positioned popups */
}

/* Aside container - Sidebar panel */
aside {
  width: 520px;
  background: var(--md-sys-color-surface);
  overflow-x: hidden;
  overflow-y: auto;
  height: 100dvh;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

/* Smooth width transitions for resize */
main,
aside {
  transition: width var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

/* Disable transitions during active resizing */
body.resizing main,
body.resizing aside {
  transition: none !important;
}

/* Disable transitions during initial sidebar setup to avoid grow/shrink on load */
body.sidebar-init main,
body.sidebar-init aside {
  transition: none !important;
}

/* -----------------------------------------------------------------------------
   Unified Tooltip Component (MD3)
   Used for all tooltips: title attributes, help popovers, and diff warnings
   -------------------------------------------------------------------------- */

.md-tooltip {
  position: fixed;
  max-width: var(--md-comp-tooltip-max-width);
  width: max-content;
  min-width: 40px;
  z-index: var(--md-comp-tooltip-z-index);
  background-color: var(--md-comp-tooltip-background);
  color: var(--md-comp-tooltip-text-color);
  border: var(--md-comp-tooltip-border-width) solid var(--md-comp-tooltip-border-color);
  border-radius: var(--md-comp-tooltip-border-radius);
  padding: var(--md-comp-tooltip-padding);
  font: var(--md-comp-tooltip-font);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-tooltip.visible {
  opacity: 1;
}

/* Wide tooltip for long content like URLs */
.md-tooltip.md-tooltip-wide {
  max-width: 400px;
}

/* Position will be set dynamically via JavaScript */

/* =============================================================================
   3. LAYOUT COMPONENTS
   Core layout and navigation components
   ============================================================================= */

/* -----------------------------------------------------------------------------
   Sidebar Components
   -------------------------------------------------------------------------- */

/* Sidebar with state-colored border */
#sidebar-panel {
  border: var(--border-width-3) solid var(--md-sys-color-surface-border);
  transform-origin: right center;
  flex-shrink: 0;
}

body[data-master-state="false"] #sidebar-panel {
  border-color: var(--md-sys-color-accent);
}

#sidebar-panel.collapsed {
  border: none;
  overflow: hidden;
}

/* Hide all sidebar content when collapsed (FAB is outside sidebar) */
#sidebar-panel.collapsed > * {
  visibility: hidden;
}

/* Unified scrollbar styling — uses standard CSS properties for native thin scrollbar with arrows.
   Add every new scrollable UI element to this selector list. */
#sidebar-panel,
.md-panel-scroll-content,
.md-tab-panel,
.ace_scrollbar,
.md-map-panel-content,
.md-map-popup-list,
.md-select,
.md-style-manager__dialog,
.md-style-manager__dialog-section-list,
.mtk-help-overlay__body {
  scrollbar-color: var(--md-comp-scrollbar-thumb) var(--md-comp-scrollbar-track);
  scrollbar-width: thin;
}

/* Sidebar Resizer - sits in flexbox between map and sidebar */
.md-sidebar-resizer {
  position: relative;
  cursor: col-resize;
  z-index: 10;
  flex-shrink: 0;
  transition:
    background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
    transform var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

/* Hover effect - wider semi-transparent overlay behind the resizer */
.md-sidebar-resizer::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -8px;
  right: -8px;
  background-color: transparent;
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
  z-index: -1;
}

.md-sidebar-resizer:hover::before {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 16%, transparent);
}

.md-sidebar-resizer:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 16%, var(--md-sys-color-surface));
}

/* Active resizing state */
body.resizing {
  cursor: col-resize !important;
  user-select: none !important;
}

/* Sidebar Toggle Button - Mini FAB */
.md-sidebar-toggle {
  position: fixed;
  top: 30px;
  /* Initial position: align with sidebar width (520px), capped at 40% of viewport */
  right: min(40%, 520px);
  width: 30px;
  height: 30px;
  padding: 0;
  /* Center on sidebar border: half the FAB extends outside */
  transform: translateX(50%);
  /* MD3 Mini FAB styling - elevated surface */
  background-color: var(--md-sys-color-surface-container);
  /* State-dependent accent-colored border */
  border: 2px solid var(--md-sys-color-surface-border);
  border-radius: 50%;
  cursor: pointer;
  z-index: var(--z-fixed);
  /* MD3 elevation level 3 for FAB */
  box-shadow: var(--md-sys-elevation-3);
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard), 
              box-shadow var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              border-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              right 0.3s cubic-bezier(0.2, 0, 0, 1);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Accent border when not in master state */
body[data-master-state="false"] .md-sidebar-toggle {
  border-color: var(--md-sys-color-accent);
}

.md-sidebar-toggle:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container));
  box-shadow: var(--md-sys-elevation-4);
}

.md-sidebar-toggle:focus-visible {
  outline: var(--focus-outline-width) solid var(--md-sys-color-primary);
  outline-offset: 2px;
  box-shadow: var(--md-sys-elevation-3), 0 0 0 var(--focus-halo-width) var(--md-sys-state-focus-halo-primary);
}

/* Material Symbols in toggle button */
.md-sidebar-toggle .material-symbols-outlined {
  font-size: var(--size-icon-large);
  color: var(--md-sys-color-on-surface-variant);
  transition: color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
  line-height: 1;
}

.md-sidebar-toggle:hover .material-symbols-outlined {
  color: var(--md-sys-color-on-surface);
}

/* Toggle icon states - reverse chevron direction */
.md-sidebar-toggle .chevron-expand {
  display: block;
}

.md-sidebar-toggle .chevron-collapse {
  display: none;
}

.md-sidebar-toggle.collapsed .chevron-expand {
  display: none;
}

.md-sidebar-toggle.collapsed .chevron-collapse {
  display: block;
}

/* -----------------------------------------------------------------------------
   App Bar (Sidebar Header)
   -------------------------------------------------------------------------- */

.md-app-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background-color: var(--md-sys-color-surface-container-low);
  border-bottom: var(--border-width-1) solid var(--md-sys-color-surface-border);
}

.md-app-bar__logo {
  display: flex;
  align-items: center;
}

.md-app-bar__logo-img {
  height: 23px;
  width: auto;
  display: block;
  margin-top: 1px;
}

.md-app-bar__title {
  font: var(--md-sys-typescale-title-small);
  font-weight: 300;  /* Thin weight for "Maker" */
  color: var(--md-sys-color-on-surface);
  margin: 0 0 0 4px;
}

.md-app-bar__title strong {
  font-weight: 600;  /* Bold weight for "Map" */
}

.md-app-bar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
  padding-right: var(--space-2);
}

.md-app-bar__actions .md-label-with-help {
  position: relative;
}

.md-app-bar__actions .md-help-popover {
  left: auto;
  right: 0;
}

.md-app-bar__actions #back-button {
  gap: var(--space-1);
}

.md-app-bar__actions #back-button .material-symbols-outlined {
  font-size: 18px;
}

/* Save Status Indicator */
.md-app-bar__save-status {
  margin-left: auto;
  margin-right: var(--space-2);
  font: var(--md-sys-typescale-body-medium);
  color: var(--md-sys-color-on-surface-variant);
  opacity: 0.7;
  transition: opacity 0.2s ease, color 0.2s ease;
}

.md-app-bar__save-status.saving {
  opacity: 1;
}

.md-app-bar__save-status.saved {
  opacity: 1;
}

.md-app-bar__save-status.error {
  opacity: 1;
  color: var(--md-sys-color-error, #b3261e);
}

/* -----------------------------------------------------------------------------
   Switch (Toggle) - Simple version for app bar
   -------------------------------------------------------------------------- */

.md-switch {
  position: relative;
  display: inline-block;
  width: 28px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.md-switch input[type="checkbox"] {
  position: absolute;
  opacity: var(--opacity-hidden);
  width: 0;
  height: 0;
}

.md-switch__track {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--md-sys-color-surface-container-highest);
  border: var(--border-width-1_5) solid var(--md-sys-color-outline);
  border-radius: var(--radius-full);
  transition: background-color var(--md-sys-motion-duration-fast), border-color var(--md-sys-motion-duration-fast);
}

.md-switch__handle {
  position: absolute;
  top: 50%;
  left: 2px;
  transform: translateY(-50%);
  width: var(--size-switch-handle);
  height: var(--size-switch-handle);
  background-color: var(--md-sys-color-outline);
  border-radius: var(--radius-full);
  transition: left var(--md-sys-motion-duration-fast), background-color var(--md-sys-motion-duration-fast);
}

.md-switch:hover input:not(:checked) + .md-switch__track {
  background-color: var(--md-comp-switch-track-hover-bg);
}

.md-switch input:checked + .md-switch__track {
  background-color: var(--md-sys-color-accent);
  border-color: var(--md-sys-color-accent);
}

.md-switch input:checked ~ .md-switch__handle {
  left: 12px;
  background-color: var(--md-comp-switch-handle-color);
}

.md-switch input:focus-visible + .md-switch__track {
  box-shadow: 0 0 0 2px var(--md-sys-color-accent), 0 0 0 6px var(--md-sys-state-focus-halo-accent);
}

.md-switch input:focus-visible ~ .md-switch__handle {
  box-shadow: 0 0 0 2px var(--md-sys-color-accent);
}

.md-switch input:focus + .md-switch__track {
  box-shadow: 0 0 0 2px var(--md-sys-color-accent), 0 0 0 6px var(--md-sys-state-focus-halo-accent);
}

.md-switch input:focus ~ .md-switch__handle {
  box-shadow: 0 0 0 2px var(--md-sys-color-accent);
}

.md-switch:focus-within .md-switch__track {
  box-shadow: 0 0 0 2px var(--md-sys-color-accent), 0 0 0 6px var(--md-sys-state-focus-halo-accent);
}

.md-switch:focus-within .md-switch__handle {
  box-shadow: 0 0 0 2px var(--md-sys-color-accent);
}

/* Switch Label (for app bar) */
.md-switch-label {
  font: var(--md-sys-typescale-label-small);
  color: var(--md-sys-color-on-surface);
  margin: 0;
  user-select: none;
  white-space: nowrap;
}

/* -----------------------------------------------------------------------------
   State Dropdown (in App Bar)
   -------------------------------------------------------------------------- */

.md-state-dropdown {
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface);
  background-color: var(--md-sys-color-surface-container-high);
  border: var(--border-width-1) solid var(--md-sys-color-outline);
  border-radius: var(--radius-small);
  padding: 4px 8px;
  cursor: pointer;
  outline: none;
  min-width: 120px;
}

.md-state-dropdown:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container-high));
  border-color: var(--md-sys-color-accent);
}

.md-state-dropdown:focus-visible {
  border-color: var(--md-sys-color-accent);
  box-shadow: 0 0 0 var(--focus-halo-width) var(--md-sys-state-focus-halo-accent);
}

.md-state-dropdown option {
  background-color: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  padding: 8px;
}

/* State Editor inline input */
.md-state-input {
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface);
  background-color: var(--md-sys-color-surface-container-high);
  border: var(--border-width-1) solid var(--md-sys-color-outline);
  border-radius: var(--radius-small);
  padding: 4px 8px;
  outline: none;
  box-sizing: border-box;
}

/* State Editor Action Buttons (Edit & Delete) */
.md-icon-button {
  background-color: var(--md-sys-color-surface-container-low);
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              opacity var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-icon-button:hover:not(:disabled) {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container-low)) !important;
  color: var(--md-sys-color-on-surface) !important;
}

.md-icon-button:active:not(:disabled) {
  background-color: var(--md-sys-color-surface-container-lighter) !important;
}

.md-icon-button:disabled {
  opacity: var(--opacity-disabled);
  cursor: not-allowed;
}

.md-state-edit-button,
.md-state-delete-button {
  margin-left: 4px;
  padding: 4px 8px;
  background: transparent;
  border: none;
  border-radius: var(--radius-small);
  color: var(--md-sys-color-outline);
  cursor: pointer;
  font-size: 14px;
  display: none;
}

/* Mode Tabs (Segmented Button Component) */
.md-mode-tabs {
  position: relative;
  padding: var(--space-3) 0;
  background-color: var(--md-sys-color-surface-container-low);
  border-bottom: var(--border-width-1) solid var(--md-sys-color-surface-border);
  height: 60px;
}

.md-mode-tab {
  /* Fixed pixel width - does not change with sidebar width */
  position: absolute;
  top: 50%;
  margin-top: -20px; /* Half of button height to center vertically */
  width: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-2);
  border-radius: var(--shape-segmented-control-radius);
  border: var(--border-width-1) solid var(--md-sys-color-outline);
  background-color: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-label-large);
  font-size: 13px;
  line-height: 18px;
  cursor: pointer;
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              border-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Position tabs at 25%, 50%, 75%. The 1st/3rd tabs are pulled outward
   (more negative / less negative margin than the centered -55px) so the gap
   to the center tab — which shrinks as the sidebar narrows — stays positive
   down to a smaller width before .md-mode-tab-icon-based tabs are needed.
   Keep MODE_TABS_COMPACT_THRESHOLD_PX (sidebar.js) in sync if these change. */
.md-mode-tab:nth-child(1) {
  left: 25%;
  margin-left: -70px;
}

.md-mode-tab:nth-child(2) {
  left: 50%;
  margin-left: -55px; /* Half of 110px width to center at 50% */
}

.md-mode-tab:nth-child(3) {
  left: 75%;
  margin-left: -40px;
}

.md-mode-tab:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container));
}

.md-mode-tab:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 var(--focus-inset-width) var(--md-sys-color-accent);
  background-color: var(--md-sys-state-layer-accent);
  border-color: var(--md-sys-color-accent);
}

.md-mode-tab:active {
  transform: scale(0.98);
}

.md-mode-tab.active {
  /* Use state accent color for dynamic highlighting */
  background-color: color-mix(in srgb, var(--md-sys-color-accent) var(--md-comp-accent-layer-15), var(--md-sys-color-surface-container));
  border-color: var(--md-sys-color-accent);
  color: var(--md-sys-color-accent);
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard), border-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

/* Hover effect on active tab - brighten like toggle */
.md-mode-tab.active:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 19%, var(--md-sys-color-surface-container));
}

/* Two classes needed: .material-symbols-outlined (24px, loaded after this
   stylesheet via vendor/fonts/fonts.css) would otherwise win the font-size
   tie at equal specificity through source order. */
.md-mode-tab .md-mode-tab-icon {
  font-size: 10px;
  line-height: 1;
  flex-shrink: 0;
  display: none; /* Only show on active tab */
}

.md-mode-tab.active .md-mode-tab-icon {
  display: inline-block;
}

.md-mode-tab:not(.active) .md-mode-tab-icon {
  display: none;
}

/* Compact mode - icon-only tabs when sidebar is narrow */
.sidebar-compact .md-mode-tab {
  width: 40px;
  padding: var(--space-2);
}

.sidebar-compact .md-mode-tab:nth-child(1) {
  margin-left: -20px;
}

.sidebar-compact .md-mode-tab:nth-child(2) {
  margin-left: -20px;
}

.sidebar-compact .md-mode-tab:nth-child(3) {
  margin-left: -20px;
}

.sidebar-compact .md-mode-tab-label {
  display: none;
}

.sidebar-compact .md-mode-tab-icon {
  display: inline-block;
  font-size: 18px;
}

.sidebar-compact .md-mode-tab.active .md-mode-tab-icon {
  display: inline-block;
}

.sidebar-compact .md-mode-tab:not(.active) .md-mode-tab-icon {
  display: inline-block;
}

/* Tab Pane Behavior */
.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* -----------------------------------------------------------------------------
   Tab System
   -------------------------------------------------------------------------- */

/* Tab content container - holds all tab panels */
.md-tab-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background-color: var(--md-sys-color-surface-container-low);
}

/* Individual tab panel - hidden by default */
.md-tab-panel {
  display: none;
  opacity: var(--opacity-hidden);
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  transition: opacity var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-emphasized);
}

/* Active panel - visible with smooth fade-in */
.md-tab-panel.active {
  display: block;
  opacity: var(--opacity-visible);
}

/* Easy mode panel - has padding for form content.
   Top padding is doubled vs. the other sides so the gap below the mode-tabs
   divider matches the gap reused below Map Settings (see .md-layer-groups-toggle). */
.md-tab-panel.md-tab-panel--padded {
  padding: var(--space-4);
  padding-top: calc(var(--space-4) * 2);
}

/* Flush panels (Expert + Photo-to-Map) use flex column to anchor footer */
.md-tab-panel.md-tab-panel--flush {
  padding: 0;
}

.md-tab-panel.md-tab-panel--flush.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.md-panel-scroll-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4);
}

/* One-sentence explainer at the top of each mode (Easy/Photo-to-Map/Expert).
   Easy Mode and .md-panel-scroll-content already have their own padding;
   flush panels (Expert) need it added explicitly — see #expert-mode below. */
.md-mode-intro {
  font: var(--md-sys-typescale-body-medium);
  color: var(--md-sys-color-on-surface-variant);
  text-align: center;
  margin: 0 7px var(--space-4);
  flex-shrink: 0;
}

.md-mode-intro a {
  color: var(--md-sys-color-accent);
}

.md-mode-intro a:hover {
  text-decoration: underline;
}

#expert-mode .md-mode-intro {
  margin: 0 7px;
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-width-1) solid var(--md-sys-color-surface-border);
}

.md-tab-panel.md-tab-panel--flush #expert-editor {
  flex: 1;
  min-height: 0;
}

.md-tab-panel.md-tab-panel--flush .md-actions-row {
  margin: 0;
  padding: 16px;
  border-top: 1px solid var(--md-sys-color-surface-border);
  background-color: var(--md-sys-color-surface-container-low);
  flex-shrink: 0;
}

/* Expert editor sub-tabs: switch between the full generated style and the
   state's expertOverlay. Left-aligned flat pills — borderless, with a subtle
   accent fill on the active one — deliberately lighter than the filled,
   outlined Mode pills so the hierarchy reads (Mode > View). */
.md-subtabs {
  display: flex;
  justify-content: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background-color: var(--md-sys-color-surface-container-low);
  border-bottom: var(--border-width-1) solid var(--md-sys-color-surface-border);
  flex-shrink: 0;
}

.md-subtab {
  padding: var(--space-1) var(--space-4);
  border: none;
  border-radius: var(--shape-segmented-control-radius);
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-medium);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-subtab:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 6%, transparent);
  color: var(--md-sys-color-on-surface);
}

.md-subtab:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 var(--focus-inset-width) var(--md-sys-color-accent);
}

.md-subtab.active {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) var(--md-comp-accent-layer-15), transparent);
  color: var(--md-sys-color-accent);
}

/* Static Style mode has no overlay concept — hide the view switcher. */
#sidebar-panel.static-style-mode #expert-subtabs {
  display: none;
}

/* org deployment: Full Style / Diff-to-parent-style sub-tabs aren't offered.
   Hiding the whole bar also removes its border-bottom, leaving just the one
   divider below .md-mode-intro. */
body.is-org #expert-subtabs {
  display: none;
}


/* =============================================================================
   4. CONTENT COMPONENTS
   Interactive content containers and form controls
   ============================================================================= */

/* -----------------------------------------------------------------------------
   Expansion Panels (Easy Mode)
   -------------------------------------------------------------------------- */

.md-expansion-panel {
  --md-comp-panel-bg: var(--md-sys-color-surface-container);
  background-color: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-surface-border);
  border-radius: var(--radius-medium);
  margin-bottom: var(--space-2);
  position: relative;
  z-index: 0;
  scroll-margin-top: var(--space-2);
  
  transition: margin var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-expansion-panel.expanded {
  margin-bottom: var(--space-4);
}

/* Panel Header */
.md-expansion-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  user-select: none;
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
  position: relative;
  scroll-margin-top: var(--space-2);
}

/* Hover effect - state color tint */
.md-expansion-header:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container));
}

.md-expansion-header:focus-visible {
  outline: none;
  box-shadow: none;
}

.md-expansion-panel-nested .md-expansion-header:focus-visible {
  outline: none;
  box-shadow: none;
}

/* Focus ring on panel to match md-layer-groups-toggle (direct child header only) */
.md-expansion-panel:has(> .md-expansion-header:focus-visible),
.md-expansion-panel-nested:has(> .md-expansion-header:focus-visible) {
  z-index: 3;
  box-shadow:
    0 0 0 calc(var(--focus-outline-width) + var(--focus-halo-width)) var(--md-sys-state-focus-halo-accent),
    0 0 0 var(--focus-outline-width) var(--md-sys-color-accent);
}

/* Allow focus ring to escape nested panel clipping when focused */
.md-expansion-panel-nested:has(> .md-expansion-header:focus-visible) {
  overflow: visible;
}

/* Header Icon (left side) */
.md-expansion-icon {
  width: var(--size-icon-medium);
  height: var(--size-icon-medium);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--md-sys-color-on-surface-variant);
  margin-right: 3px;
}

.md-expansion-icon .material-symbols-outlined {
  font-size: 24px;
  line-height: 1;
  color: currentColor;
  width: var(--size-icon-medium);
  height: var(--size-icon-medium);
  display: block; 
}

/* Color box icon for layer groups */
.md-expansion-icon-color {
  width: var(--size-icon-medium);
  height: var(--size-icon-medium);
  border-radius: 4px;
  border: var(--border-width-1) solid var(--md-sys-color-surface-border);
}

/* Header Text Content */
.md-expansion-title-wrapper {
  min-width: 0;
}

.md-expansion-title {
  font: var(--md-sys-typescale-title-small);
  color: var(--md-sys-color-on-surface);
  margin: 0;
  padding: 0;
}

.md-expansion-subtitle {
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface-variant);
  margin: 2px 0 0 0;
  padding: 0;
}

/* State-specific subtitle styling */
.md-expansion-subtitle.state-active {
  color: var(--md-sys-color-accent);
  font-style: italic;
}

/* Color Box Icon (shows layer group color) */
.md-expansion-color-box {
  width: var(--size-icon-medium);
  height: var(--size-icon-medium);
  flex-shrink: 0;
  border-radius: var(--radius-extra-small);
  border: var(--border-width-1) solid var(--md-sys-color-surface-border);
  transition: transform var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

/* Visibility Toggle (eye icon - appears on hover) */
.md-expansion-visibility {
  width: var(--size-icon-large);
  height: var(--size-icon-large);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: var(--opacity-hidden);
  transition: opacity var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
}

.md-expansion-header:hover .md-expansion-visibility {
  opacity: var(--opacity-visible);
}

/* Keep eye visible when layer is hidden (OFF state) */
.md-expansion-visibility.layer-hidden {
  opacity: 1 !important; /* Override hover state - always visible when hidden */
  color: var(--md-sys-color-outline);
}

.md-expansion-visibility .material-symbols-outlined {
  font-size: var(--size-icon-large);
  line-height: 1;
  color: currentColor;
}

/* Show/hide eye icons based on state */
.md-expansion-visibility .icon-eye {
  display: block;
}

.md-expansion-visibility .icon-eye-off {
  display: none;
}

.md-expansion-visibility.layer-hidden .icon-eye {
  display: none;
}

.md-expansion-visibility.layer-hidden .icon-eye-off {
  display: block;
}

.md-expansion-visibility:focus-visible {
  outline: var(--focus-outline-width) solid var(--md-sys-color-accent);
  outline-offset: var(--focus-outline-offset);
  box-shadow: 0 0 0 var(--focus-halo-width) var(--md-sys-state-focus-halo-accent);
  border-radius: var(--radius-full);
  opacity: var(--opacity-visible);
}

/* Diff Warning Icon (expert mode conflicts) */
.md-diff-warning {
  width: var(--size-icon-large);
  height: var(--size-icon-large);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-left: auto; /* Push to right side, creating space */
  position: relative;
  border-radius: var(--radius-full);
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-diff-warning:focus-visible {
  outline: var(--focus-outline-width) solid var(--md-sys-color-primary);
  outline-offset: var(--focus-outline-offset);
  box-shadow: 0 0 0 var(--focus-halo-width) var(--md-sys-state-focus-halo-primary);
  border-radius: var(--radius-full);
}

.md-diff-warning .material-symbols-outlined {
  font-size: var(--size-icon-large);
  line-height: 1;
  color: var(--md-sys-color-error);
  transition: color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

/* Accepted state - grey color */
.md-diff-warning.accepted .material-symbols-outlined {
  color: var(--md-sys-color-outline);
}

.md-diff-warning:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-error) 15%, transparent);
  transform: scale(1.1);
}

/* Nested Layer Items (for Contained Layers) */
.md-nested-layer-item {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-2) 0;
  color: var(--md-sys-color-on-surface);
}

/* Nested Layer Visibility Icon (always visible, simpler than header) */
.md-nested-layer-visibility {
  width: var(--size-icon-medium);
  height: var(--size-icon-medium);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  transition: color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-nested-layer-visibility:hover {
  color: var(--md-sys-color-on-surface);
}

.md-nested-layer-visibility .material-symbols-outlined {
  font-size: var(--size-icon-large);
  line-height: 1;
  color: currentColor;
}

/* Show/hide eye icons based on state */
.md-nested-layer-visibility .icon-eye {
  display: block;
}

.md-nested-layer-visibility .icon-eye-off {
  display: none;
}

.md-nested-layer-visibility.layer-hidden .icon-eye {
  display: none;
}

.md-nested-layer-visibility.layer-hidden .icon-eye-off {
  display: block;
}

/* Grey out when hidden */
.md-nested-layer-visibility.layer-hidden {
  color: var(--md-sys-color-outline);
}

/* Nested Layer Label */
.md-nested-layer-label {
  font: var(--md-sys-typescale-label-medium);
  color: var(--md-sys-color-on-surface);
  user-select: none;
}

/* Chevron (expand/collapse indicator) */
.md-expansion-chevron {
  width: var(--size-icon-large);
  height: var(--size-icon-large);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--md-sys-color-on-surface-variant);
  transition: transform var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-expansion-panel.expanded > .md-expansion-header > .md-expansion-chevron {
  transform: rotate(180deg);
}

.md-expansion-panel-nested.expanded > .md-expansion-header > .md-expansion-chevron {
  transform: rotate(180deg);
}

.md-expansion-chevron .material-symbols-outlined {
  font-size: var(--size-icon-large);
  line-height: 1;
  color: currentColor;
}

/* Panel Content */
.md-expansion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

.md-expansion-panel.expanded > .md-expansion-content {
  max-height: 2000px; /* Large enough for content */
}

.md-expansion-panel-nested.expanded > .md-expansion-content {
  max-height: 2000px; /* Large enough for content */
}

.md-expansion-body {
  padding: 0 var(--space-4) var(--space-4) var(--md-comp-panel-indent-outer);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Nested Expansion Panel (e.g., Global Color Settings) */
.md-expansion-panel-nested {
  --md-comp-panel-bg: var(--md-sys-color-surface-container-high);
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-surface-container-border);
  border-radius: var(--radius-small);
  margin-top: var(--space-2);
  overflow: hidden;
  scroll-margin-top: var(--space-2);
}

/* Hover effect for nested panel - state color tint */
.md-expansion-panel-nested .md-expansion-header:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container-high));
}

.md-expansion-panel-nested .md-expansion-header {
  padding: var(--space-2) var(--space-3);
}

/* Nested panel header with switch - compact layout */
.md-expansion-header--with-switch {
  gap: var(--space-2) !important;
}

.md-expansion-header--with-switch .md-form-switch {
  order: 0; /* Switch comes first */
  flex-shrink: 0; /* Prevent switch from shrinking */
}

.md-expansion-header--with-switch .md-expansion-title {
  flex: 0 0 auto;
  order: 1; /* Title comes after switch */
  margin-left: var(--space-2); /* Add spacing after switch */
}

.md-expansion-header--with-switch .md-reset-btn {
  order: 2; /* Reset button comes after title */
}

.md-expansion-header--with-switch .md-expansion-chevron {
  margin-left: auto;
  order: 3; /* Chevron stays at the end */
}

.md-expansion-panel-nested .md-expansion-title {
  font: var(--md-sys-typescale-label-large);
}

.md-expansion-panel-nested .md-expansion-body {
  padding: 0 var(--space-3) var(--space-3) var(--md-comp-panel-indent-nested);
  gap: var(--space-2);
}

/* -----------------------------------------------------------------------------
   Diff Box (Expert Mode Conflicts)
   -------------------------------------------------------------------------- */

.md-diff-box {
  display: none;
  background-color: var(--md-sys-color-surface-container-low);
  border-top: var(--border-width-1) solid var(--md-sys-color-surface-border);
  overflow: hidden;
  max-height: 0;
  transition: max-height var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

.md-diff-box[style*="display: block"] {
  max-height: 400px;
}

.md-diff-box-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background-color: var(--md-sys-color-surface-container-high);
  border-bottom: var(--border-width-1) solid var(--md-sys-color-surface-border);
}

/* Diff box action buttons */
.md-diff-box-header button {
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-large);
  padding: var(--space-1) var(--space-2);
  cursor: pointer;
  border-radius: var(--radius-small);
  transition: all var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

/* Keep button - green hover */
.md-diff-box-header .md-diff-btn-keep:hover {
  color: #4CAF50;
  background-color: rgba(76, 175, 80, 0.1) !important;
}

/* Edit button - accent hover (opens the layers in the Overlay view) */
.md-diff-box-header .md-diff-btn-edit:hover {
  color: var(--md-sys-color-accent);
  background-color: var(--md-sys-state-layer-accent) !important;
}

/* Close button - neutral hover */
.md-diff-btn-close {
  font-size: var(--size-icon-large);
  padding: 0;
  width: var(--size-icon-large);
  height: var(--size-icon-large);
  display: flex;
  align-items: center;
  justify-content: center;
}

.md-diff-box-header .md-diff-btn-close {
  background-color: var(--md-sys-color-surface-container-high);
}

.md-diff-box-header .md-diff-btn-close:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container-high)) !important;
}

/* Diff editor container */
.md-diff-box-editor {
  min-height: 100px;
  max-height: 300px;
  border-radius: 0 0 var(--radius-small) var(--radius-small);
  overflow: hidden;
}

/* Ensure Ace editor uses monospace font */
.md-diff-box-editor .ace_editor {
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace !important;
  font-size: 13px !important;
  line-height: 1.6 !important;
}

/* -----------------------------------------------------------------------------
   Form Controls (Material Design inputs)
   -------------------------------------------------------------------------- */

/* Form Field Container */
.md-form-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.md-form-field-header {
  display: flex;
  align-items: center;
  min-height: 24px; /* Ensure space for reset button */
}

.md-form-label {
  font: var(--md-sys-typescale-label-medium);
  color: var(--md-sys-color-on-surface);
  margin: 0;
}

.md-form-label--modified,
.md-expansion-title.md-form-label--modified,
.md-expansion-panel-nested .md-expansion-title.md-form-label--modified {
  font-weight: bold;
  font-style: italic;
}

/* -----------------------------------------------------------------------------
   Form Switch (Enhanced version for form fields with reset button support)
   -------------------------------------------------------------------------- */

.md-form-switch {
  position: relative;
  display: inline-block;
  width: var(--size-form-switch-width);
  height: var(--size-form-switch-height);
  cursor: pointer;
  flex-shrink: 0;
}

.md-form-switch input[type="checkbox"] {
  position: absolute;
  opacity: var(--opacity-hidden);
  width: 0;
  height: 0;
}

.md-form-switch__track {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--md-sys-color-surface-container-low);
  border: var(--border-width-1_5) solid var(--md-sys-color-outline);
  border-radius: var(--radius-full);
  transition: background-color var(--md-sys-motion-duration-fast), border-color var(--md-sys-motion-duration-fast);
}

.md-form-switch__handle {
  position: absolute;
  top: 50%;
  left: 2px;
  transform: translateY(-50%);
  width: var(--size-switch-handle);
  height: var(--size-switch-handle);
  background-color: var(--md-sys-color-outline);
  border-radius: var(--radius-full);
  transition: left var(--md-sys-motion-duration-fast), background-color var(--md-sys-motion-duration-fast);
}

.md-form-switch input:checked + .md-form-switch__track {
  background-color: var(--md-sys-color-accent);
  border-color: var(--md-sys-color-accent);
}

.md-form-switch input:checked ~ .md-form-switch__handle {
  left: 16px;
  background-color: var(--md-comp-switch-handle-color);
}

.md-form-switch:hover input:not(:checked) + .md-form-switch__track {
  background-color: var(--md-comp-switch-track-hover-bg);
}

.md-form-switch input:disabled + .md-form-switch__track {
  background-color: var(--md-comp-disabled-container);
  border-color: var(--md-comp-disabled-container);
  cursor: not-allowed;
}

.md-form-switch input:disabled ~ .md-form-switch__handle {
  background-color: var(--md-comp-disabled-content);
}

.md-form-switch input:focus-visible + .md-form-switch__track {
  box-shadow: 0 0 0 var(--focus-outline-width) var(--md-sys-color-accent), 0 0 0 var(--focus-halo-width) var(--md-sys-state-focus-halo-accent);
}

.md-form-switch input:focus-visible ~ .md-form-switch__handle {
  box-shadow: 0 0 0 var(--focus-outline-width) var(--md-sys-color-accent);
}

.md-form-switch:has(input:focus-visible) .md-form-switch__track {
  box-shadow: 0 0 0 var(--focus-outline-width) var(--md-sys-color-accent), 0 0 0 var(--focus-halo-width) var(--md-sys-state-focus-halo-accent);
}

.md-form-switch:has(input:focus-visible) .md-form-switch__handle {
  box-shadow: 0 0 0 var(--focus-outline-width) var(--md-sys-color-accent);
}

/* MapLibre/Mapbox map controls focus visibility */
.maplibregl-ctrl button:focus-visible,
.mapboxgl-ctrl button:focus-visible {
  outline: var(--focus-outline-width) solid var(--md-sys-color-accent) !important;
  outline-offset: var(--focus-outline-offset);
  box-shadow: 0 0 0 var(--focus-halo-width) var(--md-sys-state-focus-halo-accent) !important;
  background-color: var(--md-sys-state-layer-accent) !important;
  border-color: var(--md-sys-color-accent) !important;
}

/* Switch layout variant - switch, then label and reset button */
.md-form-field--switch {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
}

.md-form-field--switch .md-form-label {
  margin: 0;
  order: 1; /* Label comes after switch */
  margin-left: var(--space-2); /* Add spacing after switch */
}

.md-form-field--switch .md-reset-btn {
  order: 2; /* Reset button comes after label */
}

.md-form-field--switch .md-form-switch {
  order: 0; /* Switch comes first */
  flex-shrink: 0; /* Prevent switch from shrinking */
}

.md-label-with-help {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  position: relative;
}

.md-label-with-help .md-form-label {
  margin-left: 0;
  order: 0;
}

.md-form-field--switch .md-label-with-help {
  order: 1;
  margin-left: var(--space-2);
  flex: 0 1 auto;
}

/* Ensure help icon follows label inside the inline-flex wrapper */
.md-label-with-help .md-help-trigger {
  order: 1;
}

.md-help-trigger {
  width: 18px;
  height: 18px;
  min-width: 18px;
  border-radius: var(--radius-full);
  border: var(--border-width-1) transparent var(--md-sys-color-surface-border);
  background-color: var(--md-comp-panel-bg);
  color: var(--md-sys-color-on-surface-variant);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  cursor: pointer;
}

.md-help-trigger:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-comp-panel-bg));
}

.md-help-trigger:focus-visible {
  outline: 2px solid var(--md-sys-color-accent);
  box-shadow: none;
}

.md-help-trigger .material-symbols-outlined {
  font-size: 14px;
  line-height: 1;
}

.md-help-popover {
  position: absolute;
  top: calc(100% + var(--md-comp-tooltip-offset));
  left: 0;
  max-width: var(--md-comp-tooltip-max-width);
  width: max-content;
  min-width: 150px;
  z-index: var(--md-comp-tooltip-z-index);
  background-color: var(--md-comp-tooltip-background);
  color: var(--md-comp-tooltip-text-color);
  border: var(--md-comp-tooltip-border-width) solid var(--md-comp-tooltip-border-color);
  border-radius: var(--md-comp-tooltip-border-radius);
  padding: var(--md-comp-tooltip-padding);
  font: var(--md-comp-tooltip-font);
  display: none;
}

.md-help-trigger:hover + .md-help-popover,
.md-label-with-help.open .md-help-popover {
  display: block;
}

/* Allow popovers to escape content/panel clipping when active */
.md-expansion-content:has(.md-help-trigger:hover),
.md-expansion-content:has(.md-label-with-help.open),
.md-expansion-panel:has(.md-help-trigger:hover),
.md-expansion-panel:has(.md-label-with-help.open),
.md-expansion-panel-nested:has(.md-help-trigger:hover),
.md-expansion-panel-nested:has(.md-label-with-help.open) {
  overflow: visible;
}

/* Raise stacking of the hosting panel while a popover is active so it sits above siblings */
.md-expansion-panel:has(.md-help-trigger:hover),
.md-expansion-panel:has(.md-label-with-help.open),
.md-expansion-panel-nested:has(.md-help-trigger:hover),
.md-expansion-panel-nested:has(.md-label-with-help.open) {
  position: relative;
  z-index: 10;
}

/* -----------------------------------------------------------------------------
   Reset Button
   -------------------------------------------------------------------------- */

.md-reset-btn {
  background-color: var(--md-comp-panel-bg);
  border: var(--border-width-1) solid transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  font-size: 12px; /* Same size as labels */
  padding: 2px 6px;
  border-radius: var(--radius-small);
  transition: all var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
  flex-shrink: 0;
  /* Hidden by default but reserves space using opacity instead of display */
  opacity: var(--opacity-hidden);
  pointer-events: none;
  margin-left: var(--space-2);
  /* Always take up space even when hidden */
  display: inline-block !important;
}

.md-reset-btn .material-symbols-outlined {
  font-size: 13px;
  line-height: 1;
  vertical-align: text-top;
  transform: rotate(45deg);
}

.md-reset-btn:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-comp-panel-bg));
  color: var(--md-sys-color-accent);
  border-color: var(--md-sys-color-accent);
}

/* When JS sets display: inline-block, make it visible */
.md-reset-btn[style*="inline-block"] {
  opacity: var(--opacity-visible);
  pointer-events: auto;
}

.md-reset-btn:active {
  transform: scale(0.95);
}

/* -----------------------------------------------------------------------------
   Slider with Number Input
   -------------------------------------------------------------------------- */

.md-slider-group {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.md-slider {
  flex: 1;
  max-width: 213px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--md-sys-color-surface-container-low);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

/* Slider Thumb - WebKit (Chrome, Safari, Edge) */
.md-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--size-slider-thumb);
  height: var(--size-slider-thumb);
  border-radius: 50%;
  background: var(--md-sys-color-accent);
  cursor: pointer;
  transition: transform var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
  box-shadow: var(--elevation-1);
}

/* Slider Thumb - Firefox */
.md-slider::-moz-range-thumb {
  width: var(--size-slider-thumb);
  height: var(--size-slider-thumb);
  border-radius: 50%;
  background: var(--md-sys-color-accent);
  cursor: pointer;
  transition: transform var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
  box-shadow: var(--elevation-1);
}

.md-slider:hover::-webkit-slider-thumb {
  transform: scale(1.15);
}

.md-slider:hover::-moz-range-thumb {
  transform: scale(1.15);
}

.md-slider:active::-webkit-slider-thumb {
  transform: scale(1.25);
}

.md-slider:active::-moz-range-thumb {
  transform: scale(1.25);
}

.md-slider:focus {
  outline: none;
}

.md-slider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 var(--focus-halo-width) var(--md-sys-state-focus-halo-accent);
}

.md-slider:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 var(--focus-halo-width) var(--md-sys-state-focus-halo-accent);
}

/* -----------------------------------------------------------------------------
   Number Input with Suffix (e.g., "100 %")
   -------------------------------------------------------------------------- */

.md-number-input-wrapper {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-input-border);
  border-radius: var(--radius-small);
  padding: 6px 6px;
  min-width: 25px;
  flex-shrink: 0;
}

.md-number-input {
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface);
  background: transparent;
  border: none;
  outline: none;
  width: var(--size-number-input); /* Fixed width for 3-digit numbers like -100 */
  text-align: right;
}

/* Remove spinner buttons */
.md-number-input::-webkit-inner-spin-button,
.md-number-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.md-number-input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.md-input-suffix {
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface-variant);
  user-select: none;
  flex-shrink: 0;
}

/* State accent color on focus */
.md-number-input-wrapper:has(input:focus-visible) {
  border-color: var(--md-sys-color-accent);
  box-shadow: 0 0 0 var(--focus-halo-width) var(--md-sys-state-focus-halo-accent);
}

/* Hover effect with state accent */
.md-number-input-wrapper:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 4%, #000000);
  border-color: var(--md-sys-color-accent);
}

/* -----------------------------------------------------------------------------
   Select/Dropdown
   -------------------------------------------------------------------------- */

.md-select {
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-input-border);
  border-radius: var(--radius-small);
  padding: 8px 12px;
  cursor: pointer;
  outline: none;
  width: 100%;
  max-width: 275px;
}

.md-select:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 4%, #000000);
  border-color: var(--md-sys-color-accent);
}

.md-select:focus-visible {
  border-color: var(--md-sys-color-accent);
  box-shadow: 0 0 0 var(--focus-halo-width) var(--md-sys-state-focus-halo-accent);
}

.md-select option {
  background: var(--md-sys-color-surface-container-low) !important;
  color: var(--md-sys-color-on-surface) !important;
  padding: 8px;
}

/* -----------------------------------------------------------------------------
   Color Picker Input
   -------------------------------------------------------------------------- */

.md-color-input {
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-input-border);
  border-radius: var(--radius-small);
  padding: 8px 12px;
  cursor: pointer;
  outline: none;
  width: 100%;
  max-width: 275px;
  min-width: 150px;
}

.md-color-input:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 4%, #000000);
  border-color: var(--md-sys-color-accent);
}

.md-color-input:focus-visible {
  border-color: var(--md-sys-color-accent);
  box-shadow: 0 0 0 var(--focus-halo-width) var(--md-sys-state-focus-halo-accent);
}

/* =============================================================================
   5. MAP COMPONENTS
   Map viewport controls and overlays
   ============================================================================= */

/* -----------------------------------------------------------------------------
   Map Controls (Navigation, Terrain, Globe, etc.)
   -------------------------------------------------------------------------- */

/* Base control container - positioned on map */
.md-map-control {
  position: absolute;
  left: 10px;
  width: var(--size-control-width);
  background-color: var(--md-sys-color-surface-container);
  border: var(--border-width-1) solid var(--md-sys-color-surface-border);
  border-radius: var(--radius-medium);
  box-shadow: var(--elevation-2);
  z-index: var(--z-dropdown);
  overflow: hidden;
  transition: box-shadow var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-map-control:hover {
  box-shadow: var(--elevation-3);
}

/* Control display element (zoom level, etc.) */
.md-map-control-display {
  padding: var(--space-2) 0;
  text-align: center;
  font: var(--md-sys-typescale-label-medium);
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  border-bottom: var(--border-width-1) solid var(--md-sys-color-surface-border);
  user-select: none;
  background-color: var(--md-sys-color-surface-container-high);
}

/* Control button - Material Design icon button */
.md-map-control-btn {
  position: relative;
  width: 100%;
  height: 40px;
  background: var(--md-sys-color-surface-container);
  border: none;
  border-top: var(--border-width-1) solid var(--md-sys-color-surface-border);
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--size-icon-large);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
  overflow: hidden;
}

.md-map-control-btn:first-child {
  border-top: none;
}

.md-map-control-btn .material-symbols-outlined {
  font-size: var(--size-icon-large);
  line-height: 1;
  color: currentColor;
  pointer-events: none;
}

/* Hover state */
.md-map-control-btn:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container));
  color: var(--md-sys-color-on-surface);
}

/* Active/pressed state */
.md-map-control-btn:active {
  background-color: var(--md-sys-state-layer-accent);
}

/* Active toggle state (for terrain/globe) */
.md-map-control-btn.active {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 15%, var(--md-sys-color-surface-container));
  color: var(--md-sys-color-accent);
  border-color: var(--md-sys-color-accent);
}

.md-map-control-btn.active:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 19%, var(--md-sys-color-surface-container));
}

.md-map-control-btn:focus-visible {
  outline: none;
  background-color: var(--md-sys-state-layer-accent);
  box-shadow: inset 0 0 0 var(--focus-inset-width) var(--md-sys-color-accent);
}

/* Ripple effect */
.md-map-control-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: currentColor;
  opacity: var(--opacity-hidden);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s, opacity 0.6s;
}

.md-map-control-btn:active::before {
  width: 100px;
  height: 100px;
  opacity: 0.2;
  transition: 0s;
}

/* Specific control positions */
#navigation-control {
  top: 10px;
}

#terrain-toggle {
  top: 335px;
}

#globe-toggle {
  top: 385px;
}

#inspect-toggle {
  top: 185px;
}

#debug-toggle {
  top: 235px;
}

#compare-toggle {
  top: 285px;
}

/* -----------------------------------------------------------------------------
   Search Control (address search, @maplibre/maplibre-gl-geocoder against the
   Maptoolkit Geocoding API) — sits top-left, right of the navigation control's
   zoom display. Overrides the vendored library's default look to match the
   app's design tokens (loaded after material-style.css, so these selectors
   need the extra .md-search-control ancestor to win on specificity).
   -------------------------------------------------------------------------- */

.md-search-control {
  position: absolute;
  top: 10px;
  left: 60px;
  width: 280px;
  z-index: var(--z-dropdown);
}

.md-search-control .maplibregl-ctrl-geocoder {
  min-width: 0;
  width: 100%;
  max-width: none;
  font-family: var(--font-family);
  font-size: 13px;
  line-height: 1.2;
  background-color: var(--md-sys-color-surface-container);
  border: var(--border-width-1) solid var(--md-sys-color-surface-border);
  border-radius: var(--radius-medium);
  box-shadow: var(--elevation-2);
  transition: box-shadow var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-search-control .maplibregl-ctrl-geocoder:hover {
  box-shadow: var(--elevation-3);
}

.md-search-control .maplibregl-ctrl-geocoder--input,
.md-search-control .maplibregl-ctrl-geocoder--input:focus {
  height: 40px;
  padding: 6px 36px;
  color: var(--md-sys-color-on-surface);
  caret-color: var(--md-sys-color-on-surface);
  outline: none;
}

.md-search-control .maplibregl-ctrl-geocoder--input::placeholder {
  color: var(--md-sys-color-on-surface-variant);
}

/* Suppress the native WebKit "clear" button on <input type="search"> — the
   geocoder already renders its own (.maplibregl-ctrl-geocoder--icon-close),
   so without this two overlapping "x" icons show once text is entered. */
.md-search-control .maplibregl-ctrl-geocoder--input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.md-search-control .maplibregl-ctrl-geocoder--icon {
  fill: var(--md-sys-color-on-surface-variant);
}

.md-search-control .maplibregl-ctrl-geocoder--icon-search {
  top: 9px;
  left: 10px;
  width: 20px;
  height: 20px;
}

.md-search-control .maplibregl-ctrl-geocoder--button {
  background: transparent;
}

.md-search-control .maplibregl-ctrl-geocoder .suggestions {
  background-color: var(--md-sys-color-surface-container);
  border: var(--border-width-1) solid var(--md-sys-color-surface-border);
  border-radius: var(--radius-medium);
  box-shadow: var(--elevation-2);
  font-family: var(--font-family);
}

.md-search-control .maplibregl-ctrl-geocoder .suggestions > li > a {
  color: var(--md-sys-color-on-surface);
}

.md-search-control .maplibregl-ctrl-geocoder .suggestions > .active > a,
.md-search-control .maplibregl-ctrl-geocoder .suggestions > li > a:hover {
  background-color: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}

/* -----------------------------------------------------------------------------
   Map Control Panels (Inspect, Debug, Compare)
   -------------------------------------------------------------------------- */

/* Panel container - floating over map */
.md-map-panel {
  position: absolute;
  top: 60px; /* Below the search bar (top 10px + 40px input + 10px gap). Keep in sync with the panel base offset in inspect/debug/map-compare controls. */
  left: 60px; /* Position to the right of the control button */
  width: 280px;
  max-width: calc(100vw - 80px);
  max-height: calc(100vh - 90px);
  background-color: var(--md-sys-color-surface-container);
  border: var(--border-width-1) solid var(--md-sys-color-surface-border);
  border-radius: var(--radius-medium);
  box-shadow: var(--elevation-3);
  overflow: hidden;
  z-index: 10; /* Above compare views */
  transition: box-shadow var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-map-panel:hover {
  box-shadow: var(--elevation-4);
}

/* Panel header - clickable to collapse */
.md-map-panel-header {
  position: relative;
  padding: var(--space-3) 40px var(--space-3) var(--space-4);
  font: var(--md-sys-typescale-title-small);
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  background-color: var(--md-sys-color-surface-container-high);
  border-bottom: var(--border-width-1) solid var(--md-sys-color-surface-border);
  cursor: pointer;
  user-select: none;
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-map-panel-header:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container-high));
}

.md-map-panel-header:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 var(--focus-inset-width) var(--md-sys-color-accent);
}

/* Collapse button in header */
.md-map-panel-collapse-btn {
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              transform var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

.md-map-panel-collapse-btn .material-symbols-outlined {
  font-size: var(--size-icon-large);
  line-height: 1;
  color: currentColor;
  transition: transform var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-map-panel-collapse-btn {
  background-color: var(--md-sys-color-surface-container-high);
}

.md-map-panel-collapse-btn:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container-high));
  color: var(--md-sys-color-on-surface);
}

.md-map-panel-collapse-btn:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 var(--focus-inset-width) var(--md-sys-color-accent);
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container-high));
}

/* Rotate chevron when collapsed - point up when collapsed, down when expanded */
.md-map-panel.collapsed .md-map-panel-collapse-btn .material-symbols-outlined {
  transform: rotate(180deg);
}

.md-map-panel .md-map-panel-collapse-btn .material-symbols-outlined {
  transform: rotate(0deg);
}

/* Panel content - collapsible */
.md-map-panel-content {
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  overflow-x: hidden;
  transition: max-height var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

.md-map-panel.collapsed .md-map-panel-content {
  max-height: 0;
  overflow: hidden;
}


/* Panel items (layer toggles, debug options) */
.md-map-panel-item {
  padding: var(--space-2) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  border-bottom: var(--border-width-1) solid var(--md-sys-color-surface-border);
  transition: background-color var(--md-sys-motion-duration-quick) var(--md-sys-motion-easing-standard);
}

.md-map-panel-item:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container));
}

.md-map-panel-item:last-child {
  border-bottom: none;
}

/* Parent item (e.g., "All Layers") */
.md-map-panel-item-parent {
  background-color: var(--md-sys-color-surface-container);
  font-weight: 600;
}

/* Child items (indented layer items) */
.md-map-panel-item-child {
  padding-left: calc(var(--space-4) + var(--space-6));
}

/* Checkbox in panel */
.md-map-panel-checkbox {
  width: var(--size-slider-thumb);
  height: var(--size-slider-thumb);
  cursor: pointer;
  accent-color: var(--md-sys-color-accent);
  flex-shrink: 0;
}

/* Color box (for vector layer indication) */
.md-map-panel-color-box {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-extra-small);
  border: var(--border-width-1) solid var(--md-sys-color-outline);
  flex-shrink: 0;
}

/* Label in panel */
.md-map-panel-label {
  flex: 1;
  font: var(--md-sys-typescale-body-medium);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  user-select: none;
}

/* Disabled control button state */
.md-map-control-btn.disabled {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: auto; /* Allow pointer events for tooltips */
}

/* -----------------------------------------------------------------------------
   Compare Control Specific Styles
   -------------------------------------------------------------------------- */

/* Separator between sections */
.md-compare-separator {
  height: 1px;
  background-color: var(--md-sys-color-surface-border);
  margin: var(--space-2) var(--space-4);
}

/* Remove button for custom URLs */
.md-compare-remove-btn {
  background: transparent;
  border: none;
  width: 24px;
  height: 24px;
  padding: 0;
  margin-left: var(--space-2);
  border-radius: var(--radius-full);
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-compare-remove-btn .material-symbols-outlined {
  font-size: 16px;
}

.md-compare-remove-btn:hover {
  background-color: var(--md-sys-color-error-container);
  color: var(--md-sys-color-error);
}

/* Add custom URL container */
.md-compare-add-container {
  padding: var(--space-2) var(--space-4);
}

/* Add custom URL button */
.md-compare-add-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: var(--border-width-1) dashed var(--md-sys-color-outline);
  border-radius: var(--radius-small);
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-medium);
  cursor: pointer;
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              border-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-compare-add-btn .material-symbols-outlined {
  font-size: 18px;
}

.md-compare-add-btn {
  background-color: var(--md-sys-color-surface-container);
}

.md-compare-add-btn:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container));
  border-color: var(--md-sys-color-accent);
  color: var(--md-sys-color-accent);
}

/* Inline editor for custom URL */
.md-compare-inline-editor {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.md-compare-inline-input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background-color: var(--md-sys-color-surface-container-lowest);
  border: var(--border-width-1) solid var(--md-sys-color-outline);
  border-radius: var(--radius-small);
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-body-small);
  transition: border-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-compare-inline-input:focus {
  outline: none;
  border-color: var(--md-sys-color-accent);
}

.md-compare-inline-input.md-compare-input-error {
  border-color: var(--md-sys-color-error);
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Inline editor buttons */
.md-compare-inline-buttons {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-2); /* Extra space above buttons */
}

.md-compare-inline-cancel,
.md-compare-inline-confirm {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font: var(--md-sys-typescale-label-medium);
  border: none;
  cursor: pointer;
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-compare-inline-cancel {
  background: transparent;
  color: var(--md-sys-color-primary);
}

.md-compare-inline-cancel:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container));
}

.md-compare-inline-confirm {
  background: var(--md-sys-color-accent);
  color: var(--md-sys-color-surface);
}

.md-compare-inline-confirm:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-accent));
}

.md-compare-inline-confirm:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Split view container for maplibre-gl-compare */
.md-compare-split-container {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* Split view maps - both full size, clipping applied to map containers via JS */
#compare-map-left,
#compare-map-right {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Slider for split view - matches sidebar resizer style */
.md-compare-slider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 4px;
  /* Initial position set via JS based on container width */
  left: 50%;
  transform: translateX(-50%);
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 16%, var(--md-sys-color-surface));
  cursor: col-resize;
  z-index: 10; /* Above maps */
  transition:
    background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

/* Hover effect - wider semi-transparent overlay */
.md-compare-slider::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -8px;
  right: -8px;
  background-color: transparent;
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
  z-index: -1;
}

.md-compare-slider:hover::before {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 16%, transparent);
}

.md-compare-slider:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 16%, var(--md-sys-color-surface));
}

/* Labels for compare views - centered at bottom */
.md-compare-label {
  position: absolute;
  bottom: var(--space-3);
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-1) var(--space-3);
  background-color: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-label-medium);
  border-radius: var(--radius-small);
  box-shadow: var(--elevation-2);
  z-index: 10;
  pointer-events: none;
  white-space: nowrap;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Split view labels at 25% and 75% */
.md-compare-label-left {
  left: 25%;
}

.md-compare-label-right {
  left: 75%;
}

/* Grid view container */
.md-compare-grid-container {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  gap: 2px;
  background-color: var(--md-sys-color-surface-border);
}

/* 3 maps: 2 on top, 1 spanning bottom */
.md-compare-grid-3 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "map0 map1"
    "map2 map2";
}

.md-compare-grid-3 > .md-compare-grid-cell:nth-child(1) { grid-area: map0; }
.md-compare-grid-3 > .md-compare-grid-cell:nth-child(2) { grid-area: map1; }
.md-compare-grid-3 > .md-compare-grid-cell:nth-child(3) { grid-area: map2; }

/* 4 maps: 2x2 grid */
.md-compare-grid-4 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

/* Grid cell */
.md-compare-grid-cell {
  position: relative;
  overflow: hidden;
  background-color: var(--md-sys-color-surface);
  min-height: 0; /* Allow shrinking in grid */
}

/* Grid cell map container - MapLibre requires explicit width/height */
.md-compare-grid-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Current style label highlight */
.md-compare-label-current {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) var(--md-comp-accent-layer-15), var(--md-sys-color-surface-container-high));
  color: var(--md-sys-color-accent);
}

/* -----------------------------------------------------------------------------
   Layer Popup (Feature Information)
   -------------------------------------------------------------------------- */

/* Popup container - appears on map click or hover in X-Ray mode */
.md-map-popup {
  position: absolute;
  min-width: 200px;
  max-width: 320px;
  max-height: 400px;
  padding: 0;
  background-color: var(--md-sys-color-surface-container);
  border: var(--border-width-1) solid var(--md-sys-color-surface-border);
  border-radius: var(--radius-medium);
  box-shadow: var(--elevation-3);
  overflow: hidden;
  z-index: 100;
  transition: box-shadow var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-map-popup:hover {
  box-shadow: var(--elevation-4);
}

/* Close button */
.md-map-popup-close {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  transition: background-color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-map-popup-close .material-symbols-outlined {
  font-size: 18px;
  line-height: 1;
  color: currentColor;
}

.md-map-popup-close {
  background-color: var(--md-sys-color-surface-container);
}

.md-map-popup-close:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container));
  color: var(--md-sys-color-on-surface);
}

.md-map-popup-close:active {
  background-color: var(--md-sys-state-layer-accent);
}

/* Popup list */
.md-map-popup-list {
  padding: 0;
  margin: 0;
  list-style-type: none;
  max-height: 400px;
  overflow-y: auto;
}

/* Popup list items - default clickable layer items */
.md-map-popup-list li {
  padding: var(--space-3) var(--space-4);
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-body-small);
  cursor: pointer;
  border-bottom: var(--border-width-1) solid var(--md-sys-color-surface-border);
  transition: background-color var(--md-sys-motion-duration-quick) var(--md-sys-motion-easing-standard),
              padding-left var(--md-sys-motion-duration-quick) var(--md-sys-motion-easing-standard);
  position: relative;
}

.md-map-popup-list li:last-child {
  border-bottom: none;
}

.md-map-popup-list li:hover {
  background-color: var(--md-sys-color-surface-container-highest);
  padding-left: calc(var(--space-4) + var(--space-1));
}

/* Jump to layer button (special action item) */
.md-map-popup-list li.md-map-popup-action {
  font-style: italic;
  color: var(--md-sys-color-on-surface);
  border-bottom: var(--border-width-1) solid var(--md-sys-color-outline);
}

/* Layer/section header */
.md-map-popup-list li.md-map-popup-header {
  font-weight: 600;
  color: var(--md-sys-color-accent);
  background-color: color-mix(in srgb, var(--md-sys-color-accent) var(--md-comp-accent-layer-08), transparent);
  border-bottom: var(--border-width-1) solid var(--md-sys-color-outline);
  cursor: default;
  padding-left: var(--space-4);
}

.md-map-popup-list li.md-map-popup-header:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) var(--md-comp-accent-layer-08), transparent);
  padding-left: var(--space-4);
}

/* Section separator (for multiple features) */
.md-map-popup-list li.md-map-popup-header.md-map-popup-separator {
  border-top: var(--border-width-2) solid color-mix(in srgb, var(--md-sys-color-accent) var(--md-comp-accent-layer-30), transparent);
}

/* Property item (key-value pair) */
.md-map-popup-list li.md-map-popup-property {
  font: var(--md-sys-typescale-body-small);
  font-family: 'Courier New', monospace;
  font-size: 11px;
  line-height: 0.8;
  padding: var(--space-2) var(--space-4);
  cursor: default;
  padding-left: var(--space-4);
}

.md-map-popup-list li.md-map-popup-property:hover {
  background-color: transparent;
  padding-left: var(--space-4);
}

/* Alternating background for property groups */
.md-map-popup-list li.md-map-popup-property.md-map-popup-alt {
  background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 2%, transparent);
}

/* Property key (label) */
.md-map-popup-property-key {
  color: var(--md-sys-color-on-surface-variant);
}

/* Property value */
.md-map-popup-property-value {
  color: var(--md-sys-color-on-surface);
}

/* Empty state message */
.md-map-popup-list li.md-map-popup-empty {
  font-style: italic;
  color: var(--md-sys-color-on-surface-variant);
  cursor: default;
  padding-left: var(--space-4);
}

.md-map-popup-list li.md-map-popup-empty:hover {
  background-color: transparent;
  padding-left: var(--space-4);
}


/* =============================================================================
   6. UTILITIES & OVERRIDES
   Helper classes and app-specific utilities
   ============================================================================= */

/* Layer Groups toggle — styled like the collapsed Easy Mode panels above it
   (.md-expansion-header supplies the icon/title/chevron layout; this just
   adds the panel "card" look, since it isn't nested inside .md-expansion-panel). */
.md-layer-groups-toggle {
  background-color: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-surface-border);
  border-radius: var(--radius-medium);
  margin-bottom: var(--space-2);
}

/* .md-expansion-header:hover already provides the same tint (shared class) */

.md-layer-groups-toggle:focus-visible {
  outline: var(--focus-outline-width) solid var(--md-sys-color-accent);
  outline-offset: var(--focus-outline-offset);
  box-shadow: 0 0 0 var(--focus-halo-width) var(--md-sys-state-focus-halo-accent);
}

.md-layer-groups-toggle[aria-expanded="true"] {
  margin-bottom: var(--space-4);
}

.md-layer-groups-toggle[aria-expanded="true"] .md-expansion-chevron {
  transform: rotate(180deg);
}

/* Inset the per-layer panels so they read as nested under the toggle above */
#layer-groups-section {
  padding: 0 var(--space-3);
}

#layer-groups-section:not([hidden]) {
  padding-top: var(--space-1);
}

/* -----------------------------------------------------------------------------
   Ace Editor Layer Highlight
   -------------------------------------------------------------------------- */

/* Layer highlight when jumping to a layer from map popup */
.ace-layer-highlight {
  position: absolute;
  background: color-mix(in srgb, var(--md-sys-color-accent) var(--md-comp-accent-layer-20), transparent) !important;
  border: var(--border-width-1) solid color-mix(in srgb, var(--md-sys-color-accent) var(--md-comp-accent-layer-50), transparent);
  z-index: 20;
}

/* =============================================================================
   7. STATIC STYLE MODE
   Expert-only mode for editing raw MapLibre style.json files
   ============================================================================= */

/* Hide style manager panel */
#sidebar-panel.static-style-mode .md-style-manager {
  display: none;
}

/* Hide mode tabs (Easy/Photo-to-Map/Expert) */
#sidebar-panel.static-style-mode .md-mode-tabs {
  display: none;
}

/* Hide Easy Mode and Photo-to-Map panels */
#sidebar-panel.static-style-mode #easy-mode,
#sidebar-panel.static-style-mode #photo-to-map-mode {
  display: none !important;
}

/* Show Expert Mode panel directly (always active, no tab switching) */
/* Must use flex layout like .md-tab-panel--flush.active for Ace editor sizing */
#sidebar-panel.static-style-mode #expert-mode {
  display: flex !important;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Adjust tab content container for static mode - no padding needed */
#sidebar-panel.static-style-mode .md-tab-content {
  padding-top: 0;
}

/* -----------------------------------------------------------------------------
   Photo-to-Map UI
   -------------------------------------------------------------------------- */

.md-upload-zone {
  border-style: dashed;
  border-width: 2px;
  cursor: pointer;
  transition: background-color 0.2s;
  padding: 32px;
  text-align: center;
  margin-bottom: 16px;
  background-color: var(--md-sys-color-surface-container-low);
}

.md-upload-zone:hover, 
.md-upload-zone.dragover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container-low));
  border-color: var(--md-sys-color-surface-border);
}

.md-upload-icon {
  font-size: 48px;
  color: var(--md-sys-color-primary);
  margin-bottom: 8px;
}

.md-upload-title {
  margin: 0 0 4px 0;
  color: var(--md-sys-color-on-surface);
}

.md-upload-subtitle {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.9em;
}

.md-loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px;
}

.md-circular-progress {
  width: 40px;
  height: 40px;
  border: 4px solid var(--md-sys-color-surface-container-highest);
  border-top: 4px solid var(--md-sys-color-primary);
  border-radius: 50%;
  animation: md-spin 1s linear infinite;
}

@keyframes md-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.md-preview-image-container {
  position: relative;
  margin-bottom: 24px;
  border-radius: var(--radius-medium);
  overflow: hidden;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-surface-border);
}

.md-preview-image {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  display: block;
}

.md-preview-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
}

.md-preview-close:hover {
  background-color: rgba(0, 0, 0, 0.8);
}

.md-section {
  margin-bottom: 24px;
}

.md-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.md-section-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.md-color-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Palette row: 5 swatches per row, responsive width */
.md-palette-row {
  display: flex;
  gap: 4px;
  width: 100%;
}

.md-palette-swatch {
  flex: 1;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid rgba(0,0,0,0.1);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  min-width: 0;
  position: relative;
}

.md-palette-swatch:hover {
  transform: scaleY(1.2);
  box-shadow: var(--elevation-1);
  z-index: 1;
}

/* Swatch tooltips: hex on hover, "copied" on click (use MD tooltip tokens) */
.md-palette-swatch .hex-tooltip,
.md-palette-swatch .copied-toast {
  position: absolute;
  bottom: calc(100% + var(--md-comp-tooltip-offset));
  left: 50%;
  transform: translateX(-50%);
  max-width: var(--md-comp-tooltip-max-width);
  width: max-content;
  min-width: 40px;
  z-index: var(--md-comp-tooltip-z-index);
  background-color: var(--md-comp-tooltip-background);
  color: var(--md-comp-tooltip-text-color);
  border: var(--md-comp-tooltip-border-width) solid var(--md-comp-tooltip-border-color);
  border-radius: var(--md-comp-tooltip-border-radius);
  padding: var(--md-comp-tooltip-padding);
  font: var(--md-comp-tooltip-font);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

/* Show hex color on hover */
.md-palette-swatch:hover .hex-tooltip {
  opacity: 1;
}

/* Show "copied" toast when active */
.md-palette-swatch .copied-toast.show {
  opacity: 1;
}

/* While copied toast is visible, hide the hex tooltip to avoid overlap */
.md-palette-swatch .copied-toast.show ~ .hex-tooltip {
  opacity: 0;
}

/* Legacy swatch style (kept for compatibility) */
.md-color-swatch {
  aspect-ratio: 1;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid rgba(0,0,0,0.1);
  transition: transform 0.1s;
}

.md-color-swatch:hover {
  transform: scale(1.1);
  box-shadow: var(--elevation-1);
  z-index: 1;
}

.md-mapping-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.md-mapping-card {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-surface-border);
  border-radius: var(--radius-medium);
  gap: 16px;
  cursor: pointer;
  transition: background-color 0.2s;
  position: relative;
}

.md-mapping-card:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container));
}

.md-mapping-card-randomize,
.md-mapping-card-pick {
  background-color: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-small);
  transition: all var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
}

.md-mapping-card-randomize .material-symbols-outlined,
.md-mapping-card-pick .material-symbols-outlined {
  font-size: 18px;
}

.md-mapping-card-randomize:hover,
.md-mapping-card-pick:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 8%, transparent);
  color: var(--md-sys-color-accent);
}

.md-mapping-card-randomize:active,
.md-mapping-card-pick:active {
  transform: scale(0.95);
}

.md-mapping-swatch {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}

.md-mapping-info {
  flex: 1;
  min-width: 0;
  pointer-events: none;
}

.md-mapping-category {
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  font-size: 0.9rem;
  margin-bottom: 2px;
}

.md-mapping-source {
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.md-actions-row {
  margin-top: 24px;
  display: flex;
  justify-content: center;
}

.md-filled-btn--full {
  width: 100%;
  justify-content: center;
}

/* -----------------------------------------------------------------------------
   Material Design 3 Buttons (Additions)
   -------------------------------------------------------------------------- */

.md-filled-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 24px;
  border-radius: 20px;
  font: var(--md-sys-typescale-label-large);
  background-color: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-primary);
  border: none;
  cursor: pointer;
  transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  text-decoration: none;
}

.md-filled-btn:hover:not(:disabled) {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container));
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--elevation-3);
}

.md-filled-btn:active:not(:disabled) {
  background-color: color-mix(in srgb, var(--md-sys-color-surface-container), black 12%);
  box-shadow: var(--elevation-1);
  transform: translateY(0);
}

.md-filled-btn:disabled {
  background-color: color-mix(in srgb, var(--md-sys-color-on-surface), transparent 88%);
  color: color-mix(in srgb, var(--md-sys-color-on-surface), transparent 62%);
  box-shadow: none;
  cursor: not-allowed;
}

.md-filled-btn--full {
  width: 100%;
}

.md-text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 12px;
  border-radius: 20px;
  font: var(--md-sys-typescale-label-large);
  background-color: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-primary);
  border: none;
  cursor: pointer;
  transition: background-color 0.2s;
}

.md-text-btn:hover:not(:disabled) {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container-low));
}

.md-text-btn:active:not(:disabled) {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 8%, var(--md-sys-color-surface-container-low));
}

.md-text-btn:disabled {
  color: color-mix(in srgb, var(--md-sys-color-on-surface), transparent 62%);
  cursor: not-allowed;
}

/* -----------------------------------------------------------------------------
 * App-bar action pills (org deployment): Reset + Export style.
 * Low-key OUTLINED pills (no fill), compact font/padding. Collapse to icon-only
 * when the sidebar is narrow (.sidebar-compact) — mirrors the mode tabs.
 * Labels are wrapped in .md-app-bar__btn-label so they can be hidden in compact.
 * -------------------------------------------------------------------------- */
.md-pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 16px;
  font: var(--md-sys-typescale-label-medium);
  white-space: nowrap;            /* never wrap "Export style" */
  color: var(--md-sys-color-on-surface);
  background-color: transparent;
  border: var(--border-width-1) solid var(--md-sys-color-surface-border);
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.md-pill-btn .material-symbols-outlined {
  font-size: 18px;
}
.md-pill-btn:hover:not(:disabled) {
  background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}
.md-pill-btn:active:not(:disabled) {
  background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
}
.md-pill-btn:disabled {
  color: color-mix(in srgb, var(--md-sys-color-on-surface), transparent 62%);
  border-color: color-mix(in srgb, var(--md-sys-color-on-surface), transparent 80%);
  cursor: not-allowed;
}

/* Export = primary action: state-aware accent outline + text/icon, tracking the
   app-wide --md-sys-color-accent (red while editing parent, violet while editing
   a child — set via body[data-master-state] in style-manager.js). */
.md-pill-btn--accent {
  color: var(--md-sys-color-accent);
  border-color: var(--md-sys-color-accent);
}
.md-pill-btn--accent:hover:not(:disabled) {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 10%, transparent);
}
.md-pill-btn--accent:active:not(:disabled) {
  background-color: color-mix(in srgb, var(--md-sys-color-accent) 16%, transparent);
}

/* Reset icon: a notch smaller + rotated like the per-layer reset buttons. */
#reset-local-button .material-symbols-outlined {
  font-size: 16px;
  transform: rotate(45deg);
}

/* Keep Back aligned with the pills' height/typescale (it stays a borderless text btn). */
.md-app-bar__actions #back-button {
  height: 32px;
  font: var(--md-sys-typescale-label-medium);
}

/* Compact (narrow sidebar): icon-only square buttons, labels hidden. */
.sidebar-compact .md-app-bar__btn-label {
  display: none;
}
.sidebar-compact .md-app-bar__actions .md-pill-btn,
.sidebar-compact .md-app-bar__actions #back-button {
  width: 32px;
  padding: 0;
  gap: 0;
}

/* Icon Button variant for Photo-to-Map */
.md-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--md-sys-color-on-surface-variant);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.md-icon-btn:hover:not(:disabled) {
  background-color: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
}

.md-icon-btn--small {
  width: 32px;
  height: 32px;
}

.md-icon-btn--small .material-symbols-outlined {
  font-size: 20px;
}

/* =============================================================================
   STYLE MANAGER COMPONENT
   Dropdown-based panel for managing styles in a Style Family
   ============================================================================= */

/* Panel container */
.md-style-manager {
  position: relative;
  background: var(--md-sys-color-surface-container-low);
  border-bottom: var(--border-width-1) solid var(--md-sys-color-surface-border);
  overflow: visible;
}

/* Header */
.md-style-manager__header {
  display: flex;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  gap: var(--space-4);
}

.md-style-manager__title {
  font: var(--md-sys-typescale-title-medium);
  color: var(--md-sys-color-on-surface);
  font-weight: 600;
  flex-shrink: 0;
}

.md-style-manager__menu-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  flex-shrink: 0;
  margin-left: auto;
}

.md-style-manager__menu-btn .material-symbols-outlined {
  font-size: 18px;
}

/* Custom dropdown (inline in header) */
.md-style-manager__dropdown {
  position: relative;
  flex: 1;
  min-width: 0;
  max-width: 151px;
}

.md-style-manager__dropdown-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  width: 100%;
  padding: 2px 4px 2px 4px;
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-small);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}

.md-style-manager__dropdown-toggle:hover {
  border-color: var(--md-sys-color-on-surface-variant);
}

.md-style-manager__dropdown--open .md-style-manager__dropdown-toggle {
  border-color: var(--md-sys-color-accent);
}

.md-style-manager__dropdown-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.md-style-manager__dropdown-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.md-style-manager__dropdown-arrow {
  font-size: 14px;
  flex-shrink: 0;
  color: var(--md-sys-color-on-surface-variant);
  transition: transform var(--md-sys-motion-duration-fast) var(--md-sys-motion-easing-standard);
}

.md-style-manager__dropdown--open .md-style-manager__dropdown-arrow {
  transform: rotate(180deg);
}

/* Dropdown list (opens below toggle) */
.md-style-manager__dropdown-list {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  min-width: 100%;
  width: max-content;
  max-width: 240px;
  z-index: var(--z-dropdown);
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-surface-border);
  border-radius: var(--radius-small);
  box-shadow: var(--elevation-2);
  padding: var(--space-1) 0;
  overflow: hidden;
}

.md-style-manager__dropdown-option {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-1);
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  white-space: nowrap;
}

.md-style-manager__dropdown-option:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container-high));
}

.md-style-manager__dropdown-option--active {
  background: color-mix(in srgb, var(--md-sys-color-accent) 12%, transparent);
  font-weight: 500;
}

.md-style-manager__dropdown-option-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Description text below header */
.md-style-manager__description {
  margin: 0;
  padding: 0 var(--space-3) var(--space-2);
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.4;
}

.md-style-manager__description:empty {
  display: none;
}

.md-style-manager__description strong {
  color: var(--md-sys-color-on-surface);
  font-weight: 500;
}

body[data-master-state="false"] .md-style-manager__description {
  color: var(--md-sys-color-accent);
}

/* ⋮ Menu dropdown */
.md-style-manager__menu-dropdown {
  position: absolute;
  z-index: var(--z-dropdown);
  min-width: 200px;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-surface-border);
  border-radius: var(--radius-medium);
  box-shadow: var(--elevation-2);
  padding: var(--space-1) 0;
}

.md-style-manager__menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: none;
  background: none;
  font: var(--md-sys-typescale-body-medium);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  text-align: left;
}

.md-style-manager__menu-item:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container));
}

.md-style-manager__menu-item .material-symbols-outlined {
  font-size: 20px;
  color: var(--md-sys-color-on-surface-variant);
}

.md-style-manager__menu-item--disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

/* Toast notification */
.md-style-manager__toast {
  position: fixed;
  bottom: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-2) var(--space-4);
  font: var(--md-sys-typescale-body-medium);
  color: var(--md-sys-color-inverse-on-surface);
  background: var(--md-sys-color-inverse-surface);
  border-radius: var(--radius-small);
  box-shadow: var(--elevation-3);
  z-index: var(--z-toast);
  animation: slideUp 200ms ease-out;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Dialog */
.md-style-manager__dialog {
  padding: 0;
  border: none;
  border-radius: var(--radius-large);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--shadow-lg);
  max-width: 320px;
  width: 90vw;
}


.md-style-manager__dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.md-style-manager__dialog-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4);
}

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

.md-style-manager__dialog-title {
  margin: 0;
  font: var(--md-sys-typescale-title-small);
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.md-style-manager__dialog-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background-color 150ms;
}

.md-style-manager__dialog-close {
  background-color: var(--md-sys-color-surface-container);
}

.md-style-manager__dialog-close:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container-high));
}

.md-style-manager__dialog-close .material-symbols-outlined {
  font-size: 20px;
}

.md-style-manager__dialog-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  position: relative;
}

.md-style-manager__dialog-input-warning {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  padding: var(--space-1) var(--space-2);
  font: var(--md-sys-typescale-label-small);
  color: var(--md-comp-tooltip-text-color);
  background-color: var(--md-comp-tooltip-background);
  border-radius: var(--md-comp-tooltip-border-radius);
  border: var(--md-comp-tooltip-border-width) solid var(--md-comp-tooltip-border-color);
  max-width: var(--md-comp-tooltip-max-width);
  box-sizing: border-box;
  white-space: normal;
  z-index: var(--z-tooltip);
  animation: fadeIn 150ms ease-out;
}

.md-style-manager__dialog-label {
  font: var(--md-sys-typescale-label-medium);
  color: var(--md-sys-color-on-surface-variant);
}

.md-style-manager__dialog-input {
  padding: var(--space-2) var(--space-3);
  font: var(--md-sys-typescale-body-medium);
  text-transform: none;
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-small);
  outline: none;
}

.md-style-manager__dialog-input:focus {
  border-color: var(--md-sys-color-accent);
}

.md-style-manager__dialog-fieldset {
  margin: 0;
  padding: 0;
  border: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.md-style-manager__dialog-radio-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font: var(--md-sys-typescale-body-medium);
}

/* Custom radio button */
.md-style-manager__custom-radio {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--md-sys-color-outline);
  background: transparent;
  flex-shrink: 0;
  transition: border-color 150ms, background 150ms;
}

.md-style-manager__custom-radio--checked {
  border-color: var(--md-sys-color-accent);
  background: radial-gradient(circle, var(--md-sys-color-accent) 40%, transparent 45%);
}

/* Custom checkbox */
.md-style-manager__custom-checkbox {
  width: 18px;
  height: 18px;
  border-radius: var(--radius-extra-small);
  border: 2px solid var(--md-sys-color-outline);
  background: transparent;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: var(--md-sys-typescale-label-small);
  font-weight: 600;
  transition: border-color 150ms, background 150ms;
}

.md-style-manager__custom-checkbox--checked {
  border-color: var(--md-sys-color-accent);
  background: var(--md-sys-color-accent);
}

.md-style-manager__custom-checkbox--checked::after {
  content: '';
  width: 5px;
  height: 9px;
  border: solid var(--md-sys-color-surface);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

.md-style-manager__custom-checkbox--numbered {
  border-color: var(--md-sys-color-accent);
  background: var(--md-sys-color-accent);
  color: var(--md-sys-color-surface);
}

.md-style-manager__dialog-copy-selector {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2);
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--radius-small);
}

.md-style-manager__dialog-section {
  display: flex;
  flex-direction: column;
}

.md-style-manager__dialog-section-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-1) 0;
}

.md-style-manager__dialog-section-title {
  font: var(--md-sys-typescale-label-small);
  color: var(--md-sys-color-on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.md-style-manager__dialog-section-hint {
  font: var(--md-sys-typescale-label-small);
  color: var(--md-sys-color-on-surface-variant);
  font-style: italic;
}

.md-style-manager__dialog-section-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  max-height: 180px;
  overflow-y: auto;
  padding-right: var(--space-1);
}

.md-style-manager__dialog-empty {
  padding: var(--space-2);
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface-variant);
  font-style: italic;
}

.md-style-manager__dialog-copy-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-small);
  background: var(--md-sys-color-surface-container);
  margin-bottom: 2px;
}

.md-style-manager__dialog-avail-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-small);
  cursor: pointer;
  font: var(--md-sys-typescale-body-medium);
}

.md-style-manager__dialog-avail-row:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container-high));
}

.md-style-manager__dialog-avail-row:hover .md-style-manager__custom-checkbox {
  border-color: var(--md-sys-color-accent);
}

.md-style-manager__dialog-copy-name {
  flex: 1;
  font: var(--md-sys-typescale-body-medium);
}

.md-style-manager__dialog-copy-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.md-style-manager__dialog-arrow,
.md-style-manager__dialog-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background-color 150ms, color 150ms;
}

.md-style-manager__dialog-arrow,
.md-style-manager__dialog-remove {
  background-color: var(--md-sys-color-surface-container);
}

.md-style-manager__dialog-arrow:hover:not(:disabled),
.md-style-manager__dialog-remove:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container));
  color: var(--md-sys-color-on-surface);
}

.md-style-manager__dialog-arrow:disabled {
  opacity: 0.3;
  cursor: default;
}

.md-style-manager__dialog-arrow .material-symbols-outlined,
.md-style-manager__dialog-remove .material-symbols-outlined {
  font-size: 18px;
}

.md-style-manager__dialog-preview {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-2);
  background: color-mix(in srgb, var(--md-sys-color-accent) 10%, transparent);
  border-radius: var(--radius-small);
}

.md-style-manager__dialog-preview-label {
  font: var(--md-sys-typescale-label-medium);
  color: var(--md-sys-color-on-surface-variant);
}

.md-style-manager__dialog-preview-stack {
  font: var(--md-sys-typescale-body-medium);
  font-weight: 500;
  color: var(--md-sys-color-accent);
}

.md-style-manager__dialog-hint {
  margin: 0;
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface-variant);
}

.md-style-manager__dialog-message {
  margin: 0;
  font: var(--md-sys-typescale-body-medium);
  color: var(--md-sys-color-on-surface);
  line-height: 1.5;
}

.md-style-manager__dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.md-style-manager__dialog-btn {
  padding: var(--space-2) var(--space-4);
  font: var(--md-sys-typescale-label-large);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background-color var(--md-sys-motion-duration-fast);
}

.md-style-manager__dialog-btn--text {
  background: transparent;
  color: var(--md-sys-color-primary);
}

.md-style-manager__dialog-btn--text:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-surface-container));
}

.md-style-manager__dialog-btn--filled {
  background: var(--md-sys-color-accent);
  color: var(--md-sys-color-surface);
}

.md-style-manager__dialog-btn--filled:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 4%, var(--md-sys-color-accent));
}

.md-style-manager__dialog-btn--danger {
  background: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

.md-style-manager__dialog-btn--danger:hover {
  background: color-mix(in srgb, var(--md-sys-color-error) 90%, white);
}

/* Warning dialog styling */
.md-style-manager__dialog--warning .md-style-manager__dialog-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.md-style-manager__dialog-warning-icon {
  color: var(--md-sys-color-error);
  font-size: 24px;
}

.md-style-manager__dialog-btn--warning {
  background: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

.md-style-manager__dialog-btn--warning:hover {
  background: color-mix(in srgb, var(--md-sys-color-error) 90%, white);
}

/* =============================================================================
   REUSABLE MD3 DIALOG
   Generic dialog component matching Style Manager dialog design
   ============================================================================= */

.md-dialog {
  padding: 0;
  border: none;
  border-radius: var(--radius-large);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--elevation-3);
  max-width: 400px;
  width: 90vw;
}

.md-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.md-dialog__content {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4);
}

.md-dialog__title {
  margin: 0;
  font: var(--md-sys-typescale-title-small);
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.md-dialog__title--error {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--md-sys-color-error);
}

.md-dialog__message {
  margin: 0;
  font: var(--md-sys-typescale-body-medium);
  color: var(--md-sys-color-on-surface);
  line-height: 1.5;
}

.md-dialog__message p {
  margin: 0 0 var(--space-2);
}

.md-dialog__message p:last-child {
  margin-bottom: 0;
}

.md-dialog__message-lead {
  font-size: 14px;
  color: var(--md-sys-color-on-surface);
}

.md-dialog--centered .md-dialog__title {
  text-align: center;
  font-size: 18px;
}

.md-dialog--centered .md-dialog__message {
  text-align: center;
}

.md-dialog--centered .md-dialog__actions {
  justify-content: center;
}

.md-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.md-dialog__btn {
  padding: var(--space-2) var(--space-4);
  font: var(--md-sys-typescale-label-large);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background-color var(--md-sys-motion-duration-fast);
}

.md-dialog__btn--text {
  background: transparent;
  color: var(--md-sys-color-primary);
}

.md-dialog__btn--text:hover {
  background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent);
}

.md-dialog__btn--filled {
  background: var(--md-sys-color-accent);
  color: var(--md-sys-color-surface);
}

.md-dialog__btn--filled:hover {
  background: color-mix(in srgb, var(--md-sys-color-accent) 90%, white);
}

.md-dialog__btn--danger {
  background: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

.md-dialog__btn--danger:hover {
  background: color-mix(in srgb, var(--md-sys-color-error) 90%, white);
}

.md-dialog__btn--warning {
  background: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

.md-dialog__btn--warning:hover {
  background: color-mix(in srgb, var(--md-sys-color-error) 90%, white);
}

/* -----------------------------------------------------------------------------
   No-style boot screen (default deployment opened without ?name=)
   -------------------------------------------------------------------------- */

.md-no-style {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--md-sys-color-surface-dim);
}

.md-no-style__card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  max-width: 420px;
  width: 100%;
  padding: var(--space-6, 24px);
  border-radius: var(--radius-large, 12px);
  background: var(--md-sys-color-surface-container);
  box-shadow: var(--elevation-3);
  text-align: center;
}

.md-no-style__title {
  margin: 0;
  font: var(--md-sys-typescale-title-small);
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.md-no-style__message {
  margin: 0;
  font: var(--md-sys-typescale-body-medium);
  line-height: 1.5;
  color: var(--md-sys-color-on-surface-variant);
}

.md-no-style__message code {
  font-family: monospace;
  color: var(--md-sys-color-on-surface);
}

.md-no-style .md-dialog__btn--filled {
  align-self: center;
  text-decoration: none;
  display: inline-block;
}

/* -----------------------------------------------------------------------------
   Custom Map Branding (Logo)
   -------------------------------------------------------------------------- */

.mtk-map-logo {
  position: absolute;
  bottom: 6px;
  left: 6px;
  z-index: 1;
  line-height: 0;
  opacity: 0.85;
  transition: opacity 0.2s;
}

.mtk-map-logo:hover {
  opacity: 1;
}

.mtk-map-logo img {
  height: 23px;
  width: auto;
}

/* ----------------------------------------------------------------------------
 * Expert mode error panel — surfaces JSON parse + MapLibre spec + runtime
 * errors below the ACE editor. Rows are clickable to jump to the offending
 * line. The panel stays visible until errors are resolved (no dismissal).
 * Used by ExpertErrorPanel (public/js/ui/components/expert-error-panel.js).
 * ------------------------------------------------------------------------- */

.md-error-panel {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  max-height: 260px;
  border-top: var(--border-width-1) solid var(--md-sys-color-surface-border);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  font-size: 13px;
}

.md-error-panel[data-collapsed="true"] .md-error-panel__list {
  display: none;
}

.md-error-panel[data-collapsed="true"] .md-error-panel__chevron {
  transform: rotate(-90deg);
}

.md-error-panel__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: var(--border-width-1) solid var(--md-sys-color-surface-border);
}

.md-error-panel__toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  padding: 4px 6px;
  margin: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}

.md-error-panel__toggle:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 6%, transparent);
  border-radius: 4px;
}

.md-error-panel__toggle:focus-visible {
  outline: 2px solid var(--md-sys-color-error);
  outline-offset: 2px;
}

.md-error-panel__icon {
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  color: var(--md-sys-color-error);
}

.md-error-panel__chevron {
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  color: var(--md-sys-color-on-surface-variant);
  transition: transform 120ms ease;
}

.md-error-panel__count {
  flex: 1 1 auto;
  color: var(--md-sys-color-on-surface);
}

.md-error-panel__list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1 1 auto;
  scrollbar-color: var(--md-sys-color-surface-border) transparent;
}

.md-error-panel__row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: var(--border-width-1) solid var(--md-sys-color-surface-border);
  cursor: pointer;
  font-family: 'Roboto Mono', monospace;
  font-size: 12px;
  line-height: 1.45;
  color: var(--md-sys-color-on-surface);
}

.md-error-panel__row:hover,
.md-error-panel__row:focus-visible {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 6%, transparent);
  outline: none;
}

.md-error-panel__row--highlight {
  background: color-mix(in srgb, var(--md-sys-color-error) 22%, transparent);
}

.md-error-panel__row-line {
  flex-shrink: 0;
  font-weight: 600;
  min-width: 48px;
  color: var(--md-sys-color-error);
}

.md-error-panel__row-path {
  flex-shrink: 0;
  color: var(--md-sys-color-on-surface-variant);
}

.md-error-panel__row-message {
  flex: 1 1 auto;
  word-break: break-word;
  color: var(--md-sys-color-on-surface);
}

.md-error-panel__row-more {
  padding: 6px 12px;
  font-style: italic;
  color: var(--md-sys-color-on-surface-variant);
}

.md-error-panel__row-more a {
  color: var(--md-sys-color-error);
  text-decoration: underline;
}

/* ----------------------------------------------------------------------------
 * Image Color Picker — magnifier + custom crosshair shown during pick mode.
 * The OS cursor is hidden over the target image; we render our own crosshair
 * element and a magnifier that follows the mouse with a pixel-grid view.
 * Used by ColorPicker (public/js/ui/services/color-picker.js).
 * ------------------------------------------------------------------------- */

body.md-color-picker-active .md-color-picker__target {
  cursor: none;
}

.md-color-picker__magnifier {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  width: calc(100px + 2px);
  border: 1px solid var(--md-sys-color-surface-border);
  border-radius: 10px;
  background: var(--md-sys-color-surface-container-low);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.md-color-picker__magnifier-canvas {
  display: block;
  width: 100px;
  height: 100px;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
}

.md-color-picker__readout {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  font-family: 'Roboto Mono', monospace;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  border-top: 1px solid var(--md-sys-color-surface-border);
}

.md-color-picker__crosshair {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  margin-top: -11px;
}

.md-color-picker__crosshair::before,
.md-color-picker__crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
}

/* horizontal arm */
.md-color-picker__crosshair::before {
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  margin-top: -0.5px;
}

/* vertical arm */
.md-color-picker__crosshair::after {
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  margin-left: -0.5px;
}

/* =============================================================================
   ORG DEPLOYMENT — community top navigation bar
   Visible only when <body class="is-org"> (set by main.js when DEPLOYMENT==='org').
   The bar is position:fixed so the existing flex layout (aside + main) is
   unchanged; we just shift the row down by --mtk-org-topbar-h.
   ============================================================================= */

:root {
  --mtk-org-topbar-h: 0px;
}

body.is-org {
  --mtk-org-topbar-h: 33px;
  margin-top: var(--mtk-org-topbar-h);
  height: calc(100dvh - var(--mtk-org-topbar-h));
}

body.is-org aside {
  height: calc(100dvh - var(--mtk-org-topbar-h));
}

body.is-org .md-sidebar-toggle {
  top: calc(30px + var(--mtk-org-topbar-h));
}

/* Sidebar app-bar: hide logo, brand title, and Back button in org —
   Reset + Export stay right-aligned via the existing margin-left:auto on
   .md-app-bar__actions. */
body.is-org .md-app-bar__logo,
body.is-org .md-app-bar__title,
body.is-org .md-app-bar__actions #back-button {
  display: none !important;
}

.mtk-org-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--mtk-org-topbar-h, 33px);
  background-color: #1E1E1E;
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-family: var(--font-family);
  font-size: 13px;
  line-height: 1;
  z-index: 1000;
  user-select: none;
}

.mtk-org-topbar__brand {
  color: #fff;
  letter-spacing: 0.01em;
}

.mtk-org-topbar__brand-link {
  color: inherit;
  text-decoration: none;
}

.mtk-org-topbar__brand-link:hover,
.mtk-org-topbar__brand-link:focus-visible {
  text-decoration: underline;
  outline: none;
}

.mtk-org-topbar__brand-name strong {
  font-weight: 700;
}

.mtk-org-topbar__nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mtk-org-topbar__link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 0;
  padding: 4px 8px;
  color: #fff;
  font: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
}

.mtk-org-topbar__link:hover,
.mtk-org-topbar__link:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  outline: none;
}

.mtk-org-topbar__link-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* -----------------------------------------------------------------------------
   Org sidebar footer — subtle legal links pinned to the bottom of the sidebar.
   Appended as the last child of #sidebar-panel by initOrgSidebarFooter(); the
   preceding .md-tab-content is flex:1, so this sits flush at the bottom
   without needing position:sticky.
   -------------------------------------------------------------------------- */

.mtk-org-sidebar-footer {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-top: 1px solid var(--md-sys-color-surface-border);
  font-size: 11px;
  line-height: 1.4;
  color: var(--md-sys-color-on-surface-variant);
}

.mtk-org-sidebar-footer__link {
  color: inherit;
  text-decoration: none;
}

.mtk-org-sidebar-footer__link:hover,
.mtk-org-sidebar-footer__link:focus-visible {
  text-decoration: underline;
  outline: none;
}

.mtk-org-sidebar-footer__sep {
  opacity: 0.6;
}

/* -----------------------------------------------------------------------------
   Org help overlay — Markdown-rendered modal
   Triggered by the topbar's "How to use MapMaker" link.
   -------------------------------------------------------------------------- */

.mtk-help-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mtk-help-overlay[hidden] {
  display: none;
}

.mtk-help-overlay__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.mtk-help-overlay__dialog {
  position: relative;
  width: min(800px, 90vw);
  max-height: 85vh;
  background: var(--md-sys-color-surface, #fff);
  color: var(--md-sys-color-on-surface, #1c1b1f);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.32);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mtk-help-overlay__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--md-sys-color-surface-border, #e0e0e0);
}

.mtk-help-overlay__title {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  flex: 1;
}

.mtk-help-overlay__close {
  background: transparent;
  border: 0;
  padding: 4px;
  cursor: pointer;
  color: inherit;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mtk-help-overlay__close:hover,
.mtk-help-overlay__close:focus-visible {
  background: rgba(0, 0, 0, 0.06);
  outline: none;
}

.mtk-help-overlay__body {
  padding: 16px 20px 24px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.55;
}

.mtk-help-overlay__body h1,
.mtk-help-overlay__body h2,
.mtk-help-overlay__body h3 {
  clear: both;
  margin: 1em 0 0.4em;
  font-weight: 700;
  line-height: 1.25;
}

.mtk-help-overlay__body h1 { font-size: 28px; }
.mtk-help-overlay__body h2 { font-size: 21px; }
.mtk-help-overlay__body h3 { font-size: 17px; font-weight: 600; }

.mtk-help-overlay__body p,
.mtk-help-overlay__body ul,
.mtk-help-overlay__body ol {
  margin: 0.6em 0;
}

.mtk-help-overlay__body code {
  font-family: var(--font-family-mono, 'Roboto Mono', monospace);
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.92em;
}

.mtk-help-overlay__body img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

.mtk-help-overlay__body img.help-img-right {
  float: right;
  width: 400px;
  max-width: 45%;
  margin: 4px 0 12px 20px;
}

@media (max-width: 600px) {
  .mtk-help-overlay__body img.help-img-right {
    float: none;
    width: 100%;
    max-width: 100%;
    margin: 4px 0 12px;
  }
}

.mtk-help-overlay__body pre {
  background: rgba(0, 0, 0, 0.06);
  padding: 10px 12px;
  border-radius: 4px;
  overflow-x: auto;
}

.mtk-help-overlay__body pre code {
  background: transparent;
  padding: 0;
}

.mtk-help-overlay__body hr {
  clear: both;
  margin: 1.2em 0;
  border: none;
  border-top: var(--border-width-1) solid var(--md-sys-color-surface-border, rgba(255, 255, 255, 0.08));
}

.mtk-help-overlay__body blockquote {
  margin: 0.8em 0;
  padding: 0.4em 12px;
  border-left: 3px solid var(--md-sys-color-accent, #6750a4);
  color: var(--md-sys-color-on-surface-variant, #A0A0A0);
}

.mtk-help-overlay__body a {
  color: var(--md-sys-color-accent, #6750a4);
}

.mtk-help-overlay__loading,
.mtk-help-overlay__error {
  color: rgba(0, 0, 0, 0.62);
  font-style: italic;
}

.mtk-help-overlay__error {
  color: #b3261e;
  font-style: normal;
}

