:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f1f3f4;
  --text: #202124;
  --muted: #5f6368;
  --border: #dadce0;
  --accent: #1a73e8;
  --accent-text: #ffffff;
  --accent-soft: #e8f0fe;
  --danger: #d93025;
  --shadow: 0 1px 3px rgba(60, 64, 67, .3), 0 4px 8px 3px rgba(60, 64, 67, .15);
  --radius: 24px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --gutter: 12px;
  --sheet-h: 0px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1f1f;
    --surface: #2d2e30;
    --surface-2: #3c4043;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --border: #5f6368;
    --accent: #8ab4f8;
    --accent-text: #202124;
    --accent-soft: #394457;
    --danger: #f28b82;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 4px 8px 3px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: currentColor; flex: none; }
[hidden] { display: none !important; }

/* Google Maps sets an inline `position: relative` on the container, so pin it with !important
   and explicit dimensions or it collapses to zero height. */
#map { position: fixed !important; inset: 0; width: 100%; height: 100%; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Search bar ---------- */
#search-bar, #dir-card {
  position: fixed;
  z-index: 20;
  top: calc(var(--safe-top) + var(--gutter));
  left: calc(var(--safe-left) + var(--gutter));
  right: calc(var(--safe-right) + var(--gutter));
  max-width: 440px;
}
#search-bar { padding: 0; border-radius: 8px; background: transparent; box-shadow: none; }
#search-bar > .ac-slot { border-radius: 8px; box-shadow: var(--shadow); }

.ac-slot { flex: 1; min-width: 0; }
gmp-place-autocomplete {
  width: 100%;
  color-scheme: inherit;
  --gmp-mat-color-surface: var(--surface);
  --gmp-mat-color-on-surface: var(--text);
  --gmp-mat-color-on-surface-variant: var(--muted);
  --gmp-mat-color-primary: var(--accent);
  --gmp-mat-font-body-large: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- Directions card ---------- */
#dir-card { padding: 8px 8px 10px; border-radius: 20px; }
.dir-row { display: flex; align-items: flex-start; gap: 4px; }
.dir-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.dir-field {
  display: flex; align-items: center; gap: 8px;
  min-height: 44px;
}
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; margin-left: 4px; }
.dot-origin { border: 2px solid var(--muted); }
.dot-dest { background: var(--danger); border-radius: 50% 50% 50% 0; transform: rotate(-45deg); }
.dest-label {
  flex: 1; min-width: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.modes {
  display: flex; gap: 6px;
  margin-top: 8px;
  overflow-x: auto; scrollbar-width: none;
}
.modes::-webkit-scrollbar { display: none; }
.mode {
  flex: 1 0 auto;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 20px;
  background: transparent; cursor: pointer;
}
.mode svg { width: 20px; height: 20px; }
.mode.active { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
@media (max-width: 419px) {
  .mode { padding: 0 8px; }
  .mode:not(.active) span { display: none; }
}

/* ---------- Buttons ---------- */
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 50%;
  background: transparent; cursor: pointer;
  color: var(--muted);
}
.icon-btn.sm { width: 40px; height: 40px; }
.icon-btn:active { background: var(--surface-2); }

#fabs {
  position: fixed; z-index: 10;
  right: calc(var(--safe-right) + var(--gutter));
  bottom: calc(var(--safe-bottom) + 24px);
  display: flex; flex-direction: column; gap: 12px;
  transform: translateY(calc(-1 * var(--sheet-h)));
  transition: transform .25s ease;
}
.fab {
  display: grid; place-items: center;
  width: 52px; height: 52px;
  border: 0; border-radius: 50%;
  background: var(--surface); color: var(--muted);
  box-shadow: var(--shadow); cursor: pointer;
}
.fab:active { background: var(--surface-2); }
.fab.tracking { color: var(--accent); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 20px;
  background: var(--surface); color: var(--accent);
  font-weight: 600; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.pill svg { width: 18px; height: 18px; }
.pill.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.pill:active { filter: brightness(.95); }

/* ---------- Bottom sheets ---------- */
.sheet {
  position: fixed; z-index: 30;
  left: 0; right: 0; bottom: 0;
  max-height: 45dvh;
  padding: 6px 16px calc(var(--safe-bottom) + 16px);
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  transition: max-height .25s ease;
  animation: sheet-in .25s ease;
}
.sheet.expanded { max-height: 85dvh; }
@keyframes sheet-in { from { transform: translateY(100%); } }

.sheet-handle {
  position: sticky; top: -6px; z-index: 1;
  margin: 0 -16px; padding: 8px 0 10px;
  background: var(--surface); cursor: pointer;
}
.sheet-handle::before {
  content: ""; display: block; margin: 0 auto;
  width: 36px; height: 4px; border-radius: 2px; background: var(--border);
}
.sheet-head { display: flex; align-items: flex-start; gap: 8px; }
.sheet-title { flex: 1; min-width: 0; }
.sheet h2 { margin: 0; font-size: 20px; font-weight: 600; line-height: 1.3; }
.muted { margin: 2px 0 0; color: var(--muted); }

.actions {
  display: flex; gap: 8px;
  margin: 14px -16px 4px; padding: 0 16px 2px;
  overflow-x: auto; scrollbar-width: none;
}
.actions::-webkit-scrollbar { display: none; }

.details { list-style: none; margin: 8px 0 0; padding: 0; }
.details li {
  display: flex; gap: 16px; align-items: flex-start;
  padding: 12px 0; border-top: 1px solid var(--border);
  word-break: break-word;
}
.details li svg { color: var(--accent); width: 22px; height: 22px; }
.details a { color: var(--accent); text-decoration: none; }
.stars { color: #fbbc04; letter-spacing: 1px; }

.steps { list-style: none; margin: 8px 0 0; padding: 0; counter-reset: step; }
.steps li {
  display: flex; gap: 12px;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.steps li::before {
  counter-increment: step; content: counter(step);
  flex: none; display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface-2); color: var(--muted); font-size: 13px; font-weight: 600;
}
.steps .step-body { flex: 1; min-width: 0; }
.steps .step-dist { color: var(--muted); font-size: 13px; }
.transit-chip {
  display: inline-block; padding: 1px 8px; margin-right: 6px;
  border-radius: 4px; font-weight: 700; font-size: 13px;
  background: var(--accent); color: var(--accent-text);
}

/* ---------- Layers ---------- */
.type-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.type-opt {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 0; border: 0; background: none; cursor: pointer; font-size: 13px;
}
.swatch {
  width: 100%; aspect-ratio: 1.3; border-radius: 12px;
  border: 2px solid transparent; outline: 1px solid var(--border);
}
.type-opt.active { color: var(--accent); font-weight: 600; }
.type-opt.active .swatch { border-color: var(--accent); outline-color: transparent; }
.sw-road { background: linear-gradient(135deg, #e8eaed 45%, #fdd663 45% 52%, #e8eaed 52%), #e8eaed; }
.sw-sat { background: radial-gradient(circle at 30% 40%, #4a6b3a, #2c3e27 60%, #5a4a32); }
.sw-terrain { background: radial-gradient(circle at 60% 60%, #c9d8b6, #e4dccb 50%, #b9c9a8); }
.sw-traffic { background: linear-gradient(160deg, #e8eaed 40%, #1e8e3e 40% 46%, #e8eaed 46% 60%, #d93025 60% 66%, #e8eaed 66%); }
.sw-transit { background: linear-gradient(20deg, #e8eaed 42%, #1a73e8 42% 48%, #e8eaed 48% 62%, #e37400 62% 68%, #e8eaed 68%); }
.sw-bike { background: linear-gradient(120deg, #e8eaed 44%, #188038 44% 50%, #e8eaed 50%); }
.section-label { margin: 20px 0 0; font-size: 15px; font-weight: 600; }

/* ---------- Markers ---------- */
.me-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: #1a73e8; border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.15), 0 1px 4px rgba(0,0,0,.4);
  transform: translateY(50%);
}
.origin-pin {
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 4px solid #202124;
  transform: translateY(50%);
}

/* ---------- Lawn signs ---------- */
:root {
  --s-planned: #e37400;
  --s-placed: #188038;
  --s-removed: #80868b;
}
.fab.fab-primary { background: var(--accent); color: var(--accent-text); }
.fab.fab-primary:active { filter: brightness(.92); }
.pill.danger { color: var(--danger); }

.profile-chip {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 100%; min-height: 36px; margin-top: 8px; padding: 0 10px 0 12px;
  border: 0; border-radius: 18px;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); cursor: pointer; font-size: 14px; font-weight: 500;
}
.profile-chip svg { width: 18px; height: 18px; color: var(--s-planned); }
.profile-chip svg.chev { color: var(--muted); }
.profile-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-chip.offline svg:first-child { color: var(--muted); }
.profile-chip.offline span { color: var(--muted); }

.sign-marker {
  position: relative;
  display: grid; place-items: center;
  width: 32px; height: 32px; margin-bottom: 7px;
  border-radius: 10px; border: 2px solid #fff;
  background: var(--s-planned); color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.45);
  cursor: pointer;
  transition: transform .15s ease;
  transform-origin: 50% calc(100% + 7px);
}
.sign-marker::after {
  content: ""; position: absolute; left: 50%; bottom: -8px;
  width: 0; height: 0; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: #fff; border-bottom: 0;
}
.sign-marker svg { width: 18px; height: 18px; }
.sign-marker.s-placed { background: var(--s-placed); }
.sign-marker.s-removed { background: var(--s-removed); opacity: .85; }
.sign-marker.active { transform: scale(1.3); box-shadow: 0 0 0 4px rgba(26,115,232,.35), 0 2px 6px rgba(0,0,0,.5); }
.sign-marker.moving { transform: scale(1.3); animation: bob 1s ease-in-out infinite; }
@keyframes bob { 50% { transform: scale(1.3) translateY(-4px); } }

.status-dot { display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--s-planned); }
.status-dot.s-placed { background: var(--s-placed); }
.status-dot.s-removed { background: var(--s-removed); }

.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  margin-top: 14px; padding: 4px; border-radius: 14px; background: var(--surface-2);
}
.segmented button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; font-size: 14px;
}
.segmented button.active { background: var(--surface); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.2); }

.field { display: block; margin-top: 14px; }
.field > span { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field textarea, .row-form input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text);
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
}
.field textarea { resize: vertical; min-height: 72px; }
.field input:focus, .field textarea:focus, .row-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.saved { font-style: normal; font-weight: 400; color: var(--s-placed); margin-left: 6px; }

.row-form { display: flex; gap: 8px; margin-top: 14px; }
.row-form input { flex: 1; min-width: 0; }

.profile-list, .pin-list { list-style: none; margin: 10px 0 0; padding: 0; }
.profile-list li, .pin-list li { border-top: 1px solid var(--border); }
.profile-list .empty, .pin-list .empty { padding: 14px 0; color: var(--muted); }
.profile-row, .pin-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 52px; padding: 8px 4px;
  border: 0; background: none; text-align: left; cursor: pointer;
}
.profile-row { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; padding-left: 36px; position: relative; }
.profile-row::before {
  content: ""; position: absolute; left: 6px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--muted);
}
.profile-row.active::before { border-color: var(--accent); background: radial-gradient(var(--accent) 45%, transparent 50%); }
.profile-row .muted, .pin-row .muted { margin: 0; font-size: 13px; }
.profile-name { font-weight: 600; }
.pin-row-body { display: flex; flex-direction: column; min-width: 0; }
.pin-row-body > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-row:active, .pin-row:active { background: var(--surface-2); }

.filter-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.filter-chips button {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 18px; background: transparent; cursor: pointer; font-size: 14px;
}
.filter-chips button:not(.active) { opacity: .5; text-decoration: line-through; }
.filter-chips .n { color: var(--muted); }

/* Placement mode */
#crosshair, #place-bar { display: none; }
body.placing #crosshair {
  display: block; position: fixed; z-index: 15; left: 50%; top: 50%;
  transform: translate(-50%, calc(-100% - 1px)); pointer-events: none;
}
body.placing #crosshair::after {
  content: ""; position: absolute; left: 50%; bottom: -3px; width: 6px; height: 6px;
  transform: translateX(-50%); border-radius: 50%; background: #000; opacity: .45;
}
body.placing #place-bar {
  display: block; position: fixed; z-index: 30;
  left: calc(var(--safe-left) + var(--gutter)); right: calc(var(--safe-right) + var(--gutter));
  bottom: calc(var(--safe-bottom) + var(--gutter));
  max-width: 440px; margin: 0 auto; padding: 14px 16px; border-radius: 20px;
}
#place-bar p { margin: 0; }
.place-bar-actions { display: flex; gap: 8px; margin-top: 12px; }
.place-bar-actions .pill { flex: 1; justify-content: center; }
body.placing #fabs, body.placing .sheet, body.placing #profile-chip { display: none !important; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; z-index: 50;
  left: 50%; bottom: calc(var(--safe-bottom) + 24px + var(--sheet-h));
  transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  padding: 12px 18px; border-radius: 8px;
  background: #323232; color: #fff;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Setup screen ---------- */
#setup {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  background: var(--bg); overflow-y: auto;
}
.setup-card { max-width: 480px; }
.setup-card h1 { font-size: 22px; margin: 0 0 8px; }
.setup-card li { margin: 6px 0; }
.setup-card code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* Hide app chrome while Street View is open */
body.streetview #search-bar,
body.streetview #dir-card,
body.streetview #fabs,
body.streetview .sheet { display: none !important; }

/* ---------- Larger screens: floating side panel instead of bottom sheet ---------- */
@media (min-width: 768px) {
  .sheet {
    left: calc(var(--safe-left) + var(--gutter));
    right: auto; bottom: auto;
    top: calc(var(--safe-top) + var(--gutter) + var(--top-h, 60px) + 8px);
    width: 400px;
    max-height: calc(100dvh - var(--top-h, 60px) - 48px);
    border-radius: 20px;
    animation: none;
  }
  .sheet.expanded { max-height: calc(100dvh - var(--top-h, 60px) - 48px); }
  .sheet-handle { display: none; }
  .sheet { padding-top: 16px; }
  #search-bar, #dir-card { width: 400px; right: auto; }
  #fabs { transform: none; }
  #toast { bottom: calc(var(--safe-bottom) + 24px); }
}
