:root {
  --sidebar-bg: #0F172A;
  --sidebar-bg-alt: #1E293B;
  --sidebar-border: rgba(255,255,255,0.08);
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --accent-secondary: #3B82F6;
  --text-primary: #E2E8F0;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --input-bg: #0F172A;
  --input-border: rgba(255,255,255,0.10);
  --input-focus: #e94560;
  --success: #06d6a0;
  --warning: #f4a261;
  --error: #ef476f;
  --sidebar-width: 320px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --transition: 0.2s ease;
  --glass-bg: rgba(15, 23, 42, 0.78);
  --glass-border: rgba(255, 255, 255, 0.06);
  --shadow-elevated: 0 8px 32px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.06);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
}

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

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
  border-right: 1px solid var(--glass-border);
}

.sidebar-header {
  padding: 16px 20px;
  background: rgba(15,23,42,0.4);
  border-bottom: 1px solid var(--glass-border);
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-primary);
}

.sidebar-header p {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.sidebar-content::-webkit-scrollbar {
  width: 4px;
}

.sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: var(--sidebar-border);
  border-radius: 4px;
}

/* ---- Sidebar sections ---- */
.sidebar-section {
  border-bottom: 1px solid var(--sidebar-border);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.section-header:hover {
  background: rgba(255, 255, 255, 0.03);
}

.section-header h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
}

.section-chevron {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform var(--transition);
}

.sidebar-section.collapsed .section-chevron {
  transform: rotate(-90deg);
}

.sidebar-section.collapsed .section-body {
  display: none;
}

.section-body {
  padding: 0 20px 18px;
}

/* ---- Coordinate input ---- */
.coord-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.coord-row {
  display: flex;
  gap: 8px;
}

.coord-row .input-group {
  flex: 1;
}

.input-group label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 500;
}

.input-group input,
.input-group select {
  width: 100%;
  padding: 8px 10px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  transition: border-color var(--transition);
  outline: none;
}

.input-group input:focus,
.input-group select:focus {
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(233,69,96,0.15);
}

.input-group input::placeholder {
  color: var(--text-muted);
}

.input-group select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2364748B'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  outline: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 0 16px rgba(233,69,96,0.3);
}

.btn-primary:disabled {
  background: var(--sidebar-bg-alt);
  color: var(--text-muted);
  cursor: not-allowed;
}
.btn-primary.btn-loading {
  background: var(--accent);
  color: white;
  opacity: 0.85;
  cursor: wait;
  opacity: 0.6;
}

.btn-secondary {
  background: rgba(255,255,255,0.05);
  color: var(--text-secondary);
  border: 1px solid rgba(255,255,255,0.10);
}

.btn-secondary:hover {
  background: var(--input-border);
  color: var(--text-primary);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-icon {
  padding: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.btn-icon:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.btn-icon.danger:hover {
  color: var(--error);
}

/* ---- Base layer toggle (segmented control) ---- */
.base-layer-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--glass-border);
  background: transparent;
}

.base-layer-btn {
  flex: 1;
  padding: 6px 12px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.base-layer-btn + .base-layer-btn {
  border-left: 1px solid var(--glass-border);
}

.base-layer-btn:hover {
  color: var(--text-primary);
  background: var(--sidebar-bg-alt);
}

.base-layer-btn.active {
  background: var(--accent);
  color: white;
}

/* ---- Layer toggles ---- */
.layer-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
}

.layer-toggle-label {
  font-size: 13px;
  color: var(--text-primary);
}

.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--input-border);
  border-radius: 12px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  bottom: 3px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(233,69,96,0.3);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
  background: white;
}

/* ---- Opacity slider ---- */
.opacity-slider {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--input-border);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}
.opacity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.opacity-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

/* ---- Zone list ---- */
.zone-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.zone-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--sidebar-bg-alt);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}

.zone-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.zone-item.active {
  outline: 1px solid var(--accent);
}

.zone-color {
  width: 12px;
  height: 12px;
  border-radius: var(--radius-xs);
  flex-shrink: 0;
  margin-top: 4px;
}

.zone-info {
  flex: 1;
  min-width: 0;
}

.zone-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.zone-name-text {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zone-badges {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
}

.zone-area {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.zone-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition);
}

.zone-item:hover .zone-actions {
  opacity: 1;
}

.zone-type-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  border-radius: var(--radius-xs);
  padding: 2px 6px;
  margin-right: 4px;
  vertical-align: middle;
  line-height: 1.3;
}

.zone-modal-select {
  width: 100%;
  padding: 10px 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  margin-bottom: 16px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2364748B'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
}

.zone-modal-select:focus {
  border-color: var(--input-focus);
}

.zone-modal-select optgroup {
  color: var(--text-muted);
  font-style: normal;
  font-weight: 600;
  font-size: 12px;
}

.zone-modal-select option {
  color: var(--text-primary);
  background: var(--input-bg);
  padding: 4px 8px;
}

/* ---- Stato badges ---- */
.zone-stato-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  border-radius: var(--radius-xs);
  padding: 1px 5px;
  vertical-align: middle;
  line-height: 1.3;
  text-transform: uppercase;
}

.zone-stato-badge.stato-ottimo {
  background: rgba(6, 214, 160, 0.15);
  color: var(--success);
}

.zone-stato-badge.stato-scadente {
  background: rgba(239, 71, 111, 0.15);
  color: var(--error);
}

/* ---- Stato radio group (zone modal) ---- */
.stato-radio-group {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.stato-radio-group label {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  background: var(--sidebar-bg-alt);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.stato-radio-group label:hover {
  border-color: var(--text-muted);
}

.stato-radio-group input[type="radio"] {
  display: none;
}

.stato-radio-group input[type="radio"]:checked + .stato-label {
  color: var(--accent);
}

.stato-radio-group input[type="radio"]:checked ~ .stato-desc {
  color: var(--text-secondary);
}

.stato-radio-group label:has(input:checked) {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.08);
}

.stato-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.stato-desc {
  font-size: 10px;
  color: var(--text-muted);
}

/* ---- Price source info ---- */
.price-label-block {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.price-source {
  font-size: 10px;
  color: var(--text-muted);
}

.price-extrapolated {
  font-size: 10px;
  color: var(--warning);
  font-style: italic;
}

/* ---- Price info button + popup ---- */
.btn-price-info {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 50%;
  transition: all var(--transition);
  flex-shrink: 0;
  line-height: 1;
}

.btn-price-info:hover {
  color: var(--accent);
  background: rgba(233, 69, 96, 0.1);
}

.price-info-popup {
  position: fixed;
  z-index: 4000;
  background: var(--sidebar-bg);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow-elevated);
  padding: 14px 16px;
  min-width: 240px;
  max-width: 450px;
  animation: fade-in 0.15s ease;
}

.price-info-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0;
  padding-bottom: 0;
}

.price-info-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  font-size: 11px;
  color: var(--text-secondary);
}

.price-info-label {
  color: var(--text-muted);
  flex-shrink: 0;
  font-weight: 500;
}

.price-info-formula {
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
}

.price-info-separator {
  border: none;
  border-top: 1px solid var(--input-border);
  margin: 6px 0;
}

.price-info-level {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.price-info-extrapolated {
  font-size: 10px;
  color: var(--warning);
  font-style: italic;
  padding: 4px 0 2px;
}

.zone-empty {
  text-align: center;
  padding: 20px 10px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

/* ---- Price section ---- */
.price-empty {
  text-align: center;
  padding: 12px 10px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.price-alert {
  background: rgba(244, 162, 97, 0.12);
  border: 1px solid rgba(244, 162, 97, 0.3);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 11px;
  color: var(--warning);
  margin-bottom: 10px;
  line-height: 1.4;
}

.price-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
}

.price-sub-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0 2px 18px;
}

.price-sub-label {
  font-size: 10px;
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
}

.price-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.price-label {
  flex: 1;
  font-size: 12px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.price-input-wrap {
  width: 90px;
  flex-shrink: 0;
}

.price-input {
  width: 100%;
  padding: 5px 8px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
  transition: border-color var(--transition);
  -moz-appearance: textfield;
}

.price-input::-webkit-outer-spin-button,
.price-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.price-input:focus {
  border-color: var(--input-focus);
}

.price-input::placeholder {
  color: var(--text-muted);
  font-size: 11px;
}

/* ---- Estimation total and disclaimer ---- */
.estimation-total {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--sidebar-bg-alt);
  border-radius: var(--radius-sm);
  border: 1px solid var(--sidebar-border);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.estimation-total .total-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.estimation-total .total-value {
  color: var(--accent);
}

.estimation-disclaimer {
  margin-top: 6px;
  font-size: 10px;
  font-style: italic;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ---- Zone value display ---- */
.zone-value {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
}

.zone-value.muted {
  color: var(--text-muted);
  font-weight: 400;
}

/* ---- Price override button ---- */
.btn-override {
  padding: 3px 5px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  font-size: 11px;
  line-height: 1;
}

.btn-override:hover {
  color: var(--accent);
  background: rgba(233, 69, 96, 0.1);
}

.btn-override.active {
  color: var(--warning);
}

/* ---- Project name ---- */
.project-name {
  cursor: pointer;
  border-bottom: 1px dashed var(--text-muted);
  transition: all var(--transition);
  outline: none;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
}

.project-name:hover {
  border-bottom-color: var(--accent);
  background: rgba(233, 69, 96, 0.06);
  color: var(--accent-hover);
}

.project-name[contenteditable="true"] {
  cursor: text;
  border-bottom-color: var(--accent);
  background: rgba(233, 69, 96, 0.15);
  border-radius: var(--radius-xs);
  box-shadow: 0 0 0 2px rgba(233, 69, 96, 0.25);
  color: #fff;
}

/* ---- Parcel list ---- */
.parcel-list:empty {
  display: none;
}

.parcel-list {
  margin-bottom: 8px;
}

.parcel-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 6px;
  font-size: 11px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.parcel-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.parcel-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.parcel-remove {
  padding: 2px 4px;
  font-size: 10px;
  opacity: 0;
  transition: opacity var(--transition);
}

.parcel-item:hover .parcel-remove {
  opacity: 1;
}

/* ---- Zone actions bar ---- */
.zone-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

/* ---- Sidebar footer (coordinates) ---- */
.sidebar-footer {
  padding: 10px 20px;
  background: rgba(15,23,42,0.4);
  border-top: 1px solid var(--glass-border);
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

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

.coord-display span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


/* ---- Map container ---- */
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ---- Loading indicator ---- */
.loading-indicator {
  position: fixed;
  top: 12px;
  left: calc(var(--sidebar-width) + 12px);
  background: var(--sidebar-bg);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  z-index: 1001;
  display: none;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--sidebar-border);
}

.loading-indicator.visible {
  display: flex;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--input-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---- Popup styles ---- */
.catasto-popup .leaflet-popup-content-wrapper {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-elevated);
}

.catasto-popup .leaflet-popup-tip {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
}

.catasto-popup .leaflet-popup-close-button {
  color: var(--text-muted);
}

.popup-content {
  min-width: 180px;
}

.popup-content h3 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--accent);
}

.popup-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 12px;
}

.popup-row .label {
  color: var(--text-muted);
}

.popup-row .value {
  font-weight: 500;
}

.popup-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  font-size: 12px;
  color: var(--text-muted);
}

.popup-error {
  color: var(--error);
  font-size: 12px;
  padding: 8px 0;
}

/* ---- Toast notifications ---- */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: calc(var(--sidebar-width) + 20px);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: var(--shadow-elevated);
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.7s forwards;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.error { border-left: 3px solid var(--error); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-10px); }
}

.toast-with-action {
  min-width: 280px;
}

.toast-action {
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
  margin-left: 8px;
  flex-shrink: 0;
}

.toast-action:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 0.2s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 24px;
  min-width: 320px;
  max-width: 90vw;
  box-shadow: var(--shadow-elevated);
}

.modal h3 {
  font-size: 15px;
  margin-bottom: 16px;
}

.modal input {
  width: 100%;
  padding: 10px 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  margin-bottom: 16px;
}

.modal input:focus {
  border-color: var(--input-focus);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---- Layers modal ---- */
.layers-modal {
  min-width: 280px;
  max-width: 340px;
}

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

.layers-modal-header h3 {
  margin: 0;
}

.layers-modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.layers-modal-close:hover {
  color: var(--text-primary);
}

/* ---- Leaflet overrides ---- */
.leaflet-left {
  left: calc(var(--sidebar-width) + 10px) !important;
}

.leaflet-control-zoom a {
  background: var(--sidebar-bg-alt) !important;
  color: var(--text-primary) !important;
  border-color: var(--glass-border) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--sidebar-bg) !important;
}

.leaflet-bar {
  border: 1px solid var(--glass-border) !important;
  box-shadow: var(--shadow-sm) !important;
}

.layers-control-btn {
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: 30px !important;
  height: 30px !important;
  font-size: 16px;
  background: var(--sidebar-bg-alt) !important;
  color: var(--text-primary) !important;
  text-decoration: none !important;
}

.layers-control-btn:hover {
  background: var(--sidebar-bg) !important;
}

.leaflet-draw-toolbar a {
  background-color: var(--sidebar-bg-alt) !important;
  border-color: var(--glass-border) !important;
}

.leaflet-control-attribution {
  background: rgba(15, 23, 42, 0.85) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: var(--text-secondary) !important;
}

/* ---- Editing handles — petits carrés colorés ---- */
.leaflet-editing-icon {
  width: 8px !important;
  height: 8px !important;
  margin-left: -4px !important;
  margin-top: -4px !important;
  background: #fff !important;
  border: 1.5px solid rgba(255,255,255,0.7) !important;
  border-radius: 2px !important;
  box-shadow: 0 0 4px rgba(0,0,0,0.4) !important;
}


.zone-dragging,
.zone-dragging * {
  cursor: crosshair !important;
}

/* ---- Mobile toggle ---- */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1002;
  width: 40px;
  height: 40px;
  background: var(--sidebar-bg);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

/* ---- Detection panel ---- */
.detection-loading {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-primary);
  font-size: 14px;
}

.detection-panel {
  position: fixed;
  top: 60px;
  right: 20px;
  width: 320px;
  max-height: calc(100vh - 100px);
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-elevated);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fade-in 0.2s ease;
}

.detection-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}

.detection-panel-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.detection-count {
  display: inline-block;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 6px;
  vertical-align: middle;
}

.detection-close {
  font-size: 14px;
}

.detection-warning {
  background: rgba(244, 162, 97, 0.12);
  border-bottom: 1px solid rgba(244, 162, 97, 0.3);
  padding: 8px 16px;
  font-size: 11px;
  color: var(--warning);
  line-height: 1.4;
}

.detection-zone-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.detection-zone-item {
  padding: 8px 16px;
  transition: background var(--transition);
}

.detection-zone-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.detection-zone-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
}

.detection-zone-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.detection-zone-details {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  padding-left: 24px;
}

.detection-zone-area {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.detection-type-select {
  flex: 1;
  padding: 4px 8px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 11px;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2364748B'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 20px;
}

.detection-type-select:focus {
  border-color: var(--input-focus);
}

.detection-panel-footer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--sidebar-border);
}

.detection-panel-footer .btn {
  flex: 1;
}

/* Parcel confirmation info */
.detection-parcel-info {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.5;
}

.detection-parcel-info p {
  margin: 0 0 4px;
}

.detection-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

/* Auto-detect popup button disabled state */
.popup-detect-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---- Search widget ---- */
.search-widget {
  padding: 0;
}

.search-tabs {
  display: flex;
  border-bottom: 1px solid var(--sidebar-border);
}

.search-tab {
  flex: 1;
  padding: 10px 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  letter-spacing: 0.3px;
}

.search-tab:hover {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
}

.search-tab-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.search-panels {
  padding: 12px 16px 16px;
}

.search-panel {
  display: none;
}

.search-panel-active {
  display: block;
}

/* Address input wrapper */
.search-input-wrap {
  position: relative;
}

.search-input {
  width: 100%;
  padding: 9px 32px 9px 10px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}

.search-input:focus {
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(233,69,96,0.15);
}

.search-input::placeholder {
  color: var(--text-muted);
}

/* Clear button inside input */
.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  border-radius: 50%;
  transition: all var(--transition);
  padding: 0;
  line-height: 1;
}

.search-clear:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.1);
}

/* Loading spinner inside input */
.search-loading {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  border: 2px solid var(--input-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: none;
}

.search-loading-visible {
  display: block;
}

/* When loading, hide clear button */
.search-input-wrap:has(.search-loading-visible) .search-clear {
  display: none !important;
}

/* Autocomplete dropdown */
.search-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--sidebar-bg-alt);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  max-height: 280px;
  overflow-y: auto;
  z-index: 1100;
  display: none;
  box-shadow: var(--shadow-elevated);
}

.search-dropdown-visible {
  display: block;
}

.search-dropdown-item {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  line-height: 1.4;
}

.search-dropdown-item:last-child {
  border-bottom: none;
}

.search-dropdown-item:hover,
.search-dropdown-item-active {
  background: rgba(59,130,246,0.12);
}

/* Catasto form */
.search-catasto-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-catasto-row {
  display: flex;
  gap: 8px;
}

.search-catasto-row .input-group {
  flex: 1;
}

.search-error {
  font-size: 11px;
  color: var(--error);
  margin-top: 4px;
  min-height: 0;
}

/* ---- Report loading overlay ---- */
.report-loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 3500;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 0.2s ease;
}

.report-loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
}

.report-loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--input-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ---- Floor-level selectors ---- */

/* Shared floor-level container */
.floor-levels-card {
  background: var(--sidebar-bg-alt);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-top: 8px;
}

.floor-levels-card-header {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 6px 10px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* Zone list expandable section */
.floor-level-section {
  display: none;
  flex-direction: column;
  gap: 0;
  margin-top: 6px;
  background: var(--sidebar-bg-alt);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.floor-level-section.floor-level-expanded {
  display: flex;
}

.floor-level-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 11px;
  transition: background var(--transition);
}

.floor-level-row + .floor-level-row {
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.floor-level-row:hover {
  background: rgba(255, 255, 255, 0.03);
}

.floor-level-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(233, 69, 96, 0.15);
  padding: 2px 7px;
  border-radius: 4px;
  min-width: 28px;
  text-align: center;
  flex-shrink: 0;
  line-height: 1.4;
}

.floor-level-select {
  flex: 1;
  padding: 5px 8px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%2364748B'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 20px;
  transition: border-color var(--transition);
}

.floor-level-select:focus {
  border-color: var(--input-focus);
}

.floor-level-select:hover {
  border-color: var(--text-muted);
}

/* Floor levels in modal context */
#modal-floor-levels:empty {
  display: none;
}

/* Floor levels in detection panel */
.detection-floor-levels {
  margin-top: 4px;
  padding-left: 24px;
}

.detection-floor-levels:not(:empty) {
  background: var(--sidebar-bg-alt);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-left: 24px;
  margin-top: 6px;
}

.coeff-sum {
  font-size: 10px;
  opacity: 0.7;
  margin-left: 4px;
  color: var(--text-muted);
}

/* ---- Level types panel (PREZZI extended mode) ---- */
.level-types-panel {
  background: var(--sidebar-bg-alt);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  padding: 8px;
  margin-top: 8px;
}

.level-type-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

.level-type-label-input {
  flex: 1;
  padding: 4px 6px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 11px;
  outline: none;
}

.level-type-label-input:focus {
  border-color: var(--input-focus);
}

.level-type-slider {
  width: 70px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--input-border);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}

.level-type-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

.level-type-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  border: none;
  cursor: pointer;
}

.level-type-coeff-display {
  min-width: 36px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.level-type-coeff-display:hover {
  background: rgba(233, 69, 96, 0.15);
}

.level-type-coeff-edit {
  width: 44px;
  padding: 2px 4px;
  background: var(--input-bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 11px;
  outline: none;
  text-align: center;
}

.level-type-delete {
  padding: 2px 4px;
  font-size: 10px;
}

.level-type-delete.disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.level-types-toggle {
  font-size: 11px;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  .sidebar.open ~ .sidebar-toggle {
    left: calc(var(--sidebar-width) + 12px);
  }

  .leaflet-left {
    left: 10px !important;
  }

  .loading-indicator {
    left: 60px;
  }

  .toast-container {
    left: 20px;
  }
}
