/* Mobile-only workbench layout. Existing desktop and non-workbench views stay untouched. */
.mobile-workbench-only,
.workbench-sheet-scrim {
  display: none !important;
}

@media (max-width: 820px) {
  html body.workbench-mode {
    overflow-x: hidden;
    overflow-x: clip;
  }

  body.workbench-mode .app-shell,
  body.workbench-mode #workbenchView,
  body.workbench-mode #workbenchView .canvas-panel {
    min-width: 0;
    max-width: 100%;
  }

  body.workbench-mode .topbar {
    min-height: 56px;
    padding: 8px 14px;
    align-items: center;
    justify-content: center;
    flex-direction: row;
  }

  body.workbench-mode .topbar .toolbar {
    display: none !important;
  }

  body.workbench-mode .brand-strip {
    width: 100%;
    min-width: 0;
    justify-content: center;
  }

  body.workbench-mode .brand-lockup {
    width: 132px;
  }

  body.workbench-mode #workbenchView {
    display: block;
    padding: 8px 8px calc(24px + env(safe-area-inset-bottom));
    overflow-x: hidden;
    overflow-x: clip;
  }

  body.workbench-mode #workbenchView .canvas-panel {
    padding: 10px;
    overflow: hidden;
    overflow: clip;
    border-radius: 12px;
  }

  body.workbench-mode #workbenchView .plan-tabs {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-areas:
      "project project project project project project"
      "lighting lighting lighting smart smart smart"
      "illuminance illuminance illuminance schedule schedule schedule"
      "floor floor export export more more";
    align-items: stretch;
    gap: 8px;
    margin-bottom: 12px;
  }

  body.workbench-mode #workbenchView .plan-tab-group,
  body.workbench-mode #workbenchView .plan-tab-actions {
    display: contents;
  }

  body.workbench-mode #workbenchView .workbench-project-name {
    grid-area: project;
    width: 100%;
    min-width: 0;
    min-height: 46px;
    margin: 0;
    padding: 6px 8px;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 252, 246, 0.78);
  }

  body.workbench-mode #workbenchView .workbench-project-name input {
    min-width: 0;
    min-height: 34px;
  }

  body.workbench-mode #workbenchView #planTabButton { grid-area: lighting; }
  body.workbench-mode #workbenchView #smartPlanTabButton { grid-area: smart; }
  body.workbench-mode #workbenchView #illuminanceTabButton { grid-area: illuminance; }
  body.workbench-mode #workbenchView #fixtureScheduleTabButton { grid-area: schedule; }
  body.workbench-mode #workbenchView #floorManager { grid-area: floor; }
  body.workbench-mode #workbenchView #exportPdfInlineButton { grid-area: export; }
  body.workbench-mode #workbenchView .plan-tab-actions > .workbench-more-options { grid-area: more; }

  body.workbench-mode #workbenchView :is(
    #planTabButton,
    #smartPlanTabButton,
    #illuminanceTabButton,
    #fixtureScheduleTabButton,
    #floorManagerButton,
    #exportPdfInlineButton,
    #workbenchMoreOptionsButton
  ) {
    width: 100%;
    min-width: 0;
    min-height: 46px;
    padding: 6px 8px;
    line-height: 1.25;
    white-space: normal;
    touch-action: manipulation;
  }

  body.workbench-mode #workbenchView #floorManager,
  body.workbench-mode #workbenchView .plan-tab-actions > .workbench-more-options {
    min-width: 0;
    width: 100%;
  }

  body.workbench-mode #workbenchView #floorManagerButton {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.workbench-mode #workbenchView .workbench-more-options-menu {
    position: fixed;
    inset: auto 12px max(12px, env(safe-area-inset-bottom));
    z-index: 61;
    display: grid;
    width: auto;
    min-width: 0;
    max-height: min(70dvh, 560px);
    gap: 5px;
    padding: 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 18px;
    background: rgba(255, 252, 246, 0.98);
    box-shadow: 0 22px 54px rgba(38, 31, 23, 0.26);
  }

  body.workbench-mode #workbenchView .workbench-more-options-menu button {
    min-height: 48px;
    padding: 9px 14px;
    border-radius: 10px;
    font-size: 15px;
    text-align: left;
    touch-action: manipulation;
  }

  body.workbench-mode #workbenchView .floor-manager-menu .floor-menu-divider {
    margin: 5px 4px;
  }

  body.workbench-mode #workbenchSheetScrim:not(.hidden) {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: block !important;
    width: 100%;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(31, 28, 24, 0.34);
    box-shadow: none;
    cursor: default;
  }

  body.workbench-mode #workbenchView .canvas-toolbar {
    display: grid;
    grid-template-columns: 44px 66px 44px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
  }

  body.workbench-mode #workbenchView .canvas-toolbar button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 0 6px;
    touch-action: manipulation;
  }

  body.workbench-mode #workbenchView #viewStatus {
    min-width: 0;
    overflow: hidden;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.workbench-mode #workbenchView .plan-legend {
    grid-column: 1 / -1;
    justify-content: flex-start;
    flex: none;
    width: 100%;
    gap: 7px 10px;
    padding: 7px 2px 0;
  }

  body.workbench-mode #workbenchView :is(#planSvg, #illuminanceSvg) {
    width: 100%;
    height: clamp(360px, 60dvh, 620px);
    min-height: 0;
    max-height: 620px;
  }

  body.workbench-mode #workbenchView :is(.fixture-strip-hit-area, .target-hit-area:is(line)) {
    stroke-width: 36px;
    vector-effect: non-scaling-stroke;
  }

  body.workbench-mode #workbenchView :is(.illuminance-panel, .fixture-schedule) {
    min-height: 0;
    padding: 14px;
    border-radius: 10px;
  }

  body.workbench-mode #workbenchView :is(.illuminance-panel, .fixture-schedule) h2 {
    font-size: 23px;
    line-height: 1.15;
  }

  body.workbench-mode #workbenchView .illuminance-toolbar,
  body.workbench-mode #workbenchView .illuminance-actions,
  body.workbench-mode #workbenchView .illuminance-settings {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    gap: 10px;
  }

  body.workbench-mode #workbenchView .illuminance-settings label,
  body.workbench-mode #workbenchView .illuminance-run-control {
    min-width: 0;
    margin: 0;
    grid-template-rows: auto 44px;
    gap: 5px;
  }

  body.workbench-mode #workbenchView .illuminance-settings select,
  body.workbench-mode #workbenchView .illuminance-actions button {
    width: 100%;
    min-width: 0;
    height: 44px;
    min-height: 44px;
    line-height: 42px;
  }

  body.workbench-mode #workbenchView .illuminance-run-control {
    width: 100%;
    margin-left: 0;
  }

  body.workbench-mode #workbenchView .illuminance-run-control > span {
    display: none;
  }

  body.workbench-mode #workbenchView .illuminance-legend {
    width: 100%;
  }

  body.workbench-mode #workbenchView .fixture-schedule-heading {
    margin-bottom: 14px;
  }

  body.workbench-mode #workbenchView .fixture-schedule-panel {
    gap: 10px;
  }

  body.workbench-mode #workbenchView .fixture-schedule-header {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  body.workbench-mode #workbenchView .fixture-schedule-row:not(.fixture-schedule-header) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 253, 248, 0.78);
  }

  body.workbench-mode #workbenchView .fixture-schedule-row:not(.fixture-schedule-header) strong {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    font-size: 18px;
    line-height: 1.25;
  }

  body.workbench-mode #workbenchView .fixture-schedule-row:not(.fixture-schedule-header) span {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
    overflow-wrap: anywhere;
    line-height: 1.55;
  }

  body.workbench-mode #workbenchView .fixture-schedule-row:not(.fixture-schedule-header) span::before {
    content: "参数 · ";
    color: var(--ink);
    font-weight: 600;
  }

  body.workbench-mode #workbenchView .fixture-schedule-row:not(.fixture-schedule-header) b {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(184, 134, 59, 0.12);
    white-space: nowrap;
  }

  /* Mobile is a view/export surface; keep fixture editing available on desktop only. */
  body.workbench-mode #clientInspectorPanel,
  body.workbench-mode #mobileInspectorExpandButton {
    display: none !important;
  }

  body.workbench-mode :is(
    #floorExportModal,
    #floorEditModal,
    #floorDeleteModal,
    #regenerateFixturesModal
  ) .modal-actions button {
    min-height: 46px;
  }

  body.workbench-mode #floorExportModal .floor-export-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  /* Embedded customer records use one shared column so every card has the same edge. */
  body.workbench-mode #workbenchCrmPanel {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  body.workbench-mode #workbenchCrmPanel .workbench-crm-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    min-width: 0;
  }

  body.workbench-mode #workbenchCrmPanel > .workbench-crm-card,
  body.workbench-mode #workbenchCrmPanel .workbench-crm-grid > .workbench-crm-card {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
}

@media (max-width: 820px) and (max-height: 500px) {
  body.workbench-mode #workbenchView :is(#planSvg, #illuminanceSvg) {
    height: 65dvh;
    min-height: 260px;
  }
}

@media (max-width: 820px) and (prefers-reduced-transparency: reduce) {
  body.workbench-mode #workbenchView .workbench-more-options-menu {
    background: #fffaf0;
  }
}

@media (max-width: 820px) and (prefers-contrast: more) {
  body.workbench-mode #workbenchView .workbench-more-options-menu,
  body.workbench-mode #workbenchView .fixture-schedule-row:not(.fixture-schedule-header) {
    border-color: #242624;
    background: #fff;
  }
}
