/* ParkKing public site (PAR-68): city map `/` and parking page `/parking/<id>`.
   Tokens follow the admin console (frontend/src/index.css) so both read as one product. */

:root {
  --bg-primary: #f8f9fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f3f5;
  --bg-hover: #eceef1;
  --text-primary: #1c1c1c;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --accent: #3ecf8e;
  --accent-hover: #2eb872;
  --accent-dark: #249961;
  --accent-subtle: rgba(62, 207, 142, 0.12);
  --status-free: #3ecf8e;
  --status-busy: #ef4444;
  --status-warning: #f59e0b;
  --status-unknown: #9ca3af;
  --border: #e5e7eb;
  --border-subtle: #f0f1f2;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  --radius-sm: 6px;
  --topbar-h: 56px;
  --panel-w: 400px;
  --t-fast: 100ms ease;
  --t-base: 180ms ease;
  --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);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font: inherit; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── shell ─────────────────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar {
  flex: 0 0 var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 600; font-size: 16px; letter-spacing: -0.01em; }
.brand img { width: 28px; height: 28px; display: block; }
.brand-city { color: var(--text-secondary); font-weight: 400; font-size: 14px; padding-left: 10px; border-left: 1px solid var(--border); }
.topbar-spacer { flex: 1; }
.topbar-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: var(--radius-sm);
  color: var(--text-secondary); text-decoration: none; font-weight: 500;
  transition: background var(--t-fast), color var(--t-fast);
}
.topbar-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.topbar-link svg { width: 16px; height: 16px; }

.layout { flex: 1; display: flex; min-height: 0; }
.panel {
  flex: 0 0 var(--panel-w);
  display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
}
.panel-scroll { flex: 1; overflow-y: auto; }
.map-wrap { flex: 1; position: relative; min-width: 0; }
.map { position: absolute; inset: 0; background: var(--bg-tertiary); }

/* ── city list ─────────────────────────────────────────────────────────── */
.panel-head { padding: 20px 20px 12px; border-bottom: 1px solid var(--border-subtle); }
.panel-title { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.panel-sub { margin: 4px 0 14px; color: var(--text-secondary); }
.search {
  width: 100%; height: 38px; padding: 0 12px 0 36px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-primary) no-repeat 12px 50%/16px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  font-size: 14px; color: var(--text-primary);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); background-color: var(--bg-secondary); }
.chips { display: flex; gap: 6px; margin-top: 10px; }
.chip {
  padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-secondary); color: var(--text-secondary); font-size: 13px; cursor: pointer;
  transition: all var(--t-fast);
}
.chip:hover { color: var(--text-primary); }
.chip[aria-pressed="true"] { background: var(--text-primary); border-color: var(--text-primary); color: #fff; }

.list { list-style: none; margin: 0; padding: 6px 0; }
.card {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px; text-decoration: none;
  border-left: 3px solid transparent;
  transition: background var(--t-fast);
}
.card:hover, .card.is-active { background: var(--bg-tertiary); }
.card.is-active { border-left-color: var(--accent); }
.card-body { flex: 1; min-width: 0; }
.card-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; align-items: center; gap: 6px; margin-top: 3px; color: var(--text-secondary); font-size: 12.5px; }
.card-addr { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-count { text-align: right; flex: 0 0 auto; }
.card-free { font-size: 22px; font-weight: 600; line-height: 1; letter-spacing: -0.02em; }
.card-total { color: var(--text-tertiary); font-size: 12px; margin-top: 3px; }
.card.is-offline .card-free { color: var(--text-tertiary); font-size: 15px; font-weight: 500; }
.card.is-low .card-free { color: var(--status-warning); }
.empty { padding: 40px 20px; text-align: center; color: var(--text-secondary); }

/* ── status dot ────────────────────────────────────────────────────────── */
.dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--status-unknown); }
.dot.live { background: var(--status-free); box-shadow: 0 0 0 0 rgba(62, 207, 142, 0.6); animation: pulse 2s infinite; }
.dot.stale { background: var(--status-warning); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(62, 207, 142, 0.55); }
  70% { box-shadow: 0 0 0 6px rgba(62, 207, 142, 0); }
  100% { box-shadow: 0 0 0 0 rgba(62, 207, 142, 0); }
}
@media (prefers-reduced-motion: reduce) { .dot.live { animation: none; } }

/* ── map markers ───────────────────────────────────────────────────────── */
.pin {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-width: 34px; height: 28px; padding: 0 9px;
  border-radius: 999px; border: 2px solid #fff;
  background: var(--status-free); color: #fff;
  font: 600 13px/1 var(--font); font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow-md); white-space: nowrap;
  transform: translate(-50%, -50%);
  transition: transform var(--t-base);
}
.pin.low { background: var(--status-warning); }
.pin.stale { background: var(--status-warning); }
.pin.offline { background: var(--text-tertiary); }
.pin.is-active { transform: translate(-50%, -50%) scale(1.18); background: var(--text-primary); }
.pin-p { opacity: 0.75; font-weight: 700; }
.leaflet-div-icon.pin-icon { background: none; border: none; }

.legend {
  position: absolute; z-index: 500; left: 12px; bottom: 24px;
  display: flex; gap: 12px; flex-wrap: wrap;
  padding: 8px 12px; border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.94); box-shadow: var(--shadow-sm); border: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-secondary);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ── parking page ──────────────────────────────────────────────────────── */
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); text-decoration: none; font-weight: 500; margin-bottom: 14px; }
.back:hover { color: var(--text-primary); }
.back svg { width: 16px; height: 16px; }
.section { padding: 20px; border-bottom: 1px solid var(--border-subtle); }
.p-title { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.25; }
.p-addr { margin: 6px 0 0; color: var(--text-secondary); }

.avail { padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-secondary); box-shadow: var(--shadow-sm); }
.avail-row { display: flex; align-items: baseline; gap: 10px; }
.avail-free { font-size: 48px; font-weight: 650; line-height: 1; letter-spacing: -0.03em; }
.avail-label { color: var(--text-secondary); font-size: 15px; }
.avail.is-offline .avail-free { font-size: 22px; color: var(--text-secondary); font-weight: 600; }
.bar { display: flex; height: 8px; margin: 16px 0 10px; border-radius: 999px; overflow: hidden; background: var(--bg-tertiary); }
.bar > span { display: block; height: 100%; transition: width var(--t-base); }
.bar .b-free { background: var(--status-free); }
.bar .b-busy { background: var(--status-busy); }
.bar .b-unknown { background: var(--status-unknown); opacity: 0.45; }
.avail-legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--text-secondary); font-size: 12.5px; }
.avail-legend span { display: inline-flex; align-items: center; gap: 6px; }
.avail-legend i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.fresh { display: flex; align-items: center; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border-subtle); color: var(--text-secondary); font-size: 13px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-secondary);
  color: var(--text-primary); text-decoration: none; font-weight: 500;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0b2b1c; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn svg { width: 16px; height: 16px; }

.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; }
.facts dt { color: var(--text-secondary); }
.facts dd { margin: 0; }
.muted { color: var(--text-tertiary); }
.note { color: var(--text-secondary); font-size: 13px; margin: 0; }

.notfound { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 40px 20px; text-align: center; }
.notfound h1 { margin: 0; font-size: 22px; }
.notfound p { margin: 0 0 8px; color: var(--text-secondary); }

.skeleton { background: linear-gradient(90deg, var(--bg-tertiary), var(--bg-hover), var(--bg-tertiary)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 4px; color: transparent !important; }
@keyframes shimmer { to { background-position: -200% 0; } }

.leaflet-container { font-family: var(--font); }
/* Calmer OSM tiles so the parking colours carry the map. */
.leaflet-tile-pane { filter: saturate(0.45) contrast(0.92) brightness(1.04); }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; }
.popup-name { font-weight: 600; }
.popup-meta { color: var(--text-secondary); margin-top: 2px; }

/* ── mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .topbar { padding: 0 14px; }
  .brand-city { display: none; }
  .topbar-link span { display: none; }
  .layout { flex-direction: column; overflow-y: auto; }
  .panel { flex: none; border-right: 0; order: 2; }
  .panel-scroll { overflow: visible; }
  .map-wrap { flex: none; height: 46vh; order: 1; border-bottom: 1px solid var(--border); }
  .page-parking .panel { order: 1; }
  .page-parking .map-wrap { order: 2; height: 52vh; border-bottom: 0; border-top: 1px solid var(--border); }
  .panel-head, .section { padding: 16px; }
  .card { padding: 12px 16px; }
  .avail-free { font-size: 40px; }
  .legend { bottom: 12px; left: 8px; right: 60px; gap: 8px; padding: 6px 9px; font-size: 11.5px; }
}

.sw-free { background: var(--status-free); }
.sw-busy { background: var(--status-busy); }
.sw-warn { background: var(--status-warning); }
.sw-unknown { background: var(--status-unknown); }
