/* ─────────────────────────────────────────────────────────────
   CargoCore — Tracking map, live summary and timeline styles
   Used by: track.php, admin/view-details.php
   ───────────────────────────────────────────────────────────── */

/* ── Live / recorded summary ──────────────────────────────── */
.tm-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 18px 24px;
  box-shadow: 0 2px 12px rgba(15, 30, 69, 0.07);
  max-width: 100%;
  box-sizing: border-box;
}
.tm-summary-main { display: flex; align-items: center; gap: 16px; min-width: 0; flex: 1 1 280px; }
.tm-summary-icon {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: #eff6ff;
  border: 1px solid #dbeafe;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tm-summary-icon img { width: 30px; height: 30px; }
.tm-summary-text { min-width: 0; }
.tm-summary-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: #94a3b8;
  margin-bottom: 3px;
}
.tm-summary-value {
  font-size: 19px;
  font-weight: 800;
  color: #0f1e45;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.tm-summary-value-sm { font-size: 15px; font-weight: 700; }
.tm-summary-sub { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.tm-summary-transport {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
}
.tm-summary-meta-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.tm-status {
  display: inline-flex;
  align-items: center;
}
.tm-transport {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  gap: 6px;
}
.tm-transport img {
  flex-shrink: 0;
}

.tm-summary-side { text-align: right; min-width: 160px; }
.tm-summary-note { font-size: 11.5px; color: #94a3b8; margin-top: 6px; max-width: 210px; overflow-wrap: anywhere; }

.tm-badge-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 999px;
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 700;
}

.tm-live {
  display: inline-block;
  margin-top: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.tm-live-on       { background: #dcfce7; color: #15803d; box-shadow: inset 0 0 0 1px #86efac; }
.tm-live-stale    { background: #fef3c7; color: #a16207; box-shadow: inset 0 0 0 1px #fcd34d; }
.tm-live-recorded { background: #f1f5f9; color: #475569; box-shadow: inset 0 0 0 1px #cbd5e1; }

/* ── Cards ─────────────────────────────────────────────────── */
.tm-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  box-shadow: 0 2px 12px rgba(15, 30, 69, 0.07);
  overflow: hidden;
  max-width: 100%;
}
.tm-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 22px;
  border-bottom: 1px solid #eef2f7;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: #1b3c87;
  flex-wrap: wrap;
}
.tm-card-head i { color: #2563eb; margin-right: 7px; }
.tm-card-note {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: #94a3b8;
}

/* ── Map ───────────────────────────────────────────────────── */
.tm-map {
  width: 100%;
  height: 440px;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  background: #eef2f7;
  z-index: 1;
  box-sizing: border-box;
  max-width: 100%;
}
.tm-map.tm-empty { display: flex; align-items: center; justify-content: center; }

.tm-unavailable {
  text-align: center;
  color: #475569;
  padding: 20px;
  font-size: 14px;
  font-weight: 600;
}
.tm-unavailable .tm-unav-ic {
  font-size: 34px;
  line-height: 1;
  color: #cbd5e1;
  margin-bottom: 10px;
}
.tm-unavailable .tm-unav-sub {
  font-weight: 400;
  font-size: 12.5px;
  color: #94a3b8;
  margin-top: 4px;
}

.tm-icon { background: transparent; border: none; }

/* Transport marker: the shipment itself */
.tm-icon-transport { background: transparent; border: none; }
.tm-transport {
  position: relative;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tm-transport-img {
  width: 34px;
  height: 34px;
  z-index: 2;
  filter: drop-shadow(0 2px 4px rgba(15, 23, 42, .4));
  transition: transform .4s linear;
}
.tm-transport-pulse {
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: rgba(37, 99, 235, .18);
  opacity: 0;
}
.tm-live-on ~ .tm-transport .tm-transport-pulse,
.tm-transport-live .tm-transport-pulse { animation: tm-halo 2s ease-out infinite; opacity: 1; }
@keyframes tm-halo {
  0%   { transform: scale(.55); opacity: .55; }
  70%  { transform: scale(1.1); opacity: 0; }
  100% { transform: scale(1.1); opacity: 0; }
}

/* Pins (origin / destination) */
.tm-pin {
  width: 30px;
  height: 36px;
  position: relative;
}
.tm-pin i {
  position: absolute;
  left: 0;
  top: 0;
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35);
}
.tm-pin i::after {
  content: "";
  position: absolute;
  left: 9px;
  top: 9px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffffff;
}
.tm-pin-origin i  { background: #10b981; }
.tm-pin-dest i    { background: #ef4444; }

/* Dots (events / current) */
.tm-dot {
  width: 22px;
  height: 22px;
  position: relative;
}
.tm-dot i {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.35);
}
.tm-dot-event i    { background: #2563eb; width: 14px; height: 14px; left: 4px; top: 4px; }
.tm-dot-anim i     { background: #f59e0b; width: 18px; height: 18px; left: 2px; top: 2px; }
.tm-dot-anim       { animation: tm-pulse 1s infinite; }
.tm-dot-current i  { background: #1b3c87; width: 18px; height: 18px; left: 2px; top: 2px; }
.tm-dot-current    { animation: tm-pulse 1.6s infinite; }

@keyframes tm-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(27, 60, 135, 0.45); }
  70%  { box-shadow: 0 0 0 10px rgba(27, 60, 135, 0); }
  100% { box-shadow: 0 0 0 0 rgba(27, 60, 135, 0); }
}

/* Popups */
.tm-pop-status   { font-weight: 700; color: #1b3c87; font-size: 13px; text-transform: uppercase; letter-spacing: .3px; }
.tm-pop-location { font-weight: 600; color: #0f172a; font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.tm-pop-time     { color: #64748b; font-size: 12px; margin-top: 2px; }
.tm-pop-desc     { color: #475569; font-size: 12.5px; margin-top: 6px; padding-top: 6px; border-top: 1px solid #eef2f7; overflow-wrap: anywhere; }

.leaflet-popup-content { margin: 12px 14px; }
.leaflet-popup-content-wrapper { border-radius: 10px; box-shadow: 0 8px 24px rgba(15,23,42,.18); }

/* Playback + route controls */
.tm-replay {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin: 12px 0 0;
  padding: 0 2px;
  max-width: 100%;
}
.tm-replay-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  /* Touch target stays comfortable on phones. */
  min-height: 40px;
  margin: 0;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #1b3c87;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  white-space: nowrap;
}
.tm-replay-btn:hover { background: #eff6ff; }
.tm-replay-btn:focus-visible { outline: 3px solid rgba(37,99,235,.5); outline-offset: 2px; }
.tm-replay-btn-ghost { color: #475569; }
.tm-replay-btn[disabled] { opacity: .5; cursor: not-allowed; }

.tm-replay-ic { font-size: 11px; line-height: 1; }

.tm-replay-speed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
}
.tm-replay-select {
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #0f1e45;
  font-size: 13px;
  font-weight: 600;
}
.tm-replay-select:focus-visible { outline: 3px solid rgba(37,99,235,.5); outline-offset: 2px; }

.tm-replay-bar {
  flex: 1 1 140px;
  min-width: 110px;
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}
.tm-replay-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #1b3c87);
  transition: width .1s linear;
}
.tm-replay-stamp {
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tm-replay-scale {
  flex: 1 1 100%;
  font-size: 11.5px;
  color: #94a3b8;
  overflow-wrap: anywhere;
}
.tm-replay-on .tm-replay-bar { box-shadow: 0 0 0 2px rgba(37,99,235,.18); }
.tm-replay-disabled { opacity: .55; }

.tm-fit-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  margin: 10px 8px 0 2px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1b3c87;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, box-shadow .15s, transform .1s;
}
.tm-fit-btn:hover { background: #eff6ff; }
.tm-fit-btn:active { background: #dbeafe; transform: scale(0.98); }
.tm-fit-btn:focus-visible { outline: 3px solid rgba(37,99,235,.5); outline-offset: 2px; }
.tm-fit-btn:disabled { opacity: .5; cursor: not-allowed; }

/* Route legend — always states what the line is */
.tm-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin: 10px 0 0;
  font-size: 12px;
  color: #475569;
  max-width: 100%;
}
.tm-legend-item { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; color: #0f1e45; }
.tm-legend-swatch {
  width: 26px;
  height: 0;
  border-top-width: 4px;
  border-top-style: solid;
  border-radius: 2px;
}
.tm-legend-swatch[style*="--tm-dash"] { border-top-style: dashed; }
.tm-legend-meta { color: #64748b; }
.tm-legend-flag {
  padding: 2px 8px;
  border-radius: 999px;
  background: #fef3c7;
  color: #a16207;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
}

/* ── Timeline ──────────────────────────────────────────────── */
.tm-timeline {
  list-style: none;
  margin: 0;
  padding: 6px 22px 18px;
  max-height: 520px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
.tl-item {
  position: relative;
  padding: 14px 0 14px 30px;
  border-bottom: 1px dashed #e2e8f0;
  max-width: 100%;
}
.tl-item:last-child { border-bottom: 0; }
.tl-item::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 26px;
  bottom: -14px;
  width: 2px;
  background: #e2e8f0;
}
.tl-item:last-child::before { display: none; }
.tl-dot {
  position: absolute;
  left: 0;
  top: 18px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid #2563eb;
  box-shadow: 0 0 0 3px #ffffff;
  z-index: 1;
}
.tl-item-current .tl-dot {
  border-color: #15803d;
  background: #dcfce7;
  box-shadow: 0 0 0 3px #ffffff, 0 0 0 7px rgba(34, 197, 94, .18);
}
.tl-body { min-width: 0; overflow-wrap: anywhere; }
.tl-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tl-head strong { font-size: 14.5px; color: #0f1e45; overflow-wrap: anywhere; }
.tl-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .4px;
  text-transform: uppercase;
}
.tl-chip-gps     { background: #dbeafe; color: #1d4ed8; }
.tl-chip-current { background: #dcfce7; color: #15803d; }
.tl-loc { color: #334155; font-size: 13.5px; margin-top: 4px; overflow-wrap: anywhere; }
.tl-loc i { color: #2563eb; margin-right: 5px; }
.tl-desc {
  color: #64748b;
  font-size: 12.5px;
  margin-top: 3px;
  /* Long unbroken references (consignment ids, barcodes pasted into a
     note) must wrap instead of widening the page. */
  overflow-wrap: anywhere;
  word-break: break-word;
}
.tl-time { color: #94a3b8; font-size: 12px; margin-top: 5px; font-weight: 600; white-space: nowrap; }
.tl-head strong { overflow-wrap: anywhere; }

/* Timeline ↔ map sync highlight */
.tl-item.tm-active,
[data-map-event-id].tm-active {
  background: #eff6ff;
  box-shadow: inset 3px 0 0 #2563eb;
  border-radius: 8px;
  padding-left: 26px;
  transition: background .2s, box-shadow .2s;
}
.tm-marker-active { z-index: 900 !important; }
.tm-marker-active img { filter: drop-shadow(0 0 6px rgba(37, 99, 235, .9)); }

/* Layout readiness: the map fills its box only once Leaflet has measured it.
   Scoped to wide viewports so that exactly one height rule is ever in play —
   a bare `.tm-ready .tm-map` here outranks the `.tm-map` rules inside the
   mobile media queries below, which silently overrode them. */
@media (min-width: 576px) {
  .tm-ready .tm-map { height: 440px; }
}

@media (max-width: 767px) {
  .tm-summary { padding: 16px 18px; }
  .tm-summary-side { text-align: left; min-width: 0; }
  .tm-summary-note { max-width: none; }
  .tm-timeline { padding: 4px 16px 14px; max-height: none; }
}

@media (max-width: 575px) {
  .tm-map { height: 340px; }
  .tm-card-head { padding: 13px 16px; font-size: 12px; }
  .tm-summary-value { font-size: 17px; }
  .tm-replay { gap: 8px; }
  .tm-replay-stamp { flex: 1 1 100%; }
  .tm-replay-bar { order: 10; flex-basis: 100%; }
  .tm-fit-btn { margin: 8px 6px 0 0; }
  .tm-replay-tx { font-size: 12.5px; }
}

@media (max-width: 390px) {
  .tm-map { height: 300px; }
  .tl-item { padding-left: 26px; }
  .tm-summary { padding: 14px 14px; }
  .tm-summary-main { gap: 12px; }
  .tm-summary-icon { width: 48px; height: 48px; }
  .tm-summary-value { font-size: 16px; }
}

@media (max-width: 320px) {
  .tm-map { height: 280px; }
  .tl-item { padding-left: 22px; }
  .tm-replay-btn { padding: 6px 12px; font-size: 12px; }
  .tm-replay-select { padding: 5px 8px; font-size: 12px; }
  .tm-fit-btn { padding: 6px 10px; font-size: 12px; }
  .tl-dot { left: -2px; }
}

@media (prefers-reduced-motion: reduce) {
  .tm-dot-anim,
  .tm-dot-current,
  .tm-transport-pulse { animation: none !important; }
  .tm-transport-img { transition: none; }
}