:root {
  /* Light theme (default) — matches the KAD Field Visits design spec. */
  --bg: #f6f7f9;
  --bg-elevated: rgba(255, 255, 255, 0.9);
  --bg-card: #ffffff;
  --bg-card-pressed: #eef0f3;
  --border: #e7e9ed;
  --text: #111318;
  --text-dim: #5b6270;
  --text-tertiary: #9aa1ab;
  --accent: #1677ff;
  --accent-dark: #0b5ed6;
  --success: #16a765;
  --warning: #f59e0b;
  --danger: #e5484d;
  --inactive: #adb3bc;
  --radius: 14px;
  --radius-lg: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --pin-border: #ffffff;
  --shadow-subtle: 0 1px 3px rgba(17, 19, 24, 0.06);
  --shadow-elevated: 0 8px 24px rgba(17, 19, 24, 0.12);
}

:root[data-theme="dark"] {
  --bg: #000000;
  --bg-elevated: rgba(28, 28, 30, 0.86);
  --bg-card: #1c1c1e;
  --bg-card-pressed: #232326;
  --border: #38383a;
  --text: #f5f5f7;
  --text-dim: #98989d;
  --text-tertiary: #6c6c70;
  --accent: #3d8bff;
  --accent-dark: #1677ff;
  --success: #30d158;
  --warning: #ff9f0a;
  --danger: #ff453a;
  --inactive: #636366;
  --pin-border: #000000;
  --shadow-subtle: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-elevated: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* Light is the deliberate default regardless of system preference (matches
   the approved design), so dark mode only applies via an explicit user
   toggle — see theme.js. */

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

/* Defends every element that toggles visibility via the `hidden` attribute
   from being re-shown by a later class rule that sets `display` (e.g.
   `.top-bar { display: flex }`) — those would otherwise win over the
   browser's default `[hidden] { display: none }` since author CSS always
   outranks user-agent CSS at equal specificity. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  /* Suppresses iOS Safari's double-tap-to-zoom gesture app-wide (the
     viewport meta's maximum-scale alone doesn't reliably do this,
     especially in standalone/installed mode) without blocking normal
     single-finger scrolling, unlike touch-action: none. */
  touch-action: manipulation;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

a {
  color: var(--accent);
}

.muted {
  color: var(--text-dim);
}

/* Press feedback, iOS-style */

.btn,
.nav-item,
.card,
.chip,
.fab {
  transition: transform 0.12s ease, opacity 0.12s ease, background-color 0.12s ease;
}

.btn:active,
.card:active,
.fab:active {
  transform: scale(0.97);
  opacity: 0.85;
}

.nav-item:active {
  opacity: 0.6;
}

/* Top bar */

.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
  /* sticky (not just relative) keeps this pinned during iOS Safari's
     momentum-scroll repaint, which can otherwise let a flex sibling drift
     with the scrolled content on a long list. */
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-logo {
  width: 22px;
  height: 22px;
  background: #ffffff;
  border-radius: 6px;
  padding: 3px;
  object-fit: contain;
}

.topbar-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text);
}

.topbar-user {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 0.88rem;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 4px;
  font-size: 0.92rem;
}

/* Nav bar */

.nav-bar {
  display: flex;
  align-items: flex-start;
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--border);
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
  /* sticky (not just relative) keeps this pinned during iOS Safari's
     momentum-scroll repaint on a long list (e.g. Customers, "Not visited"
     filter) instead of drifting with the scrolled content. */
  position: sticky;
  bottom: 0;
  z-index: 10;
  height: calc(48px + var(--safe-bottom));
}

.nav-item {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 48px;
  padding: 0 2px;
  font-size: 0.62rem;
  font-weight: 500;
  cursor: pointer;
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-item-active {
  color: var(--accent);
}

.nav-item-center-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 48px;
}

.nav-item-center {
  width: 50px;
  height: 50px;
  margin-top: -18px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  border: 4px solid var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.nav-item-center-active {
  filter: brightness(1.1);
}

.nav-icon-center {
  font-size: 1.3rem;
  line-height: 1;
  display: flex;
}

.nav-item-center-label {
  font-size: 0.64rem;
  font-weight: 600;
  color: var(--accent);
  margin-top: 1px;
}

/* Sync banner */

.sync-banner {
  background: var(--accent);
  color: #17181a;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 10px;
  padding-top: calc(6px + var(--safe-top));
}

/* Install banner */

.install-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  margin: 0 12px calc(10px + var(--safe-bottom));
  position: fixed;
  left: 0;
  right: 0;
  bottom: 62px;
  z-index: 900;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: slide-up 0.25s ease;
}

@keyframes slide-up {
  from {
    transform: translateY(16px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.install-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
}

.install-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.install-copy strong {
  font-size: 0.88rem;
}

.install-copy span {
  font-size: 0.76rem;
  color: var(--text-dim);
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.82rem;
  white-space: nowrap;
}

.install-dismiss {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}

.install-sheet .ios-steps {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.install-sheet .ios-steps li {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.95rem;
}

.ios-step-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.ios-anim-share svg {
  animation: bob 1.3s ease-in-out infinite;
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

/* App main */

.app-main {
  flex: 1;
  overflow-y: auto;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

/* While the map view is mounted, the app shell must not scroll — an
   ancestor with overflow:auto fights Leaflet's own pan/zoom touch
   handling on iOS and can make the map feel like it's freezing. */
.app-main-locked {
  overflow: hidden;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 13px 16px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-primary:disabled {
  opacity: 0.4;
}

.btn-block {
  width: 100%;
}

.btn-accent {
  color: var(--accent);
  font-weight: 700;
}

/* Forms */

form label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 14px;
}

form input,
form textarea,
form select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
}

form input:focus,
form textarea:focus,
form select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: -6px 0 12px;
}

.form-success {
  color: var(--success);
  font-size: 0.85rem;
  margin: -6px 0 12px;
}

/* Login */

.login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  background: #ffffff;
  border-radius: 12px;
  width: 46px;
  height: 46px;
  padding: 8px;
  object-fit: contain;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.login-brand h1 {
  font-size: 1.5rem;
  margin: 0;
  letter-spacing: -0.02em;
}

/* Cards / badges */

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 16px 16px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
}

.card:active {
  background: var(--bg-card-pressed);
}

.customer-card,
.activity-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.customer-card-main,
.activity-row-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.customer-card-main strong,
.activity-row-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-trailing {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chevron {
  color: var(--text-dim);
  opacity: 0.7;
  font-size: 1rem;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-success {
  background: rgba(48, 209, 88, 0.15);
  color: var(--success);
}

.badge-danger {
  background: rgba(255, 69, 58, 0.15);
  color: var(--danger);
}

.badge-neutral {
  background: rgba(152, 152, 157, 0.15);
  color: var(--text-dim);
}

.badge-accent {
  background: rgba(255, 106, 19, 0.15);
  color: var(--accent);
}

.badge-info {
  background: rgba(10, 132, 255, 0.15);
  color: #0a84ff;
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

/* List view */

.list-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.list-toolbar input[type="search"] {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}

.dropdown-menu {
  position: absolute;
  right: 16px;
  top: calc(100% + 4px);
  z-index: 20;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-elevated);
  padding: 6px;
  display: flex;
  flex-direction: column;
  min-width: 160px;
}

.dropdown-menu button {
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  cursor: pointer;
}

.dropdown-menu button:active {
  background: var(--bg-card-pressed);
}

/* Segmented control, iOS style */

.segmented {
  display: flex;
  background: var(--bg-card);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}

.chip {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.chip-active {
  background: var(--accent);
  color: #ffffff;
}

/* Detail view */

.detail-view,
.checkin-view,
.dashboard-view,
.admin-view {
  padding: 16px;
}

.dashboard-view h1 {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
}

.detail-facts {
  color: var(--text-dim);
  font-size: 0.92rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 10px 0 18px;
}

.section-title {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 26px 0 10px;
}

.checkin-card-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.checkin-note {
  margin: 8px 0 0;
}

.brand-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.brand-tag {
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 3px 9px;
}

.checkin-photo {
  margin-top: 10px;
  width: 100%;
  border-radius: 10px;
  display: block;
}

/* Check-in flow */

.checkin-view h1 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.gps-status {
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.gps-status.gps-ok {
  color: var(--success);
  border-color: var(--success);
}

.gps-status.gps-error {
  color: var(--danger);
  border-color: var(--danger);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.brands-label {
  margin-bottom: 18px;
}

.brand-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.brand-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--text);
  margin: 0;
  cursor: pointer;
}

.brand-chip input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  margin: 0;
  flex-shrink: 0;
}

.brand-chip:has(input:checked) {
  border-color: var(--accent);
  background: rgba(255, 106, 19, 0.1);
}

.camera-field {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.camera-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px dashed var(--border);
  color: var(--text-dim);
  font-size: 0.72rem;
  cursor: pointer;
}

.camera-btn:active {
  background: var(--bg-card-pressed);
}

.photo-preview-wrap {
  position: relative;
  width: 100%;
  max-width: 280px;
}

.photo-preview-wrap img {
  width: 100%;
  border-radius: var(--radius-lg);
  display: block;
  aspect-ratio: 1;
  object-fit: cover;
}

.photo-retake-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.checkin-result {
  text-align: center;
  padding: 24px 16px;
}

.result-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  margin: 0 auto 12px;
  font-weight: 700;
}

.result-success .result-icon {
  background: rgba(48, 209, 88, 0.15);
  color: var(--success);
}

.result-warning .result-icon {
  background: rgba(255, 106, 19, 0.15);
  color: var(--accent);
}

/* Dashboard */

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0 6px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.stat-label {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.manager-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: default;
}

.user-row {
  cursor: default;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-row-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.user-row-top > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-row-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-row-actions {
  display: flex;
  gap: 14px;
}

.btn-link-danger {
  color: var(--danger);
}

/* Settings view */

.settings-view {
  padding: 16px;
}

.settings-view h1 {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: default;
  margin-bottom: 16px;
}

.settings-account-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.radius-help {
  font-size: 0.8rem;
  margin: -8px 0 14px;
}

#radius-form .btn-primary {
  width: 100%;
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 30px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background-color 0.2s ease;
}

.switch-track::before {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  left: 2px;
  top: 2px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease;
}

.switch input:checked + .switch-track {
  background: var(--success);
}

.switch input:checked + .switch-track::before {
  transform: translateX(20px);
}

/* Plan view */

.plan-view {
  padding: 16px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.plan-empty {
  text-align: center;
  max-width: 300px;
}

.plan-empty-icon {
  font-size: 2.6rem;
  margin-bottom: 12px;
}

.plan-empty h1 {
  font-size: 1.3rem;
  font-weight: 800;
  margin: 0 0 8px;
}

/* Map view */

.map-view {
  position: absolute;
  inset: 0;
}

#leaflet-map {
  width: 100%;
  height: 100%;
  background: var(--bg);
}

.map-picking {
  cursor: crosshair;
}

.fab {
  position: absolute;
  right: 16px;
  bottom: calc(16px + var(--safe-bottom));
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  border: none;
  font-size: 1.8rem;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  z-index: 1000;
}

.fab-active {
  background: var(--bg-card);
  color: var(--accent);
  border: 2px solid var(--accent);
}

.relocate-banner {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--text);
}

.relocate-banner button {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.map-hint {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius);
  text-align: center;
  font-size: 0.85rem;
  z-index: 1000;
}

.pin {
  width: 18px;
  height: 18px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid var(--pin-border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.pin-today {
  background: var(--success);
}

.pin-week {
  background: #0a84ff;
}

.pin-pending {
  background: var(--accent);
}

.pin-new {
  width: 26px;
  height: 26px;
  background: #0a84ff;
  border-width: 3px;
  animation: pin-drop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pin-drop {
  from {
    transform: rotate(-45deg) translateY(-16px) scale(0.6);
    opacity: 0;
  }
  to {
    transform: rotate(-45deg) translateY(0) scale(1);
    opacity: 1;
  }
}

.pin-check {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: rotate(45deg) translate(-50%, -50%);
  color: #ffffff;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

.team-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #af52de;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.me-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #0a84ff;
  border: 3px solid #ffffff;
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.35), 0 1px 4px rgba(0, 0, 0, 0.4);
}

.map-controls {
  position: absolute;
  right: 12px;
  top: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  z-index: 1000;
}

.map-control-cluster {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.map-control-divider {
  height: 1px;
  background: var(--border);
}

.map-control-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
}

.map-control-btn:active {
  background: var(--bg-card-pressed);
}

.map-control-standalone {
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.map-control-active {
  color: #0a84ff;
}

.map-popup {
  color: #1a1a1a;
}

.popup-category {
  color: #555;
  font-size: 0.82rem;
}

.popup-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.popup-actions button {
  border: 1px solid #ccc;
  background: #f4f4f4;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 0.82rem;
  cursor: pointer;
}

.popup-actions .btn-accent {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

/* Sheets (bottom modal) */

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  z-index: 2000;
}

/* Used for the "new customer" sheet, opened right after dropping a pin —
   a lighter wash keeps the just-placed pin clearly visible above the sheet
   instead of being obscured by a near-opaque backdrop. */
.sheet-overlay-light {
  background: rgba(0, 0, 0, 0.15);
}

.sheet {
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
}

.sheet h2 {
  margin-top: 0;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.sheet-actions {
  display: flex;
  gap: 10px;
}

.sheet-actions .btn {
  flex: 1;
}

/* ===== Dashboard / Activity redesign ===== */

.text-success {
  color: var(--success);
}

.text-danger {
  color: var(--danger);
}

.greeting-row {
  margin-bottom: 14px;
}

.greeting-row h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 2px;
}

.card {
  box-shadow: var(--shadow-subtle);
}

.progress-card {
  margin: 4px 0 18px;
  padding: 18px;
}

.progress-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-dim);
}

.progress-main {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin: 8px 0 14px;
}

.progress-fraction {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.02em;
  line-height: 1;
}

.progress-fraction-total {
  font-size: 1.3rem;
  color: var(--text-dim);
  font-weight: 700;
}

.progress-side {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.progress-side-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-success {
  background: var(--success);
}

.dot-warning {
  background: var(--warning);
}

.dot-danger {
  background: var(--danger);
}

.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.next-visit-card {
  margin-bottom: 18px;
  padding: 16px;
}

.erp-card {
  margin-bottom: 18px;
  padding: 16px;
}

.erp-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.erp-debt-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.erp-debt-amount {
  font-size: 1.1rem;
  font-weight: 700;
}

.erp-order-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85rem;
  padding: 10px 4px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  min-height: 44px;
  align-items: center;
}

.erp-order-row:active {
  background: var(--bg-card-pressed);
}

.erp-order-id {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.erp-show-all-btn {
  margin-top: 12px;
}

.erp-suggest-wrap {
  position: relative;
}

.erp-suggest-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 20;
  margin-top: 4px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.erp-suggest-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  min-height: 44px;
  align-items: center;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.erp-suggest-item:last-child {
  border-bottom: none;
}

.erp-suggest-item:active {
  background: var(--bg-card-pressed);
}

.erp-line-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85rem;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.order-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.order-detail-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.next-visit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
}

.next-visit-body {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 14px;
}

.next-visit-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.next-visit-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.next-visit-info strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.next-visit-actions {
  display: flex;
  gap: 10px;
}

.next-visit-actions .btn {
  flex: 1;
}

.next-visit-due {
  margin-top: 8px;
}

/* .dashboard-view already carries 16px padding on all sides (shared with
   .detail-view/.checkin-view), so nested .stat-grid/.card-list — which
   normally add their own 16px side padding for unpadded containers like
   .list-view — must not double it up here. */
.dashboard-view .stat-grid,
.dashboard-view .card-list {
  padding-left: 0;
  padding-right: 0;
}

.stat-grid-4 {
  margin-bottom: 6px;
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title-inline {
  margin: 26px 0 10px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px;
}

.quick-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-bottom: 8px;
}

.quick-action {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.quick-action-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.quick-action-icon-accent {
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

/* ===== Customers list redesign ===== */

.list-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 16px 0;
  gap: 10px;
}

.list-header h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
}

.customer-stats-bar {
  display: flex;
  gap: 8px;
  padding: 14px 16px 0;
  overflow-x: auto;
}

.stat-pill {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 84px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
}

.stat-pill strong {
  font-size: 1.15rem;
  font-weight: 800;
}

.stat-pill span {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.stat-pill-active {
  background: var(--accent);
  border-color: var(--accent);
}

.stat-pill-active strong,
.stat-pill-active span {
  color: #ffffff;
}

.customer-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.customer-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.customer-card-last-visit {
  font-size: 0.76rem;
}

/* ===== Customer detail redesign ===== */

.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.detail-header-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
}

.detail-header-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.detail-header-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn-danger {
  color: var(--danger);
}

.checkin-photo-wrap {
  position: relative;
  margin-top: 10px;
}

.checkin-photo-wrap .checkin-photo {
  margin-top: 0;
}

.photo-delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  border: none;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.pending-request-card {
  margin-bottom: 18px;
}

.pending-request-card-quiet {
  padding: 12px 14px;
}

.pending-request-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.proposed-changes-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 6px;
}

.proposed-change {
  font-size: 0.88rem;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.proposed-change:last-of-type {
  border-bottom: none;
}

.detail-header-title h1 {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-facts-card {
  margin: 14px 0;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-fact {
  font-size: 0.9rem;
  display: flex;
  gap: 8px;
}

.detail-fact a {
  color: var(--text);
  text-decoration: none;
}

.detail-actions-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 18px 0;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 4px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.action-btn span:first-child {
  font-size: 1.2rem;
}

.action-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.checkin-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ===== Check-in redesign ===== */

.verify-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.verify-banner strong {
  display: block;
  font-size: 0.92rem;
}

.verify-banner .muted {
  font-size: 0.8rem;
}

.verify-banner-success {
  background: rgba(22, 167, 101, 0.12);
}

.verify-banner-warning {
  background: rgba(245, 158, 11, 0.12);
}

.verify-banner-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex-shrink: 0;
  color: #ffffff;
}

.verify-banner-success .verify-banner-icon {
  background: var(--success);
}

.verify-banner-warning .verify-banner-icon {
  background: var(--warning);
}

.outcome-label {
  margin-bottom: 18px;
}

.outcome-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.outcome-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.82rem;
  color: var(--text);
  margin: 0;
  cursor: pointer;
}

.outcome-chip input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.outcome-chip:has(input:checked) {
  border-color: var(--accent);
  background: rgba(22, 119, 255, 0.1);
  color: var(--accent);
  font-weight: 600;
}

.outcome-icon {
  font-size: 1rem;
}

/* ===== Map redesign ===== */

.map-filter-row {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 70px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  z-index: 1000;
}

.map-filter-chip {
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-subtle);
}

.map-filter-chip.chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.nearby-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  max-height: 55%;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-elevated, 0 -4px 20px rgba(0, 0, 0, 0.2));
}

.nearby-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.nearby-panel-header #nearby-panel-close {
  font-size: 1.3rem;
  line-height: 1;
  color: var(--text-dim);
}

.nearby-list {
  overflow-y: auto;
  padding: 8px 12px;
  flex: 1;
}

.nearby-view-all {
  border: none;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 12px;
  cursor: pointer;
}

.pin-overdue {
  background: var(--danger);
}

/* Required OSM/CARTO attribution (see map.js), shrunk to an unobtrusive
   corner label instead of Leaflet's default full-contrast bar. */
.leaflet-control-attribution {
  font-size: 0.6rem;
  opacity: 0.55;
  background: transparent;
  box-shadow: none;
  padding: 0 4px;
}

/* The manifest's "orientation": "portrait" is honored by Android in
   standalone mode, but iOS Safari/WebKit ignores it even when installed to
   the home screen -- there is no web API to force-lock orientation there.
   This overlay is the practical fallback: it blocks interaction and asks
   the user to rotate back, rather than letting the layout break. */
.rotate-overlay {
  display: none;
}

@media (orientation: landscape) and (max-device-width: 926px) {
  .rotate-overlay {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: var(--bg);
    color: var(--text);
    text-align: center;
    padding: 24px;
  }

  .rotate-overlay-icon {
    font-size: 3rem;
    transform: rotate(90deg);
  }
}
