/* ============================================================
   Roof Area Calculator - Comprehensive Stylesheet
   Tailwind-style utility classes + custom component styles
   ============================================================ */

/* ── 1. CSS Variables ─────────────────────────────────────── */
:root {
  /* Primary palette */
  --color-primary:        #FF5722;
  --color-primary-dark:   #E64A19;
  --color-primary-light:  #FF8A65;

  /* Secondary palette */
  --color-secondary:      #1976D2;
  --color-secondary-dark: #1565C0;
  --color-secondary-light:#42A5F5;

  /* Backgrounds */
  --color-bg:             #F5F5F5;
  --color-card-bg:        #FFFFFF;
  --color-panel-bg:       #FFFFFF;

  /* Text */
  --color-text-primary:   #212121;
  --color-text-secondary: #757575;
  --color-text-muted:     #9E9E9E;
  --color-text-inverse:   #FFFFFF;

  /* Borders & dividers */
  --color-border:         #E0E0E0;
  --color-border-light:   #EEEEEE;
  --color-divider:        #BDBDBD;

  /* Semantic */
  --color-success:        #4CAF50;
  --color-success-bg:     #E8F5E9;
  --color-warning:        #FFC107;
  --color-warning-bg:     #FFF8E1;
  --color-error:          #F44336;
  --color-error-bg:       #FFEBEE;
  --color-info:           #2196F3;
  --color-info-bg:        #E3F2FD;

  /* Spacing scale */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Border radius */
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm:  0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md:  0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg:  0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --shadow-xl:  0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --shadow-panel: 2px 0 12px rgba(0, 0, 0, 0.08);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-elevated: 0 8px 24px rgba(0, 0, 0, 0.12);

  /* Typography */
  --font-family:  -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono:     'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;

  --text-xs:   11px;
  --text-sm:   13px;
  --text-base: 14px;
  --text-md:   15px;
  --text-lg:   16px;
  --text-xl:   18px;
  --text-2xl:  22px;
  --text-3xl:  28px;
  --text-4xl:  36px;

  /* Transitions */
  --transition-fast:   150ms ease;
  --transition-base:   250ms ease;
  --transition-slow:   350ms ease;

  /* Layout */
  --panel-width:        380px;
  --header-height:      56px;
  --toolbar-height:     48px;
  --result-card-height: 88px;
}

/* ── 2. Reset & Base ─────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-family);
  font-size: var(--text-base);
  color: var(--color-text-primary);
  background-color: var(--color-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--color-secondary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  display: block;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--color-divider);
}

/* Text selection */
::selection {
  background: var(--color-primary-light);
  color: var(--color-text-inverse);
}

/* Focus ring */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ── 3. Layout ─────────────────────────────────────────────── */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.panel-left {
  width: var(--panel-width);
  min-width: var(--panel-width);
  height: 100%;
  background: var(--color-panel-bg);
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 10;
  position: relative;
}

.panel-right {
  flex: 1;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.map-container {
  width: 100%;
  height: 100%;
}

.map-container iframe,
.map-container #map,
#map {
  width: 100%;
  height: 100%;
  border: none;
  cursor: crosshair;
}

/* Mobile: stacked layout */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }

  .panel-left {
    width: 100%;
    min-width: 100%;
    height: auto;
    max-height: 50vh;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 20;
  }

  .panel-right {
    height: 50vh;
    min-height: 50vh;
  }

  .map-container {
    height: 100%;
  }
}

/* ── 4. Panel Header ─────────────────────────────────────── */
.panel-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border-light);
  background: var(--color-card-bg);
  position: sticky;
  top: 0;
  z-index: 5;
}

.panel-header__title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.panel-header__subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-top: var(--space-1);
}

/* ── 5. Panel Sections ───────────────────────────────────── */
.panel-section {
  border-bottom: 1px solid var(--color-border-light);
}

.panel-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  cursor: pointer;
  user-select: none;
  transition: background-color var(--transition-fast);
}

.panel-section__header:hover {
  background-color: var(--color-bg);
}

.panel-section__title {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.panel-section__toggle {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: transform var(--transition-base);
}

.panel-section__toggle svg {
  transition: transform var(--transition-base);
}

.panel-section.is-collapsed .panel-section__toggle svg {
  transform: rotate(-90deg);
}

.panel-section__body {
  padding: var(--space-4) var(--space-5);
  overflow: hidden;
  transition: max-height var(--transition-base), padding var(--transition-base), opacity var(--transition-base);
  max-height: 1000px;
  opacity: 1;
}

.panel-section.is-collapsed .panel-section__body {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  overflow: hidden;
}

/* ── 6. Form Controls ─────────────────────────────────────── */
.form-group {
  margin-bottom: var(--space-4);
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-1);
}

.form-label__hint {
  font-weight: 400;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.form-input {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  color: var(--color-text-primary);
  background: var(--color-card-bg);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(255, 87, 34, 0.15);
}

.form-input:disabled {
  background: var(--color-bg);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.form-input--error {
  border-color: var(--color-error);
}

.form-input--error:focus {
  box-shadow: 0 0 0 3px rgba(244, 67, 54, 0.15);
}

.form-input-group {
  display: flex;
  align-items: stretch;
}

.form-input-group .form-input {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  flex: 1;
}

.form-input-suffix {
  display: flex;
  align-items: center;
  padding: 0 var(--space-3);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-left: none;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

/* Range slider */
.form-range {
  width: 100%;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-border);
  appearance: none;
  cursor: pointer;
  margin: var(--space-2) 0;
}

.form-range::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: var(--shadow-md);
  transition: transform var(--transition-fast);
}

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

.form-range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: var(--shadow-md);
}

/* Select */
.form-select {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-8) 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  color: var(--color-text-primary);
  background: var(--color-card-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23757575' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
  appearance: none;
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(255, 87, 34, 0.15);
}

/* Inline form row */
.form-row {
  display: flex;
  gap: var(--space-3);
}

.form-row .form-group {
  flex: 1;
}

/* ── 7. Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 40px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  transition: all var(--transition-fast);
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Primary */
.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}
.btn-primary:hover {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
}
.btn-primary:active {
  transform: scale(0.97);
}

/* Secondary */
.btn-secondary {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.btn-secondary:hover {
  background: rgba(255, 87, 34, 0.06);
}
.btn-secondary:active {
  transform: scale(0.97);
}

/* Outline / Ghost */
.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}
.btn-ghost:hover {
  background: var(--color-bg);
  color: var(--color-text-primary);
}

/* Text button */
.btn-text {
  background: transparent;
  color: var(--color-secondary);
  border-color: transparent;
  padding: 0 var(--space-2);
  height: auto;
}
.btn-text:hover {
  text-decoration: underline;
}

/* Danger */
.btn-danger {
  background: var(--color-error);
  color: var(--color-text-inverse);
  border-color: var(--color-error);
}
.btn-danger:hover {
  background: #d32f2f;
  border-color: #d32f2f;
}

/* Small button */
.btn-sm {
  height: 32px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

.btn-sm svg {
  width: 14px;
  height: 14px;
}

/* Full width */
.btn-block {
  width: 100%;
}

/* Icon button */
.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
}
.btn-icon.btn-sm {
  width: 32px;
  height: 32px;
}

/* Button group */
.btn-group {
  display: flex;
  gap: var(--space-2);
}

.btn-group .btn {
  flex: 1;
}

/* ── 8. Tool Buttons ──────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5);
  background: var(--color-card-bg);
  border-bottom: 1px solid var(--color-border-light);
}

.toolbar--vertical {
  flex-direction: column;
  border-bottom: none;
  border-right: 1px solid var(--color-border-light);
  padding: var(--space-3);
  gap: var(--space-2);
  position: absolute;
  right: var(--space-3);
  top: var(--space-3);
  z-index: 10;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
}

.tool-btn {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.tool-btn svg {
  width: 22px;
  height: 22px;
}

.tool-btn:hover {
  background: var(--color-bg);
  color: var(--color-text-primary);
}

.tool-btn.is-active {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(255, 87, 34, 0.3);
}

.tool-btn.is-disabled {
  opacity: 0.4;
  pointer-events: none;
}

.tool-btn__tooltip {
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--color-text-primary);
  color: var(--color-text-inverse);
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  z-index: 100;
}

.tool-btn:hover .tool-btn__tooltip {
  opacity: 1;
}

/* ── 9. Result Cards ──────────────────────────────────────── */
.results-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}

.result-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.result-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--color-border-light);
  transition: background var(--transition-fast);
}

.result-card--highlight {
  border-color: var(--color-primary);
  background: #FFF3E0;
}

.result-card--highlight::before {
  background: var(--color-primary);
}

.result-card--highlight .result-card__value {
  color: var(--color-primary);
}

.result-card:hover {
  box-shadow: var(--shadow-card);
}

.result-card__label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.result-card__value {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1.2;
  transition: color var(--transition-base);
}

.result-card__unit {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  font-weight: 500;
}

/* Result value animation */
.result-value-animate {
  animation: resultPulse 0.4s ease-out;
}

@keyframes resultPulse {
  0%   { opacity: 0.3; transform: scale(0.96); }
  50%  { opacity: 1;   transform: scale(1.02); }
  100% { opacity: 1;   transform: scale(1); }
}

/* Single column on mobile */
@media (max-width: 480px) {
  .results-grid {
    grid-template-columns: 1fr;
  }
}

/* ── 10. Section Headers & Dividers ───────────────────────── */
.section-header {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.section-header::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border-light);
}

.divider {
  height: 1px;
  background: var(--color-border-light);
  margin: var(--space-4) 0;
}

/* ── 11. Map Controls Overlay ──────────────────────────────── */
.map-overlay {
  position: absolute;
  z-index: 10;
  pointer-events: none;
}

.map-overlay > * {
  pointer-events: auto;
}

.map-overlay--top-right {
  top: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.map-overlay--top-left {
  top: var(--space-4);
  left: var(--space-4);
}

.map-overlay--bottom-left {
  bottom: var(--space-6);
  left: var(--space-4);
}

.map-overlay--bottom-right {
  bottom: var(--space-6);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: flex-end;
}

/* Map search box */
.map-search {
  display: flex;
  align-items: center;
  background: var(--color-card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  padding: var(--space-1);
  gap: var(--space-1);
  width: 320px;
  max-width: calc(100vw - var(--space-8));
}

.map-search__input {
  flex: 1;
  border: none;
  outline: none;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-base);
  color: var(--color-text-primary);
  background: transparent;
  min-width: 0;
}

.map-search__input::placeholder {
  color: var(--color-text-muted);
}

.map-search__btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  background: transparent;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.map-search__btn:hover {
  background: var(--color-bg);
  color: var(--color-text-primary);
}

.map-search__btn svg {
  width: 18px;
  height: 18px;
}

/* Map type toggle */
.map-type-toggle {
  background: var(--color-card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  overflow: hidden;
  display: flex;
}

.map-type-toggle__btn {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  background: transparent;
  transition: all var(--transition-fast);
  border: none;
  cursor: pointer;
}

.map-type-toggle__btn:hover {
  background: var(--color-bg);
}

.map-type-toggle__btn.is-active {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

/* Zoom controls */
.map-zoom-controls {
  background: var(--color-card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.map-zoom-controls__btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--color-text-primary);
  cursor: pointer;
  transition: background var(--transition-fast);
  font-size: 20px;
  font-weight: 300;
  line-height: 1;
}

.map-zoom-controls__btn:hover {
  background: var(--color-bg);
}

.map-zoom-controls__btn:active {
  background: var(--color-border-light);
}

.map-zoom-controls__divider {
  height: 1px;
  background: var(--color-border-light);
}

/* Measurement info bar */
.measurement-bar {
  background: var(--color-card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-5);
  font-size: var(--text-sm);
}

.measurement-bar__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.measurement-bar__icon {
  width: 16px;
  height: 16px;
  color: var(--color-primary);
}

.measurement-bar__label {
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.measurement-bar__value {
  color: var(--color-text-primary);
  font-weight: 700;
  font-size: var(--text-md);
}

.measurement-bar__unit {
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: 400;
}

.measurement-bar__divider {
  width: 1px;
  height: 24px;
  background: var(--color-border-light);
}

/* ── 12. Polygon Info Tooltip ──────────────────────────────── */
.polygon-tooltip {
  position: absolute;
  z-index: 20;
  background: var(--color-card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  padding: var(--space-3) var(--space-4);
  pointer-events: none;
  transition: opacity var(--transition-base), transform var(--transition-base);
  max-width: 220px;
  min-width: 160px;
}

.polygon-tooltip.is-hidden {
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
}

.polygon-tooltip__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.polygon-tooltip__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-size: var(--text-xs);
  font-weight: 700;
}

.polygon-tooltip__title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-primary);
}

.polygon-tooltip__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-1) 0;
  font-size: var(--text-sm);
}

.polygon-tooltip__row + .polygon-tooltip__row {
  border-top: 1px solid var(--color-border-light);
}

.polygon-tooltip__row-label {
  color: var(--color-text-secondary);
}

.polygon-tooltip__row-value {
  font-weight: 600;
  color: var(--color-text-primary);
}

/* ── 13. Polygon List ─────────────────────────────────────── */
.polygon-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.polygon-list__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.polygon-list__item:hover {
  border-color: var(--color-primary);
  background: #FFF3E0;
}

.polygon-list__item.is-selected {
  border-color: var(--color-primary);
  background: #FFF3E0;
  box-shadow: 0 0 0 2px rgba(255, 87, 34, 0.15);
}

.polygon-list__badge {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  flex-shrink: 0;
}

.polygon-list__info {
  flex: 1;
  min-width: 0;
}

.polygon-list__name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.polygon-list__area {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.polygon-list__actions {
  display: flex;
  gap: var(--space-1);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.polygon-list__item:hover .polygon-list__actions {
  opacity: 1;
}

.polygon-list__action-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
}

.polygon-list__action-btn:hover {
  background: var(--color-card-bg);
  color: var(--color-text-primary);
}

.polygon-list__action-btn--delete:hover {
  background: var(--color-error-bg);
  color: var(--color-error);
}

.polygon-list__action-btn svg {
  width: 14px;
  height: 14px;
}

.polygon-list__empty {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.polygon-list__empty svg {
  width: 40px;
  height: 40px;
  margin: 0 auto var(--space-3);
  opacity: 0.4;
}

/* ── 14. Loading States ───────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity var(--transition-base);
}

.loading-overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--color-border-light);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: var(--space-4);
}

.loading-spinner--sm {
  width: 24px;
  height: 24px;
  border-width: 3px;
  margin-bottom: 0;
}

.loading-spinner--lg {
  width: 64px;
  height: 64px;
  border-width: 5px;
}

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

.loading-message {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
  text-align: center;
}

/* Button loading state */
.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  top: 50%;
  left: 50%;
  margin: -9px 0 0 -9px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── 15. Toast Notifications ──────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: center;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  font-size: var(--text-sm);
  font-weight: 500;
  max-width: 400px;
  pointer-events: auto;
  animation: toastIn 0.3s ease-out;
  border: 1px solid transparent;
}

.toast.is-exiting {
  animation: toastOut 0.25s ease-in forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(8px) scale(0.95); }
}

.toast--success {
  background: var(--color-success-bg);
  color: #2E7D32;
  border-color: #C8E6C9;
}

.toast--error {
  background: var(--color-error-bg);
  color: #C62828;
  border-color: #FFCDD2;
}

.toast--info {
  background: var(--color-info-bg);
  color: #1565C0;
  border-color: #BBDEFB;
}

.toast--warning {
  background: var(--color-warning-bg);
  color: #F57F17;
  border-color: #FFF9C4;
}

.toast__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.toast__message {
  flex: 1;
  line-height: 1.4;
}

.toast__close {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: inherit;
  opacity: 0.6;
  transition: opacity var(--transition-fast);
  flex-shrink: 0;
}

.toast__close:hover {
  opacity: 1;
}

/* ── 16. Unit Toggle ──────────────────────────────────────── */
.unit-toggle {
  display: flex;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 2px;
}

.unit-toggle__btn {
  flex: 1;
  padding: var(--space-1) var(--space-3);
  border-radius: calc(var(--radius-md) - 2px);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.unit-toggle__btn:hover {
  color: var(--color-text-primary);
}

.unit-toggle__btn.is-active {
  background: var(--color-card-bg);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

/* ── 17. Config Summary ───────────────────────────────────── */
.config-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--color-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-light);
}

.config-summary__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.config-summary__label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 500;
}

.config-summary__value {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-primary);
}

/* ── 18. Edit Mode Indicators ──────────────────────────────── */
.edit-mode-banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-5);
  background: var(--color-warning-bg);
  border-bottom: 1px solid #FFE082;
  font-size: var(--text-sm);
  color: #F57F17;
}

.edit-mode-banner__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-warning);
  flex-shrink: 0;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}

.edit-mode-banner__text {
  flex: 1;
  font-weight: 500;
}

.edit-mode-banner__actions {
  display: flex;
  gap: var(--space-2);
}

/* ── 19. Modal / Dialog ───────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  transition: opacity var(--transition-base);
}

.modal-backdrop.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.modal {
  background: var(--color-card-bg);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5);
  border-bottom: 1px solid var(--color-border-light);
}

.modal__title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text-primary);
}

.modal__close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  background: transparent;
  transition: all var(--transition-fast);
}

.modal__close:hover {
  background: var(--color-bg);
  color: var(--color-text-primary);
}

.modal__body {
  padding: var(--space-5);
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border-light);
  background: var(--color-bg);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* ── 20. Empty / Placeholder States ──────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-8) var(--space-6);
  color: var(--color-text-muted);
}

.empty-state__icon {
  width: 56px;
  height: 56px;
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.empty-state__title {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

.empty-state__description {
  font-size: var(--text-sm);
  line-height: 1.6;
  max-width: 280px;
}

/* ── 21. Utility Classes ───────────────────────────────────── */
.text-xs    { font-size: var(--text-xs); }
.text-sm    { font-size: var(--text-sm); }
.text-base  { font-size: var(--text-base); }
.text-md    { font-size: var(--text-md); }
.text-lg    { font-size: var(--text-lg); }
.text-xl    { font-size: var(--text-xl); }
.text-2xl   { font-size: var(--text-2xl); }
.text-3xl   { font-size: var(--text-3xl); }
.text-4xl   { font-size: var(--text-4xl); }

.font-normal   { font-weight: 400; }
.font-medium   { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }

.text-muted     { color: var(--color-text-muted); }
.text-secondary { color: var(--color-text-secondary); }
.text-primary   { color: var(--color-primary); }
.text-success   { color: var(--color-success); }
.text-error     { color: var(--color-error); }
.text-warning   { color: var(--color-warning); }

.text-center { text-align: center; }
.text-right  { text-align: right; }

.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.flex-wrap   { flex-wrap: wrap; }
.items-center  { align-items: center; }
.items-start   { align-items: flex-start; }
.items-end     { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.justify-end     { justify-content: flex-end; }
.flex-1      { flex: 1; }
.gap-1       { gap: var(--space-1); }
.gap-2       { gap: var(--space-2); }
.gap-3       { gap: var(--space-3); }
.gap-4       { gap: var(--space-4); }
.gap-5       { gap: var(--space-5); }

.w-full  { width: 100%; }
.h-full  { height: 100%; }

.mt-1  { margin-top: var(--space-1); }
.mt-2  { margin-top: var(--space-2); }
.mt-3  { margin-top: var(--space-3); }
.mt-4  { margin-top: var(--space-4); }
.mb-2  { margin-bottom: var(--space-2); }
.mb-3  { margin-bottom: var(--space-3); }
.mb-4  { margin-bottom: var(--space-4); }
.mb-5  { margin-bottom: var(--space-5); }
.p-2   { padding: var(--space-2); }
.p-3   { padding: var(--space-3); }
.p-4   { padding: var(--space-4); }
.p-5   { padding: var(--space-5); }

.rounded     { border-radius: var(--radius-md); }
.rounded-lg  { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }

.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

.overflow-hidden { overflow: hidden; }
.overflow-auto  { overflow: auto; }

.relative { position: relative; }
.absolute { position: absolute; }
.fixed    { position: fixed; }

.inset-0  { inset: 0; }
.top-0    { top: 0; }
.bottom-0 { bottom: 0; }
.left-0   { left: 0; }
.right-0  { right: 0; }

.z-10 { z-index: 10; }
.z-20 { z-index: 20; }
.z-50 { z-index: 50; }
.z-100 { z-index: 100; }

.hidden    { display: none; }
.visible   { visibility: visible; }
.invisible { visibility: hidden; }
.opacity-0 { opacity: 0; }
.opacity-50 { opacity: 0.5; }
.opacity-100 { opacity: 1; }

.cursor-pointer { cursor: pointer; }
.cursor-default { cursor: default; }
.pointer-events-none { pointer-events: none; }

.select-none { user-select: none; }

.transition { transition: all var(--transition-base); }
.transition-fast { transition: all var(--transition-fast); }

/* ── 22. Print / PDF Styles ───────────────────────────────── */
@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  body {
    overflow: visible;
    background: white;
  }

  .app-container {
    display: block;
    height: auto;
    overflow: visible;
  }

  .panel-left {
    width: 100%;
    min-width: 100%;
    height: auto;
    box-shadow: none;
    overflow: visible;
  }

  .panel-right,
  .map-container {
    display: none;
  }

  .panel-header {
    box-shadow: none;
    border-bottom: 2px solid var(--color-primary);
  }

  .panel-section__body {
    max-height: none !important;
    opacity: 1 !important;
    overflow: visible !important;
  }

  .panel-section__toggle {
    display: none;
  }

  .results-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .result-card {
    break-inside: avoid;
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }

  .result-card--highlight {
    border: 2px solid var(--color-primary);
    background: #FFF3E0 !important;
  }

  .btn,
  .toolbar,
  .loading-overlay,
  .toast-container,
  .modal-backdrop,
  .edit-mode-banner,
  .map-overlay,
  .polygon-tooltip {
    display: none !important;
  }

  .config-summary {
    border: 1px solid #ccc;
  }

  .print-header {
    display: block !important;
    text-align: center;
    padding: var(--space-4);
    margin-bottom: var(--space-4);
    border-bottom: 1px solid var(--color-border);
  }

  .print-footer {
    display: block !important;
    text-align: center;
    padding: var(--space-4);
    margin-top: var(--space-4);
    border-top: 1px solid var(--color-border);
    font-size: var(--text-xs);
    color: var(--color-text-muted);
  }
}

/* Print-only elements */
.print-header,
.print-footer {
  display: none;
}

/* ── 23. Responsive Adjustments ───────────────────────────── */
@media (max-width: 768px) {
  :root {
    --panel-width: 100%;
  }

  .map-search {
    width: 100%;
    max-width: none;
  }

  .measurement-bar {
    flex-wrap: wrap;
    gap: var(--space-3);
  }

  .measurement-bar__divider {
    display: none;
  }

  .map-overlay--top-right {
    top: var(--space-2);
    right: var(--space-2);
  }

  .map-overlay--bottom-left,
  .map-overlay--bottom-right {
    bottom: var(--space-2);
    left: var(--space-2);
    right: var(--space-2);
  }

  .toast-container {
    bottom: var(--space-4);
    left: var(--space-4);
    right: var(--space-4);
    transform: none;
  }

  .toast {
    max-width: none;
  }

  .modal {
    max-width: none;
    margin: 0;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 85vh;
  }

  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
}

@media (max-width: 480px) {
  .results-grid {
    grid-template-columns: 1fr;
  }

  .form-row {
    flex-direction: column;
  }

  .btn-group {
    flex-direction: column;
  }

  .config-summary {
    grid-template-columns: 1fr;
  }
}

/* ── 24. Accessibility ────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --color-border: #000;
    --color-text-secondary: #000;
    --color-text-muted: #444;
  }

  .result-card,
  .tool-btn,
  .btn {
    border-width: 2px;
  }
}
