:root {
  --bg: #ffe9d2;
  --bg-dot: #f4d3b3;
  --glow-a: rgba(255, 201, 60, 0.35);
  --glow-b: rgba(255, 92, 56, 0.14);
  --panel: #fffdf8;
  --ink: #2b2119;
  --text: #2b2119;
  --muted: #8a7a66;
  --border: #2b2119;
  --accent: #ff5c38;
  --accent-ink: #ffffff;
  --accent-soft: #ffe4d8;
  --sun: #ffc93c;
  --green: #00a884;
  --amber: #e8960c;
  --red: #e0442b;
  --card-shadow: 3px 3px 0 rgba(43, 33, 25, 0.18);
  --card-shadow-lift: 5px 5px 0 rgba(43, 33, 25, 0.22);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1811;
    --bg-dot: #2d2318;
    --glow-a: rgba(255, 175, 60, 0.10);
    --glow-b: rgba(255, 92, 56, 0.10);
    --panel: #2e2620;
    --ink: #f5ead9;
    --text: #f5ead9;
    --muted: #a8998a;
    --border: #4a3d31;
    --accent: #ff6a45;
    --accent-ink: #fff;
    --accent-soft: #45291f;
    --sun: #e0ae2e;
    --green: #2fc79e;
    --amber: #e8b04a;
    --red: #f07a5e;
    --card-shadow: 3px 3px 0 rgba(0, 0, 0, 0.45);
    --card-shadow-lift: 5px 5px 0 rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 92% -5%, var(--glow-a), transparent 42%),
    radial-gradient(circle at 6% 108%, var(--glow-b), transparent 46%),
    radial-gradient(var(--bg-dot) 1.5px, transparent 1.5px);
  background-size: 100% 100%, 100% 100%, 22px 22px;
  background-attachment: fixed, fixed, scroll;
  color: var(--text);
}

/* ---------- Motion ---------- */
@keyframes float-in {
  from { opacity: 0; transform: translateY(9px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pop-in {
  0% { opacity: 0; transform: scale(0.2); }
  70% { transform: scale(1.12); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes wiggle {
  0%, 100% { transform: rotate(-8deg); }
  25% { transform: rotate(6deg) scale(1.12); }
  60% { transform: rotate(-12deg) scale(1.08); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}
@keyframes pop-count {
  0% { transform: scale(1); }
  40% { transform: scale(1.16); color: var(--accent); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

.app { display: flex; height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 380px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  background: transparent;
  border-right: 2px solid var(--border);
}

.sidebar-head { padding: 16px 16px 12px; }

.sidebar-head h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.sidebar-head h1 .logo-emoji {
  display: inline-block;
  transform: rotate(-8deg);
  transform-origin: 70% 70%;
  margin-right: 2px;
  cursor: pointer;
}
.sidebar-head h1:hover .logo-emoji {
  animation: wiggle 0.6s ease-in-out;
}

.tagline {
  margin: 2px 0 10px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.data-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.74rem;
  color: var(--muted);
}

#refresh-btn {
  border: 2px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--card-shadow);
  transition: transform 0.1s, box-shadow 0.1s;
}
#refresh-btn:hover { transform: translate(-1px, -1px); box-shadow: var(--card-shadow-lift); }
#refresh-btn:active { transform: translate(2px, 2px); box-shadow: none; }
#refresh-btn:disabled { opacity: 0.65; cursor: wait; transform: none; }

.refresh-icon { display: inline-block; }
#refresh-btn:hover .refresh-icon { animation: spin 0.7s ease-in-out; }
#refresh-btn.loading .refresh-icon { animation: spin 0.8s linear infinite; }

/* ---------- Filters ---------- */
.filters {
  padding: 4px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.filters input[type="search"], .filters select {
  width: 100%;
  padding: 10px 13px;
  font-size: 0.87rem;
  font-family: inherit;
  font-weight: 600;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--card-shadow);
}
.filters input::placeholder { color: var(--muted); font-weight: 500; }
.filters input:focus, .filters select:focus {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

.chips { display: flex; flex-wrap: wrap; gap: 7px; }

.chip {
  border: 2px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--card-shadow);
  transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
}
.chip:hover { transform: translate(-1px, -1px); box-shadow: var(--card-shadow-lift); }
.chip.active {
  background: var(--accent);
  color: var(--accent-ink);
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 rgba(43, 33, 25, 0.25);
}

.selects { display: flex; gap: 9px; }
.selects select { cursor: pointer; }

.result-bar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}
#result-count { display: inline-block; transform-origin: left center; }

.linkish {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}
.linkish:hover { text-decoration: underline; }

/* ---------- Results list ---------- */
.results {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 4px 16px 16px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
  scrollbar-width: none; /* Firefox */
}
.results { -ms-overflow-style: none; } /* legacy Edge/IE */

.result-item {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  padding: 11px 12px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--card-shadow);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  animation: float-in 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: calc(var(--i, 0) * 22ms);
}
.result-item:hover {
  transform: translate(-1px, -1px);
  box-shadow: var(--card-shadow-lift);
}
.result-item:hover .r-emoji { transform: rotate(-6deg) scale(1.08); }
.r-emoji { transition: transform 0.15s ease; }
.result-item.selected {
  background: var(--accent-soft);
  outline: 3px solid var(--accent);
  outline-offset: -1px;
}

.r-emoji {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 12px;
}

.r-body { min-width: 0; flex: 1; }

.result-item .r-name {
  font-weight: 800;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.result-item .r-food {
  font-size: 0.77rem;
  color: var(--muted);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.result-item .r-addr { font-size: 0.74rem; color: var(--muted); margin-top: 3px; font-weight: 600; }
.result-item .r-nomap { color: var(--amber); }

.empty-note {
  padding: 30px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}
.empty-note .big {
  font-size: 2.2rem;
  display: block;
  margin-bottom: 8px;
  animation: bob 2.4s ease-in-out infinite;
}

/* ---------- Badges ---------- */
.badge {
  font-size: 0.64rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  text-transform: capitalize;
  border: 1.5px solid currentColor;
}
.badge.approved, .badge.issued { color: var(--green); background: color-mix(in srgb, var(--green) 12%, transparent); }
.badge.requested { color: var(--amber); background: color-mix(in srgb, var(--amber) 12%, transparent); }
.badge.expired, .badge.suspend { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.badge.open-now {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}
.badge.open-now::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 4px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.75); }
}

/* ---------- Main / map / table ---------- */
.main { flex: 1; position: relative; min-width: 0; }

/* z-index: 0 isolates Leaflet's internal z-indexes (up to 1000) so the
   table view and toggle can sit above the whole map. */
#map { height: 100%; width: 100%; background: var(--bg); position: relative; z-index: 0; }

.view-toggle {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  gap: 0;
  border-radius: 999px;
  overflow: hidden;
  border: 2px solid var(--border);
  box-shadow: var(--card-shadow);
}
.view-toggle button {
  border: none;
  background: var(--panel);
  color: var(--muted);
  padding: 8px 18px;
  font-size: 0.82rem;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
}
.view-toggle button.active { background: var(--accent); color: var(--accent-ink); }

.table-wrap {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: auto;
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-dot) 1.5px, transparent 1.5px);
  background-size: 22px 22px;
  padding: 18px 18px 74px;
}

.table-wrap table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--card-shadow);
  font-size: 0.83rem;
}

.table-wrap th, .table-wrap td {
  text-align: left;
  padding: 10px 13px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 30%, transparent);
  vertical-align: top;
}

.table-wrap th {
  position: sticky;
  top: 0;
  background: var(--panel);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
}

.table-wrap tr:hover td { background: var(--accent-soft); cursor: pointer; }

/* ---------- Map pins & popups ---------- */
.pin-emoji {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  font-size: 17px;
  background: var(--panel);
  border: 2.5px solid var(--green);
  border-radius: 50% 50% 50% 4px;
  box-shadow: 2px 2px 0 rgba(43, 33, 25, 0.3);
  transition: transform 0.12s;
  animation: pop-in 0.34s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.pin-emoji:hover { transform: scale(1.22) translateY(-2px); z-index: 10; }
.pin-emoji.requested { border-color: var(--amber); }
.pin-emoji.expired, .pin-emoji.suspend, .pin-emoji.unknown { border-color: var(--red); filter: grayscale(0.6); }

.leaflet-popup-content-wrapper {
  background: var(--panel);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--card-shadow-lift);
}
.leaflet-popup-tip { background: var(--panel); border: 2px solid var(--border); }
.leaflet-popup-content {
  margin: 13px 15px;
  font-size: 0.82rem;
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, sans-serif;
}

.popup h3 { margin: 0 0 5px; font-size: 1rem; font-weight: 800; }
.popup .p-food { color: var(--muted); margin: 5px 0; }
.popup .p-addr { margin: 5px 0; font-weight: 600; }
.popup table { border-collapse: collapse; margin-top: 7px; }
.popup td { padding: 1px 8px 1px 0; color: var(--muted); }
.popup td:first-child { font-weight: 800; color: var(--text); }
.popup .p-nosched { color: var(--muted); font-style: italic; margin-top: 7px; }
.popup .p-permit { margin-top: 8px; font-size: 0.7rem; color: var(--muted); font-weight: 600; }

/* ---------- Scrollbar (webkit) ---------- */
.results::-webkit-scrollbar { width: 0; height: 0; } /* Chrome/Safari — hide */

/* ---------- Narrow screens ---------- */
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; max-height: 48vh; border-right: none; border-bottom: 2px solid var(--border); }
}
