:root {
  color-scheme: light;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --surface: #ffffff;
  --soft: #f3f4f6;
  --green: #16a34a;
  --yellow: #d97706;
  --red: #dc2626;
  --stale: #facc15;
  --gray: #9ca3af;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--ink);
  background: var(--surface);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.subscription-lock {
  position: fixed;
  z-index: 3000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #fff;
}

.subscription-lock > div {
  width: min(100%, 340px);
  text-align: center;
}

.subscription-lock h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.subscription-lock p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.subscription-lock button {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 8px;
  background: #fff;
}

.subscription-lock button.primary {
  border: 0;
  background: var(--blue);
}

.phonebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  background: #fff7ed;
  color: #7c2d12;
  font-size: 13px;
  border-bottom: 1px solid #fed7aa;
}

.phonebar button,
.primary {
  border: 0;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  padding: 10px 14px;
}

main {
  flex: 1;
  min-height: 0;
  position: relative;
}

.tab {
  position: absolute;
  inset: 0;
  display: none;
  overflow-y: auto;
  background: var(--surface);
}

.tab.active {
  display: block;
}

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

.loading {
  position: absolute;
  z-index: 600;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 999px;
  color: #fff;
  background: rgba(17, 24, 39, 0.82);
  font-size: 13px;
}

.search-bar {
  position: absolute;
  z-index: 500;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
}

.search-bar input {
  min-width: 0;
  flex: 1;
  height: 42px;
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 8px;
  padding: 0 13px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
  outline: none;
}

.search-bar button,
.fab {
  border: 0;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
}

.search-bar button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  background: var(--blue);
  font-size: 21px;
}

.fab {
  position: absolute;
  z-index: 500;
  right: 14px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-size: 21px;
}

.locate {
  bottom: 106px;
}

.refresh {
  bottom: 44px;
}

.filter {
  bottom: 168px;
}

.filter.active {
  color: #fff;
  background: var(--blue);
}

.legend {
  position: absolute;
  z-index: 510;
  left: 12px;
  bottom: 12px;
  display: grid;
  gap: 5px;
  min-width: 154px;
  padding: 9px 11px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.15);
  color: #111827;
  font-size: 12px;
  line-height: 1.15;
}

.legend span,
.station-row,
.metric-row,
.actions,
.history-row {
  display: flex;
  align-items: center;
}

.legend span {
  gap: 7px;
}

.legend .dot {
  width: 12px;
  height: 12px;
}

.dot {
  width: 11px;
  height: 11px;
  display: inline-block;
  border-radius: 50%;
}

.green {
  background: var(--green);
}

.yellow {
  background: var(--yellow);
}

.red {
  background: var(--red);
}

.stale {
  background: var(--stale);
}

.gray {
  background: var(--gray);
}

.filter-panel {
  position: absolute;
  z-index: 520;
  top: 62px;
  left: 12px;
  right: 12px;
  display: grid;
  gap: 6px;
  padding: 7px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
}

.filter-panel .chip {
  padding: 6px 10px;
  font-size: 12px;
}

#tab-map.filter-open .leaflet-top.leaflet-right {
  top: 132px;
}

.filter-row,
.prefs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.filter-row::-webkit-scrollbar,
.prefs::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  padding: 7px 12px;
  background: var(--soft);
  color: #374151;
  font-size: 13px;
  white-space: nowrap;
}

.chip.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.tabbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  background: #fff;
}

.tabbar button {
  display: grid;
  gap: 2px;
  justify-items: center;
  border: 0;
  padding: 8px 0 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.tabbar span {
  font-size: 18px;
}

.tabbar button.active {
  color: var(--blue);
}

.screen-head {
  padding: 20px 16px 10px;
}

.screen-head h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

.screen-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.list,
.panel,
.metric-row,
.wide {
  margin-left: 16px;
  margin-right: 16px;
}

.list {
  padding-bottom: 90px;
}

.station-row {
  gap: 10px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  margin-bottom: 8px;
  text-align: left;
}

.station-row strong {
  display: block;
  margin-bottom: 2px;
}

.station-row small {
  color: var(--muted);
}

.empty {
  padding: 38px 14px;
  text-align: center;
  color: var(--muted);
}

.metric-row {
  gap: 8px;
  margin-bottom: 12px;
}

.metric-row span,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.metric-row span {
  flex: 1;
  padding: 10px;
  font-size: 13px;
}

.panel {
  padding: 14px;
  margin-bottom: 12px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

.leaderboard {
  display: grid;
  gap: 8px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 8px;
  color: #374151;
  font-size: 14px;
}

.wide {
  display: block;
  width: calc(100% - 32px);
  margin-bottom: 8px;
  border-radius: 8px;
  padding: 13px 14px;
  text-align: center;
  text-decoration: none;
}

.wide.link {
  border: 1px solid var(--line);
  color: var(--blue);
  background: #fff;
}

.sheet {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: flex;
  align-items: flex-end;
  background: rgba(15, 23, 42, 0.4);
}

.sheet-inner {
  position: relative;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  border-radius: 12px 12px 0 0;
  background: #fff;
  padding: 12px 16px 24px;
}

.handle {
  width: 40px;
  height: 4px;
  margin: 2px auto 14px;
  border-radius: 999px;
  background: #d1d5db;
}

.close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--soft);
  color: var(--muted);
  font-size: 22px;
}

.sheet h2 {
  margin: 0;
  padding-right: 34px;
  font-size: 22px;
}

#s-brand {
  margin: 3px 0 12px;
  color: var(--muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 7px 12px;
  background: var(--soft);
  font-size: 13px;
}

.price-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.price-grid span {
  border-radius: 8px;
  padding: 7px 9px;
  background: #eff6ff;
  color: #1e40af;
  font-size: 13px;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.actions button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 11px 10px;
  min-width: 0;
}

#notify-btn {
  grid-column: 1 / -1;
  order: 3;
}

#route-btn {
  order: 2;
}

.mark-box {
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fafafa;
}

.mark-box h3,
.sheet section h3 {
  margin: 0;
  font-size: 16px;
}

.queue-box h4 {
  margin: 0 0 8px;
  font-size: 14px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.segmented button,
.mark-box select,
.mark-box textarea {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.segmented button.active {
  border-color: var(--blue);
  color: #fff;
  background: var(--blue);
}

.actions button.favorite-active {
  border-color: rgba(37, 99, 235, 0.35);
  color: var(--blue);
  background: rgba(37, 99, 235, 0.08);
}

.mark-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.option-chip {
  border: 1px solid #d1d5db;
  border-radius: 999px;
  background: #fff;
  color: #374151;
  padding: 9px 12px;
  font-size: 14px;
}

.option-chip.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.mark-box textarea {
  min-height: 72px;
  resize: vertical;
}

.history {
  display: grid;
  gap: 8px;
}

.history-row {
  align-items: flex-start;
  gap: 9px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  font-size: 13px;
}

.history-row div {
  flex: 1;
  min-width: 0;
}

.history-row strong {
  display: block;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.history-row small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
}

.history-row > small {
  flex: 0 0 auto;
  white-space: nowrap;
}

.cluster {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 5px 18px rgba(15, 23, 42, 0.35);
  font-weight: 700;
}

.marker {
  width: 18px;
  height: 18px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.35);
}

.marker-pin {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  background: var(--pin-color);
  box-shadow: 0 7px 18px rgba(15, 23, 42, 0.32);
  transform: rotate(-45deg);
}

.marker-pin svg {
  width: 17px;
  height: 17px;
  fill: #fff;
  transform: rotate(45deg);
}

.marker-pin::after {
  content: "";
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.18);
  filter: blur(2px);
}

.leaflet-top.leaflet-right {
  top: 58px;
}

@media (min-width: 720px) {
  body {
    max-width: 430px;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  .sheet {
    left: 50%;
    width: 430px;
    transform: translateX(-50%);
  }
}
