/* ─── Design tokens ─── */
:root {
  --appbar-height: 60px;
  --page-bg: #eff4f9;
  --paper: #ffffff;
  --ink: #111827;
  --muted: #5f6b7a;
  --line: #d7e0eb;
  --accent: #2563eb;
  --accent-soft: rgba(37,99,235,0.10);
  --shadow: 0 4px 24px rgba(17,24,39,0.10);
  --sans: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sidebar-w: 320px;
}

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

html, body {
  margin: 0; padding: 0;
  height: 100%; width: 100%;
  overflow: hidden;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--page-bg);
}

/* ─── Map ─── */
#hw-map {
  position: fixed;
  top: var(--appbar-height, 60px);
  left: 0; right: 0; bottom: 0;
  z-index: 1;
}

/* ─── Sidebar ─── */
.hw-sidebar {
  position: fixed;
  top: var(--appbar-height, 60px);
  left: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--appbar-height, 60px));
  background: var(--paper);
  border-right: 1px solid var(--line);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateX(calc(-1 * var(--sidebar-w)));
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  box-shadow: var(--shadow);
}
.hw-sidebar.open { transform: translateX(0); }

.hw-sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(17,24,39,0.3);
  z-index: 199;
}
.hw-sidebar-overlay.open { display: block; }

.hw-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.hw-sidebar-title {
  font-size: 14px; font-weight: 700; color: var(--ink);
}
.hw-sidebar-count {
  font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
  padding: 2px 8px; border-radius: 20px;
}

.hw-sidebar-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
}
.hw-sidebar-list::-webkit-scrollbar { width: 4px; }
.hw-sidebar-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }

/* Establishment row in sidebar */
.hw-est-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(215,224,235,0.5);
  transition: background 0.12s;
}
.hw-est-row:hover { background: var(--accent-soft); }
.hw-est-row.dimmed { opacity: 0.35; }

.hw-est-icon {
  width: 32px; height: 32px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.hw-est-icon-restaurant { background: #eff6ff; }
.hw-est-icon-pool       { background: #ecfeff; }
.hw-est-icon-school     { background: #faf5ff; }

.hw-est-info { flex: 1; min-width: 0; }
.hw-est-name {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hw-est-addr {
  font-size: 11px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.hw-est-badge {
  font-size: 13px; font-weight: 800;
  padding: 3px 7px; border-radius: 6px;
  flex-shrink: 0;
}
.hw-badge-A { background: #dcfce7; color: #15803d; }
.hw-badge-B { background: #fef9c3; color: #a16207; }
.hw-badge-C { background: #ffedd5; color: #c2410c; }
.hw-badge-score { background: #f1f5f9; color: var(--ink); }

/* ─── Legend (Leaflet custom control) ─── */
.hw-legend {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: var(--sans);
  font-size: 12px;
  min-width: 172px;
  box-shadow: var(--shadow);
  user-select: none;
}
.hw-legend-title {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-bottom: 10px;
}
.hw-legend-group { margin-bottom: 10px; }
.hw-legend-group:last-child { margin-bottom: 0; }

.hw-legend-type {
  display: flex; align-items: center; gap: 7px;
  font-weight: 700; font-size: 12px;
  margin-bottom: 6px;
  cursor: pointer;
}
.hw-legend-type input[type=checkbox] {
  accent-color: var(--accent);
  width: 13px; height: 13px;
  cursor: pointer; flex-shrink: 0;
}
.hw-legend-type-icon { font-size: 14px; }

.hw-legend-item {
  display: flex; align-items: center; gap: 7px;
  margin-bottom: 4px; padding-left: 20px;
  color: var(--muted);
}
.hw-legend-swatch {
  width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
}
.hw-legend-swatch-diamond {
  width: 11px; height: 11px; flex-shrink: 0;
  transform: rotate(45deg);
  border-radius: 2px;
}
.hw-legend-swatch-square {
  width: 11px; height: 11px; flex-shrink: 0;
  border-radius: 3px;
}
.hw-legend-divider {
  border: none; border-top: 1px solid var(--line);
  margin: 8px 0;
}
.hw-legend-overdue {
  display: flex; align-items: center; gap: 7px;
  color: #ea580c; font-weight: 600;
}
.hw-legend-pulse {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid #f97316;
  animation: pulse-ring 1.5s ease-out infinite;
  flex-shrink: 0;
}

/* ─── Overdue pulse ─── */
@keyframes pulse-ring {
  0%   { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(2); opacity: 0; }
}
.hw-overdue-ring {
  position: absolute;
  top: -5px; left: -5px;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 3px solid #f97316;
  animation: pulse-ring 1.5s ease-out infinite;
  pointer-events: none;
}

/* ─── Modal ─── */
.hw-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(17,24,39,0.5);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  backdrop-filter: blur(2px);
}
.hw-modal-overlay.hidden { display: none; }

.hw-modal {
  background: var(--paper);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(17,24,39,0.20);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

.hw-modal-close {
  position: absolute; top: 14px; right: 14px;
  background: var(--line); border: none;
  border-radius: 50%; width: 28px; height: 28px;
  cursor: pointer; font-size: 13px; font-weight: 700;
  color: var(--muted); display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  z-index: 1;
}
.hw-modal-close:hover { background: #cbd5e1; }

.hw-modal-body { padding: 20px 22px 24px; }

/* Modal: login prompt */
.hw-modal-login {
  text-align: center;
  padding: 32px 20px;
}
.hw-modal-login-icon { font-size: 40px; margin-bottom: 12px; }
.hw-modal-login-title {
  font-size: 18px; font-weight: 800; margin-bottom: 8px;
}
.hw-modal-login-sub {
  font-size: 14px; color: var(--muted); margin-bottom: 20px; line-height: 1.6;
}
.hw-modal-login-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 22px;
  background: var(--accent); color: white;
  border: none; border-radius: 8px;
  font-size: 14px; font-weight: 700;
  cursor: pointer; transition: background 0.15s;
  font-family: var(--sans);
}
.hw-modal-login-btn:hover { background: #1d4ed8; }

/* Modal: detail content */
.hw-modal-type-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; margin-bottom: 8px;
}
.hw-type-restaurant { background: #eff6ff; color: #1d4ed8; }
.hw-type-pool       { background: #ecfeff; color: #0e7490; }
.hw-type-school     { background: #faf5ff; color: #7e22ce; }

.hw-modal-name {
  font-size: 22px; font-weight: 800; line-height: 1.2;
  margin-bottom: 4px;
}
.hw-modal-addr { font-size: 13px; color: var(--muted); margin-bottom: 16px; }

.hw-modal-scores {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px;
}
.hw-grade-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border-radius: 12px;
  font-size: 24px; font-weight: 800;
}
.hw-grade-A { background: #dcfce7; color: #15803d; }
.hw-grade-B { background: #fef9c3; color: #a16207; }
.hw-grade-C { background: #ffedd5; color: #c2410c; }
.hw-grade-none { background: #f1f5f9; color: var(--ink); font-size: 18px; }

.hw-modal-section { margin-bottom: 16px; }
.hw-modal-section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--muted);
  margin-bottom: 6px;
}
.hw-modal-meta { font-size: 13px; color: var(--ink); line-height: 1.8; }

/* Sparkline */
.hw-sparkline { display: block; margin-top: 4px; }

/* Trend */
.hw-trend {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 700; margin-top: 6px;
  padding: 3px 8px; border-radius: 20px;
}
.hw-trend-up    { background: #dcfce7; color: #15803d; }
.hw-trend-down  { background: #fee2e2; color: #b91c1c; }
.hw-trend-flat  { background: #f1f5f9; color: var(--muted); }

/* Violations */
.hw-violation {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(215,224,235,0.5);
  font-size: 13px;
}
.hw-violation:last-child { border-bottom: none; }
.hw-viol-dot {
  width: 8px; height: 8px; border-radius: 50%;
  margin-top: 4px; flex-shrink: 0;
}
.hw-viol-critical { background: #dc2626; }
.hw-viol-major    { background: #d97706; }
.hw-viol-minor    { background: #2563eb; }
.hw-viol-text { flex: 1; line-height: 1.5; }
.hw-viol-status {
  font-size: 11px; font-weight: 600; flex-shrink: 0;
  padding: 2px 6px; border-radius: 20px;
}
.hw-viol-corrected   { background: #dcfce7; color: #15803d; }
.hw-viol-uncorrected { background: #fee2e2; color: #b91c1c; }

.hw-modal-pdf {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 12px;
  padding: 9px 18px;
  background: var(--accent); color: white;
  border: none; border-radius: 8px;
  font-size: 13px; font-weight: 700;
  text-decoration: none; cursor: pointer;
  transition: background 0.15s;
}
.hw-modal-pdf:hover { background: #1d4ed8; }

.hw-overdue-banner {
  display: flex; align-items: center; gap: 7px;
  background: #fff7ed; color: #c2410c;
  border: 1px solid #fed7aa;
  border-radius: 8px; padding: 8px 12px;
  font-size: 12px; font-weight: 600; margin-bottom: 14px;
}
