:root {
  --color-primary: #2563eb;
  --color-green: #16a34a;
  --color-text: #1f2937;
  --color-muted: #6b7280;
  --color-border: #e5e7eb;
  --topbar-height: 60px;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--color-text);
}

/* Top bar */
#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: #ffffff;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-sizing: border-box;
  z-index: 1000;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.live-tag {
  background: var(--color-green);
  color: white;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
}

#menuToggle {
  width: 34px;
  height: 34px;
  padding: 8px 0;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

#menuToggle span {
  display: block;
  height: 2px;
  background: var(--color-text);
  border-radius: 2px;
}

#navMenu {
  position: absolute;
  top: var(--topbar-height);
  right: 20px;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 220px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}

#navMenu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.nav-item {
  display: block;
  box-sizing: border-box;
  width: 100%;
  background: none;
  border: none;
  border-top: 1px solid var(--color-border);
  text-align: left;
  text-decoration: none;
  padding: 12px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--color-text);
}

.nav-item:first-child { border-top: none; }
.nav-item:hover { background: #f3f4f6; }
.nav-item.active {
  background: #eff6ff;
  color: var(--color-primary);
  font-weight: 600;
}

/* Content area */
#content {
  position: absolute;
  top: var(--topbar-height);
  left: 0;
  right: 0;
  bottom: 0;
}

.view { display: none; height: 100%; }
.view.active { display: block; }

.view.page {
  overflow-y: auto;
  box-sizing: border-box;
  padding: 28px 32px 60px;
}

.view.page h1 { margin: 0 0 4px; font-size: 24px; }
.page-subtitle { color: var(--color-muted); margin: 0 0 24px; font-size: 14px; }

/* Tracking view */
#view-tracking { position: relative; }

#map {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

#sidebar {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 360px;
  max-height: calc(100% - 32px);
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  padding: 16px;
  box-sizing: border-box;
}

.load-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 12px;
}

.load-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
}

.load-header h1 {
  margin: 2px 0 0;
  font-size: 20px;
}

.status-badge {
  background: var(--color-muted);
  color: white;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.status-badge.in-transit { background: var(--color-primary); }
.status-badge.delivered { background: var(--color-green); }

.last-updated {
  font-size: 12px;
  color: var(--color-muted);
  margin-bottom: 12px;
}

.secondary-btn {
  display: block;
  width: 100%;
  background: #eff6ff;
  color: var(--color-primary);
  border: 1px solid #bfdbfe;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 14px;
  box-sizing: border-box;
}

.secondary-btn:hover { background: #dbeafe; }

/* Stepper */
.stepper {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}

.stepper li {
  position: relative;
  padding: 0 0 18px 26px;
  font-size: 13px;
  color: var(--color-muted);
}

.stepper li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d1d5db;
  border: 2px solid #d1d5db;
}

.stepper li::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 14px;
  width: 2px;
  height: calc(100% - 10px);
  background: #e5e7eb;
}

.stepper li:last-child::after { display: none; }

.stepper li.done {
  color: var(--color-text);
}
.stepper li.done::before {
  background: var(--color-green);
  border-color: var(--color-green);
}
.stepper li.done::after {
  background: var(--color-green);
}

.stepper li.active {
  color: var(--color-text);
  font-weight: 600;
}
.stepper li.active::before {
  background: var(--color-primary);
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2);
}

/* Stop cards */
.stop-card {
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}

.stop-card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin: 0 0 8px;
}

.stop-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: white;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.stop-tag-a { background: var(--color-green); }
.stop-tag-b { background: #1f2937; }

.stop-body div {
  font-size: 13px;
  line-height: 1.5;
}

.stop-body .business-name {
  font-weight: 600;
  font-size: 14px;
}

.stop-body .muted {
  color: var(--color-muted);
}

/* Location history */
.ping-history-card summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ping-history-card summary::-webkit-details-marker {
  display: none;
}

.ping-history-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}

.ping-history-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--color-border);
}

.ping-history-list li:first-child {
  border-top: none;
}

.ping-time {
  color: var(--color-text);
  font-weight: 600;
  white-space: nowrap;
}

.ping-coords {
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}

.ping-popup {
  font-size: 12px;
  line-height: 1.6;
  max-width: 220px;
}

.ping-popup strong {
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
}

.ping-history-empty {
  color: var(--color-muted);
  font-size: 13px;
  border-top: none !important;
}

/* Toast */
#toast {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translate(-50%, -20px);
  background: #111827;
  color: white;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  max-width: min(90vw, 480px);
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  z-index: 2000;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Presenter controls */
#controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  background: rgba(17, 24, 39, 0.92);
  padding: 12px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 220px;
}

.controls-label {
  color: #9ca3af;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#controls button {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

#nextBtn {
  background: var(--color-primary);
  color: white;
}

#nextBtn:disabled {
  background: #9ca3af;
  cursor: default;
}

#resetBtn {
  background: transparent;
  color: #d1d5db;
  border: 1px solid #4b5563;
}

/* Truck marker */
.truck-marker {
  font-size: 22px;
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.4));
}

/* New Load form */
.form-grid {
  display: flex;
  gap: 24px;
  max-width: 900px;
  flex-wrap: wrap;
}

.form-col {
  flex: 1;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 16px;
  box-sizing: border-box;
}

.form-col-narrow {
  max-width: 340px;
  margin-bottom: 24px;
}

.form-col h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  margin: 0 0 4px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--color-muted);
}

input, select, textarea {
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-text);
  font-family: inherit;
  resize: vertical;
}

input:disabled {
  background: #f9fafb;
  color: var(--color-muted);
}

.address-row {
  display: flex;
  gap: 8px;
}

.address-row label { flex: 1; }
.address-row .city-field { flex: 2; }
.address-row .state-field,
.address-row .zip-field { flex: 1; min-width: 0; }

.required-mark {
  color: #dc2626;
}

.time-fields {
  display: flex;
  gap: 8px;
}

.time-fields label { flex: 1; }

.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  z-index: 50;
  max-height: 220px;
  overflow-y: auto;
}

.autocomplete-dropdown:empty { display: none; }

.autocomplete-item {
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  color: var(--color-text);
}

.autocomplete-item:hover { background: #f3f4f6; }

.primary-btn {
  margin-top: 20px;
  background: var(--color-primary);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn:disabled {
  background: #9ca3af;
  cursor: default;
}

.field-hint {
  font-size: 12px;
  color: var(--color-muted);
  margin: 0;
}

.created-panel {
  max-width: 900px;
  margin-top: 20px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  padding: 16px 20px;
}

.created-panel-title {
  font-weight: 700;
  color: var(--color-green);
  margin-bottom: 4px;
}

.created-panel p {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--color-muted);
}

.link-row {
  display: flex;
  gap: 8px;
}

.link-row input {
  flex: 1;
  background: white;
}

.created-copy-btn {
  width: auto;
  margin-bottom: 0;
  white-space: nowrap;
}

/* Load lists */
.load-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 720px;
}

.load-card {
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  background: white;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.load-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-color: #c7d2e0;
}

.load-card-id { font-weight: 700; font-size: 14px; }
.load-card-route { font-size: 13px; color: var(--color-muted); margin-top: 2px; }
.load-card-meta { font-size: 12px; color: var(--color-muted); margin-top: 4px; }

.logo-preview {
  max-width: 160px;
  max-height: 80px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  display: block;
}

/* Auth */
.auth-card {
  max-width: 380px;
  margin: 60px auto;
  padding: 24px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-toggle {
  text-align: center;
  font-size: 13px;
  color: var(--color-muted);
  margin-top: 16px;
}

.auth-toggle a {
  color: var(--color-primary);
  font-weight: 600;
  text-decoration: none;
}

.slug-status {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: -6px;
}

.slug-status-good { color: var(--color-green); }
.slug-status-bad { color: #dc2626; }

/* Client lookup page */
.lookup-card {
  max-width: 420px;
  margin: 60px auto;
  padding: 24px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
}

.lookup-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.error-text {
  color: #dc2626;
  font-size: 13px;
  margin-top: 10px;
}

body.embed-mode #topbar { display: none; }
body.embed-mode #content { top: 0; }
body.embed-mode .lookup-card { margin: 20px auto; }

/* Settings */
.settings-card {
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 20px;
}

@media (max-width: 640px) {
  #sidebar {
    width: calc(100% - 32px);
  }
  .form-grid {
    flex-direction: column;
  }
}
