body.tm-trip-replay-active .layout-main { position: relative; min-height: calc(100vh - 72px); }
body.tm-trip-replay-active .layout-main > :not(#tm-trip-replay-root) { visibility: hidden !important; pointer-events: none !important; }

#tm-trip-replay-root {
  position: absolute;
  inset: 0;
  z-index: 20;
  min-height: calc(100vh - 72px);
  overflow: auto;
  background: #f5f7fa;
  color: #142033;
  font-family: Inter, "DM Sans", system-ui, sans-serif;
}

.tm-replay-page { max-width: 1800px; min-height: 100%; margin: 0 auto; padding: 1.25rem 1.4rem 1.5rem; }
.tm-replay-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.tm-replay-eyebrow { display: block; margin-bottom: .25rem; color: #2563eb; font-size: .68rem; font-weight: 800; letter-spacing: .14em; }
.tm-replay-header h1 { margin: 0; color: #0f172a; font-size: clamp(1.55rem, 2.1vw, 2.1rem); line-height: 1.1; letter-spacing: -.035em; }
.tm-replay-header p { margin: .35rem 0 0; color: #64748b; font-size: .88rem; }
.tm-replay-header svg, .tm-replay-controls svg, .tm-replay-follow svg, .tm-replay-trip-copy svg { width: 1rem; height: 1rem; }
.tm-replay-day-button { display: inline-flex; align-items: center; gap: .5rem; min-height: 42px; padding: .6rem .9rem; border: 1px solid #1d4ed8; border-radius: 9px; background: #2563eb; color: #fff; font-weight: 750; cursor: pointer; box-shadow: 0 5px 14px rgba(37,99,235,.22); }
.tm-replay-day-button:hover { background: #1d4ed8; }

.tm-replay-summary { display: grid; grid-template-columns: repeat(8, minmax(105px, 1fr)); gap: .65rem; margin-bottom: .85rem; }
.tm-replay-stat { min-width: 0; padding: .72rem .8rem; border: 1px solid #e2e8f0; border-radius: 10px; background: #fff; box-shadow: 0 2px 8px rgba(15,23,42,.035); }
.tm-replay-stat span { display: block; overflow: hidden; color: #64748b; font-size: .64rem; font-weight: 800; letter-spacing: .06em; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.tm-replay-stat strong { display: block; margin-top: .28rem; overflow: hidden; color: #0f172a; font-size: 1rem; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.tm-replay-stat small { color: #94a3b8; font-size: .7rem; }

.tm-replay-workspace { display: grid; grid-template-columns: minmax(255px, 315px) minmax(0, 1fr); min-height: 660px; overflow: hidden; border: 1px solid #dce3ec; border-radius: 14px; background: #fff; box-shadow: 0 12px 34px rgba(15,23,42,.08); }
.tm-replay-sidebar { display: flex; min-width: 0; flex-direction: column; border-right: 1px solid #e2e8f0; background: #fff; }
.tm-replay-filters { padding: .9rem; border-bottom: 1px solid #e2e8f0; background: #f8fafc; }
.tm-replay-filters label, .tm-replay-date-label { display: grid; gap: .35rem; margin-bottom: .6rem; color: #475569; font-size: .68rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.tm-replay-filters select, .tm-replay-filters input { width: 100%; min-height: 40px; padding: .45rem .65rem; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: #172033; font: 600 .85rem/1.2 inherit; outline: none; }
.tm-replay-filters select:focus, .tm-replay-filters input:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.tm-replay-date-label { margin: .1rem 0 .3rem; }
.tm-replay-date-row { display: grid; grid-template-columns: 36px 1fr 36px; gap: .35rem; }
.tm-replay-date-row button, .tm-replay-presets button { border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: #334155; font-weight: 750; cursor: pointer; }
.tm-replay-date-row button:hover, .tm-replay-presets button:hover { border-color: #94a3b8; background: #f1f5f9; }
.tm-replay-presets { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin-top: .5rem; }
.tm-replay-presets button { min-height: 34px; font-size: .76rem; }
.tm-replay-list-heading { display: flex; align-items: center; justify-content: space-between; padding: .75rem .9rem .6rem; }
.tm-replay-list-heading div { display: flex; align-items: baseline; gap: .45rem; }
.tm-replay-list-heading span { color: #64748b; font-size: .68rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.tm-replay-list-heading strong { color: #0f172a; font-size: .82rem; }
.tm-replay-loading { color: #2563eb !important; font-size: .66rem !important; letter-spacing: 0 !important; text-transform: none !important; }
.tm-replay-trip-list { flex: 1; min-height: 0; max-height: 575px; overflow: auto; padding: 0 .55rem .7rem; scrollbar-width: thin; }
.tm-replay-trip { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: .55rem; width: 100%; margin: 0 0 .45rem; padding: .72rem .65rem; border: 1px solid transparent; border-radius: 9px; background: transparent; color: inherit; text-align: left; cursor: pointer; transition: background .15s ease, border-color .15s ease, box-shadow .15s ease; }
.tm-replay-trip:hover { border-color: #dbe4ee; background: #f8fafc; }
.tm-replay-trip.active { border-color: #bfdbfe; background: #eff6ff; box-shadow: inset 3px 0 #2563eb; }
.tm-replay-trip-index { display: grid; width: 27px; height: 27px; place-items: center; border-radius: 7px; background: #e2e8f0; color: #475569; font-size: .68rem; font-weight: 800; }
.tm-replay-trip.active .tm-replay-trip-index { background: #2563eb; color: #fff; }
.tm-replay-trip-copy { display: grid; min-width: 0; grid-template-columns: 1fr; }
.tm-replay-trip-copy strong { margin-bottom: .35rem; color: #0f172a; font-size: .8rem; }
.tm-replay-trip-copy span { overflow: hidden; color: #475569; font-size: .75rem; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.tm-replay-trip-copy em { height: 13px; color: #94a3b8; }
.tm-replay-trip-copy em svg { display: block; width: 12px; height: 12px; margin: 0 0 0 2px; }
.tm-replay-trip-copy small { margin-top: .42rem; color: #64748b; font-size: .68rem; line-height: 1.35; }
.tm-replay-empty { display: grid; place-items: center; gap: .35rem; min-height: 170px; padding: 1.25rem; color: #64748b; text-align: center; }
.tm-replay-empty strong { color: #334155; }
.tm-replay-empty button { margin-top: .5rem; padding: .5rem .75rem; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; cursor: pointer; }
.tm-replay-empty.error strong { color: #b91c1c; }

.tm-replay-main { display: grid; min-width: 0; grid-template-rows: minmax(470px, 1fr) auto; background: #eef2f6; }
.tm-replay-map-wrap { position: relative; min-width: 0; min-height: 470px; overflow: hidden; background: #e7ecf2; }
.tm-replay-map { position: absolute; inset: 0; }
.tm-replay-map-empty { position: absolute; z-index: 3; inset: 50% auto auto 50%; max-width: 340px; padding: .8rem 1rem; transform: translate(-50%, -50%); border: 1px solid rgba(203,213,225,.9); border-radius: 9px; background: rgba(255,255,255,.94); color: #64748b; font-size: .82rem; text-align: center; box-shadow: 0 4px 16px rgba(15,23,42,.1); }
.tm-replay-follow { position: absolute; z-index: 4; top: 12px; right: 12px; display: inline-flex; align-items: center; gap: .4rem; min-height: 38px; padding: .45rem .7rem; border: 1px solid #d5dde7; border-radius: 8px; background: #fff; color: #334155; font-weight: 700; cursor: pointer; box-shadow: 0 2px 8px rgba(15,23,42,.15); }
.tm-replay-now { position: absolute; z-index: 4; left: 12px; bottom: 12px; display: grid; min-width: 235px; max-width: calc(100% - 24px); padding: .65rem .8rem; border: 1px solid rgba(255,255,255,.35); border-radius: 9px; background: rgba(15,23,42,.9); color: #fff; box-shadow: 0 4px 14px rgba(15,23,42,.25); backdrop-filter: blur(8px); }
.tm-replay-now strong { font-size: .8rem; }
.tm-replay-now span { overflow: hidden; color: #cbd5e1; font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
.tm-replay-now span:last-child { color: #93c5fd; font-weight: 750; }

.tm-replay-player { padding: .75rem .9rem .7rem; border-top: 1px solid #dce3ec; background: #fff; }
.tm-replay-controls { display: flex; align-items: center; gap: .35rem; }
.tm-replay-controls > button { display: inline-flex; min-width: 36px; min-height: 36px; align-items: center; justify-content: center; border: 1px solid #d7dee8; border-radius: 8px; background: #fff; color: #334155; cursor: pointer; }
.tm-replay-controls > button:hover { background: #f1f5f9; }
.tm-replay-controls .tm-replay-play { min-width: 88px; gap: .42rem; border-color: #1d4ed8; background: #2563eb; color: #fff; font-weight: 750; }
.tm-replay-controls .tm-replay-play:hover { background: #1d4ed8; }
.tm-replay-speeds { display: flex; gap: .25rem; margin-left: auto; padding: .2rem; border-radius: 8px; background: #f1f5f9; }
.tm-replay-speeds button { min-width: 35px; min-height: 30px; border: 0; border-radius: 6px; background: transparent; color: #64748b; font-size: .72rem; font-weight: 800; cursor: pointer; }
.tm-replay-speeds button.active { background: #fff; color: #2563eb; box-shadow: 0 1px 4px rgba(15,23,42,.12); }
.tm-replay-clock { display: flex; justify-content: space-between; margin: .5rem 0 .28rem; color: #64748b; font-variant-numeric: tabular-nums; font-size: .68rem; font-weight: 700; }
.tm-replay-timeline { position: relative; height: 24px; }
.tm-replay-segments { position: absolute; top: 8px; right: 0; left: 0; height: 8px; overflow: hidden; border-radius: 999px; background: #e2e8f0; }
.tm-replay-segments span { position: absolute; top: 0; bottom: 0; min-width: 2px; }
.tm-replay-segments .driving, .tm-replay-legend .driving { background: #2563eb; }
.tm-replay-segments .idling, .tm-replay-legend .idling { background: #f59e0b; }
.tm-replay-segments .stopped, .tm-replay-legend .stopped { background: #64748b; }
.tm-replay-timeline input { position: absolute; z-index: 2; inset: 0; width: 100%; height: 24px; margin: 0; opacity: .02; cursor: ew-resize; }
.tm-replay-timeline input::-webkit-slider-thumb { width: 20px; height: 20px; }
.tm-replay-legend { display: flex; gap: .85rem; margin-top: .15rem; color: #64748b; font-size: .66rem; }
.tm-replay-legend span { display: inline-flex; align-items: center; gap: .28rem; }
.tm-replay-legend i { width: 7px; height: 7px; border-radius: 50%; }

@media (max-width: 1180px) {
  .tm-replay-summary { grid-template-columns: repeat(4, 1fr); }
  .tm-replay-workspace { grid-template-columns: minmax(240px, 280px) minmax(0, 1fr); }
}

@media (max-width: 850px) {
  #tm-trip-replay-root { position: relative; min-height: calc(100vh - 64px); }
  .tm-replay-page { padding: .85rem; }
  .tm-replay-workspace { grid-template-columns: 1fr; overflow: visible; }
  .tm-replay-sidebar { border-right: 0; border-bottom: 1px solid #e2e8f0; }
  .tm-replay-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .65rem; }
  .tm-replay-date-label { grid-column: 2; grid-row: 1; align-self: end; }
  .tm-replay-date-row { grid-column: 2; grid-row: 2; }
  .tm-replay-presets { grid-column: 1 / -1; }
  .tm-replay-trip-list { display: flex; max-height: none; gap: .5rem; overflow-x: auto; padding: 0 .75rem .75rem; }
  .tm-replay-trip { flex: 0 0 min(310px, 82vw); margin: 0; }
  .tm-replay-main { grid-template-rows: minmax(430px, 52vh) auto; }
  .tm-replay-map-wrap { min-height: 430px; }
}

@media (max-width: 600px) {
  .tm-replay-page { padding: .65rem; }
  .tm-replay-header { align-items: flex-end; }
  .tm-replay-header p { font-size: .76rem; }
  .tm-replay-day-button { min-height: 40px; padding: .52rem .68rem; font-size: .76rem; }
  .tm-replay-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; }
  .tm-replay-stat { padding: .62rem .68rem; }
  .tm-replay-workspace { min-height: 0; border-radius: 11px; }
  .tm-replay-filters { grid-template-columns: 1fr; }
  .tm-replay-date-label, .tm-replay-date-row { grid-column: 1; grid-row: auto; }
  .tm-replay-main { grid-template-rows: minmax(360px, 46vh) auto; }
  .tm-replay-map-wrap { min-height: 360px; }
  .tm-replay-player { padding: .65rem; }
  .tm-replay-controls { flex-wrap: wrap; }
  .tm-replay-controls .tm-replay-play { min-width: 76px; }
  .tm-replay-speeds { order: 2; width: 100%; margin: .2rem 0 0; justify-content: space-between; }
  .tm-replay-speeds button { flex: 1; }
  .tm-replay-now { right: 8px; bottom: 8px; left: 8px; min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .tm-replay-trip, .tm-replay-day-button { transition: none; }
}
