:root {
  --bg: #fbf7f0;
  --surface: #ffffff;
  --ink: #2a2118;
  --muted: #7a6a58;
  --line: #eadfce;
  --brand: #b45309;      /* turmeric / brass */
  --brand-ink: #ffffff;
  --brand-soft: #fdecd3;
  --good: #3f7d3a;
  --bad: #b42318;
  --radius: 14px;
  --tabbar: 64px;
  --topbar: 52px;
  --filters: 48px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
/* Always light: the app is mostly used outdoors in bright light. */
:root { color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
a, a:visited, .leaflet-container a { color: var(--brand); text-decoration-color: color-mix(in srgb, var(--brand) 45%, transparent); text-underline-offset: 2px; }
a:hover, .leaflet-container a:hover { text-decoration-color: var(--brand); }
h2 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.empty { color: var(--muted); text-align: center; padding: 1.5rem 0; }
.center { text-align: center; }

/* ---------- top bar & filters ---------- */
.topbar {
  position: sticky; top: 0; z-index: 1000; height: var(--topbar);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-size: 1.1rem; margin: 0; display: flex; align-items: center; gap: 8px; }
.brand-icon { width: 30px; height: 30px; border-radius: 8px; display: block; }
.auth-area { display: flex; align-items: center; gap: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--line); }
.rep { font-size: .8rem; background: var(--brand-soft); color: var(--brand); padding: 2px 8px; border-radius: 999px; font-weight: 600; }

.filters {
  position: sticky; top: var(--topbar); z-index: 999;
  display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.filters label { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.filters select { font-size: .9rem; }
.filters[hidden] { display: none; }

select, input, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%;
}
.filters select { width: auto; padding: 4px 8px; }
textarea { resize: vertical; }

/* ---------- views ---------- */
main { width: 100%; }
.view { display: none; padding: 12px 12px calc(var(--tabbar) + 24px + env(safe-area-inset-bottom)); max-width: 900px; margin: 0 auto; }
.view.active { display: block; }
#view-map { padding: 0; position: relative; max-width: none; }
#map { height: calc(100dvh - var(--topbar) - var(--filters) - var(--tabbar) - env(safe-area-inset-bottom)); min-height: 320px; }
.map-top { position: absolute; top: 10px; left: 10px; right: 10px; z-index: 700; display: flex;
  flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.map-top > * { pointer-events: auto; }
.map-search { position: relative; width: 100%; max-width: 420px; }
.map-search input { border-radius: 999px; padding: 10px 16px; border: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(0,0,0,.12); background: var(--surface); font-size: 1rem; }
.map-search .suggest { text-align: left; }
.map-summary {
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; font-size: .9rem; box-shadow: 0 2px 10px rgba(0,0,0,.12); white-space: nowrap;
}
.legend {
  position: absolute; bottom: 14px; left: 10px; z-index: 500; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: .75rem;
}
.legend .bar { height: 8px; width: 140px; border-radius: 4px; margin: 4px 0;
  background: linear-gradient(90deg, #fde68a, #f59e0b, #c2410c, #7f1d1d); }
.legend .ends { display: flex; justify-content: space-between; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }

/* ---------- buttons ---------- */
.btn { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 8px 14px; cursor: pointer; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn.wide { width: 100%; padding: 12px; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { background: none; border: none; font: inherit; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.icon-btn.on { color: var(--brand); font-weight: 600; }

/* ---------- tabs ---------- */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
}
.tab { flex: 1; background: none; border: none; font: inherit; font-size: .72rem; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; }
.tab span { font-size: 1.25rem; }
.tab.active { color: var(--brand); font-weight: 600; }
.tab.add span { background: var(--brand); color: var(--brand-ink); width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.4rem; }

/* ---------- forms ---------- */
.form label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 0; }
.form label > input, .form label > select, .form label > textarea { margin-top: 4px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form .check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.form .check input { width: auto; }
.file { display: block; border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; cursor: pointer; color: var(--brand) !important; font-weight: 600; }
.file input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.preview { width: 100%; max-height: 300px; object-fit: contain; border-radius: 10px; margin-top: 10px; background: var(--line); }
.rotate-bar { display: flex; justify-content: center; gap: 8px; margin-top: 8px; }
.rotate-bar[hidden] { display: none; }
.meta-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-size: .78rem; padding: 3px 9px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.chip.warn { background: #fef3c7; color: #92400e; }
.plates { margin-top: 12px; }
.plates-head, .plate-row { display: grid; grid-template-columns: 1fr 1fr 36px; gap: 8px; align-items: center; }
.plates-head { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.plate-row { margin-bottom: 8px; }
.plate-row .remove { border: none; background: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; }
.loc { border: 1px solid var(--line); border-radius: var(--radius); margin: 14px 0; padding: 10px; }
.loc legend { font-size: .85rem; color: var(--muted); padding: 0 6px; }
.loc-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.town-search { position: relative; margin-top: 0 !important; }
.suggest {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 1200; margin: 4px 0 0; padding: 4px 0;
  list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,.15); max-height: 260px; overflow-y: auto;
}
.suggest li { padding: 8px 12px; cursor: pointer; color: var(--ink); font-size: .92rem; }
.suggest li small { display: block; color: var(--muted); font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggest li.active, .suggest li:hover { background: var(--brand-soft); }
.suggest li.note { cursor: default; color: var(--muted); font-size: .8rem; }
.suggest li.note:hover { background: none; }
.mini-map { height: 220px; border-radius: 10px; margin-top: 8px; }
.segmented { display: flex; background: var(--line); border-radius: 999px; padding: 3px; margin-bottom: 12px; }
.seg { flex: 1; border: none; background: none; font: inherit; padding: 8px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.seg.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ---------- feed ---------- */
.feed { display: grid; gap: 12px; }
.post { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.post-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.post-head .who { flex: 1; min-width: 0; }
.post-head .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post-img { width: 100%; max-height: 520px; object-fit: cover; display: block; background: var(--line); }
.post-body { padding: 10px 12px; }
.post-actions { display: flex; gap: 6px; padding: 0 8px 8px; align-items: center; }
.post-actions .spacer { flex: 1; }
.price-tag { font-weight: 700; color: var(--brand); }

/* ---------- town sheet ---------- */
.sheet { border: none; border-radius: 18px 18px 0 0; padding: 18px 16px 24px; width: 100%; max-width: 720px;
  margin: auto auto 0; max-height: 88dvh; overflow-y: auto; background: var(--surface); color: var(--ink); }
.sheet::backdrop { background: rgba(0,0,0,.45); }
.sheet .close { position: sticky; top: 0; float: right; border: none; background: var(--line); border-radius: 50%;
  width: 32px; height: 32px; cursor: pointer; color: var(--ink); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 14px; }
.stat { background: var(--bg); border-radius: 10px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 1.3rem; }
.stat span { font-size: .75rem; color: var(--muted); }
.report { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.report img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--line); cursor: zoom-in; }
.report .info { flex: 1; min-width: 0; font-size: .88rem; }
.report .actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.status { font-size: .72rem; padding: 2px 7px; border-radius: 999px; background: var(--line); }
.status.hidden, .status.removed { background: #fee4e2; color: var(--bad); }

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); }
.chart .axis { stroke: var(--muted); }
.chart .tick, .chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .dot { fill: var(--brand); fill-opacity: .8; stroke: var(--surface); stroke-width: 1.5; }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 2.5; }
.chart .fit { stroke: var(--muted); stroke-dasharray: 5 4; stroke-width: 1.5; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar) + 16px); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 2000; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Price pins on the main map */
.pin {
  transform: translate(-50%, -50%); display: inline-block; white-space: nowrap;
  font-weight: 700; font-size: 12px; padding: 3px 7px; border-radius: 999px;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); cursor: pointer;
}

/* Leaflet popups follow theme */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--ink); }
.leaflet-popup-content { margin: 10px 12px; }
.leaflet-container { background: var(--bg); font: inherit; }

/* ---------- profiles & badges ---------- */
.profile-head { display: flex; gap: 12px; align-items: center; }
.avatar-initial { display: inline-grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 700; flex: none; }
.avatar { flex: none; }
.avatar-btn { border: none; background: none; padding: 0; cursor: pointer; border-radius: 50%; }
.bio { margin: 10px 0 0; white-space: pre-wrap; }
.badge-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.badges { display: inline-flex; gap: 3px; margin-left: 4px; vertical-align: middle; }
.trek-badge {
  display: inline-block; font-size: .66rem; font-weight: 700; letter-spacing: .02em; line-height: 1;
  padding: 3px 5px; border-radius: 5px; color: #fff; background: var(--c, var(--muted)); white-space: nowrap;
}
.trek-badge.more { background: var(--line); color: var(--muted); }
.rep-mini { color: var(--muted); font-size: .85em; }
[data-action="profile"] { cursor: pointer; }
.by[data-action="profile"]:hover .who-name, .name[data-action="profile"]:hover .who-name { text-decoration: underline; }
.trek-list { list-style: none; padding: 0; margin: 0; }
.trek-list li { padding: 5px 0; border-bottom: 1px solid var(--line); }
.treks-pick .check { margin: 4px 0 !important; }
#feedback-form .seg { cursor: pointer; font-size: .85rem; }

/* ---------- installable app / offline ---------- */
.photo-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-pick .file { padding: 18px 8px; }
.pick-camera { font: inherit; font-weight: 600; color: var(--brand); cursor: pointer; width: 100%;
 background: var(--brand-soft); border-style: solid !important; border-color: var(--brand) !important; }
.offline-banner { position: sticky; top: var(--topbar); z-index: 998; background: #fef3c7; color: #92400e;
  font-size: .85rem; text-align: center; padding: 6px 10px; border-bottom: 1px solid #fde68a; }
.offline-banner[hidden], .queue-status[hidden], #install-btn[hidden] { display: none; }
.queue-status { background: var(--brand-soft); color: var(--brand); border-radius: var(--radius); padding: 10px 12px;
  margin-bottom: 12px; font-size: .9rem; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.install-card ol { margin: 6px 0 0; padding-left: 20px; }
.qr-box { width: min(280px, 80vw); margin: 12px auto; background: #fff; border-radius: 12px; padding: 8px; }
.qr-box svg { width: 100%; height: auto; display: block; }
.gps-help { background: #fef3c7; color: #92400e; border-radius: 10px; padding: 8px 10px; margin: 8px 0 0; }
.gps-help[hidden] { display: none; }

/* ---------- desktop: navigation as a left sidebar ---------- */
@media (min-width: 900px) and (hover: hover) {
  :root { --sidebar: 92px; }
  body { padding-left: var(--sidebar); }
  .topbar { margin-left: calc(-1 * var(--sidebar)); padding-left: 20px; }
  .tabs {
    top: var(--topbar); bottom: 0; left: 0; right: auto; width: var(--sidebar); height: auto;
    padding: 14px 0 0; flex-direction: column; justify-content: flex-start; gap: 6px;
    border-top: none; border-right: 1px solid var(--line);
  }
  .tab { flex: none; height: 68px; font-size: .78rem; border-radius: 12px; margin: 0 8px; }
  .tab:hover { background: var(--bg); }
  .tab.active { background: var(--brand-soft); }
  .view { padding-bottom: 32px; }
  #map { height: calc(100dvh - var(--topbar) - var(--filters)); }
  .toast { bottom: 24px; left: calc(50% + var(--sidebar) / 2); }
  .tab.add { display: none; }           /* "Add" lives on the map as a floating button */
  .fab { display: inline-flex; }
}

/* Floating "Add price" button on the desktop map */
.fab {
  display: none; position: absolute; right: 18px; bottom: 34px; z-index: 600;
  align-items: center; gap: 6px; padding: 12px 18px 12px 14px; border: none; border-radius: 999px;
  background: var(--brand); color: var(--brand-ink); font: inherit; font-weight: 700; font-size: 1rem;
  box-shadow: 0 6px 18px rgba(0,0,0,.25); cursor: pointer;
}
.fab:hover { filter: brightness(1.08); }
.fab span { font-size: .95rem; }

/* ---------- contribution celebration ---------- */
.celebrate { position: fixed; inset: 0; z-index: 3000; pointer-events: none; overflow: hidden; }
.celebrate-card {
  position: absolute; top: calc(var(--topbar) + 14px); left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 2px solid var(--brand); border-radius: 18px; padding: 12px 22px;
  text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.2); pointer-events: auto; max-width: 90vw;
  width: max-content; min-width: 240px; z-index: 2;
  animation: pop-in .45s cubic-bezier(.2, 1.6, .4, 1) both;
}
.celebrate-points { font-size: 2.2rem; font-weight: 800; color: var(--brand); line-height: 1.1; font-variant-numeric: tabular-nums; }
.celebrate-star { display: inline-block; animation: star-spin .9s ease-out .2s both; }
.celebrate-msg { font-size: .9rem; color: var(--ink); margin-top: 2px; }
.celebrate.leaving .celebrate-card { animation: pop-out .5s ease-in both; }
.confetti {
  position: absolute; top: -48px; line-height: 1; will-change: transform; z-index: 1;
  animation-name: confetti-fall; animation-timing-function: cubic-bezier(.3, .1, .6, 1); animation-fill-mode: both;
}
@keyframes confetti-fall {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  85% { opacity: 1; }
  100% { transform: translate(var(--drift), 105vh) rotate(var(--spin)); opacity: 0; }
}
@keyframes pop-in { from { transform: translateX(-50%) scale(.4); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes pop-out { to { transform: translateX(-50%) translateY(-30px) scale(.9); opacity: 0; } }
@keyframes star-spin { from { transform: rotate(-180deg) scale(.2); } 60% { transform: rotate(20deg) scale(1.3); } to { transform: rotate(0) scale(1); } }
.rep-bump { animation: rep-bump 1s ease-out; }
@keyframes rep-bump { 30% { transform: scale(1.35); background: var(--brand); color: var(--brand-ink); } }
@media (prefers-reduced-motion: reduce) {
  .celebrate-card, .celebrate-star, .rep-bump { animation: none; }
}

/* Compact, collapsible map credits */
.leaflet-control-attribution.attr { display: flex; align-items: center; gap: 6px; font-size: 10px;
  background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--muted);
  border-radius: 8px 0 0 0; padding: 2px 4px 2px 8px; }
.attr-toggle { border: none; background: none; color: var(--muted); font-size: 14px; line-height: 1;
  padding: 2px; cursor: pointer; order: 2; }
.attr.attr-collapsed { font-size: 0; padding: 2px; border-radius: 50%; margin: 0 4px 4px 0 !important; }
.attr.attr-collapsed > :not(.attr-toggle) { display: none; }
.attr.attr-collapsed .attr-toggle { font-size: 16px; }
/* Single-line prompt that shrinks to fit narrow phones */
.one-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: min(1rem, 3.9vw); }
.icon { width: 1.05em; height: 1.05em; vertical-align: -0.17em; }
.icon-btn { display: inline-flex; align-items: center; gap: 4px; }
.icon-btn[data-action="delete"]:hover { color: var(--bad); }
.sheet-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-right: 40px; }
.sheet-title h2 { margin: 0; }
.install-nudge { display: flex; gap: 12px; align-items: flex-start; text-align: left; margin-top: 16px;
  padding: 12px; border-radius: 12px; background: var(--brand-soft); }
.install-nudge img { border-radius: 10px; flex: none; }
.install-nudge-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.install-nudge-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
