/* Floating vehicle detail panel over the map */

#mapWrap {
  position: relative;
  width: auto;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

#mapWrap .map-main-area {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#mapWrap .map-main-area > #map {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  width: auto !important;
  height: auto !important;
}

/* —— Floating panel shell (transparent — only widget cards float) —— */
#widgets.map-vehicle-action-wrapper {
  position: absolute;
  top: 58px;
  bottom: 14px;
  inset-inline-end: 12px;
  width: 276px;
  max-width: calc(100% - 24px);
  height: auto;
  z-index: 996;
  float: none !important;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: visible;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  pointer-events: none;
  transition: width 0.25s ease, opacity 0.25s ease;
}

#widgets.map-vehicle-action-wrapper .widgets-panel-toggle {
  position: absolute;
  top: auto;
  bottom: calc(var(--map-fab-bottom, 20px) + (var(--map-fab-size, 48px) + var(--map-fab-gap, 12px)) * 2 + 10px);
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 52px;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.14), 0 1px 4px rgba(15, 23, 42, 0.06);
  color: #16a34a;
  text-decoration: none;
  cursor: pointer;
  pointer-events: auto;
  transform: none;
  transition: background 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, border-color 0.2s ease, bottom 0.25s ease;
}

#widgets.map-vehicle-action-wrapper .widgets-panel-toggle:before,
#widgets.map-vehicle-action-wrapper .widgets-panel-toggle:after {
  display: none !important;
}

#widgets.map-vehicle-action-wrapper .widgets-panel-toggle:hover {
  background: #fff;
  border-color: #16a34a;
  color: #15803d;
  box-shadow: 0 6px 20px rgba(22, 163, 74, 0.18);
  text-decoration: none;
}

#widgets.map-vehicle-action-wrapper .widgets-panel-toggle__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 14px;
  line-height: 1;
  transition: transform 0.25s ease;
}

#widgets.map-vehicle-action-wrapper .widgets-panel-toggle__icon i {
  font-weight: bold;
}

/* Outside panel — map side */
html[dir="rtl"] #widgets.map-vehicle-action-wrapper .widgets-panel-toggle {
  left: calc(100% + 10px);
  right: auto;
}

html:not([dir="rtl"]) #widgets.map-vehicle-action-wrapper .widgets-panel-toggle {
  right: calc(100% + 10px);
  left: auto;
}

/* RTL: open panel → arrow points right (hide); collapsed → points left (show) */
html[dir="rtl"] #widgets.map-vehicle-action-wrapper:not(.collapsed) .widgets-panel-toggle__icon {
  transform: scaleX(-1);
}

html[dir="rtl"] #widgets.map-vehicle-action-wrapper.collapsed .widgets-panel-toggle__icon {
  transform: none;
}

/* LTR: open → arrow left; collapsed → arrow right */
html:not([dir="rtl"]) #widgets.map-vehicle-action-wrapper.collapsed .widgets-panel-toggle__icon {
  transform: scaleX(-1);
}

#widgets.map-vehicle-action-wrapper.collapsed {
  width: 0;
  max-width: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

#widgets.map-vehicle-action-wrapper.collapsed .detail-wrapper,
#widgets.map-vehicle-action-wrapper.collapsed .widgets-content {
  display: none !important;
  height: auto !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

/* —— Scrollable content —— */
#widgets.map-vehicle-action-wrapper .detail-wrapper.widgets-content {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  row-gap: 10px;
  padding: 0 2px 10px 0;
  white-space: normal !important;
  font-size: 12px !important;
  background: transparent;
  color: #334155;
  pointer-events: auto;
}

/* —— Widget cards —— */
#widgets.map-vehicle-action-wrapper .widget {
  display: block !important;
  width: 100% !important;
  height: auto !important;
  margin: 0 !important;
  border: 1px solid rgba(226, 232, 240, 0.95) !important;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.1), 0 1px 4px rgba(15, 23, 42, 0.05);
  vertical-align: initial !important;
  overflow: hidden;
  flex-shrink: 0;
  pointer-events: auto;
}

#widgets.map-vehicle-action-wrapper .widget + .widget {
  margin-inline-start: 0 !important;
  margin-left: 0 !important;
}

#widgets.map-vehicle-action-wrapper .widget-heading,
#widgets.map-vehicle-action-wrapper .card-heading {
  padding: 9px 12px 7px;
  border-bottom: 1px solid #eef2f6;
  background: #fff;
}

#widgets.map-vehicle-action-wrapper .widget-heading .widget-actions {
  float: inline-end;
}

#widgets.map-vehicle-action-wrapper .widget-title,
#widgets.map-vehicle-action-wrapper .card-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: #1e293b;
  line-height: 1.35;
  text-align: start;
}

#widgets.map-vehicle-action-wrapper .widget-title .icon,
#widgets.map-vehicle-action-wrapper .card-title__icon {
  color: #16a34a;
  font-size: 13px;
  width: 16px;
  text-align: center;
  float: none;
  margin-inline-end: 0;
}

#widgets.map-vehicle-action-wrapper .card-status-row {
  margin-top: 4px;
}

#widgets.map-vehicle-action-wrapper .vehicle-popup__status {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
}

#widgets.map-vehicle-action-wrapper .vehicle-popup__status.is-offline {
  background: rgba(148, 163, 184, 0.15);
  color: #64748b;
}

#widgets.map-vehicle-action-wrapper .vehicle-popup__status.is-moving,
#widgets.map-vehicle-action-wrapper .vehicle-popup__status.is-online {
  background: rgba(34, 197, 94, 0.12);
  color: #16a34a;
}

#widgets.map-vehicle-action-wrapper .vehicle-popup__status.is-stopped,
#widgets.map-vehicle-action-wrapper .vehicle-popup__status.is-ack {
  background: rgba(249, 115, 22, 0.12);
  color: #ea580c;
}

#widgets.map-vehicle-action-wrapper .vehicle-popup__status.is-engine {
  background: rgba(234, 179, 8, 0.15);
  color: #ca8a04;
}

#widgets.map-vehicle-action-wrapper .widget-body,
#widgets.map-vehicle-action-wrapper .card-body {
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  padding: 9px 12px 11px;
  overflow: visible;
  font-size: 12px;
}

/* —— Internal tables (sensors, services, driver, etc.) —— */
#widgets.map-vehicle-action-wrapper .widget .table {
  float: none !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  table-layout: fixed;
  border-collapse: collapse;
}

#widgets.map-vehicle-action-wrapper .widget .table + .table {
  margin-left: 0 !important;
  margin-top: 6px;
}

#widgets.map-vehicle-action-wrapper .widget-sensors .table,
#widgets.map-vehicle-action-wrapper .widget-temp-humidity .table,
#widgets.map-vehicle-action-wrapper .widget-driver .table,
#widgets.map-vehicle-action-wrapper .widget-services .table,
#widgets.map-vehicle-action-wrapper .widget-device .table,
#widgets.map-vehicle-action-wrapper .widget-locking .table,
#widgets.map-vehicle-action-wrapper .widget-gprs-command .table,
#widgets.map-vehicle-action-wrapper .widget-recent-events .table {
  width: 100% !important;
}

#widgets.map-vehicle-action-wrapper .widget .table tr > td,
#widgets.map-vehicle-action-wrapper .widget .table tr > th {
  max-width: none !important;
  width: auto !important;
  white-space: normal !important;
  word-break: break-word;
  overflow: visible !important;
  text-overflow: unset !important;
  vertical-align: top;
  padding: 4px 4px;
  line-height: 1.4;
  font-size: 11px;
}

#widgets.map-vehicle-action-wrapper .widget .table tr > td:first-child {
  width: 40% !important;
  color: #64748b;
  font-weight: 600;
}

#widgets.map-vehicle-action-wrapper .widget .table tr > td + td {
  width: auto !important;
  max-width: none !important;
  color: #1e293b;
  font-weight: 500;
}

#widgets.map-vehicle-action-wrapper .widget-sensors .table tr > td,
#widgets.map-vehicle-action-wrapper .widget-temp-humidity .table tr > td {
  width: auto !important;
}

#widgets.map-vehicle-action-wrapper .widget-sensors .table .icon,
#widgets.map-vehicle-action-wrapper .widget-temp-humidity .table .icon {
  float: none;
  display: inline-block;
  vertical-align: middle;
  margin-inline-end: 6px;
  font-size: 1.4em;
  color: #94a3b8;
}

#widgets.map-vehicle-action-wrapper .widget-gprs-command .table td + td {
  text-align: end;
  width: auto !important;
}

#widgets.map-vehicle-action-wrapper .widget-recent-events table tr {
  text-align: start;
}

#widgets.map-vehicle-action-wrapper .widget-recent-events table tr[onclick]:hover {
  background: rgba(22, 163, 74, 0.06);
  cursor: pointer;
}

#widgets.map-vehicle-action-wrapper .widget-body .full-text {
  white-space: normal !important;
}

#widgets.map-vehicle-action-wrapper .widget-body .widget-empty {
  width: 100% !important;
  height: auto !important;
  min-height: 72px;
  text-align: center;
  background-position: center bottom;
  background-size: 48px auto;
}

#widgets.map-vehicle-action-wrapper .widget-body .widget-empty > .btn {
  margin-top: 12px;
}

#widgets.map-vehicle-action-wrapper .widget-body .widget-empty > p {
  padding-top: 12px;
}

/* Scrollable sections with many rows */
#widgets.map-vehicle-action-wrapper .widget-sensors .widget-body,
#widgets.map-vehicle-action-wrapper .widget-temp-humidity .widget-body,
#widgets.map-vehicle-action-wrapper .widget-recent-events .widget-body,
#widgets.map-vehicle-action-wrapper .widget-services .widget-body {
  max-height: 180px;
  overflow-y: auto !important;
  overflow-x: hidden;
}

/* Vehicle information grid */
#widgets.map-vehicle-action-wrapper .vehicle-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

#widgets.map-vehicle-action-wrapper .vehicle-info-item--full {
  grid-column: 1 / -1;
}

#widgets.map-vehicle-action-wrapper .vehicle-info-item__label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: 2px;
}

#widgets.map-vehicle-action-wrapper .vehicle-info-item__value {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  word-break: break-word;
}

#widgets.map-vehicle-action-wrapper .vehicle-info-item__value--speed {
  color: #16a34a;
}

#widgets.map-vehicle-action-wrapper .vehicle-info-item__value--address {
  font-weight: 500;
  font-size: 11px;
  line-height: 1.35;
}

/* Today's activity */
#widgets.map-vehicle-action-wrapper .today-activity__distance {
  margin-bottom: 12px;
}

#widgets.map-vehicle-action-wrapper .today-activity__distance-label {
  display: block;
  font-size: 11px;
  color: #64748b;
  font-weight: 600;
  margin-bottom: 6px;
}

#widgets.map-vehicle-action-wrapper .today-activity__distance-value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: #16a34a;
  line-height: 1.2;
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

#widgets.map-vehicle-action-wrapper .today-activity__progress-track {
  height: 6px;
  border-radius: 999px;
  background: #e8edf3;
  overflow: hidden;
}

#widgets.map-vehicle-action-wrapper .today-activity__progress-bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #16a34a, #22c55e);
  transition: width 0.35s ease;
}

#widgets.map-vehicle-action-wrapper .today-activity__stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
}

#widgets.map-vehicle-action-wrapper .today-activity__stat {
  min-width: 0;
  padding: 7px 8px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid #eef2f6;
}

#widgets.map-vehicle-action-wrapper .today-activity__stat-label {
  display: block;
  font-size: 10px;
  color: #64748b;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 4px;
  word-break: break-word;
}

#widgets.map-vehicle-action-wrapper .today-activity__stat-value {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: #1e293b;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

#widgets.map-vehicle-action-wrapper .duration-value,
#widgets.map-vehicle-action-wrapper .today-activity__stat-value.duration-value,
#widgets.map-vehicle-action-wrapper .vehicle-info-item__value.duration-value {
  direction: ltr;
  unicode-bidi: plaintext;
  white-space: nowrap;
  letter-spacing: 0.02em;
  word-break: normal;
  font-variant-numeric: tabular-nums;
}

#widgets.map-vehicle-action-wrapper .vehicle-info-item__value.duration-value {
  font-weight: 700;
}

#widgets.map-vehicle-action-wrapper .today-activity__stat-value--alert {
  color: #ea580c;
}

/* Vehicle metrics */
#widgets.map-vehicle-action-wrapper .vehicle-metrics__list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#widgets.map-vehicle-action-wrapper .vehicle-metric-row__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

#widgets.map-vehicle-action-wrapper .vehicle-metric-row__label {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  line-height: 1.35;
  word-break: break-word;
}

#widgets.map-vehicle-action-wrapper .vehicle-metric-row__value {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  white-space: nowrap;
  direction: ltr;
}

#widgets.map-vehicle-action-wrapper .vehicle-metric-row__number {
  font-size: 16px;
  font-weight: 700;
  color: #16a34a;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

#widgets.map-vehicle-action-wrapper .vehicle-metric-row--max .vehicle-metric-row__number {
  color: #0ea5e9;
}

#widgets.map-vehicle-action-wrapper .vehicle-metric-row__unit {
  font-size: 10px;
  font-weight: 600;
  color: #94a3b8;
  line-height: 1;
}

#widgets.map-vehicle-action-wrapper .vehicle-metric-row__track {
  height: 6px;
  border-radius: 999px;
  background: #e8edf3;
  overflow: hidden;
}

#widgets.map-vehicle-action-wrapper .vehicle-metric-row__bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #16a34a, #22c55e);
  transition: width 0.35s ease;
}

#widgets.map-vehicle-action-wrapper .vehicle-metric-row__bar--max {
  background: linear-gradient(90deg, #0ea5e9, #38bdf8);
}

/* Weight */
#widgets.map-vehicle-action-wrapper .weight-display {
  text-align: center;
  padding: 8px 0 4px;
}

#widgets.map-vehicle-action-wrapper .weight-display__value {
  font-size: 18px;
  font-weight: 700;
  color: #1e293b;
}

/* Media widgets */
#widgets.map-vehicle-action-wrapper .widget-streetview .widget-body {
  width: 100% !important;
  padding: 0;
}

#widgets.map-vehicle-action-wrapper .widget-streetview .widget-body img,
#widgets.map-vehicle-action-wrapper .widget-camera .camera-image .image {
  width: 100%;
  max-height: 110px;
  object-fit: cover;
}

#widgets.map-vehicle-action-wrapper .widget-camera .widget-body,
#widgets.map-vehicle-action-wrapper .widget-image .widget-body {
  width: 100% !important;
  padding: 0;
}

#widgets.map-vehicle-action-wrapper .widget-sensor-graph .widget-body {
  width: 100% !important;
  padding: 0;
}

#widgets.map-vehicle-action-wrapper .widget-sensor-graph .sensor-graph {
  width: 100% !important;
  height: 100px;
}

#widgets.map-vehicle-action-wrapper .widget-image .widget-body {
  overflow: hidden;
}

/* Map controls — shift when floating panel is open */
@media (min-width: 769px) {
  body.map-widgets-panel-open {
    --map-fab-inline-end: var(--map-fab-panel-offset, calc(12px + 276px + 16px));
  }

  #mapWrap.map-widgets-floating-open .map-main-area #map-controls {
    inset-inline-end: 296px;
    transition: inset-inline-end 0.25s ease;
  }
}

#mapWrap .map-main-area #map-controls {
  transition: inset-inline-end 0.25s ease;
}

/* RTL */
html[dir="rtl"] #widgets.map-vehicle-action-wrapper {
  inset-inline-end: 10px;
}

html[dir="rtl"] #widgets.map-vehicle-action-wrapper .widget-heading .widget-actions {
  float: left;
}

html[dir="rtl"] #widgets.map-vehicle-action-wrapper .widget-heading .widget-title .icon {
  float: right;
  margin-left: 5px;
  margin-right: 0;
}

html[dir="rtl"] #widgets.map-vehicle-action-wrapper .widget-sensors .table .icon,
html[dir="rtl"] #widgets.map-vehicle-action-wrapper .widget-temp-humidity .table .icon {
  float: right;
  margin-right: 0;
  margin-left: 5px;
}

/* Mobile — bottom floating widgets */
@media (max-width: 768px) {
  #widgets.map-vehicle-action-wrapper {
    top: auto;
    bottom: calc(var(--map-fab-bottom, 20px) + (var(--map-fab-size, 48px) + var(--map-fab-gap, 12px)) * 2 + 10px);
    left: 10px;
    right: 10px;
    inset-inline: 10px;
    width: auto;
    max-width: none;
    max-height: 40vh;
  }

  #widgets.map-vehicle-action-wrapper .widgets-panel-toggle {
    bottom: auto;
    top: -26px;
    inset-inline-end: 12px;
    inset-inline-start: auto;
    right: 12px;
    left: auto;
  }

  html[dir="rtl"] #widgets.map-vehicle-action-wrapper .widgets-panel-toggle {
    left: 12px;
    right: auto;
  }

  #widgets.map-vehicle-action-wrapper .detail-wrapper.widgets-content {
    max-height: 40vh;
  }

  #mapWrap.map-widgets-floating-open .map-main-area #map-controls {
    inset-inline-end: 0;
  }

  body.map-widgets-panel-open {
    --map-fab-inline-end: 20px;
  }
}

@media (max-width: 500px) {
  #widgets.map-vehicle-action-wrapper .vehicle-info-grid {
    grid-template-columns: 1fr;
  }
}
