:root {
  --primary: #0b6cc8;
  --primary-dark: #083861;
  --primary-soft: #eff7ff;
  --secondary: #14b8a6;
  --background: #edf3f9;
  --surface: #ffffff;
  --surface-muted: #f7f9fc;
  --text: #122033;
  --text-muted: #5f6c7b;
  --border: #d9e3ee;
  --success: #15803d;
  --success-soft: #effaf3;
  --warning: #b45309;
  --warning-soft: #fff8eb;
  --danger: #b42318;
  --danger-soft: #fff3f2;
  --focus: #60a5fa;
  --radius-sm: 0.75rem;
  --radius: 1.15rem;
  --radius-lg: 1.65rem;
  --shadow-sm: 0 0.5rem 1.5rem -1rem rgb(15 23 42 / 0.26);
  --shadow: 0 1.5rem 3.5rem -2.35rem rgb(15 23 42 / 0.38);
  --space-1: 0.35rem;
  --space-2: 0.65rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  --space-6: 3rem;
  font-family: "Aptos", "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--background);
  color-scheme: light;
  line-height: 1.5;
}

* { box-sizing: border-box; }

html { min-width: 0; min-height: 100%; background: var(--background); }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 12% 0%, rgb(11 108 200 / 0.14), transparent 30rem),
    radial-gradient(circle at 90% 8%, rgb(20 184 166 / 0.09), transparent 24rem),
    linear-gradient(180deg, #f6f9fc 0%, var(--background) 60%, #e8eef5 100%);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
a, button, input { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.topbar {
  position: relative;
  z-index: 1100;
  border-bottom: 1px solid rgb(255 255 255 / 0.16);
  color: #fff;
  background: linear-gradient(105deg, var(--primary) 0%, #0a5ca9 52%, var(--primary-dark) 100%);
  box-shadow: 0 1rem 3rem -2rem rgb(8 56 97 / 0.8);
}

.topbar-inner {
  width: min(100% - 2rem, 58rem);
  min-height: 5rem;
  margin: 0 auto;
  padding: calc(0.7rem + env(safe-area-inset-top)) 0 0.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.brand { min-height: 44px; display: inline-flex; align-items: center; gap: 0.7rem; color: #fff; text-decoration: none; white-space: nowrap; }
.brand img { width: 2.35rem; height: 2.35rem; border-radius: 0.78rem; box-shadow: 0 0.7rem 1.4rem -0.8rem rgb(0 0 0 / 0.6); }
.brand-wordmark { font-family: "Bahnschrift", "Aptos Display", "Segoe UI", sans-serif; font-size: 1.35rem; font-weight: 500; letter-spacing: -0.035em; }
.brand-wordmark strong { color: #7ce8d2; font-weight: 700; }
.account-block { display: grid; justify-items: end; gap: 0.15rem; min-width: 0; }
.account-name { max-width: 28rem; overflow: hidden; color: rgb(255 255 255 / 0.78); font-size: 0.72rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.topbar nav { display: flex; align-items: center; gap: 0.2rem; }
.topbar form { margin: 0; }
.topbar nav a, .topbar nav .link {
  min-height: 44px;
  padding: 0.58rem 0.75rem;
  display: inline-flex;
  align-items: center;
  border: 0;
  border-radius: 0.7rem;
  color: #fff;
  background: transparent;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 160ms ease, transform 160ms ease;
}
.topbar nav a:hover, .topbar nav .link:hover { background: rgb(255 255 255 / 0.12); }
.topbar nav a:active, .topbar nav .link:active { transform: translateY(1px); }

main { width: min(100% - 2rem, 54rem); margin: clamp(1.5rem, 4vw, 3rem) auto calc(5rem + env(safe-area-inset-bottom)); }
.page-heading { margin-bottom: var(--space-4); }
.page-heading h1 { margin-bottom: 0.55rem; }
.page-intro { max-width: 42rem; color: var(--text-muted); font-size: 0.98rem; }
.worker-identity { color: var(--text-muted); font-weight: 650; overflow-wrap: anywhere; }
.eyebrow { margin: 0 0 0.3rem; color: var(--primary); font-size: 0.71rem; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; }
h1, h2, h3 { font-family: "Bahnschrift", "Aptos Display", "Segoe UI", sans-serif; color: var(--text); letter-spacing: -0.035em; }
h1 { margin: 0; font-size: clamp(2rem, 7vw, 3.25rem); line-height: 1.02; }
h2 { margin: 0; font-size: 1.25rem; line-height: 1.15; }
.section-heading { margin: var(--space-5) 0 var(--space-3); }

.card { padding: clamp(1rem, 3vw, 1.4rem); border: 1px solid rgb(217 227 238 / 0.95); border-radius: var(--radius-lg); background: rgb(255 255 255 / 0.94); box-shadow: var(--shadow); backdrop-filter: blur(10px); }
.card-heading { margin-bottom: var(--space-3); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.status-chip { padding: 0.38rem 0.68rem; border: 1px solid #bddcff; border-radius: 999px; color: var(--primary-dark); background: var(--primary-soft); font-size: 0.72rem; font-weight: 750; }
.status-chip.success { border-color: #bdeacb; color: #166534; background: var(--success-soft); }

.auth { max-width: 29rem; margin: clamp(2rem, 10vh, 6rem) auto; padding: clamp(1.35rem, 5vw, 2.25rem); }
.auth h1 { margin-bottom: 0.85rem; font-size: clamp(2rem, 8vw, 2.8rem); }
.auth-mark { width: 3.25rem; height: 3.25rem; margin-bottom: var(--space-4); display: grid; place-items: center; border-radius: 1.05rem; color: #fff; background: linear-gradient(135deg, var(--primary), #0a5ca9); box-shadow: 0 1.15rem 2.5rem -1.5rem rgb(11 108 200 / 0.78); font-family: "Bahnschrift", sans-serif; font-size: 1.4rem; font-weight: 700; }
.stack p { margin: var(--space-3) 0; display: grid; gap: 0.38rem; }
label { color: #334155; font-size: 0.88rem; font-weight: 700; }
input, textarea, select { width: 100%; min-height: 3rem; padding: 0.75rem 0.9rem; border: 1px solid #b8c7d8; border-radius: var(--radius-sm); color: var(--text); background: #fff; box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.6), 0 0.65rem 1.7rem -1.45rem rgb(15 23 42 / 0.55); transition: border-color 160ms ease, box-shadow 160ms ease; }
input:hover, textarea:hover, select:hover { border-color: #8ca6bd; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); outline: 0; box-shadow: 0 0 0 4px rgb(11 108 200 / 0.12); }

.primary, .secondary, .danger, .danger-link, .location-grid button, .undo button, .retry button { min-height: 3.15rem; border-radius: var(--radius-sm); font: inherit; font-weight: 750; cursor: pointer; transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease, background-color 150ms ease; }
.primary { width: 100%; padding: 0.85rem 1rem; border: 1px solid var(--primary); color: #fff; background: linear-gradient(135deg, var(--primary), #0a5ca9); box-shadow: 0 1rem 2rem -1.35rem rgb(11 108 200 / 0.88); }
.primary:hover { background: linear-gradient(135deg, #0a63b7, var(--primary-dark)); box-shadow: 0 1.15rem 2.2rem -1.3rem rgb(8 56 97 / 0.9); }
.primary:active, .secondary:active, .danger:active, .danger-link:active, .location-grid button:active { transform: translateY(1px); }
.primary:disabled { opacity: 0.46; box-shadow: none; cursor: not-allowed; }
.button { display: block; text-align: center; text-decoration: none; }
.secondary { padding: 0.8rem 1rem; border: 1px solid #aac0d3; color: var(--primary-dark); background: #fff; }
.secondary:hover { border-color: var(--primary); background: var(--primary-soft); }
.danger, .danger-link { width: 100%; padding: 0.8rem 1rem; border: 1px solid #f0b5af; color: var(--danger); background: var(--danger-soft); }
.danger:hover, .danger-link:hover { border-color: var(--danger); background: #ffe7e5; }
.auth-alternative { min-height: 2.75rem; margin-top: var(--space-3); display: flex; align-items: center; justify-content: center; color: var(--primary); font-size: 0.9rem; font-weight: 700; text-decoration: none; }

.route-list { padding: clamp(0.95rem, 3vw, 1.35rem); }
.stop { min-height: 3.85rem; padding: 0.4rem 0; display: flex; align-items: center; gap: 0.78rem; }
.number { width: 2.25rem; height: 2.25rem; flex: 0 0 2.25rem; display: grid; place-items: center; border: 1px solid #bddcff; border-radius: 0.78rem; color: var(--primary-dark); background: var(--primary-soft); font-weight: 850; }
.stop-label { min-width: 0; display: grid; line-height: 1.25; }
.stop-label strong { overflow-wrap: anywhere; }
.stop-label small { margin-top: 0.2rem; color: var(--text-muted); font-size: 0.72rem; }
.stop-actions { margin-left: auto; display: flex; gap: 0.3rem; }
.stop-actions form { margin: 0; }
.stop-actions button { min-width: 2.75rem; min-height: 2.75rem; border: 1px solid var(--border); border-radius: 0.75rem; color: #334155; background: #fff; font-size: 1.08rem; cursor: pointer; }
.stop-actions button:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.stop-actions .icon-danger { border-color: #f1c1bc; color: var(--danger); }
.leg { margin-left: 1.1rem; padding: 0.25rem 0 0.25rem 2rem; border-left: 2px solid #70d8ce; color: var(--text-muted); font-size: 0.82rem; }
.total { margin: var(--space-3) 0 0; padding: var(--space-3); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); border: 1px solid #bddcff; border-radius: var(--radius); color: var(--primary-dark); background: linear-gradient(135deg, var(--primary-soft), #fff); }
.total span { font-size: 0.82rem; font-weight: 700; }
.total strong { color: var(--primary); font-family: "Bahnschrift", sans-serif; font-size: 1.25rem; white-space: nowrap; }

.location-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; }
.location-grid form { margin: 0; }
.location-grid button { width: 100%; min-height: 4.4rem; padding: 0.75rem 0.55rem; border: 1px solid #bddcff; color: var(--primary-dark); background: rgb(255 255 255 / 0.9); box-shadow: var(--shadow-sm); overflow-wrap: anywhere; }
.location-grid button:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); transform: translateY(-1px); }
.location-grid .office-location { border-color: #9be1d7; color: #0f675f; background: #eefcfb; }
.location-grid .office-location:hover { border-color: var(--secondary); background: #dff8f5; }
.finish { margin-top: var(--space-4); }
.finish .primary { border-color: #0f766e; background: linear-gradient(135deg, #1296a2, #0f766e); box-shadow: 0 1rem 2rem -1.35rem rgb(15 118 110 / 0.8); }
.finish .primary:hover { background: linear-gradient(135deg, #0f8792, #0b5d57); }
.custom-stop-link, .day-actions, .danger-link { margin-top: 0.75rem; }
.custom-stop-link { width: 100%; }
.day-actions, .confirm-action { display: grid; gap: 0.65rem; }
.undo, .retry { margin: 0.75rem 0; }
.undo button, .retry button { width: 100%; padding: 0.75rem; border: 1px solid #aac0d3; color: #334155; background: #fff; }
.undo button:hover { border-color: var(--primary); background: var(--primary-soft); }
.retry button { border-color: #f0c484; color: #92400e; background: var(--warning-soft); }

.message { margin: 0 0 var(--space-3); padding: 0.85rem 1rem; display: flex; align-items: flex-start; gap: 0.65rem; border: 1px solid #bddcff; border-radius: var(--radius-sm); color: var(--primary-dark); background: var(--primary-soft); box-shadow: var(--shadow-sm); }
.message > span { color: var(--primary); font-size: 0.65rem; line-height: 1.5rem; }
.message.error { border-color: #f0b5af; color: #8f1d16; background: var(--danger-soft); }
.message.error > span { color: var(--danger); }
.message.success { border-color: #bdeacb; color: #166534; background: var(--success-soft); }
.message.success > span { color: var(--success); }
.errorlist { margin: 0.25rem 0; padding-left: 1.25rem; color: var(--danger); font-size: 0.85rem; }

.history-list { padding: 0.35rem; overflow: hidden; }
.history-list a, .snapshot { min-height: 4.5rem; padding: 0.9rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; }
.history-list a { border-radius: var(--radius); transition: background-color 150ms ease, transform 150ms ease; }
.history-list a:hover { background: var(--primary-soft); transform: translateX(2px); }
.history-list a:last-child, .snapshot:last-child { border-bottom: 0; }
.history-list a > span:first-child, .history-metric { display: grid; gap: 0.12rem; }
.history-list small { color: var(--text-muted); font-size: 0.73rem; text-transform: capitalize; }
.history-metric { justify-items: end; text-align: right; }
.history-metric strong { color: var(--primary); }
.history-add { margin-top: var(--space-3); }
.month-navigation { margin: var(--space-4) 0 var(--space-3); display: flex; gap: 0.5rem; overflow-x: auto; padding-bottom: 0.25rem; }
.month-navigation a { padding: 0.55rem 0.8rem; border: 1px solid #aac0d3; border-radius: 999px; color: var(--primary-dark); background: #fff; font-size: 0.82rem; font-weight: 750; text-decoration: none; text-transform: capitalize; white-space: nowrap; }
.month-navigation a[aria-current="page"] { border-color: var(--primary); color: #fff; background: var(--primary); }
.monthly-summary h2 { margin-bottom: var(--space-3); text-transform: capitalize; }
.monthly-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.monthly-metrics p { margin: 0; padding: 0.9rem; display: grid; gap: 0.25rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-muted); }
.monthly-metrics span { color: var(--text-muted); font-size: 0.78rem; font-weight: 700; }
.monthly-metrics strong { color: var(--primary-dark); font-size: 1.1rem; }
.rate-warning { margin: var(--space-3) 0 0; color: var(--warning); font-size: 0.85rem; }
.monthly-reports { margin-top: var(--space-3); }
.monthly-reports h2, .monthly-email-confirm h2 { text-transform: capitalize; }
.monthly-reports > p:not(.eyebrow), .pending-note { color: var(--text-muted); }
.monthly-empty { padding-block: 1.25rem; }
.monthly-report-actions { margin-top: var(--space-3); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; }
.monthly-report-actions .secondary { width: 100%; }
.monthly-report-actions button:disabled { opacity: 0.46; cursor: not-allowed; }
.report-confirmation-details { margin: var(--space-3) 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.65rem; }
.report-confirmation-details div { padding: 0.85rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-muted); }
.report-confirmation-details dt { color: var(--text-muted); font-size: 0.76rem; font-weight: 700; }
.report-confirmation-details dd { margin: 0.2rem 0 0; color: var(--primary-dark); font-size: 1.05rem; font-weight: 800; }
.recipient-options { margin: 0 0 var(--space-3); padding: 0; border: 0; }
.recipient-options legend { margin-bottom: 0.55rem; font-weight: 750; }
.recipient-options label { margin-bottom: 0.55rem; padding: 0.8rem; display: flex; align-items: center; gap: 0.7rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; cursor: pointer; }
.recipient-options input { width: 1.2rem; min-height: 1.2rem; margin: 0; flex: 0 0 auto; }
.recipient-options span { min-width: 0; display: grid; gap: 0.15rem; font-weight: 750; }
.recipient-options small { color: var(--text-muted); font-weight: 500; overflow-wrap: anywhere; }
.report-actions { margin-top: var(--space-4); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; }
.report-actions form, .report-actions button { width: 100%; height: 100%; margin: 0; }
.empty { margin: 0; padding: 2.5rem 1rem; color: var(--text-muted); text-align: center; }

.map-card { margin: var(--space-4) 0; }
.map-card[open] { padding-bottom: 0.1rem; }
.map-card summary { padding: 0.9rem 0; display: flex; align-items: center; justify-content: space-between; gap: 1rem; color: var(--text); font-weight: 800; cursor: pointer; }
.map-card summary small { color: var(--text-muted); font-size: 0.72rem; font-weight: 600; }
.route-map { height: clamp(17rem, 48vh, 27rem); border: 1px solid #b8c7d8; border-radius: var(--radius-lg); background: #e8eef5; box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.55), var(--shadow-sm); overflow: hidden; }
.point-map { margin: 0.5rem 0 1rem; }
.custom-stop-modal {
  width: min(calc(100% - 1.25rem), 43rem);
  max-height: min(90vh, 48rem);
  padding: clamp(1rem, 4vw, 1.5rem);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 2rem 5rem -2rem rgb(8 56 97 / 0.65);
  overflow: auto;
}
.custom-stop-modal::backdrop { background: rgb(8 28 45 / 0.62); backdrop-filter: blur(3px); }
.modal-heading { margin-bottom: var(--space-3); display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.modal-close { width: 2.75rem; height: 2.75rem; flex: 0 0 2.75rem; border: 1px solid var(--border); border-radius: 50%; color: var(--text-muted); background: #fff; font-size: 1.45rem; cursor: pointer; }
.modal-close:hover { border-color: var(--primary); color: var(--primary); }
.modal-intro, .map-help, .geocoding-attribution { color: var(--text-muted); }
.modal-intro { margin: 0 0 var(--space-3); }
.geocoding-search-row { margin-top: 0.4rem; display: grid; grid-template-columns: 1fr auto; gap: 0.65rem; }
.geocoding-search-row .primary { width: auto; min-width: 6.5rem; }
.geocoding-status { min-height: 1.5rem; margin: 0.65rem 0; color: var(--text-muted); font-size: 0.88rem; }
.geocoding-results { display: grid; gap: 0.55rem; }
.geocoding-result { width: 100%; min-height: 3.8rem; padding: 0.8rem 0.9rem; border: 1px solid #b8c7d8; border-radius: var(--radius-sm); color: var(--text); background: #fff; text-align: left; font: inherit; font-weight: 650; cursor: pointer; overflow-wrap: anywhere; }
.geocoding-result:hover { border-color: var(--primary); background: var(--primary-soft); }
.direct-map-button { width: 100%; margin-top: var(--space-3); }
.geocoding-attribution { margin: 0.8rem 0 0; font-size: 0.72rem; }
.geocoding-attribution a { color: inherit; }
.selected-address { margin: 0 0 var(--space-3); padding: 0.75rem 0.85rem; border-left: 3px solid var(--primary); color: var(--primary-dark); background: var(--primary-soft); font-weight: 700; overflow-wrap: anywhere; }
.custom-stop-modal form > p { display: grid; gap: 0.4rem; }
.custom-stop-modal .point-map { height: min(46vh, 22rem); }
.map-help { margin: -0.3rem 0 0; font-size: 0.82rem; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; }
.modal-actions .primary { width: 100%; }
.pdf-button { margin-top: var(--space-4); }
.leaflet-tooltip { border: 0; border-radius: 0.6rem; font-family: inherit; font-weight: 700; box-shadow: var(--shadow-sm); }
.map-stop { width: 26px; height: 26px; display: grid; place-items: center; border: 2px solid #fff; border-radius: 0.6rem; color: #fff; font: 750 12px/1 "Segoe UI", sans-serif; box-shadow: 0 3px 10px rgb(15 23 42 / 0.42); }
.map-start { background: var(--primary-dark); }
.map-middle { border-radius: 50%; background: #0f766e; }
.map-finish { background: var(--danger); }

.loading-status { position: fixed; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); left: 1rem; z-index: 1200; max-width: 32rem; margin: auto; padding: 0.9rem 1rem; border: 1px solid rgb(255 255 255 / 0.18); border-radius: var(--radius); color: #fff; background: var(--primary-dark); box-shadow: 0 1.4rem 3rem -1.5rem rgb(8 56 97 / 0.9); text-align: center; font-weight: 700; }
.loading-status::before { content: ""; width: 0.85rem; height: 0.85rem; margin-right: 0.65rem; display: inline-block; vertical-align: -0.12rem; border: 2px solid rgb(255 255 255 / 0.32); border-top-color: #fff; border-radius: 50%; animation: spin 0.75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 620px) {
  .topbar-inner { width: min(100% - 1.25rem, 58rem); min-height: auto; padding-bottom: 0.6rem; align-items: flex-start; flex-direction: column; gap: 0.45rem; }
  .account-block { width: 100%; justify-items: stretch; }
  .account-name { max-width: 100%; padding-left: 0.15rem; }
  .topbar nav { width: 100%; justify-content: space-between; gap: 0; }
  .topbar nav a, .topbar nav .link { padding-inline: 0.55rem; }
  main { width: min(100% - 1.25rem, 54rem); margin-top: 1.5rem; }
  .monthly-metrics, .monthly-report-actions, .report-actions { grid-template-columns: 1fr; }
  .report-confirmation-details { grid-template-columns: 1fr; }
  .custom-stop-modal { max-height: calc(100vh - 1rem - env(safe-area-inset-top) - env(safe-area-inset-bottom)); padding: 1rem; }
  .geocoding-search-row { grid-template-columns: 1fr; }
  .geocoding-search-row .primary { width: 100%; }
}

@media (max-width: 360px) {
  .brand img { width: 2.1rem; height: 2.1rem; }
  .brand-wordmark { font-size: 1.2rem; }
  .topbar nav a, .topbar nav .link { padding-inline: 0.42rem; font-size: 0.82rem; }
  .location-grid { gap: 0.5rem; }
  .location-grid button { min-height: 4rem; font-size: 0.86rem; }
  .stop { align-items: flex-start; }
  .stop-actions { display: grid; grid-template-columns: repeat(3, 2.5rem); }
  .stop-actions button { min-width: 2.5rem; min-height: 2.5rem; }
  .history-list a { padding-inline: 0.7rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

@media (display-mode: standalone) {
  .topbar { padding-top: env(safe-area-inset-top); }
  main { padding-bottom: env(safe-area-inset-bottom); }
}
