* {
  box-sizing: border-box;
  outline: none;
}

html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  background: var(--slate-50);
  color: var(--slate-700);
  font-family: var(--font-stack);
  font-size: 13px;
  overflow: hidden;
  overscroll-behavior-x: none;
}

button {
  cursor: pointer;
  font-family: inherit;
}

img {
  display: block;
  max-width: 100%;
}

.header {
  height: var(--header-height);
  background: var(--white);
  border-bottom: 1px solid var(--slate-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
}

.header-title {
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--slate-800);
}

.header-sub {
  font-size: 11px;
  color: var(--slate-500);
  font-weight: 600;
}

.header-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.content {
  height: calc(100vh - var(--header-height));
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
}

#banner {
  margin: 14px 14px 0 14px;
  flex: 0 0 auto;
}

.card {
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.card + .card {
  margin-top: 12px;
}

.card-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--slate-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 12px;
  gap: 8px;
  white-space: nowrap;
  background: var(--white);
  color: var(--slate-700);
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--white);
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-outline {
  border-color: var(--slate-200);
  background: transparent;
}
.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--white);
}
.btn-ghost {
  background: transparent;
  color: var(--slate-500);
}
.btn-ghost:hover {
  background: var(--slate-100);
  color: var(--slate-900);
}
.btn-icon {
  width: 38px;
  padding: 0;
}

input,
select,
textarea {
  width: 100%;
  height: 38px;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-md);
  padding: 0 10px;
  font-size: 12px;
  font-family: inherit;
  background: var(--white);
  color: var(--slate-900);
}

textarea {
  height: auto;
  min-height: 90px;
  padding: 10px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-subtle);
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.row > * {
  flex: 1;
}

.muted {
  color: var(--slate-500);
  font-size: 12px;
}

.banner {
  border-radius: var(--radius-md);
  padding: 10px 12px;
  border: 1px solid var(--slate-200);
  background: var(--slate-100);
  color: var(--slate-700);
  font-weight: 600;
  font-size: 12px;
}

.banner.warn {
  background: var(--warning-bg);
  border-color: #fde68a;
  color: #92400e;
}

.banner.danger {
  background: var(--danger-bg);
  border-color: #fecaca;
  color: #991b1b;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border: 1px solid var(--slate-200);
  background: var(--white);
  color: var(--slate-700);
}

.pill.ok {
  background: var(--success-bg);
  border-color: #a7f3d0;
  color: #065f46;
}

.pill.off {
  background: var(--slate-100);
  color: var(--slate-500);
}

.section {
  display: none;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.section.active {
  display: block;
  animation: fadeIn 0.18s ease-out;
}

/* Home view manages its own scrolling (tabs + map). */
#viewHome.section {
  overflow: hidden;
}

.view-scroll {
  flex: 1;
  overflow: auto;
  padding: 14px;
  -webkit-overflow-scrolling: touch;
}

/* Home tabs */
.home {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.home-panels {
  flex: 1;
  overflow: hidden;
}

.home-panel {
  display: none;
  height: 100%;
  overflow: auto;
  padding: 14px;
  -webkit-overflow-scrolling: touch;
}

.home-panel.active {
  display: block;
}

.home-panel.route {
  padding: 0;
  overflow: hidden;
}

.home-nav {
  flex: 0 0 auto;
  height: 64px;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--white);
  border-top: 1px solid var(--slate-200);
  display: flex;
}

.home-nav .nav-btn {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 10px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--slate-500);
  font-weight: 900;
  font-size: 10px;
  letter-spacing: 0.35px;
  text-transform: uppercase;
  position: relative;
}

.home-nav .nav-btn.active {
  color: var(--primary);
}

.home-nav .nav-btn svg {
  width: 20px;
  height: 20px;
}

.home-nav .nav-badge {
  position: absolute;
  top: 6px;
  right: 22px;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  line-height: 18px;
  font-weight: 900;
  display: none;
}

.home-nav .nav-badge.show {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Route panel */
.nav-wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.nav-map {
  flex: 1;
  min-height: 240px;
}

.route-drawer {
  flex: 0 0 auto;
  background: var(--white);
  border-top: 1px solid var(--slate-200);
  padding: 12px 14px;
  overflow: auto;
  max-height: 46%;
  -webkit-overflow-scrolling: touch;
}

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

.route-top .title {
  font-size: 11px;
  font-weight: 900;
  color: var(--slate-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.btn-sm {
  height: 32px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 12px;
}

.route-stops {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.route-stop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--slate-200);
}

.route-stop:last-child {
  border-bottom: none;
}

.route-stop-left {
  min-width: 0;
}

.route-stop-title {
  font-size: 12px;
  font-weight: 900;
  color: var(--slate-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.route-stop-sub {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--slate-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.route-stop.delivered {
  opacity: 0.55;
}

.route-stop.selected {
  background: var(--primary-subtle);
}

.route-stop-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.route-stop-btn {
  height: 34px;
}

.route-stop-move {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--slate-200);
  background: var(--white);
  color: var(--slate-600);
  font-weight: 900;
}

.route-stop-move:active {
  transform: translateY(1px);
}

/* Prevent accidental horizontal scroll on long text blocks */
.mono {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.install-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.install-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.install-step {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px 10px;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  background: var(--slate-50);
}

.step-num {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 12px;
  background: var(--primary-subtle);
  color: #075985;
  border: 1px solid #bae6fd;
}

.step-title {
  font-weight: 800;
  font-size: 12px;
  color: var(--slate-800);
}

.step-sub {
  font-size: 12px;
  color: var(--slate-600);
  margin-top: 2px;
}

.install-token {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius-lg);
  border: 1px dashed var(--slate-300);
  background: var(--white);
}

.install-token .k {
  color: var(--slate-500);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-size: 10px;
  margin-bottom: 6px;
}

.install-token-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.install-token-row .mono {
  flex: 1;
  padding: 10px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--slate-200);
  background: var(--slate-50);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(2px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#toast {
  visibility: hidden;
  min-width: 240px;
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 12px 14px;
  border-radius: 10px;
  background: #111827;
  color: white;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s, bottom 0.2s;
  z-index: 9999;
}
#toast.show {
  visibility: visible;
  opacity: 1;
  bottom: 26px;
}
#toast.success {
  background: var(--success);
}
#toast.error {
  background: var(--danger);
}
