/*
 * 手机工作台适配，使用 700px 断点，并覆盖手机横屏的低高度触摸视口。
 * 除录入弹窗外置操作栏的基础间距外，布局覆盖均限定在手机视口内。
 */
.mobile-nav,
.mobile-advice-toggle { display: none; }

/* 操作栏移出照片滚动区后仍关联原表单，桌面沿用原按钮排列。 */
.product-upload-actions { margin: 0; padding: 18px 30px; }
.product-upload-actions .form-message { flex: 1; min-width: 0; }

@media (max-width: 700px), (max-width: 960px) and (max-height: 500px) and (pointer: coarse) {
  body {
    --mobile-nav-space: calc(64px + env(safe-area-inset-bottom, 0px));
    background-attachment: scroll;
  }
  body.mobile-workbench { padding-bottom: var(--mobile-nav-space); }
  body.mobile-keyboard-open { --mobile-nav-space: 0px; }
  body.mobile-modal-open { overflow: hidden; overscroll-behavior: none; }

  /* 输入框保持可读字号，按钮提供明确的触摸区域，不依赖悬停才能使用。 */
  input.luxury-input,
  select.luxury-input,
  textarea.luxury-input,
  .luxury-input-mini,
  .closet-product-search input { font-size: 16px; min-width: 0; max-width: 100%; }
  .luxury-input-mini { min-height: 44px; }
  button { touch-action: manipulation; }
  .gold-border-btn, .gold-border-btn-mini, .primary-gold-button,
  .compact-button, .filter-tab, .close-btn, .product-preview-remove,
  .product-edit-button, .product-delete-button { min-height: 44px; }
  .close-btn { min-width: 44px; flex-shrink: 0; }
  .form-message, .panel-intro, .p-rack-location, .p-internal-code { overflow-wrap: anywhere; }
  .auth-screen { padding: 16px; overflow-y: auto; align-items: safe center; }
  .auth-card { padding: 28px 22px; margin-block: 16px; }

  /* 手机顶栏只呈现身份与服务状态，原有导航移入“更多”。 */
  /* 新品牌独占一行，身份、连接与额度在下一行排列；长门店名沿用省略显示。 */
  .mobile-workbench #app-header { grid-template-columns: minmax(0, 1fr); padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px; gap: 6px 10px; }
  .mobile-workbench #app-header .logo-area { grid-row: auto; }
  .mobile-workbench #app-header .brand-title { font-size: 21px; }
  .mobile-workbench #app-header .header-context { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 2px 8px; }
  .mobile-workbench #app-header .status-badge { padding: 1px 0; font-size: 11px; background: transparent; }
  .mobile-workbench #app-header #current-user-badge { text-align: left; font-size: 12px; }
  .mobile-workbench #app-header #generation-quota-badge { border: 0; }

  .mobile-nav {
    position: fixed;
    z-index: 110;
    inset: auto 0 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 5px max(8px, env(safe-area-inset-right, 0px)) calc(5px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
    border-top: 1px solid var(--color-line);
    background: var(--color-white);
    box-shadow: 0 -4px 20px rgba(28, 27, 24, .04);
  }
  .mobile-nav button {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 54px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--color-muted);
    font: inherit;
    font-size: 12px;
  }
  .mobile-nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  .mobile-nav button[aria-current="page"] { background: var(--color-surface-soft); color: var(--color-accent-strong); font-weight: 700; }
  .mobile-history-indicator { position: absolute; top: 0; left: 56%; min-width: 18px; padding: 0 4px; border-radius: 20px; background: var(--color-accent-strong); color: white; font-size: 10px; }
  .mobile-keyboard-open .mobile-nav { display: none; }

  /* 只隐藏展示区域，不修改 HTML hidden 的权限状态，不移除顾客表单与商品 DOM。 */
  .mobile-workbench[data-mobile-view="reception"] .workbench-right,
  .mobile-workbench[data-mobile-view="products"] .workbench-left,
  .mobile-workbench[data-mobile-view="more"] #sales-workbench,
  .mobile-workbench:not([data-mobile-view="more"]) #admin-dashboard { display: none; }
  .workbench { grid-template-columns: minmax(0, 1fr); padding: 0 12px; margin: 12px auto 24px; gap: 12px; }
  .fashion-glass-card, .closet-card { padding: 16px; border-radius: 16px; }
  .card-title-bar { gap: 8px; margin-bottom: 16px; padding-bottom: 12px; }
  .card-main-title, .closet-header .card-main-title { font-size: 22px; }
  .count-pill { padding: 5px 8px; font-size: 11px; max-width: 46%; }
  .recommend-form-layout { gap: 16px; }
  .form-section-unit { padding: 14px; }
  .unit-title { margin-bottom: 10px; }
  .customer-profile-summary { flex-direction: row; align-items: center; padding: 10px; gap: 8px; }
  .customer-profile-summary > div { min-width: 0; }
  .customer-profile-summary > button { flex-shrink: 0; padding-inline: 10px; }
  .image-preview-wrap { height: 190px; }
  .image-preview-wrap.has-ready { height: 112px; }
  .customer-photo-status, .customer-photo-ready { padding: 14px; gap: 12px; }
  .customer-photo-status strong, .customer-photo-ready strong { font-size: 16px; }
  .customer-photo-status p, .customer-photo-ready p { font-size: 12px; }
  .customer-photo-ready-icon, .customer-photo-status-spinner { width: 34px; height: 34px; font-size: 22px; }
  /* 手机接待页直接衔接照片、搭配方向和生成按钮，省去重复的功能说明。 */
  .recommendation-intro { display: none; }
  .placeholder-box { padding: 12px; }
  .placeholder-main-text { font-size: 15px; }
  .placeholder-sub-text { font-size: 12px; }
  .file-trigger-wrap { display: grid; grid-template-columns: 1fr 1fr; width: 100%; gap: 8px; }
  .file-trigger-wrap > button { padding-inline: 8px; white-space: normal; }
  .action-dock { gap: 10px; }
  .action-dock .stylist-primary-button { min-height: 50px; padding: 12px; font-size: 16px; }

  .mobile-more { margin: 12px; }
  #mobile-account-description { margin: 8px 0 18px; }
  #mobile-more .header-actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
  #mobile-more .header-actions > button { width: 100%; text-align: left; justify-content: flex-start; }
  #mobile-more #reception-history-button { display: none; }
  .mobile-workbench #admin-dashboard { padding: 0 12px 24px; gap: 16px; }
  .mobile-workbench .admin-wide-card { padding: 16px; }
  .mobile-workbench .sales-account-row { flex-wrap: wrap; gap: 12px; }

  /* 两列商品使用可收缩轨道；商品库随页面滚动，避免小屏出现双层长列表滚动。 */
  .closet-header { margin-bottom: 14px; gap: 12px; }
  .closet-header-actions > button { padding-inline: 12px; }
  .closet-product-search { order: 1; min-height: 44px; }
  .closet-filter-bar { margin-bottom: 12px; gap: 6px; }
  .filter-tab { padding: 8px 12px; }
  .closet-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 0; max-height: none; overflow: visible; }
  .product-card { min-width: 0; padding: 8px; border-radius: 12px; }
  .product-card-img-wrap { height: auto; aspect-ratio: 3 / 4; margin-bottom: 8px; overflow: visible; }
  .product-card-img-wrap > img { border-radius: 8px; }
  .lux-switch-wrap { position: static; margin-top: 6px; }
  .product-card-img-wrap:has(.lux-switch-wrap) { aspect-ratio: auto; }
  .product-card-img-wrap > img { aspect-ratio: 3 / 4; height: auto; }
  .lux-switch-label { min-height: 44px; padding: 6px; justify-content: center; font-size: 12px; box-shadow: none; }
  .p-internal-code { font-size: 12px; }
  .p-meta-specs { gap: 4px; }
  .p-chip { font-size: 10px; padding: 3px 6px; }
  .product-card-admin-actions { gap: 6px; margin-top: 8px; padding-top: 8px; }
  .specified-try-on-bar { grid-template-columns: minmax(0, 1fr); padding: 12px; margin: 0 0 14px; }
  .specified-try-on-bar > button { grid-column: auto; width: 100%; }
  .mobile-workbench .workbench-right { padding-bottom: var(--mobile-selection-space, 0px); }
  .mobile-workbench .specified-try-on-bar[data-has-selection="true"] {
    position: fixed;
    z-index: 105;
    left: max(12px, env(safe-area-inset-left, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    bottom: calc(var(--mobile-nav-space) + 6px);
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px 10px;
    margin: 0;
    background: var(--color-white);
    box-shadow: var(--shadow-light);
  }
  .specified-try-on-bar[data-has-selection="true"] > button { width: auto; padding: 10px; font-size: 12px; }
  .specified-try-on-bar[data-has-selection="true"] strong { display: none; }
  .specified-try-on-bar .form-message:empty { display: none; }
  .product-ingestion-panel { padding: 10px; }
  .product-ingestion-list { max-height: none; }

  /* 统一可视高度和安全区域；内容在弹窗内部滚动，关闭按钮不随长表单滚走。 */
  .modal-overlay {
    top: var(--mobile-viewport-top, 0px);
    height: var(--mobile-viewport-height, 100dvh);
    width: 100%;
    padding: max(8px, env(safe-area-inset-top, 0px)) max(8px, env(safe-area-inset-right, 0px)) max(8px, env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
    transition: none;
  }
  .modal-overlay .modal-box { display: flex; flex-direction: column; width: 100%; max-height: 100%; min-height: 0; border-radius: 16px; transform: none; transition: none; }
  .modal-header, .style-picker-modal-box .modal-header { flex-shrink: 0; gap: 8px; padding: 12px 16px; }
  .modal-header h3 { font-size: 18px; }
  .modal-header .section-label { display: none; }
  .modal-header .panel-intro { font-size: 12px; }
  /* 操作区不参与文字压缩，避免“刷新”在窄屏被挤成两行。 */
  .modal-header > div:first-child { min-width: 0; }
  .modal-header-actions { flex-shrink: 0; gap: 4px; }
  .modal-header-actions > button { white-space: nowrap; }
  .modal-header-actions > .compact-button { padding-inline: 12px; }
  .modal-body, .reception-history-body { min-height: 0; max-height: none; padding: 16px; overflow-y: auto; overscroll-behavior-y: contain; }
  .modal-box > form { min-height: 0; overflow-y: auto; padding: 16px; }
  .modal-form-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .customer-profile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .customer-profile-actions, .purchase-actions { flex-direction: row; }
  .customer-profile-actions > button, .purchase-actions > button { flex: 1; min-width: 0; padding-inline: 10px; }
  .customer-profile-actions, .purchase-actions, .product-edit-actions {
    position: sticky; bottom: -16px; z-index: 1; padding: 12px 0; background: var(--color-white);
  }
  .modal-box > .style-picker-form { display: grid; padding: 0; overflow: hidden; }
  .style-picker-body { max-height: none; min-height: 0; padding: 16px; }
  .style-picker-actions { flex-shrink: 0; padding: 12px 16px; }
  .style-picker-actions > button { padding-inline: 10px; }
  .style-choice-grid, .season-choice-grid { grid-template-columns: minmax(0, 1fr); }
  .purchase-product-list { max-height: none; overflow: visible; }
  /* 历史页把空间留给记录：标题与操作固定同排，状态标签和次要操作适度收紧。 */
  #reception-history-modal .modal-header .panel-intro { display: none; }
  #reception-history-modal .modal-header { padding-block: 10px; }
  #reception-history-close { border-radius: 50%; background: var(--color-surface-soft); }
  .reception-history-card { min-width: 0; gap: 10px; }
  .reception-history-thumb { align-self: start; }
  .reception-history-copy strong { font-size: 14px; line-height: 1.5; }
  .reception-history-copy > span, .reception-history-copy > small { font-size: 12px; }
  .reception-history-actions { flex-wrap: wrap; }
  .reception-history-actions > button { justify-content: center; text-align: center; padding-inline: 12px; }
  .reception-history-actions > .danger-button { flex: 0 0 64px; border-color: var(--color-line); }
  .generation-status-chip { min-height: 28px; display: inline-flex; align-items: center; }
  button.generation-status-chip { min-height: 44px; }
  #reception-history-message:empty { display: none; }

  /* 长列表与试穿结果采用全屏弹窗，底部操作栏占正常布局空间，不覆盖照片。 */
  #try-on-modal, #add-product-modal, #reception-history-modal, #recommendation-style-modal { padding: 0; }
  #try-on-modal > .modal-box, #add-product-modal > .modal-box,
  #reception-history-modal > .modal-box, #recommendation-style-modal > .modal-box {
    height: 100%; border: 0; border-radius: 0;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  }
  #add-product-modal .modal-body, .reception-history-body, .style-picker-form { flex: 1; }
  .product-upload-actions { flex-shrink: 0; flex-wrap: wrap; padding: 12px 16px; gap: 8px; }
  .product-upload-actions .form-message { flex-basis: 100%; }
  .product-upload-actions .form-message:empty { display: none; }
  .product-upload-actions > button { flex: 1; padding-inline: 10px; }
  .modal-img-placeholder { height: 180px; }
  .product-preview-track { grid-auto-columns: 76%; touch-action: auto; }
  .product-preview-card img { height: 220px; object-fit: contain; }
  .product-photo-actions { width: 100%; display: grid; grid-template-columns: 1fr; gap: 8px; }

  /* 入库弹窗背景覆盖完整布局视口，只有内容面板跟随可视视口。
     iOS键盘/悬浮工具栏改变高度时，面板下方不会露出后面的商品列表。 */
  #add-product-modal { top: 0; height: 100%; background: var(--color-white); }
  #add-product-modal > .modal-box {
    position: absolute; top: var(--mobile-viewport-top, 0px); left: 0;
    height: var(--mobile-viewport-height, 100dvh); max-height: none;
  }
  #add-product-modal .modal-body { scroll-padding-block: 12px; overflow-anchor: none; }
  /* 选填货架提前到首屏，缩短说明；按钮优先，空照片框不再占据半屏。 */
  #add-product-modal .modal-fields { order: -1; gap: 8px; }
  #add-product-modal .batch-rack-location-field { order: -1; }
  #add-product-modal .batch-rack-location-field > span { display: flex; flex-wrap: wrap; gap: 4px 8px; }
  #add-product-modal .modal-fields > .panel-intro { margin: 0; font-size: 12px; }
  #add-product-modal .product-photo-actions { order: -1; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #add-product-modal .product-photo-actions > button { min-width: 0; min-height: 54px; padding: 10px 6px; white-space: normal; }
  #add-product-modal .modal-img-placeholder { height: 88px; padding: 12px; }
  #add-product-modal .modal-img-placeholder svg { width: 22px; height: 22px; }
  #add-product-modal .product-preview-card img { height: 160px; }
  #add-product-modal #modal-product-selection-summary:empty { display: none; }
  .mobile-keyboard-open #add-product-modal > .modal-box { padding-bottom: 0; }
  .mobile-keyboard-open #add-product-modal .modal-header { padding-block: 4px; }
  .mobile-keyboard-open #add-product-modal .product-upload-actions { padding-block: 8px; }

  .try-on-modal-body { display: block; flex: 1; min-height: 0; padding: 12px; overflow-y: auto; overscroll-behavior-y: contain; }
  .try-on-selection { flex: 1; min-height: 0; padding: 18px 16px; overscroll-behavior-y: contain; }
  .try-on-selection-list { grid-template-columns: 1fr; gap: 12px; }
  .try-on-selection-card { grid-template-columns: 56px minmax(0, 1fr) auto; gap: 2px 12px; padding: 18px 16px; }
  .try-on-selection-number { grid-row: 1 / 3; font-size: 42px; }
  .try-on-selection-name { grid-column: 2; font-size: 17px; }
  .try-on-selection-status { grid-column: 2; grid-row: 2; }
  .try-on-selection-action { grid-column: 3; grid-row: 1 / 3; margin: 0; padding: 0; border: 0; }
  .try-on-selection-footer { align-items: flex-start; flex-wrap: wrap; }
  .try-on-detail-navigation { padding: 10px 12px 0; }
  .try-on-content { display: flex; flex-direction: column; gap: 12px; }
  .try-on-visual { min-height: 0; touch-action: pan-y pinch-zoom; }
  .try-on-result-image { max-height: 62dvh; max-height: calc(var(--mobile-viewport-height, 100dvh) - 250px); min-height: 120px; object-fit: contain; }
  .try-on-loading { min-height: 220px; padding: 16px; }
  #try-on-error:empty { display: none; }
  .try-on-advice { padding: 0; border: 0; background: transparent; box-shadow: none; }
  .try-on-advice > .section-label, .try-on-advice > h4 { display: none; }
  .mobile-advice-toggle { display: block; min-height: 44px; width: 100%; border: 1px solid var(--color-line); border-radius: 10px; background: var(--color-white); color: var(--color-accent-strong); font: inherit; font-size: 14px; }
  .mobile-advice-toggle[aria-expanded="false"] + .try-on-reason { display: none; }
  .try-on-reason { margin-top: 12px; padding: 0 8px 12px; }
  .try-on-products { order: 1; padding: 12px; box-shadow: none; }
  .try-on-product-list { grid-template-columns: minmax(0, 1fr); }
  .try-on-actions { display: grid; flex-shrink: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 8px 12px 12px; }
  .try-on-actions > button { min-width: 0; min-height: 44px; font-size: 12px; padding: 8px; white-space: normal; }
  #try-on-regenerate { order: 1; }
  #feedback-end { order: 2; }
  .try-on-actions:has(#try-on-regenerate[hidden]) #feedback-end { grid-column: 1 / -1; }
  /* 等待弹窗保留当前阶段、预计进度和退出操作，隐藏解释性段落，减少手机阅读负担。
     子项不压缩，低高度横屏由弹窗滚动承载，进度条与取消按钮始终保留实际高度。 */
  .modal-overlay .recommend-progress-box { width: min(100%, 380px); overflow-y: auto; padding: 24px; border-radius: 22px; }
  .recommend-progress-box > * { flex-shrink: 0; }
  .recommend-progress-close { min-width: 44px; min-height: 44px; top: 12px; right: 12px; }
  .recommend-progress-visual { width: 44px; height: 44px; margin-bottom: 18px; border-radius: 12px; font-size: 18px; white-space: nowrap; }
  .recommend-progress-kicker,
  #recommend-progress-description, .recommend-progress-note { display: none; }
  .recommend-progress-box h3 { margin: 0; font-size: 22px; line-height: 1.4; }
  .recommend-progress-meta { margin-top: 18px; }
  .recommend-progress-stages { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 20px; gap: 12px; }
  .recommend-progress-stages li { padding-top: 9px; font-size: 12px; }
  .recommend-progress-actions { margin-top: 20px; padding-top: 16px; }
  .recommend-progress-actions > button { justify-content: center; text-align: center; }

  /* 消息条限制在屏幕内；弹窗开启时避开反馈操作栏，普通页面避开底部导航。 */
  .toast-overlay { width: calc(100% - 24px); pointer-events: none; visibility: hidden; }
  .toast-overlay.active { bottom: calc(var(--mobile-nav-space) + 16px); visibility: visible; }
  .mobile-modal-open .toast-overlay.active { top: calc(var(--mobile-viewport-top, 0px) + env(safe-area-inset-top, 0px) + 68px); bottom: auto; }
  .toast-box { min-width: 0; width: 100%; padding: 12px 16px; gap: 12px; }
  .toast-icon { flex-shrink: 0; }
  .toast-content { min-width: 0; overflow-wrap: anywhere; }
}

/* 手机横屏和低高度窗口缩减装饰空间，给照片与可滚动内容留下实际高度。 */
@media (max-width: 700px) and (max-height: 540px), (max-width: 960px) and (max-height: 500px) and (pointer: coarse) {
  .modal-header { padding-block: 4px; }
  .try-on-actions { padding-block: 4px; gap: 4px; }
  .try-on-result-image { max-height: max(100px, calc(var(--mobile-viewport-height, 100dvh) - 230px)); min-height: 80px; }
}
