:root {
  --bg: #f4f5f7;
  --panel-bg: #ffffff;
  --border: #dde1e6;
  --text: #1f2430;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --existing: #7c3aed;
  --recommended: #16a34a;
  --danger: #dc2626;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

#sidebar {
  width: 340px;
  min-width: 340px;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

#map {
  flex: 1;
  height: 100vh;
}

h1 {
  font-size: 17px;
  margin: 0 0 4px 0;
}

h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 8px 0;
}

.subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0 0 8px 0;
  line-height: 1.4;
}

.section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

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

input[type="number"], select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  width: 90px;
  background: #fff;
  color: var(--text);
}

select { width: auto; }

input[type="range"] {
  width: 100%;
}

button {
  border: none;
  border-radius: 6px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.primary:disabled { background: #9ca3af; }

button.secondary {
  background: #eef0f3;
  color: var(--text);
}
button.secondary:hover:not(:disabled) { background: #e2e5ea; }

button.small {
  padding: 4px 8px;
  font-size: 12px;
  background: #eef0f3;
}

.hint {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

#blacklist-list {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  max-height: 140px;
  overflow-y: auto;
}
#blacklist-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  padding: 4px 6px;
  border-radius: 5px;
  background: #fef2f2;
  margin-bottom: 4px;
}
#blacklist-list li button {
  background: none;
  color: var(--danger);
  padding: 0 4px;
  font-size: 14px;
}

button.small.active,
#add-zone.active {
  background: var(--accent);
  color: #fff;
}

/* --- дропдаун плану + список зон --- */
#plan-select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}
#plan-params input:disabled { background: #f1f2f4; color: var(--text-muted); }

#areas-list {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}
#areas-list .area-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 4px;
}
.area-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 5px;
  background: #fff;
}
.area-item.active {
  border-color: #f59e0b;
  background: #fff7ed;
}
.area-item .area-main { flex: 1; cursor: pointer; }
.area-item .area-actions { display: flex; gap: 2px; }
.area-item .area-actions button {
  background: #eef0f3;
  color: var(--text);
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 12px;
  font-weight: 600;
}
.area-item .area-actions button:hover { background: #e2e5ea; }
.area-item .area-actions button[data-act="delete"] { color: var(--danger); }

#stats-detail { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ручки в кутках активного прямокутника зони */
.rect-handle {
  background: #f59e0b;
  border: 2px solid #b45309;
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  opacity: 0.9;
}
.rect-handle:hover { opacity: 1; background: #fbbf24; }
.rect-handle.d1 { cursor: nwse-resize; }
.rect-handle.d2 { cursor: nesw-resize; }

.mode-toggle {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.mode-toggle label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

#stats-box {
  background: #f7f8fa;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
}
#stats-box .big {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

#warnings {
  font-size: 12px;
  color: #92400e;
  background: #fef3c7;
  border-radius: 6px;
  padding: 8px 10px;
  display: none;
}
#warnings.visible { display: block; }

#status-line {
  font-size: 12px;
  color: var(--text-muted);
  min-height: 16px;
}

.progress-bar {
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  overflow: hidden;
  margin: 4px 0 8px 0;
}
.progress-bar-fill {
  height: 100%;
  width: 35%;
  border-radius: 3px;
  background: var(--accent);
  animation: progress-indeterminate 1.1s ease-in-out infinite;
}
@keyframes progress-indeterminate {
  0% { margin-left: -35%; }
  100% { margin-left: 100%; }
}

.leaflet-popup-content { font-size: 12.5px; }

/* --- модальний діалог вибору плану --- */
#plan-modal[hidden] { display: none; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(15, 20, 32, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-card {
  background: var(--panel-bg);
  border-radius: var(--radius);
  padding: 20px 22px;
  width: 340px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.35);
}
.modal-card h2 {
  font-size: 15px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  margin: 0 0 14px 0;
}
/* `button.small` задає світло-сірий фон, тож у комбінації primary+small кнопка
   виглядала сірою з білим текстом (наче задізейблена) - фіксуємо адресно */
#modal-open-plan {
  flex: 0 0 auto;
  width: auto;
  background: var(--accent);
  color: #fff;
}
#modal-open-plan:hover:not(:disabled) { background: var(--accent-hover); }
#modal-open-plan:disabled { background: #9ca3af; }

/* --- кнопка "карта висот дахів" + легенда --- */
/* висока специфічність - щоб перекрити і .leaflet-bar a (26px), і
   .leaflet-touch .leaflet-bar a (30px), інакше текст не влазить */
.leaflet-bar.height-toggle a,
.leaflet-touch .leaflet-bar.height-toggle a {
  width: auto;
  min-width: 0;
  height: auto;
  padding: 6px 12px;
  font: 600 12px/1.25 -apple-system, "Segoe UI", sans-serif;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}
.height-toggle.active a {
  background: #0d9488;
  color: #fff;
}

.height-legend {
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
  padding: 6px 8px;
  font-size: 11px;
  color: var(--text);
  line-height: 1.3;
}
.height-legend-title { font-weight: 600; margin-bottom: 4px; max-width: 150px; }
.height-legend-body { display: flex; gap: 6px; }
.height-legend-bar {
  width: 12px;
  height: 96px;
  border-radius: 2px;
  /* viridis: низько (низ) -> високо (верх) */
  background: linear-gradient(to top, #440154, #21908c, #fde725);
}
.height-legend-ticks {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

footer.assumptions {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
