/* 1100px 及以上保持 1672×941 原稿；窄窗口使用真实字号和自然页面滚动。
   本文件须在 live.css 后加载。fit() 的窄窗口分支应使用 scale=1，并 resize 图表。 */
@media (max-width: 1099px) {
  html,
  body {
    width: 100%;
    min-width: 320px;
    overflow-x: hidden;
  }

  #viewport {
    width: 100% !important;
    height: auto !important;
    overflow: visible;
  }

  #dashboard {
    position: relative;
    inset: auto;
    width: 100%;
    height: auto;
    min-height: 100vh;
    transform: none;
  }

  #header {
    height: auto;
    min-height: 70px;
    padding: 8px 12px;
    gap: 8px 16px;
    flex-wrap: wrap;
  }

  #header .brand {
    width: min(390px, 48vw);
    height: auto;
  }

  #header .project-name {
    flex: 1;
    width: auto;
    min-width: 180px;
    max-width: none;
    margin: 0;
    font-size: 14px;
  }

  #header .header-meta {
    flex: 1 0 100%;
    gap: 12px;
    margin: 0;
    padding: 4px 0;
    overflow-x: auto;
    white-space: nowrap;
  }

  .header-meta > * {
    flex-shrink: 0;
  }

  .header-meta > .meta-item {
    padding-left: 10px;
  }

  #navigation {
    margin: 0;
    height: 52px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  #navigation a {
    flex: 0 0 133px;
    width: auto;
    gap: 8px;
    font-size: 14px;
  }

  #navigation img {
    width: 28px;
    height: 28px;
  }

  #main {
    position: relative;
    inset: auto;
    padding: 12px;
    width: 100%;
  }

  .page {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 12px;
    width: 100%;
    height: auto;
  }

  /* 仅解除页面一级面板坐标；地图工具、详情与图表内部绝对定位保持有效。 */
  .page > .positioned {
    position: relative !important;
    inset: auto !important;
    width: auto !important;
    height: auto !important;
    min-width: 0;
    margin: 0;
  }

  .page > .panel {
    display: flex;
    flex-direction: column;
    min-height: 200px;
  }

  .page > .panel > .panel-body {
    height: auto !important;
    flex: 1;
    min-height: 0;
    min-width: 0;
    padding: 12px;
  }

  .page .panel-title {
    flex-shrink: 0;
    height: auto !important;
    min-height: 42px;
    padding-top: 8px;
    padding-bottom: 8px;
    flex-wrap: wrap;
    font-size: 16px;
    line-height: 1.4;
    white-space: normal;
  }

  .page .panel-title .tools,
  .page .section-tabs,
  .page .section-tabs .right {
    flex-wrap: wrap;
    height: auto;
    gap: 6px;
  }

  .page .panel-title .tools {
    min-width: 0;
    max-width: 100%;
  }

  .page .panel-title .tools button,
  .page .section-tabs button,
  .page .tabs button {
    height: auto;
    min-height: 32px;
    padding: 5px 10px;
    font-size: 13px;
  }

  .page .tabs {
    flex-wrap: wrap;
    gap: 5px;
  }

  .page > .metrics,
  .page > .query,
  .page > .map,
  .page > .panel:has(.data-table),
  .page > .panel:has(#video-wall),
  .page > .panel:has(.project-details),
  .page > .device-heading,
  .organization-page > .positioned:first-child {
    grid-column: 1 / -1;
  }

  .page > .metrics {
    order: -1;
  }

  .page .metrics {
    grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)) !important;
    height: auto !important;
    gap: 8px;
  }

  .page .metric,
  .page .metric.compact {
    min-height: 96px;
    padding: 12px;
    gap: 10px;
  }

  .page .metric > img,
  .page .metric.compact > img {
    width: 42px;
    height: 42px;
  }

  .page .metric .label,
  .page .metric.compact .label {
    font-size: 13px;
    letter-spacing: 0;
  }

  .page .metric .value,
  .page .metric.compact .value {
    font-size: 29px;
  }

  .page .metric .unit {
    margin-left: 4px;
    font-size: 13px;
  }

  .page .metric .trend {
    position: static;
    white-space: normal;
    font-size: 11px;
  }

  .page .metric .progress {
    position: static;
    width: auto;
    margin-top: 8px;
  }

  .page > .query {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px !important;
    min-height: 0;
    padding: 14px;
    order: -2;
  }

  .page > .query > label,
  .page > .query > .query-date-range {
    display: grid !important;
    grid-template-columns: minmax(80px, auto) minmax(0, 1fr);
    align-items: center;
    width: auto !important;
    max-width: none;
    min-width: 0;
    margin: 0;
    gap: 8px;
    font-size: 13px;
  }

  .page > .query > label input,
  .page > .query > label select,
  .page > .query .date-range-inputs input {
    width: 100% !important;
    height: 36px;
    margin: 0;
    font-size: 14px;
  }

  .page > .query > .buttons,
  .page > .query > .query-title,
  .alarms > .query > .query-date-range,
  .vehicles-page > .query > label:last-of-type {
    grid-column: 1 / -1;
  }

  .page > .query > .buttons {
    margin: 0;
    padding: 0;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  /* 原稿将报警查询标题和表单分成两层，流式布局不再保留空白底板。 */
  .alarms > .panel:first-child:has(> .panel-body:empty) {
    display: none;
  }

  .page > .panel:has(.chart),
  .page > .low-battery-panel {
    height: 320px !important;
  }

  .page > .panel > .panel-body > .chart {
    height: 100%;
    min-height: 220px;
  }

  .overview > .overview-left {
    min-height: 310px;
  }

  .overview-left .onsite-ring {
    width: 55%;
    height: 210px;
  }

  .overview-left .onsite-stats {
    width: 43%;
    right: 8px;
  }

  .overview-videos {
    min-height: 240px;
  }

  .page > .map {
    height: 450px !important;
  }

  .page .map-tools {
    width: auto;
    height: auto;
    max-width: calc(100% - 20px);
    top: 10px;
    left: 10px;
  }

  .page .map-tools button {
    height: 34px;
    padding: 5px 12px;
    font-size: 12px;
  }

  .page .map-side {
    top: 60px;
    left: 10px;
  }

  .page .map-side button {
    width: 44px;
    height: 49px;
  }

  .page .map-zoom {
    left: 15px;
    right: auto;
    bottom: 45px;
  }

  .page.location .map-zoom {
    left: auto;
    right: 13px;
    bottom: 30px;
  }

  .page .map-data-note {
    left: 80px;
    bottom: 24px;
    max-width: calc(100% - 90px);
  }

  .page .map > .person-detail {
    position: absolute !important;
    left: auto !important;
    right: 10px;
    top: 54px !important;
    width: min(310px, calc(100% - 78px)) !important;
    height: 354px !important;
    max-height: calc(100% - 90px);
  }

  .page .person-detail > .panel-body {
    height: calc(100% - 42px);
    overflow: auto;
  }

  .page > .panel:has(.data-table) {
    height: 430px !important;
  }

  .page > .panel:has(.data-table) > .panel-body,
  .page .live-table-body {
    display: flex;
    flex-direction: column;
    height: auto !important;
    min-height: 0;
    flex: 1;
  }

  .page .table-wrap {
    width: 100%;
    height: auto !important;
    min-height: 100px;
    max-height: none !important;
    overflow: auto;
    flex: 1;
  }

  .page .table-wrap .data-table {
    min-width: 760px;
    width: 100%;
    font-size: 13px;
  }

  .page .table-wrap .data-table th,
  .page .table-wrap .data-table td {
    font-size: 13px;
    height: 36px;
    line-height: 1.5;
  }

  .page .pagination {
    flex-wrap: wrap;
    flex-shrink: 0;
    height: auto !important;
    min-height: 40px;
    gap: 8px;
    padding: 8px 4px;
  }

  .location > .location-list {
    height: 570px !important;
    order: 1;
  }

  .location > .panel:last-child {
    order: 2;
  }

  .location-list .table-wrap .data-table {
    min-width: 620px;
  }

  .page .tree,
  .page #fence-groups,
  .page .channel-list {
    max-height: 330px;
    overflow: auto;
  }

  .page .tree-search {
    width: 100%;
    font-size: 14px;
  }

  .page .device-heading {
    height: auto;
    min-height: 42px;
    flex-wrap: wrap;
    order: -3;
  }

  .page .device-heading .tabs button {
    min-width: 0;
  }

  .organization-page > .positioned:first-child {
    order: -2;
  }

  .page .project-photo {
    width: 32%;
    min-width: 0;
    max-height: 260px;
  }

  .page .project-details {
    flex: 1;
    min-width: 0;
  }

  .page .project-details h2 {
    flex-wrap: wrap;
    white-space: normal;
    font-size: 18px;
  }

  .page .project-properties .property {
    width: auto;
    height: auto;
    min-height: 34px;
    white-space: normal;
    flex-wrap: wrap;
  }

  .page .project-properties .property > span {
    width: auto;
    min-width: 64px;
  }

  .page .vehicle-preview {
    gap: 12px;
    height: auto;
  }


  .page .vehicle-info {
    width: auto;
    min-width: 0;
    flex: 1;
  }

  .video-page > .panel:has(#video-wall) {
    height: 640px !important;
  }

  .video-page #video-wall {
    min-height: 0;
    height: 100%;
  }

  .video-wall.nine .video-top {
    font-size: 12px;
  }

  .video-page > .panel:has(.metrics) {
    grid-column: 1 / -1;
    min-height: 0;
  }

  .activity-row {
    grid-template-columns: 23px minmax(80px, 1fr) minmax(120px, 2fr);
    height: auto;
    min-height: 52px;
    gap: 4px 8px;
  }

  .activity-row time {
    grid-column: 2 / -1;
    font-size: 12px;
  }

  #modal {
    width: min(900px, calc(100vw - 24px));
    min-width: 0;
    max-width: calc(100vw - 24px);
  }

  #toast {
    width: max-content;
    max-width: calc(100vw - 24px);
    white-space: normal;
    text-align: center;
  }

  .component-page {
    display: block;
  }

  .components-mode #header {
    height: auto;
  }

  .components-mode #header > a > img {
    max-width: 100%;
    height: auto;
  }

  .components-mode #main {
    inset: auto;
  }

  .components-mode .page {
    width: 100%;
    height: auto;
  }

  .component-page .components-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    height: auto;
  }

  .component-page .components-grid > .panel {
    position: relative;
    inset: auto;
    width: auto;
    height: auto;
    min-height: 300px;
    overflow-x: auto;
  }

  .component-page .components-grid > .panel > .panel-body {
    min-width: 640px;
  }
}

@media (max-width: 680px) {
  #header .brand {
    width: min(360px, 100%);
    margin: 0 auto;
  }

  #header .project-name {
    flex-basis: 100%;
  }

  #main {
    padding: 8px;
  }

  .page {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  .page > .query {
    grid-template-columns: minmax(0, 1fr);
  }

  .page > .query > label,
  .page > .query > .query-date-range {
    grid-template-columns: 84px minmax(0, 1fr);
  }

  .page .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .page .metric,
  .page .metric.compact {
    padding: 10px 8px;
    gap: 7px;
  }

  .page .metric > img,
  .page .metric.compact > img {
    width: 34px;
    height: 34px;
  }

  .page .metric .value,
  .page .metric.compact .value {
    font-size: 25px;
  }

  .page .section-tabs .right,
  .page .panel-title .tools {
    margin-left: 0;
  }

  .page .map > .person-detail {
    right: 8px;
    width: min(280px, calc(100% - 72px)) !important;
  }

  .page .map-tools button {
    padding: 5px 9px;
  }

  .page .project-photo {
    width: 100%;
    height: 180px;
  }

  .page .panel-body > .flex:has(.project-details) {
    height: auto !important;
    flex-direction: column;
  }

  .page .project-details h2 {
    font-size: 17px;
  }



  .video-page > .panel:has(#video-wall) {
    height: auto !important;
    min-height: 290px;
  }

  .video-page #video-wall:not(:fullscreen) {
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-auto-rows: 230px;
  }

  .modal-content {
    padding: 16px;
  }

  .modal-header {
    padding: 0 14px;
  }
}

@media (max-width: 1099px) {
  .video-page > .panel:has(#video-wall) {
    order: 1;
  }
  .video-page > .panel:has(.metrics) {
    order: 2;
  }
  .video-page .video-wall:not(.nine):not(:fullscreen) {
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 680px) {
  .video-page .video-wall:not(.nine):not(:fullscreen) {
    grid-template-rows: none;
  }
}

@media (min-width: 681px) and (max-width: 1099px) {
  .location > .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
}
