/* Web preglednik za zagreb-parkiralista. Mobile-first, fullscreen Leaflet karta
   s overlay-panelima za slojeve, headline statistikom i tablicom totala po
   administrativnim razinama. */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #1a1a1a;
  background: #f5f5f5;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* Top bar — title + headline stats */
#topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-bottom: 1px solid #e0e0e0;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#topbar h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
}

.topbar-title-text {
  white-space: nowrap;
}

.topbar-tagline {
  font-size: 11px;
  font-weight: 400;
  color: #6b7280;
  margin-left: 6px;
}

#headline-stats {
  display: flex;
  gap: 18px;
  align-items: baseline;
}

.headline-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.1;
  gap: 1px;
}

.headline-stat-value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #1e3a8a;
}

.headline-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
}

.headline-stat-sub {
  font-size: 10px;
  color: #6b7280;
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
}

/* Layer + admin panel */
.panel {
  position: absolute;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid #d8d8d8;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  font-size: 13px;
}

#legend {
  top: 72px;
  right: 12px;
  max-width: 240px;
}

.panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #666;
  margin: 0 0 8px;
  font-weight: 600;
}

.panel h2:not(:first-child) {
  margin-top: 14px;
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  cursor: pointer;
  user-select: none;
}

.layer-toggle input[type="checkbox"] { margin: 0; }
.layer-toggle input:disabled + .swatch { opacity: 0.35; }
.layer-toggle input:disabled ~ .layer-label { color: #999; }

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.swatch-open { background: #2563eb; }
.swatch-enclosed { background: #7c3aed; border-color: #581c87; }
.swatch-ml { background: #f59e0b; }
.swatch-informal { background: #dc2626; }
.layer-link {
  font-size: 0.72rem;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  background: #1d4ed8;
  border-radius: 4px;
  padding: 0.2rem 0.6rem;
  margin-left: 0.3rem;
  display: inline-block;
  cursor: pointer;
}
.layer-link:hover { background: #1e40af; }

.swatch-street-view { background: #64748b; border-color: #334155; }
.swatch-street-view-pending { background: #8b5cf6; border-color: #4c1d95; }
.swatch-street-view-suspect { background: #fbbf24; border-color: #b45309; }
.swatch-llm { background: #14b8a6; border-color: #134e4a; }
.swatch-llm-anthropic { background: #14b8a6; border-color: #134e4a; }
.swatch-llm-openai { background: #ec4899; border-color: #831843; }

.layer-group {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px dashed #e5e7eb;
}

.layer-group-label {
  font-size: 11px;
  color: #555;
  font-weight: 600;
  margin-bottom: 4px;
  margin-left: 2px;
}

.layer-toggle-sub {
  margin-left: 14px;
  font-size: 12px;
}

/* Per-type breakdown shown beneath the informal layer toggle. Populated from
   the informal_by_type metadata block produced by 20_detect_informal.py. */
.informal-breakdown {
  margin: 4px 0 0 24px;
  padding-left: 4px;
  border-left: 2px solid #e5e7eb;
}

.informal-breakdown .informal-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  font-size: 11px;
}

.informal-breakdown .informal-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid #1f2937;
  flex-shrink: 0;
}

.informal-breakdown .informal-label {
  flex: 1;
  color: #4b5563;
}

.layer-label { flex: 1; }

.count {
  color: #888;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}

/* Capacity colour scale */
.capacity-scale {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
}

.cap-cell {
  font-size: 10px;
  padding: 4px 2px;
  text-align: center;
  color: white;
  border-radius: 2px;
}

.cap-cell.c1 { background: #cfe2ff; color: #1e3a8a; }
.cap-cell.c2 { background: #93c5fd; color: #1e3a8a; }
.cap-cell.c3 { background: #3b82f6; }
.cap-cell.c4 { background: #1d4ed8; }
.cap-cell.c5 { background: #1e3a8a; }

/* Admin level dropdown — sits at the top of the totals panel as the control
   that drives what the rest of the panel shows. */
.admin-control {
  padding: 12px 12px 10px;
  border-bottom: 1px solid #e8e8e8;
}

.admin-control h2 {
  margin: 0 0 6px;
}

.admin-select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: white;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.admin-status {
  margin-top: 6px;
  font-size: 11px;
  color: #888;
  font-style: italic;
  min-height: 14px;
}

/* Totals panel — left side, always visible. The admin-control header is
   permanent; the totals-content beneath collapses to nothing when "Cijeli grad"
   is selected. */
.totals-panel {
  top: 72px;
  left: 12px;
  width: 360px;
  max-height: calc(100vh - 90px);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.totals-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.totals-content[hidden] { display: none; }

.totals-header {
  padding: 10px 12px 6px;
  border-bottom: 1px solid #f0f0f0;
}

.totals-header h2 {
  font-size: 14px;
  text-transform: none;
  letter-spacing: normal;
  color: #1a1a1a;
  margin: 0;
  font-weight: 600;
}

.totals-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid #f0f0f0;
}

.totals-summary {
  font-size: 11px;
  color: #666;
}

.totals-sort {
  font-size: 11px;
  border: 1px solid #d8d8d8;
  border-radius: 3px;
  padding: 3px 6px;
  background: white;
  cursor: pointer;
}

.totals-table-wrap {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.totals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.totals-table thead {
  position: sticky;
  top: 0;
  background: #f7f9fc;
  z-index: 1;
}

.totals-table th {
  text-align: left;
  padding: 6px 6px;
  font-weight: 600;
  color: #555;
  border-bottom: 1px solid #e0e0e0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.totals-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.totals-table th.sortable:hover {
  color: #1d4ed8;
}

.totals-table th.sort-active {
  color: #1d4ed8;
}

.totals-table th:first-child,
.totals-table td:first-child {
  padding-left: 10px;
}

.totals-table th:last-child,
.totals-table td:last-child {
  padding-right: 10px;
}

.totals-table th.num,
.totals-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.totals-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

.totals-table tbody tr:hover {
  background: #eef2ff;
}

.totals-table tbody tr.selected {
  background: #dbeafe;
}

.totals-table td {
  padding: 6px 6px;
  border-bottom: 1px solid #f3f3f3;
  font-size: 11px;
}

.totals-table td:first-child {
  font-weight: 500;
  font-size: 12px;
}

.totals-table td.num.muted {
  color: #b8b8b8;
}

/* Source-tile preview shown in informal parking popups. The popup shows a
   256×256 crop of the original CDOF tile centered on the detected car, with a
   red bbox overlay marking the YOLO detection. Background-position trick avoids
   needing pre-cropped images on disk. */
.tile-crop {
  width: 256px;
  height: 256px;
  background-size: 1024px 1024px;
  background-repeat: no-repeat;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  margin: 8px 0 6px;
  position: relative;
  overflow: hidden;
}

.tile-crop-bbox {
  position: absolute;
  border: 2px solid #ff2c2c;
  background: rgba(255, 44, 44, 0.15);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6) inset;
  pointer-events: none;
  border-radius: 1px;
}

.tile-crop-caption {
  font-size: 10px;
  color: #888;
  text-align: center;
  margin: -2px 0 4px;
  font-variant-numeric: tabular-nums;
}

/* Custom Leaflet marker for OSM enclosed parking nodes (underground / multi-storey
   garages mapped as a single point because they have no surface footprint). */
.parking-pin {
  background: transparent !important;
  border: none !important;
}

.parking-pin-inner {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #7c3aed;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  color: white;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  letter-spacing: -0.5px;
}

.parking-pin-inner.parking-pin-small {
  width: 18px;
  height: 18px;
  font-size: 10px;
}

/* Popup styling for parking polygon clicks */
.popup-table {
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 6px;
}

.popup-table th {
  text-align: left;
  font-weight: 500;
  color: #666;
  padding: 2px 8px 2px 0;
  vertical-align: top;
}

.popup-table td { padding: 2px 0; }
.popup-table a { color: #2563eb; }

a.popup-review-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: #1d4ed8;
  border-radius: 4px;
  padding: 3px 8px;
  text-decoration: none;
}
.popup-review-link:hover { background: #1e40af; }

/* Formality cross-filter — formal / informal checkboxes in the topbar */
.formality-filter {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}

.formality-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: #374151;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.formality-label input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

/* Mobile toggle buttons — hidden on desktop */
.mobile-toggles {
  display: none;
}

.mobile-toggle-btn {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-family: inherit;
}

.mobile-toggle-btn.active {
  background: #1d4ed8;
  color: #fff;
  border-color: #1d4ed8;
}

/* Mobile breakpoint */
@media (max-width: 720px) {
  #topbar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
  }

  #topbar h1 { font-size: 14px; }
  .topbar-tagline { font-size: 9px; }

  .formality-filter { gap: 8px; }
  .formality-label { font-size: 11px; }

  .mobile-toggles {
    display: flex;
    gap: 4px;
  }

  #headline-stats {
    gap: 14px;
    width: 100%;
    justify-content: space-between;
    order: 3;
  }

  .headline-stat { align-items: flex-start; }
  .headline-stat-value { font-size: 16px; }

  #legend {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    max-width: none;
    border-radius: 12px 12px 0 0;
    max-height: 55vh;
    overflow-y: auto;
    display: none;
  }

  #legend.mobile-open {
    display: block;
  }

  .totals-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-height: 55vh;
    border-radius: 12px 12px 0 0;
    display: none;
  }

  .totals-panel.mobile-open {
    display: flex;
  }
}
