/* Hermes — custom styles beyond Tailwind */

/* ── Base ─────────────────────────────────────────── */
html, body {
  min-height: 100vh;
  min-height: 100dvh;
  background-color: #0f172a; /* slate-900 */
  color: #f1f5f9;            /* slate-100 */
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* Safe-area insets for notched phones */
body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ── Map container ────────────────────────────────── */
.map-container {
  height: 280px;
  width: 100%;
  border-radius: 0.5rem;
  overflow: hidden;
  position: relative;
  z-index: 0;
}

@media (min-height: 700px) {
  .map-container { height: 320px; }
}

/* Fix Leaflet z-index under modals */
.leaflet-pane { z-index: 1; }
.leaflet-top, .leaflet-bottom { z-index: 2; }

/* ── Pickup cards ─────────────────────────────────── */
.pickup-card {
  background-color: #1e293b; /* slate-800 */
  border: 1px solid #334155; /* slate-700 */
  border-radius: 0.75rem;
  padding: 1rem;
  margin-bottom: 0.75rem;
  transition: border-color 0.15s ease;
}

.pickup-card:active {
  border-color: #0ea5e9;
}

/* Large tap targets — minimum 44px */
.tap-target {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.action-btn {
  min-height: 48px;
  min-width: 48px;
  padding: 0.625rem 1.25rem;
  border-radius: 0.5rem;
  font-weight: 600;
  font-size: 0.9375rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: opacity 0.15s ease, transform 0.1s ease;
  border: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.action-btn:active {
  opacity: 0.8;
  transform: scale(0.97);
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Action button colors */
.btn-start   { background-color: #3b82f6; color: #fff; } /* blue-500 */
.btn-complete { background-color: #22c55e; color: #fff; } /* green-500 */
.btn-dropoff  { background-color: #a855f7; color: #fff; } /* purple-500 */
.btn-nav      { background-color: #0ea5e9; color: #fff; } /* sky-500 */
.btn-danger   { background-color: #ef4444; color: #fff; } /* red-500 */
.btn-neutral  { background-color: #475569; color: #fff; } /* slate-600 */
.btn-submit   { background-color: #0ea5e9; color: #fff; } /* sky-500 */

/* ── Status badges ────────────────────────────────── */
.status-badge {
  display: inline-block;
  padding: 0.125rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-assigned   { background-color: #475569; color: #e2e8f0; } /* slate */
.badge-en_route   { background-color: #2563eb; color: #fff; }     /* blue */
.badge-picked_up  { background-color: #16a34a; color: #fff; }     /* green */
.badge-dropped_off { background-color: #7c3aed; color: #fff; }    /* purple */
.badge-cancelled  { background-color: #dc2626; color: #fff; }     /* red */

/* ── Notes textarea ───────────────────────────────── */
.notes-textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  background-color: #0f172a;
  border: 1px solid #475569;
  border-radius: 0.5rem;
  color: #f1f5f9;
  font-size: 0.875rem;
  resize: vertical;
  transition: border-color 0.15s ease;
}

.notes-textarea:focus {
  outline: none;
  border-color: #0ea5e9;
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.2);
}

/* ── Inspection photo grid ────────────────────────── */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.photo-thumb {
  aspect-ratio: 1;
  border-radius: 0.5rem;
  overflow: hidden;
  position: relative;
  background-color: #1e293b;
  border: 1px solid #334155;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-thumb .remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: rgba(239, 68, 68, 0.9);
  color: white;
  font-size: 14px;
  line-height: 24px;
  text-align: center;
  cursor: pointer;
  border: none;
}

/* ── Bottom status bar ────────────────────────────── */
.status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  min-height: 36px;
  background-color: #1e293b;
  border-top: 1px solid #334155;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
  font-size: 0.75rem;
  color: #94a3b8;
  z-index: 50;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.375rem;
}

.dot-online  { background-color: #22c55e; }
.dot-offline { background-color: #ef4444; }
.dot-gps     { background-color: #0ea5e9; }

/* ── Status bar as clickable button ────────────── */
.status-bar-button {
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  border-top: 1px solid #334155;
  /* Make sure it looks exactly like the div version */
  background-color: #1e293b;
  appearance: none;
  -webkit-appearance: none;
}
.status-bar-button:hover  { background-color: #263449; }
.status-bar-button:active { background-color: #2f425c; }
.status-bar-button:focus-visible {
  outline: 2px solid #0ea5e9;
  outline-offset: -2px;
}

/* Syncing indicator (replaces the GPS chip while a flush is in flight) */
.status-spinner {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #334155;
  border-top-color: #0ea5e9;
  display: inline-block;
  margin-right: 0.375rem;
  animation: spin 0.8s linear infinite;
}

/* Sync count pills */
.sync-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 0.25rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
}
.sync-pill-pending { background-color: #f59e0b; color: #0f172a; }
.sync-pill-stuck   { background-color: #ef4444; color: #fff; }

/* ── Offline / stuck banners (top of viewport) ───── */
.offline-banner,
.stuck-banner {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  padding-top: calc(0.5rem + env(safe-area-inset-top));
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.3;
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.offline-banner { background-color: #b45309; } /* amber-700: offline is "saved locally" not "broken" */
.stuck-banner   { background-color: #b91c1c; } /* red-700: stuck actually IS broken */

.offline-banner-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.2);
}

.offline-banner-text { flex: 1; }

.offline-banner-action {
  background-color: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  flex-shrink: 0;
}
.offline-banner-action:hover { background-color: rgba(255, 255, 255, 0.25); }
.offline-banner-action:active { background-color: rgba(255, 255, 255, 0.35); }

/* Transient toast */
.sync-toast {
  position: fixed;
  left: 50%;
  bottom: calc(60px + env(safe-area-inset-bottom) + 0.5rem);
  transform: translateX(-50%);
  z-index: 70;
  background-color: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
  padding: 0.625rem 1rem;
  border-radius: 8px;
  font-size: 0.8125rem;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  max-width: calc(100% - 2rem);
  text-align: center;
}

/* ── Sync details drawer ─────────────────────────── */
.sync-drawer-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 80;
}

.sync-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  background-color: #0f172a;
  border-top: 1px solid #334155;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Drawer slide-up transition */
.sync-drawer-enter {
  transition: transform 220ms ease-out, opacity 220ms ease-out;
}
.sync-drawer-enter-start { transform: translateY(100%); opacity: 0; }
.sync-drawer-enter-end   { transform: translateY(0);    opacity: 1; }
.sync-drawer-leave {
  transition: transform 180ms ease-in, opacity 180ms ease-in;
}
.sync-drawer-leave-start { transform: translateY(0);    opacity: 1; }
.sync-drawer-leave-end   { transform: translateY(100%); opacity: 0; }

.sync-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}

.sync-drawer-close {
  color: #94a3b8;
  background: transparent;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sync-drawer-close:hover { color: #f1f5f9; background-color: #1e293b; }

.sync-drawer-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

.sync-drawer-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid #1e293b;
  flex-shrink: 0;
}

.sync-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.sync-summary-card {
  background-color: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 0.625rem;
  text-align: center;
}

.sync-summary-label {
  font-size: 0.6875rem;
  font-weight: 500;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.sync-summary-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
}

.sync-error-callout {
  background-color: rgba(127, 29, 29, 0.25);
  border: 1px solid #7f1d1d;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.8125rem;
}

.sync-section { margin-bottom: 1rem; }
.sync-section:last-child { margin-bottom: 0; }

.sync-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  margin-bottom: 0.5rem;
}

.sync-breakdown-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border: 1px solid #1e293b;
  border-radius: 8px;
  overflow: hidden;
}

.sync-breakdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.875rem;
  background-color: #1e293b;
  border-bottom: 1px solid #0f172a;
  font-size: 0.875rem;
  color: #e2e8f0;
}
.sync-breakdown-row:last-child { border-bottom: none; }

.sync-empty-state {
  text-align: center;
  padding: 1.5rem 1rem;
  color: #94a3b8;
  font-size: 0.875rem;
  background-color: #1e293b;
  border-radius: 8px;
}

.sync-link-btn {
  background: transparent;
  color: #38bdf8;
  border: none;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.125rem 0.25rem;
}
.sync-link-btn:hover { color: #7dd3fc; text-decoration: underline; }

.sync-stuck-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sync-stuck-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  background-color: rgba(127, 29, 29, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 8px;
}

.sync-stuck-info { flex: 1; min-width: 0; }

.sync-stuck-action {
  font-size: 0.875rem;
  font-weight: 600;
  color: #fecaca;
}

.sync-stuck-meta {
  font-size: 0.6875rem;
  color: #cbd5e1;
  margin-top: 0.125rem;
}

.sync-stuck-actions {
  display: flex;
  gap: 0.375rem;
  flex-shrink: 0;
}

.btn-retry,
.btn-discard {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3125rem 0.625rem;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  background-color: transparent;
}

.btn-retry {
  background-color: #0284c7;
  color: #fff;
}
.btn-retry:hover { background-color: #0369a1; }

.btn-discard {
  border-color: #475569;
  color: #cbd5e1;
}
.btn-discard:hover { background-color: #1e293b; border-color: #64748b; }

.btn-sync-now {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: #fff;
  background-color: #0284c7;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 150ms;
}
.btn-sync-now:hover:not(:disabled) { background-color: #0369a1; }
.btn-sync-now:disabled {
  background-color: #334155;
  color: #64748b;
  cursor: not-allowed;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Utility ──────────────────────────────────────── */
.content-area {
  padding-bottom: calc(60px + env(safe-area-inset-bottom)); /* clear status bar + safe area */
}

/* Loading spinner */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #334155;
  border-top-color: #0ea5e9;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Smooth view transitions */
[x-cloak] { display: none !important; }

/* Header dropdown styling */
.header-select {
  background-color: #0f172a;
  border: 1px solid #475569;
  border-radius: 0.375rem;
  color: #f1f5f9;
  padding: 0.375rem 0.5rem;
  font-size: 0.8125rem;
  min-height: 36px;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  padding-right: 1.75rem;
  /* Cap dropdown width so long driver names do not skew the header row */
  max-width: 12rem;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.header-select:focus {
  outline: none;
  border-color: #0ea5e9;
}

@media (max-width: 420px) {
  .header-select {
    max-width: 9rem;
    font-size: 0.75rem;
  }
}

/* Status-bar driver name - truncate with ellipsis so long names
   do not push other status-bar items off-screen. */
.status-bar-driver-name {
  display: inline-block;
  max-width: 10rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

@media (max-width: 420px) {
  .status-bar-driver-name {
    max-width: 6rem;
  }
}

/* ── Navigation overlay ──────────────────────────── */
/* z-index 70 so we clear the bottom status bar (z-50) — otherwise
   the End Nav / Maps buttons get covered by the status bar. */
.nav-overlay {
  /* z-100 sits above modals (z-70) and the sync drawer (z-80/90) — when
     turn-by-turn is live, no other overlay should be reachable. */
  position: fixed;
  inset: 0;
  z-index: 100;
  background-color: #0f172a;
  display: flex;
  flex-direction: column;
}

.nav-instruction-bar {
  background-color: #1e293b;
  border-bottom: 1px solid #334155;
  padding: 1rem 1.25rem;
  padding-top: calc(1rem + env(safe-area-inset-top));
  flex-shrink: 0;
}

.nav-maneuver-icon {
  font-size: 48px;
  line-height: 1;
  color: #3b82f6;
  flex-shrink: 0;
  width: 56px;
  text-align: center;
}

.nav-distance-text {
  font-size: 28px;
  font-weight: 700;
  color: #fff;
  line-height: 1.1;
}

.nav-street-text {
  font-size: 16px;
  color: #94a3b8;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-map-area {
  flex: 1;
  position: relative;
  min-height: 0;
}

.nav-loading-overlay,
.nav-error-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(15, 23, 42, 0.85);
  z-index: 10;
}

.nav-error-overlay {
  flex-direction: column;
}

.nav-bottom-bar {
  background-color: #1e293b;
  border-top: 1px solid #334155;
  padding: 0.75rem 1.25rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
  flex-shrink: 0;
}
