.sg-route-builder {
  position: fixed;
  inset: 0;
  z-index: 42;
  pointer-events: none;
}

.sg-route-bar,
.sg-route-sheet {
  pointer-events: auto;
  font-family: inherit;
}

.sg-route-bar {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 28px));
  min-height: 64px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.18);
  display: grid;
  grid-template-columns: 46px 1fr 42px;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  color: #0f172a;
  cursor: pointer;
}

.sg-route-bar--play {
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  transform: none;
  width: auto;
  min-height: 72px;
  grid-template-columns: minmax(0, 1fr) 36px 36px 36px;
  border-radius: 14px;
  padding: 7px;
}

.sg-route-bar__icon,
.sg-route-bar__count {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}

.sg-route-bar__icon {
  color: #2563eb;
  background: #dbeafe;
}

.sg-route-bar__count {
  color: #fff;
  background: #2563eb;
}

.sg-route-bar__copy {
  min-width: 0;
  text-align: left;
}

.sg-route-bar__copy strong,
.sg-route-bar__copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sg-route-bar__copy strong {
  font-size: 16px;
  line-height: 1.1;
}

.sg-route-bar__copy small {
  color: #64748b;
  font-size: 13px;
  margin-top: 3px;
}

.sg-route-bar__exit,
.sg-route-bar__btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: #f1f5f9;
  color: #334155;
  cursor: pointer;
}

.sg-route-bar__exit {
  background: #fee2e2;
  color: #dc2626;
}

.sg-route-bar__btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.sg-route-bar__open {
  min-width: 0;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.sg-route-bar__open:active {
  transform: translateY(1px);
}

.sg-route-bar__thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #2563eb;
  background: #dbeafe;
}

.sg-route-bar__thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sg-route-bar__play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.28);
  color: #fff;
  font-size: 16px;
}

.sg-route-bar__play i {
  margin-left: 2px;
}

.sg-route-bar__main,
.sg-route-bar__title,
.sg-route-bar__current,
.sg-route-bar__progress {
  min-width: 0;
  display: block;
}

.sg-route-bar__title,
.sg-route-bar__current,
.sg-route-bar__progress {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sg-route-bar__title {
  color: #475569;
  font-size: 11px;
  font-weight: 800;
}

.sg-route-bar__current {
  color: #0f172a;
  font-size: 13px;
  font-weight: 900;
}

.sg-route-bar__progress {
  color: #2563eb;
  font-size: 11px;
  font-weight: 800;
}

.sg-route-sheet {
  position: absolute;
  left: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: min(460px, calc(100vw - 24px));
  max-height: min(72vh, 620px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  border: 1px solid rgba(148, 163, 184, 0.34);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.2);
  color: #0f172a;
  overflow: hidden;
  overscroll-behavior: contain;
  padding: 10px 12px 12px;
  touch-action: pan-y;
  font-size: 13px;
}

.sg-route-sheet__handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: #cbd5e1;
  margin: 0 auto 10px;
  cursor: grab;
  touch-action: pan-y;
}

.sg-route-sheet__head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  padding: 0 2px 8px;
  position: relative;
  z-index: 2;
  background: rgba(255, 255, 255, 0.97);
}

.sg-route-sheet__body {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0 0 2px;
}

.sg-route-sheet__head--manage,
.sg-route-sheet__head--sub {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.sg-route-sheet__head p {
  margin: 0 0 3px;
  color: #2563eb;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.sg-route-sheet__head h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.2;
  letter-spacing: 0;
}

.sg-route-sheet__controls button,
.sg-route-actions button,
.sg-route-stop__tools button,
.sg-route-saved-row button,
.sg-route-group__head,
.sg-route-sheet__back {
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #334155;
  cursor: pointer;
}

.sg-route-sheet__controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.sg-route-sheet__controls button {
  width: 36px;
  height: 36px;
  border-radius: 999px;
}

.sg-route-sheet__controls .sg-route-sheet__exit {
  background: #f1f5f9;
  border-color: #f1f5f9;
  color: #64748b;
}

.sg-route-sheet__controls .sg-route-sheet__add {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.sg-route-sheet__back {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #f8fafc;
  color: #0f172a;
  font-size: 16px;
}

.sg-route-name,
.sg-route-dates label,
.sg-route-add-panel label,
.sg-route-plan-form label {
  display: grid;
  gap: 6px;
  margin: 0 0 12px;
  color: #475569;
  font-size: 12px;
  font-weight: 800;
}

.sg-route-name input,
.sg-route-dates input,
.sg-route-add-panel input,
.sg-route-add-panel select,
.sg-route-add-panel textarea,
.sg-route-plan-form input,
.sg-route-plan-form select,
.sg-route-plan-form textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  font: inherit;
  color: #0f172a;
  background: #f8fafc;
}

.sg-route-name input,
.sg-route-dates input,
.sg-route-add-panel input,
.sg-route-add-panel select,
.sg-route-plan-form input,
.sg-route-plan-form select {
  height: 40px;
  padding: 0 12px;
}

.sg-route-add-panel textarea,
.sg-route-plan-form textarea {
  min-height: 74px;
  padding: 10px 12px;
  resize: vertical;
}

.sg-route-add-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 12px;
}

.sg-route-add-tabs button {
  min-width: 0;
  height: 38px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #475569;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 900;
}

.sg-route-add-tabs button[aria-selected="true"] {
  border-color: #2563eb;
  background: #eff6ff;
  color: #2563eb;
}

.sg-route-add-tabs i {
  font-size: 12px;
}

.sg-route-add-panel {
  display: grid;
}

.sg-route-plan-types {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.sg-route-plan-types button {
  min-width: 0;
  min-height: 58px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #334155;
  display: grid;
  place-items: center;
  gap: 5px;
  padding: 8px 6px;
  font-size: 11px;
  font-weight: 900;
}

.sg-route-plan-types button[aria-pressed="true"] {
  border-color: #2563eb;
  background: #eff6ff;
  color: #2563eb;
}

.sg-route-plan-types i {
  font-size: 16px;
}

.sg-route-plan-form {
  display: grid;
  gap: 0;
}

.sg-route-plan-form__actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.sg-route-plan-form__actions > button:not(.sg-route-primary) {
  border: 1px solid #dbe3ef;
  background: #fff;
  color: #334155;
}

.sg-route-plan-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.sg-route-insert,
.sg-route-segment {
  display: grid;
  align-items: center;
  gap: 8px;
}

.sg-route-insert {
  justify-items: center;
  margin: 2px 0;
}

.sg-route-insert > button,
.sg-route-segment > button:first-child {
  width: 28px;
  min-width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #2563eb;
  padding: 0;
  font-size: 12px;
  cursor: pointer;
}

.sg-route-insert > span {
  color: #64748b;
  font-size: 12px;
  font-weight: 800;
}

.sg-route-segment {
  grid-template-columns: 1fr 32px;
  margin: 0 8px 0 50px;
}

.sg-route-segment > button:first-child {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
}

.sg-route-segment__directions {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  height: 30px;
  border: 0;
  background: transparent;
  color: #64748b;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  padding: 0 4px;
  font-size: 12px;
  font-weight: 800;
}

.sg-route-segment__spacer {
  grid-column: 1;
  grid-row: 1;
  min-height: 22px;
}

.sg-route-insert-panel {
  grid-column: 1 / -1;
  width: 100%;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #dbeafe;
  border-radius: 14px;
  background: rgba(239, 246, 255, 0.78);
}

.sg-route-plan-edit {
  width: calc(100% - 72px);
  justify-self: end;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #dbeafe;
  border-radius: 14px;
  background: rgba(239, 246, 255, 0.9);
}

.sg-route-insert-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sg-route-insert-panel__head > strong {
  color: #0f172a;
  font-size: 12px;
  font-weight: 900;
}

.sg-route-insert-panel__head > button {
  border: 0;
  background: transparent;
  color: #64748b;
  padding: 0;
  font-size: 12px;
  font-weight: 900;
}

.sg-route-insert-panel__head > button:hover {
  color: #2563eb;
}

.sg-route-dates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.sg-route-dates label {
  margin: 0;
}

.sg-route-stops {
  display: grid;
  gap: 8px;
}

.sg-route-empty {
  margin: 0;
  padding: 13px;
  border-radius: 12px;
  background: #f8fafc;
  color: #64748b;
  font-size: 13px;
  font-weight: 700;
}

.sg-route-stop,
.sg-route-saved-row,
.sg-route-place-list button {
  display: grid;
  align-items: center;
  gap: 10px;
  border: 1px solid #e2e8f0;
  background: #fff;
}

.sg-route-stop {
  grid-template-columns: 28px 44px 1fr auto;
  border-radius: 14px;
  padding: 8px;
  cursor: grab;
  touch-action: pan-y;
}

.sg-route-stop--plan {
  grid-template-columns: 44px 1fr auto;
  width: calc(100% - 72px);
  justify-self: end;
  border-color: #bfdbfe;
  background: #f8fbff;
  cursor: pointer;
}

.sg-route-stop--plan .sg-route-stop__order--empty {
  display: none;
}

.sg-route-stop--plan .sg-route-stop__icon {
  background: #dbeafe;
  color: #2563eb;
}

.sg-route-stop.is-drag-ready {
  animation: sg-route-drag-ready 0.7s ease-in-out infinite;
}

.sg-route-stop.is-dragging {
  position: relative;
  z-index: 2;
  border-color: #93c5fd;
  background: #eff6ff;
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.18);
  animation: none;
  cursor: grabbing;
}

.sg-route-sheet.is-stop-reordering {
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

.sg-route-stop__order {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #2563eb;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.sg-route-stop__order--empty {
  background: transparent;
  color: transparent;
}

.sg-route-stop img,
.sg-route-stop__icon,
.sg-route-place-list img,
.sg-route-select-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  background: #e2e8f0;
}

.sg-route-stop__icon,
.sg-route-select-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #2563eb;
  background: #eff6ff;
  font-size: 17px;
}

.sg-route-stop strong,
.sg-route-place-list strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.sg-route-stop__content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}

.sg-route-stop__time {
  width: fit-content;
  min-width: 0;
  height: auto;
  border: 0;
  background: transparent;
  color: #64748b;
  padding: 0;
  font-size: 11px;
  font-weight: 800;
  text-align: left;
}

.sg-route-stop__time:hover {
  color: #2563eb;
}

.sg-route-stop__warning {
  color: #b45309;
  font-size: 10.5px;
  font-weight: 800;
}

.sg-route-stop__meta {
  color: #64748b;
  font-size: 10.5px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sg-route-stop__tools {
  display: flex;
  gap: 4px;
}

.sg-route-stop__tools button,
.sg-route-saved-row button {
  min-width: 32px;
  height: 32px;
  border-radius: 9px;
}

.sg-route-stops.is-reordering {
  user-select: none;
  touch-action: none;
}

body.sg-route-stop-dragging {
  cursor: grabbing;
}

.sg-route-stop-time {
  grid-column: 2 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 8px 0 0;
}

.sg-route-stop-time label {
  display: grid;
  gap: 5px;
  color: #475569;
  font-size: 11px;
  font-weight: 800;
}

.sg-route-stop-time input {
  width: 100%;
  height: 34px;
  border: 1px solid #dbe3ef;
  border-radius: 10px;
  background: #f8fafc;
  color: #0f172a;
  padding: 0 9px;
  font: inherit;
}

.sg-route-stop-time__actions {
  display: flex;
  gap: 6px;
}

.sg-route-stop-time__actions button {
  height: 34px;
  border-radius: 10px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

@keyframes sg-route-drag-ready {
  0%,
  100% {
    border-color: #dbeafe;
    box-shadow: 0 0 0 rgba(37, 99, 235, 0);
  }

  50% {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
  }
}

@media (max-width: 520px) {
  .sg-route-plan-types,
  .sg-route-plan-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sg-route-stop--plan {
    width: calc(100% - 42px);
  }

  .sg-route-plan-edit {
    width: calc(100% - 42px);
  }

  .sg-route-stop-time {
    grid-template-columns: 1fr 1fr;
  }

  .sg-route-stop-time__actions {
    grid-column: 1 / -1;
  }
}

.sg-route-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 12px 0 14px;
}

.sg-route-actions button {
  height: 38px;
  border-radius: 12px;
  padding: 0 12px;
  font-weight: 800;
  font-size: 13px;
}

.sg-route-actions .sg-route-primary {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.sg-route-primary {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.sg-route-meta-form {
  display: grid;
  gap: 0;
}

.sg-route-date-pill {
  width: fit-content;
  max-width: 100%;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: #e5e7eb;
  color: #111827;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.sg-route-date-pill:hover {
  background: #dbeafe;
}

.sg-route-actions button:disabled,
.sg-route-stop__tools button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.sg-route-saved {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.sg-route-group {
  display: grid;
  gap: 8px;
}

.sg-route-group + .sg-route-group {
  margin-top: 14px;
}

.sg-route-group__head {
  width: 100%;
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid #bfdbfe;
  border-radius: 14px;
  background: #eff6ff;
  padding: 7px 10px;
  text-align: left;
}

.sg-route-group__head strong {
  min-width: 0;
  overflow: hidden;
  color: #0f172a;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sg-route-group__head:hover .sg-route-date-pill {
  background: #bfdbfe;
}

.sg-route-saved-row {
  grid-template-columns: 1fr;
  border-radius: 12px;
  padding: 8px;
}

.sg-route-saved-row__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px 34px;
  gap: 6px;
  align-items: center;
}

.sg-route-saved-row__head .sg-route-day {
  min-width: 0;
  height: auto;
  display: block;
  border: 0;
  background: transparent;
  color: #0f172a;
  padding: 4px 2px;
  text-align: left;
}

.sg-route-saved-row__head .sg-route-day:hover {
  color: #2563eb;
}

.sg-route-saved-row__main,
.sg-route-share {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.sg-route-saved-row__main {
  margin-top: 8px;
}

.sg-route-sun {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 5px 2px 2px;
  color: #64748b;
  font-size: 11px;
  font-weight: 800;
}

.sg-route-sun span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.sg-route-sun i {
  font-size: 12px;
}

.sg-route-sun__rise i {
  color: #f59e0b;
}

.sg-route-sun__set i {
  color: #475569;
}

.sg-route-saved-row__main button,
.sg-route-share button,
.sg-route-share__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  font-weight: 800;
}

.sg-route-saved-row__main .sg-route-start {
  min-width: 96px;
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}

.sg-route-share__toggle {
  min-width: 116px;
  height: 32px;
  font-size: 12px;
}

.sg-route-copy {
  width: 34px;
  min-width: 34px;
  padding: 0;
}

.sg-route-share__switch {
  position: relative;
  display: inline-flex;
  width: 34px;
  height: 20px;
  align-items: center;
  padding: 2px;
  border-radius: 999px;
  background: #cbd5e1;
}

.sg-route-share__switch span {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
  transform: translateX(0);
  transition: transform 0.16s ease;
}

.sg-route-share__toggle[aria-checked="true"] .sg-route-share__switch {
  background: #16a34a;
}

.sg-route-share__toggle[aria-checked="true"] .sg-route-share__switch span {
  transform: translateX(14px);
}

.sg-route-saved-row span,
.sg-route-place-list span {
  min-width: 0;
}

.sg-route-saved-row strong,
.sg-route-saved-row small,
.sg-route-place-list strong,
.sg-route-place-list small {
  display: block;
}

.sg-route-saved-row small,
.sg-route-place-list small {
  color: #64748b;
  font-size: 11px;
  margin-top: 2px;
}

.sg-route-place-list {
  display: grid;
  gap: 8px;
}

.sg-route-place-list button {
  grid-template-columns: 38px 1fr 28px;
  min-height: 54px;
  border-radius: 14px;
  padding: 8px;
  color: #0f172a;
  text-align: left;
  cursor: pointer;
}

.sg-route-place-list img,
.sg-route-select-icon {
  width: 38px;
  height: 38px;
}

.sg-panel__body .sg-place-actions .sg-act-route.is-on {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}

body.sg-route-active .sg-map-controls {
  bottom: calc(env(safe-area-inset-bottom) + 96px);
}

body.sg-tour-active .sg-route-builder {
  display: none;
}

body.sg-route-playing .sg-city-welcome {
  display: none !important;
}

body.sg-route-playing .sg-maplibre-marker .sg-marker-pin:not(.sg-marker-pin--route) {
  background: #cbd5e1 !important;
  color: #334155 !important;
  opacity: 1;
  filter: none;
  box-shadow: 0 2px 7px rgba(15, 23, 42, 0.22);
}

@media (max-width: 768px) {
  .sg-route-sheet {
    left: 50%;
    right: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: min(460px, calc(100vw - 24px));
    max-height: min(72vh, 620px);
    border-radius: 18px;
    padding: 10px 12px 12px;
    transform: translateX(-50%);
  }

  .sg-route-bar {
    bottom: calc(env(safe-area-inset-bottom) + 16px);
  }

  body.sg-route-active .sg-map-controls {
    bottom: calc(env(safe-area-inset-bottom) + 92px);
  }
}
