/* Auckland Waste & Recycling Services — civic utility styling */

:root {
  --ink: #17211c;
  --ink-soft: #46534c;
  --ink-faint: #6b7a72;
  --paper: #f6f7f5;
  --card: #ffffff;
  --line: #dde3de;
  --line-soft: #eaeeea;
  --accent: #0e7a4e;
  --accent-ink: #0b5c3c;
  --error: #b42318;
  --warn-bg: #fdf3e7;
  --warn-line: #eed9bd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(23, 33, 28, 0.06), 0 4px 14px rgba(23, 33, 28, 0.07);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---------- header ---------- */

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  z-index: 20;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1600px;
  margin: 0 auto;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  flex: none;
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-sub {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--ink-faint);
}

.topbar-status { display: flex; align-items: center; gap: 10px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  background: var(--paper);
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #9aa7a0;
}

.status-live::before { background: #16a34a; }
.status-cache::before { background: #2563eb; }
.status-stale { border-color: #f0c8c2; background: #fdf0ee; color: var(--error); }
.status-stale::before { background: var(--error); }
.status-loading::before { background: #d97706; animation: pulse 1.1s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  min-height: 36px;
}

.btn:hover { background: var(--paper); border-color: #c9d2cb; }
.btn:active { transform: translateY(1px); }
.btn-small { padding: 5px 11px; min-height: 32px; font-size: 12.5px; margin-top: 8px; }
.btn-ghost { background: transparent; }
.refresh-icon { font-size: 14px; }

/* ---------- layout ---------- */

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

.map-wrap { position: relative; flex: 1; min-width: 0; }

#map { position: absolute; inset: 0; background: #e8ece8; }

.panel {
  width: 380px;
  flex: none;
  background: var(--paper);
  border-left: 1px solid var(--line);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-scroll { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }

.panel-toggle { display: none; }

/* ---------- cards ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
}

.muted-card p { font-size: 13.5px; line-height: 1.55; color: var(--ink-soft); margin: 0 0 8px; }
.muted-small { font-size: 12px !important; color: var(--ink-faint) !important; margin: 8px 0 0 !important; }

/* ---------- search ---------- */

.search-box { position: relative; }

#address-input {
  width: 100%;
  font: inherit;
  font-size: 15px;
  padding: 11px 38px 11px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

#address-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 122, 78, 0.14);
  background: #fff;
}

.address-clear {
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
}

.address-clear:hover { color: var(--ink); background: var(--line-soft); }

.address-results {
  list-style: none;
  margin: 8px 0 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  box-shadow: 0 8px 24px rgba(23, 33, 28, 0.12);
  max-height: 264px;
  overflow-y: auto;
}

.address-results li {
  padding: 10px 11px;
  font-size: 13.5px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.35;
}

.address-results li:hover,
.address-results li:focus { background: #eef4f0; outline: none; }
.address-results li.addr-busy { color: var(--ink-faint); cursor: default; }
.address-results li.addr-busy:hover { background: transparent; }

.search-note { font-size: 12.5px; color: var(--ink-faint); margin: 8px 2px 0; line-height: 1.45; }
.search-note.note-error { color: var(--error); }

/* ---------- result cards ---------- */

.lookup-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: var(--ink-soft);
  padding: 6px 0 2px;
}

.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}

.spinner-dark { border-color: #d3dad4; border-top-color: var(--ink-soft); }

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

.notice {
  border-radius: 8px;
  padding: 11px 13px;
  font-size: 13.5px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 4px 0 8px;
}

.notice span { color: var(--ink-soft); font-size: 12.8px; }
.notice-error { background: #fdf0ee; border: 1px solid #f0c8c2; color: var(--error); }
.notice-empty { background: #f2f4f2; border: 1px solid var(--line); color: var(--ink); }
.notice-warn { background: var(--warn-bg); border: 1px solid var(--warn-line); color: #8a5a13; }
.notice-warn span { color: #96702f; }

.summary-row {
  display: flex;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
  align-items: flex-start;
}

.summary-row:last-of-type { border-bottom: none; }

.dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--dot, #999);
  margin-top: 4px;
  flex: none;
}

.summary-primary { margin: 0; font-size: 13.8px; line-height: 1.5; }
.summary-extra { margin: 2px 0 0; font-size: 12.3px; color: var(--ink-faint); }

.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--chip);
  border: 1px solid var(--chip);
  border-radius: 5px;
  padding: 3px 7px;
}

.detail-head { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.detail-name { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -0.01em; }
.detail-lead { font-size: 13.8px; line-height: 1.55; color: var(--ink-soft); margin: 10px 0; }

.field-table { border-top: 1px solid var(--line-soft); margin-top: 4px; }

.field-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
}

.field-label { color: var(--ink-faint); flex: none; }
.field-value { text-align: right; font-weight: 550; word-break: break-word; }

/* ---------- layers card ---------- */

.layers-head { display: flex; align-items: baseline; justify-content: space-between; }
.feature-count { font-size: 12px; color: var(--ink-faint); }

.layer-list { display: flex; flex-direction: column; gap: 4px; }

.layer-row { padding: 7px 6px; border-radius: 8px; transition: background 0.12s ease; }
.layer-row:hover { background: var(--line-soft); }

.layer-main {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-height: 34px;
}

.layer-main input[type="checkbox"] {
  width: 17px; height: 17px;
  accent-color: var(--accent);
  cursor: pointer;
  flex: none;
}

.layer-label { font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.layer-count { font-weight: 400; color: var(--ink-faint); font-size: 12px; }

.layer-desc {
  margin: 3px 0 0 27px;
  font-size: 12px;
  color: var(--ink-faint);
  line-height: 1.45;
}

.sub-legend {
  margin: 6px 0 2px 27px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.sub-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-soft);
}

/* ---------- map overlay / tip ---------- */

.map-overlay[hidden] { display: none !important; }

.map-overlay {
  position: absolute;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(246, 247, 245, 0.72);
  backdrop-filter: blur(2px);
}

.overlay-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 20px;
  box-shadow: var(--shadow);
  font-size: 14px;
  max-width: min(420px, 86vw);
  line-height: 1.5;
}

.overlay-card p { margin: 0; }

.map-tip {
  position: absolute;
  left: 14px;
  bottom: 16px;
  z-index: 800;
  background: rgba(23, 33, 28, 0.88);
  color: #f2f5f2;
  font-size: 12.8px;
  line-height: 1.5;
  padding: 9px 13px;
  border-radius: 9px;
  max-width: 320px;
  box-shadow: var(--shadow);
  animation: tip-in 0.5s ease 0.4s backwards;
}

@keyframes tip-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- footer ---------- */

.footer {
  border-top: 1px solid var(--line);
  background: var(--card);
  padding: 10px 16px;
}

.footer p {
  margin: 0 auto;
  max-width: 1600px;
  font-size: 11.8px;
  color: var(--ink-faint);
  line-height: 1.6;
}

.footer a { color: var(--accent-ink); }
.footer code {
  font-size: 11px;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  padding: 0 4px;
}

/* ---------- leaflet polish ---------- */

.leaflet-container { font-family: var(--font); }

/* Polygons respond on their borders only — a tap inside an area should run
 * the point lookup, not get swallowed by a fill. */
.leaflet-pane svg path.leaflet-interactive {
  pointer-events: visibleStroke;
}

.leaflet-control-layers,
.leaflet-bar a {
  border-radius: 8px !important;
  border-color: var(--line) !important;
}

.leaflet-bar a { width: 34px !important; height: 34px !important; line-height: 34px !important; }

.leaflet-control-attribution {
  font-size: 10.5px;
  background: rgba(255, 255, 255, 0.82) !important;
}

/* ---------- mobile ---------- */

@media (max-width: 820px) {
  .topbar { padding: 9px 12px; }
  .brand-mark { width: 32px; height: 32px; font-size: 18px; }
  .brand-text h1 { font-size: 14.5px; white-space: normal; }
  .brand-sub { font-size: 11px; }
  .topbar-status { gap: 7px; }
  .status-pill { font-size: 11px; padding: 4px 9px; }
  #refresh-btn { font-size: 0; padding: 6px 10px; min-height: 40px; }
  #refresh-btn .refresh-icon { font-size: 17px; }

  .layer-main input[type="checkbox"] { width: 20px; height: 20px; }

  .layout { flex-direction: column; }
  .map-wrap { flex: 1; }

  .panel {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: 62vh;
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    background: var(--paper);
    box-shadow: 0 -8px 28px rgba(23, 33, 28, 0.18);
    z-index: 950;
    transform: translateY(calc(100% - 0px));
    transition: transform 0.3s ease;
    visibility: hidden;
  }

  .panel.open { transform: translateY(0); visibility: visible; }
  .panel-scroll { padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); }

  .panel-toggle {
    display: flex;
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    z-index: 960;
    align-items: center;
    gap: 8px;
    font: inherit;
    font-size: 13.5px;
    font-weight: 650;
    color: #fff;
    background: #243028;
    border: none;
    border-radius: 999px;
    padding: 11px 18px;
    box-shadow: 0 4px 16px rgba(23, 33, 28, 0.35);
    cursor: pointer;
    min-height: 44px;
    transition: bottom 0.3s ease;
  }

  .panel-toggle .chevron {
    width: 9px; height: 9px;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transform: rotate(45deg);
    margin-top: -4px;
    transition: transform 0.25s ease;
  }

  .panel-toggle.open { bottom: calc(62vh + 10px); }
  .panel-toggle.open .chevron { transform: rotate(225deg); margin-top: 2px; }

  .map-tip { left: 10px; right: 96px; bottom: 72px; max-width: none; font-size: 12.3px; }

  .footer { display: none; }
}
