/* R9: desktop viewport workspace — keep the browser canvas fixed and make long tools self-contained. */
@media (min-width: 901px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  .app {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .main {
    display: grid;
    grid-template-rows: 76px minmax(0, 1fr);
    width: 100%;
    height: 100dvh;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
  }

  .topbar {
    position: relative;
    min-height: 0;
    height: 76px;
    padding: 10px 24px;
  }

  .heading h1 {
    font-size: 24px;
  }

  .content {
    min-width: 0;
    min-height: 0;
    padding: 18px 24px 20px;
    overflow: hidden;
  }

  .view.active {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #b7b7bd transparent;
  }

  .view.active::-webkit-scrollbar,
  .detail-pane.active::-webkit-scrollbar,
  .visual-controls-r4::-webkit-scrollbar,
  .test-data-console-r5::-webkit-scrollbar {
    width: 7px;
    height: 7px;
  }

  .view.active::-webkit-scrollbar-thumb,
  .detail-pane.active::-webkit-scrollbar-thumb,
  .visual-controls-r4::-webkit-scrollbar-thumb,
  .test-data-console-r5::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: #b7b7bd;
  }

  .section-head {
    margin-bottom: 14px;
  }

  .section-head h2,
  .detail-hero h2 {
    font-size: 24px;
  }

  .section-head p,
  .detail-hero p {
    margin-top: 4px;
    font-size: 13px;
  }

  .btn {
    min-height: 38px;
    padding-inline: 14px;
    border-radius: 10px;
  }

  .panel {
    border-radius: 16px;
  }

  /* Account permissions: four concise columns replace the tall two-column stack. */
  #admins.view.active {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
  }

  #admins .form-card {
    min-height: 0;
    padding: 18px;
    overflow: auto;
    scrollbar-width: thin;
  }

  #admins .form-grid {
    gap: 12px;
    margin-bottom: 14px !important;
  }

  #admins .label input {
    height: 44px;
  }

  #admins .permission-groups {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
  }

  #admins .permission-group {
    padding: 12px;
  }

  #admins .permission-head {
    margin-bottom: 8px;
  }

  #admins .checks {
    gap: 6px;
  }

  #admins .check {
    gap: 7px;
    padding: 8px;
  }

  #admins .check b {
    font-size: 12px;
  }

  #admins .check small {
    font-size: 10px;
    line-height: 1.35;
  }

  /* Activity editor: header and navigation stay fixed; only the selected tool pane can scroll. */
  #activities.view.active {
    overflow: hidden;
  }

  #activities .activity-detail.show {
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr);
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  #activities .back {
    width: max-content;
    margin-bottom: 10px;
  }

  #activities .detail-hero {
    margin-bottom: 12px;
  }

  #activities .detail-tabs {
    flex-wrap: nowrap;
    min-width: 0;
    margin-bottom: 12px;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  #activities .detail-tabs button {
    padding: 9px 14px;
  }

  #activities .detail-pane.active {
    min-width: 0;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  #activities #pane-test.active,
  #activities #pane-visual.active {
    overflow: hidden;
  }

  /* Complete test flow: readable phone scale, bounded preview and persistent data actions. */
  .test-console-r5 {
    grid-template-columns: minmax(300px, 0.78fr) minmax(480px, 1.22fr);
    height: 100%;
    min-height: 0;
    gap: 16px;
    align-items: stretch;
  }

  .test-preview-shell-r5,
  .test-data-console-r5 {
    min-height: 0;
    padding: 14px;
  }

  .test-preview-shell-r5 {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .test-preview-head-r5 {
    margin-bottom: 10px;
  }

  .test-flow-tabs-r5 {
    flex: 0 0 auto;
    margin-bottom: 10px;
  }

  .test-flow-tabs-r5 button {
    min-height: 32px;
  }

  .test-device-r5 {
    flex: 0 0 auto;
    width: auto;
    height: clamp(430px, calc(100dvh - 434px), 560px);
    aspect-ratio: 9 / 16;
    border-width: 8px;
    border-radius: 30px;
  }

  .test-data-console-r5 {
    display: flex;
    flex-direction: column;
    overflow: auto;
    scrollbar-width: thin;
  }

  .test-data-head-r5 {
    margin-bottom: 10px;
  }

  .test-data-list-r5 {
    gap: 8px;
  }

  .test-data-row-r5 {
    padding: 10px;
  }

  .test-data-row-r5 input,
  .remove-test-r5 {
    height: 36px;
  }

  .test-actions-r5 {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin-top: 12px;
    padding-top: 8px;
    background: #fff;
  }

  .test-actions-r5 button {
    min-height: 40px;
  }

  .test-save-state-r5 {
    margin-top: 8px;
    padding: 10px;
  }

  /* Visual editor: both live preview and controls remain inside the selected pane. */
  .visual-workspace-r4 {
    grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
    height: 100%;
    min-height: 0;
    gap: 16px;
    align-items: stretch;
  }

  .visual-preview-r4,
  .visual-controls-r4 {
    min-height: 0;
  }

  .visual-preview-r4 {
    position: static;
    display: flex;
    flex-direction: column;
    padding: 12px;
    overflow: hidden;
  }

  .visual-device-r4 {
    flex: 0 0 auto;
    width: auto;
    height: clamp(430px, calc(100dvh - 386px), 560px);
    aspect-ratio: 9 / 16;
    border-width: 8px;
    border-radius: 32px;
  }

  .visual-tabs-r4 {
    flex: 0 0 auto;
    margin-top: 8px;
  }

  .visual-tabs-r4 button {
    min-height: 34px;
  }

  .visual-controls-r4 {
    padding: 16px;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  .visual-controls-r4 .control-section {
    padding: 14px 0;
  }

  /* Data dashboard: overview and full流水 are two viewport-sized workspaces. */
  #analytics.view.active {
    display: grid;
    grid-template-columns: minmax(0, 1.16fr) minmax(500px, 0.84fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: 12px;
    overflow: hidden;
  }

  #analytics .section-head {
    position: relative;
    grid-column: 1 / -1;
    margin: 0;
    z-index: 4;
    background: #f5f5f7;
  }

  #analytics .analytics-overview {
    grid-column: 1 / -1;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 8px;
  }

  #analytics .metric {
    min-height: 104px;
    padding: 15px;
  }

  #analytics .metric b {
    margin-top: 10px;
    font-size: 25px;
  }

  #analytics .metric small {
    font-size: 9px;
  }

  #analytics .reservation-card {
    grid-column: 1;
    grid-row: 3;
    min-height: 0;
    margin-top: 0;
    padding: 16px;
    overflow: auto;
    scrollbar-width: thin;
  }

  #analytics .chart-title {
    margin-bottom: 12px;
  }

  #analytics .reservation-summary {
    gap: 8px;
  }

  #analytics .reservation-metric {
    padding: 11px;
  }

  #analytics .reservation-layout {
    gap: 10px;
    margin-top: 10px;
  }

  #analytics .reservation-list {
    padding: 12px;
  }

  #analytics .reservation-line {
    padding: 8px 0;
  }

  #analytics .analytics-layout {
    grid-column: 2;
    grid-row: 3;
    grid-template-columns: minmax(0, 1.2fr) minmax(180px, 0.8fr);
    min-height: 0;
    height: 100%;
    gap: 10px;
    margin-top: 0;
    overflow: hidden;
  }

  #analytics .analytics-layout > .panel {
    min-width: 0;
    min-height: 0;
    padding: 14px;
    overflow: auto;
    scrollbar-width: thin;
  }

  #analytics .analytics-layout .chart-title {
    margin-bottom: 10px;
  }

  #analytics .distribution-list {
    gap: 10px;
  }

  #analytics .distribution-row {
    grid-template-columns: 58px minmax(0, 1fr) 54px;
    gap: 7px;
  }

  #analytics .distribution-row span {
    display: none;
  }

  #analytics .participation-ring {
    width: 124px;
    margin: 6px auto 10px;
  }

  #analytics .participation-ring::after {
    width: 84px;
  }

  #analytics .legend-list {
    gap: 4px;
  }

  #analytics .legend-row {
    padding: 7px 0;
  }

  #analytics .analytics-detail,
  #analytics .analytics-footnote {
    display: none;
  }

  #analytics.view.active.show-detail-r9 {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  #analytics.show-detail-r9 .analytics-overview,
  #analytics.show-detail-r9 .reservation-card,
  #analytics.show-detail-r9 .analytics-layout {
    display: none;
  }

  #analytics.show-detail-r9 .analytics-detail {
    display: grid;
    grid-column: 1;
    grid-row: 2;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-height: 0;
    height: 100%;
    gap: 12px;
    margin: 0;
  }

  #analytics.show-detail-r9 .analytics-detail > .panel {
    min-height: 0;
    overflow: auto;
    scrollbar-width: thin;
  }
}

@media (min-width: 901px) and (max-width: 1320px) {
  #admins .permission-groups {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #analytics .analytics-overview {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  #analytics.view.active {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  #analytics .reservation-card {
    display: none;
  }

  #analytics .analytics-layout {
    grid-column: 1;
  }
}
