/* ============================================================
   HydrantMap UK — Stylesheet
   ============================================================ */

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

:root {
  --red:        #C0221B;
  --red-dark:   #9a1a14;
  --green:      #22a05a;
  --green-bg:   #e3f5ec;
  --green-text: #166035;
  --amber:      #e8930a;
  --amber-bg:   #fef3e2;
  --amber-text: #7a4a05;
  --grey:       #888780;
  --grey-bg:    #ebebeb;
  --grey-text:  #555;

  --bg:         #f5f5f4;
  --surface:    #ffffff;
  --border:     #e2e2e0;
  --border-lt:  #ececea;
  --text:       #1a1a18;
  --text-2:     #6b6b68;
  --text-3:     #9e9e9b;

  --radius-sm:  6px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,.1), 0 1px 3px rgba(0,0,0,.06);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

/* ── Layout ─────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Topbar ─────────────────────────────────────────────── */
#topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
  user-select: none;
}
.logo-icon {
  width: 30px; height: 30px;
  background: var(--red);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.search-wrap {
  flex: 1;
  position: relative;
  max-width: 420px;
}
.search-wrap svg {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}
#search-input {
  width: 100%;
  padding: 7px 12px 7px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#search-input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(192,34,27,.12);
}
#search-input::placeholder { color: var(--text-3); }

#search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 2000;
  overflow: hidden;
  display: none;
}
#search-results.open { display: block; }
.search-result-item {
  padding: 9px 14px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-lt);
  color: var(--text);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg); }
.search-result-sub { font-size: 11px; color: var(--text-2); margin-top: 1px; }

.topbar-actions { display: flex; gap: 8px; margin-left: auto; }

.btn {
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg); }
.btn-primary {
  background: var(--red);
  color: white;
  border-color: var(--red);
}
.btn-primary:hover { background: var(--red-dark); border-color: var(--red-dark); }

/* ── Body ───────────────────────────────────────────────── */
#body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────── */
#sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-filters {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-lt);
}
.filter-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-2);
  margin-bottom: 8px;
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
}
.filter-row:last-child { margin-bottom: 0; }

.pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  transition: background .1s, color .1s, border-color .1s;
}
.pill:hover { border-color: var(--text-3); color: var(--text); }
.pill.active { background: var(--red); color: white; border-color: var(--red); }
.pill.active-grey { background: var(--grey); color: white; border-color: var(--grey); }

.sidebar-list-header {
  padding: 10px 14px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.list-count { font-size: 12px; color: var(--text-2); }

#hydrant-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}
#hydrant-list::-webkit-scrollbar { width: 4px; }
#hydrant-list::-webkit-scrollbar-track { background: transparent; }
#hydrant-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.hydrant-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-bottom: 2px;
  border: 1px solid transparent;
  transition: background .1s;
}
.hydrant-item:hover { background: var(--bg); border-color: var(--border-lt); }
.hydrant-item.selected { background: var(--bg); border-color: var(--border); }

.h-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-active      { background: var(--green); }
.dot-inactive    { background: var(--grey); }
.dot-maintenance { background: var(--amber); }
.dot-unknown     { background: #ccc; }

.h-info { flex: 1; min-width: 0; }
.h-id   { font-size: 13px; font-weight: 500; color: var(--text); }
.h-addr { font-size: 11px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 12px;
  flex-shrink: 0;
}
.badge-active      { background: var(--green-bg);  color: var(--green-text); }
.badge-inactive    { background: var(--grey-bg);    color: var(--grey-text); }
.badge-maintenance { background: var(--amber-bg);   color: var(--amber-text); }
.badge-unknown     { background: #f0f0ee;            color: var(--text-2); }

/* Empty / loading states */
.list-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-2);
  font-size: 13px;
}
.list-state .state-icon { font-size: 28px; margin-bottom: 8px; }
.list-state .state-title { font-weight: 500; color: var(--text); margin-bottom: 4px; }
.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Map ────────────────────────────────────────────────── */
#map-wrap { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }

/* Leaflet overrides */
.leaflet-container { font-family: inherit; }
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 0;
  overflow: hidden;
}
.leaflet-popup-content { margin: 0; }
.leaflet-popup-tip-container { display: none; }

/* Map overlays */
.map-control-group {
  position: absolute;
  z-index: 900;
}
.map-control-group.top-right { top: 12px; right: 12px; display: flex; flex-direction: column; gap: 6px; }
.map-control-group.bottom-left { bottom: 12px; left: 12px; }

.map-btn {
  width: 34px; height: 34px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
  transition: background .1s;
  user-select: none;
}
.map-btn:hover { background: var(--bg); }

/* Legend */
.map-legend {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
  font-size: 11px;
}
.legend-title { font-weight: 600; color: var(--text-2); margin-bottom: 7px; text-transform: uppercase; letter-spacing: .04em; }
.legend-row { display: flex; align-items: center; gap: 7px; color: var(--text-2); margin-bottom: 4px; }
.legend-row:last-child { margin-bottom: 0; }

/* Detail panel */
#detail-panel {
  position: absolute;
  bottom: 12px; right: 12px;
  width: 224px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-md);
  z-index: 800;
  display: none;
}
#detail-panel.open { display: block; }
.detail-close {
  position: absolute;
  top: 10px; right: 10px;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-3);
  font-size: 14px;
  transition: background .1s;
}
.detail-close:hover { background: var(--bg); color: var(--text); }
.detail-id { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 10px; padding-right: 24px; }
.detail-status { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 500; margin-bottom: 12px; }
.detail-row { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; gap: 8px; }
.detail-row:last-child { margin-bottom: 0; }
.d-label { font-size: 12px; color: var(--text-2); }
.d-val   { font-size: 12px; font-weight: 500; color: var(--text); text-align: right; max-width: 140px; }
.detail-actions { margin-top: 12px; display: flex; gap: 6px; }
.detail-actions .btn { flex: 1; padding: 6px 10px; font-size: 11px; text-align: center; }

/* ── Stats bar ──────────────────────────────────────────── */
#statsbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 16px;
  height: 38px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-2);
  z-index: 100;
}
.stat-item strong { color: var(--text); font-weight: 600; }
.stat-item.green  strong { color: var(--green-text); }
.stat-item.amber  strong { color: var(--amber-text); }
.stat-item.grey   strong { color: var(--grey-text);  }
#data-source-label { margin-left: auto; font-size: 11px; color: var(--text-3); }

/* ── Data source banner ─────────────────────────────────── */
#data-banner {
  position: absolute;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
  z-index: 800;
  white-space: nowrap;
  display: none;
}
#data-banner.visible { display: flex; align-items: center; gap: 8px; }
#data-banner .spinner { width: 14px; height: 14px; border-width: 1.5px; margin: 0; }

/* ── Report modal ───────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
}
#modal-overlay.open { display: flex; }
#modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
  position: relative;
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.modal-sub   { font-size: 13px; color: var(--text-2); margin-bottom: 18px; }
.form-group  { margin-bottom: 14px; }
.form-label  { font-size: 12px; font-weight: 500; color: var(--text); margin-bottom: 5px; display: block; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(192,34,27,.1);
}
.form-textarea { resize: vertical; min-height: 80px; }
.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-3);
  font-size: 18px;
  transition: background .1s;
}
.modal-close:hover { background: var(--bg); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ── Custom marker styles ───────────────────────────────── */
.h-marker {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2.5px solid white;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
  display: flex; align-items: center; justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: white;
  cursor: pointer;
}
.h-marker.active      { background: var(--green); }
.h-marker.inactive    { background: var(--grey);  }
.h-marker.maintenance { background: var(--amber); }
.h-marker.unknown     { background: #aaa; }
.h-marker.selected    { transform: scale(1.3); z-index: 1000 !important; }

/* Cluster markers */
.marker-cluster-custom {
  background: rgba(192,34,27,.15);
  border: 2px solid rgba(192,34,27,.4);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--red-dark);
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 640px) {
  #sidebar { width: 100%; position: absolute; bottom: 0; left: 0; right: 0; z-index: 700; max-height: 40vh; border-right: none; border-top: 1px solid var(--border); }
  #body { position: relative; }
  #map-wrap { width: 100%; }
}
