/* Mobile layout shared by the fleet map and every administration page. */
@media (max-width: 700px) {
  html, body { min-width: 0; overflow-x: hidden; }

  /* Fleet map */
  .topbar {
    height: 58px;
    padding: 0 8px;
    gap: 6px;
  }
  .topbar .brand { min-width: 0; }
  .topbar .brand img { width: 92px; height: 34px; object-fit: contain; }
  .topbar .brand strong { font-size: 12px; white-space: nowrap; }
  .topbar .brand small, .topbar .live-note, .topbar .label-switch { display: none; }
  .topbar nav {
    min-width: 0;
    margin-left: auto;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .topbar nav::-webkit-scrollbar { display: none; }
  .topbar nav button { flex: 0 0 auto; padding: 8px 7px; font-size: 10px; }
  .sidebar {
    top: 68px;
    left: 8px;
    bottom: 8px;
    width: calc(100% - 16px);
    max-width: 390px;
    transform: translateX(calc(-100% - 16px));
  }
  .panel-toggle { top: 76px; left: 8px; border-radius: 9px; }
  .sidebar.open + .panel-toggle { left: auto; }
  .sidebar.open ~ .panel-toggle { left: min(calc(100% - 36px), 362px); }
  .detail {
    inset: 66px 8px 8px;
    width: auto;
    padding: 14px;
    border-radius: 13px;
  }
  .detail-head { padding-right: 28px; }
  .detail-head .big { width: 48px; height: 48px; }
  .detail-head h2 { font-size: 18px; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .alerts { left: 8px; right: 8px; top: 118px; width: auto; }
  .alerts-button { top: 66px; right: 8px; }
  .fit-map { right: 10px; bottom: 12px; }

  /* Shared workspace shell */
  .workspace > header {
    height: 58px;
    padding: 0 10px;
  }
  .workspace > header .brand img { width: 94px; height: 30px; object-fit: contain; }
  .workspace > header .brand strong { display: none; }
  .workspace-actions { gap: 2px; }
  .workspace > header button { min-height: 38px; padding: 8px 10px; font-size: 12px; }
  .workspace-body { width: 100%; padding: 12px 10px 30px; }
  .tool-page h1 { margin-bottom: 12px; font-size: 25px; line-height: 1.1; }
  .tool-page h2 { font-size: 19px; }
  .panel { margin: 12px 0; padding: 15px; border-radius: 12px; }
  .panel input, .panel select { max-width: 100%; }
  .actions { flex-wrap: wrap; }
  .actions button { flex: 1 1 150px; }

  /* Reports */
  .report-hero { margin: -12px -10px 0; padding: 18px 10px; }
  .report-hero h1 { font-size: 28px; }
  .report-hero p { font-size: 14px; line-height: 1.35; }
  .report-controls { margin-top: 15px; padding: 9px; }
  .report-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .report-picker, .route-filter-field { grid-column: 1 / -1; }
  .report-filters > button { width: 100%; min-width: 0; }
  .report-filters .export { min-width: 0; }
  .calendar-trigger { width: 100%; }
  .quick-ranges {
    margin-top: 9px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .quick-ranges > span { grid-column: 1 / -1; }
  .quick-ranges button { min-width: 0; white-space: normal; }
  .report-summary { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric-card { min-height: 96px; padding: 13px; }
  .metric-card b { font-size: 22px; }
  .report-visuals { grid-template-columns: 1fr; }
  .report-chart { min-height: 240px; padding: 14px; overflow: hidden; }
  .donut-wrap { gap: 14px; transform: scale(.9); transform-origin: center; }
  .report-details-head { gap: 8px; }
  .report-details-head h2 { font-size: 21px; }
  .report-legend { font-size: 11px; }
  .report-table,
  .report-table[data-report-type="completion"] {
    max-width: 100%;
    max-height: none;
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch;
  }
  .report-table table,
  .report-table[data-report-type="completion"] table {
    width: max-content;
    min-width: 1100px;
    table-layout: fixed;
  }
  .report-table-tools {
    position: sticky;
    left: 0;
    width: 100vw;
    min-width: 330px;
    padding: 8px;
    font-size: 10px;
  }
  .report-table-tools button { padding: 6px 8px; font-size: 9px; }
  .report-table .report-sort-row th { top: 0; }
  .report-table .report-column-filters th { top: 46px; }
  .report-filter-popover {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    top: 74px !important;
    width: auto !important;
    max-height: calc(100vh - 90px);
  }

  /* Devices, integrations, users and GTFS */
  .security-summary, .integration-summary { grid-template-columns: 1fr 1fr; gap: 8px; }
  .security-grid, .integration-grid, .gtfs-grid, .users-grid { grid-template-columns: 1fr; }
  .secure-device { grid-template-columns: 1fr; }
  .device-actions { justify-content: flex-start; }
  .integration-head, .security-head, .users-head, .integration-section-head {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }
  .integration-head > button, .security-head > button { width: 100%; }
  .integration-search { width: 100%; flex-wrap: wrap; }
  .integration-search input { width: 100%; min-width: 0; }
  .integration-table { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .integration-table table { min-width: 720px; }
  .sync-row { grid-template-columns: 1fr; gap: 3px; }
  .admin-user-row, .login-audit-row { grid-template-columns: 1fr; }
  .user-actions { grid-column: auto; flex-wrap: wrap; }
  .users-grid > div:last-child { display: block; }
  #currentAdmin { width: 100%; }
  .login form { width: calc(100% - 24px); padding: 24px 18px; }
  .login img { width: min(190px, 80%); }
}

@media (max-width: 390px) {
  .topbar .brand strong { display: none; }
  .report-summary, .security-summary, .integration-summary { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid .wide { grid-column: auto; }
}
