/* Spoons Tracker — mobile-first styles */

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2563eb;
  --brand-ink: #ffffff;
  --error: #b91c1c;
  --ok: #15803d;
  --radius: 14px;
  --tap: 44px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.grow { flex: 1; }
.foot { text-align: center; padding: 8px 0 0; }
.pad { padding: 0 4px 8px; }

button { font-family: inherit; cursor: pointer; }

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

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.brand { text-align: center; margin-bottom: 18px; }
.brand-spoon { font-size: 44px; display: block; line-height: 1.1; }
.brand h1 { font-size: 1.45rem; margin: 6px 0 2px; }
.brand p { margin: 0; font-size: 0.95rem; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand-sm { font-weight: 700; font-size: 1.05rem; }

/* ---------------------------------------------------------------- forms ---- */

.tab-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 16px;
}
.tab-bar button {
  min-height: var(--tap);
  border: 0;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
  border-radius: 8px;
}
.tab-bar button.active {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 5px;
}
.field input,
input[type='search'] {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
.field input:focus,
input[type='search']:focus {
  outline: 2px solid var(--brand);
  border-color: var(--brand);
}

.primary {
  background: var(--brand);
  color: var(--brand-ink);
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  min-height: var(--tap);
}
.primary:disabled { opacity: 0.6; }
.primary:active { filter: brightness(0.95); }
.big { width: 100%; margin-top: 4px; }
.wide { width: 100%; }

.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 600;
  min-height: var(--tap);
}
.icon-btn { padding: 8px 12px; line-height: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  min-height: var(--tap);
  cursor: pointer;
}

.row { display: flex; align-items: flex-end; gap: 10px; }
.row .field { margin-bottom: 0; }
.actions-row { display: flex; gap: 10px; margin-top: 12px; }

.error { color: var(--error); font-size: 0.92rem; min-height: 1.1em; margin: 2px 0 8px; }

/* ------------------------------------------------------------- auth view --- */

.auth-wrap { max-width: 560px; margin: 0 auto; padding: 40px 16px; }

/* -------------------------------------------------------------- avatars ---- */

.avatar-lg {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--card);
  box-shadow: 0 0 0 2px var(--line);
  background: var(--brand);
}

.avatar-row { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.avatar-row h1 { font-size: 1.25rem; margin: 0 0 2px; }
.avatar-row p { margin: 0; font-size: 0.9rem; overflow-wrap: anywhere; }

.actions { margin: 14px 0; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

/* --------------------------------------------------------------- me page --- */

#me-view { max-width: 640px; margin: 0 auto; padding-bottom: 40px; }
#me-view .topbar {
  max-width: 640px;
  border-radius: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.stat {
  background: var(--bg);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
.stat-n { font-size: 1.5rem; font-weight: 700; }
.stat-l { font-size: 0.8rem; color: var(--muted); }

.top-row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.top-row:last-child { border-bottom: 0; }
.top-rank {
  display: inline-block;
  min-width: 20px;
  text-align: center;
  background: var(--brand);
  color: #fff;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  margin-right: 4px;
}

.pubsync-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0;
  text-align: center;
}
.pubsync-grid > div { background: var(--bg); border-radius: 10px; padding: 10px 4px; font-size: 0.85rem; }
.pubsync-grid .stat-n { font-size: 1.25rem; display: block; }

/* -------------------------------------------------------------- map view --- */

#map-view { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }

.map-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.me-chip { display: inline-flex; align-items: center; gap: 6px; }
.me-chip-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--brand);
}

.filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
  z-index: 4;
}
.filter-bar::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  min-height: 38px;
}
.chip img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
}
.chip.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

#map { flex: 1; width: 100%; }

/* empty state retired — the map always shows all pubs (grey = unvisited) */

/* floating action button */
.fab {
  position: absolute;
  right: 16px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 4;
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 14px 22px;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.45);
}
.fab:active { filter: brightness(0.95); }

/* tiny map attribution — replaces MapLibre's big attribution box.
   OSM / OpenFreeMap ask for visible credit; one small line keeps it
   out of the way of the check-in button. */
.map-credit {
  position: absolute;
  left: 6px;
  bottom: calc(6px + env(safe-area-inset-bottom));
  z-index: 4;
  margin: 0;
  padding: 1px 6px;
  font-size: 8.5px;
  line-height: 1.4;
  color: rgba(31, 41, 51, 0.35);
  background: rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  pointer-events: auto;
}
.map-credit a { color: inherit; text-decoration: none; }

/* ------------------------------------------------------------ map markers -- */

/* NOTE: no `position` here on purpose — MapLibre positions markers via the
   .maplibregl-marker class (position:absolute + inline transform). Setting
   position:relative here overrides it and the badge sticks to the top-left. */
.spoon-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* count badge: plain number on a green dot (visited = green) */
.m-count {
  min-width: 26px;
  height: 26px;
  padding: 0 7px;
  background: #16a34a;
  color: #fff;
  border: 2px solid #ffffff;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.spoon-marker.closed .m-count {
  border-color: #d1d5db;
  filter: saturate(0.75);
}

/* ----------------------------------------------------------------- sheet --- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  z-index: 10;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 85dvh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 8px 18px calc(20px + env(safe-area-inset-bottom));
  z-index: 11;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2);
  animation: sheet-up 0.22s ease-out;
}
@keyframes sheet-up {
  from { transform: translateY(40px); opacity: 0.4; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-handle {
  width: 42px;
  height: 5px;
  border-radius: 999px;
  background: var(--line);
  margin: 4px auto 12px;
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.sheet-head h2 { margin: 0 0 2px; font-size: 1.2rem; }
.sheet-head .grow { min-width: 0; }

.badge-closed {
  display: inline-block;
  background: #f3f4f6;
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 8px;
  vertical-align: middle;
  text-transform: uppercase;
}

.who-line { margin: 0 0 10px; font-weight: 600; }

.visit-list {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 8px;
}
.visit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.visit-row:last-child { border-bottom: 0; }
.visit-row img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--brand);
  flex-shrink: 0;
}
.visit-row .grow { min-width: 0; }
.visit-row strong { font-size: 0.95rem; }
.you { color: var(--brand); font-size: 0.8rem; font-weight: 700; }

/* check-in rows */
.ci-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
}
.ci-info { min-width: 0; }
.ci-info strong { display: block; }
.ci-dist { font-size: 0.8rem; color: var(--ok); font-weight: 700; }

/* search */
#search-input { margin-bottom: 12px; }
.search-results { max-height: 50dvh; overflow-y: auto; }
.search-row {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 12px 4px;
  font-size: 1rem;
}
.search-row:last-child { border-bottom: 0; }

/* ----------------------------------------------------------------- toast --- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 600;
  max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 50;
}
.toast.error { background: var(--error); }
