/* Shared mobile presentation for staff and customer accounts. Desktop rules remain in workbench.css. */
.mobile-nav-heading, .mobile-nav-search, .mobile-nav-results, .mobile-nav-backdrop { display: none; }
.mobile-filter-toggle { display: none; }
.mobile-table-hint { color: #65789b; font-size: 12px; margin: 8px 0; }
.password-field { position: relative; min-width: 0; }
#login-screen .password-field > input { width: 100%; padding: 12px 68px 12px 14px; }
.password-field > button { position: absolute; inset: 1px 1px 1px auto; padding: 0 12px; border: 0; background: transparent; color: #4263b5; }

@media (max-width: 900px), (max-width: 1100px) and (pointer: coarse) and (max-height: 600px) {
  :root { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { min-width: 0; }
  button, a, summary, input, select, textarea { -webkit-tap-highlight-color: #4263eb20; }
  button, .button-link, summary { touch-action: manipulation; }
  /* 16px fields avoid automatic zoom on iOS; do not disable user pinch zoom. */
  body input:not([type=checkbox]):not([type=radio]):not([type=hidden]),
  body select, body textarea, body .ss-search, body .ss-multi-search {
    font-size: 16px !important;
    min-height: 44px;
    max-width: 100%;
  }
  body button, body .button-link, body .ss-trigger, body .ss-option { min-height: 44px !important; }
  body button, body .button-link { white-space: normal; overflow-wrap: anywhere; }
  input[type=checkbox], input[type=radio] { flex: none; }
  label:has(> input[type=checkbox]), label:has(> input[type=radio]) { min-height: 44px; }
  input[type=date], input[type=datetime-local] { min-width: 0; width: 100%; }
  textarea { width: 100%; }
  fieldset { min-width: 0; }
  .app-shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
  .main-area { width: 100%; flex: 1; min-height: 0; }
  .page-header {
    display: grid;
    grid-template-columns: 44px minmax(0,1fr) auto;
    gap: 8px;
    align-items: center;
    padding: max(4px,env(safe-area-inset-top)) max(10px,env(safe-area-inset-right)) 4px max(10px,env(safe-area-inset-left));
    min-height: 52px;
  }
  .mobile-menu { display: inline-flex; width: 44px; height: 44px; padding: 8px; }
  .page-heading h1 { font-size: 19px; line-height: 1.4; overflow-wrap: anywhere; }
  .page-heading p, .page-header .eyebrow { display: none; }
  .toolbar { max-width: none; gap: 4px; margin: 0; flex-wrap: nowrap; }
  .toolbar #staff-session { max-width: 92px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .toolbar .badge { display: none; }
  .toolbar #refresh { display: inline-flex; padding: 7px 9px; }
  .toolbar #toggle { max-width: 100px; }
  .page-header:has(#toggle:not([hidden])) .toolbar { grid-column: 1/-1; flex-wrap: wrap; justify-content: flex-end; }
  .content-area {
    padding: 8px max(8px,env(safe-area-inset-right)) max(12px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left));
    min-width: 0;
    scrollbar-gutter: auto;
    overscroll-behavior-y: contain;
    scroll-padding-block: 20px;
  }
  .content-area > section, .card, [role=tabpanel], [data-ui-panel] { min-width: 0; max-width: 100%; }
  .content-area .card { padding: 10px; border-radius: 10px; margin-bottom: 10px; }
  .card .card { padding: 8px; }
  .status-bar { display: none; }
  .status-bar #last-refresh { display: none; }
  #notice, #restart-required { margin: 10px 12px 0; }
  .notice { align-items: flex-start; }
  .notice > span, .banner, .error-text, .muted, .section-heading p { overflow-wrap: anywhere; }
  .notice > button { flex: 0 0 44px; }

  /* Full-height navigation, independent of the varying header and device safe areas. */
  #main-navigation {
    display: none;
    position: fixed;
    z-index: 101;
    inset: 0 auto 0 0;
    width: min(360px,calc(100vw - 32px));
    height: 100vh;
    height: 100dvh;
    max-height: none;
    padding: max(12px,env(safe-area-inset-top)) 16px max(20px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));
    border: 0;
    box-shadow: 12px 0 40px #20345c30;
    overscroll-behavior: contain;
    overflow: auto;
  }
  .app-shell.nav-open #main-navigation { display: flex; }
  .mobile-nav-backdrop { display: block; position: fixed; inset: 0; z-index: 100; width: 100%; height: 100%; background: #14244470; border: 0; border-radius: 0; }
  .mobile-nav-backdrop:hover { background: #14244470; }
  .mobile-nav-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; flex: none; }
  .mobile-nav-heading strong { font-size: 19px; color: #263b65; }
  #main-navigation > .brand { margin-bottom: 8px; font-size: 15px; }
  #main-navigation > .brand .app-mark { width: 36px; height: 36px; }
  #main-navigation > .brand small { font-size: 11px; }
  .mobile-nav-search { display: grid; gap: 4px; margin: 0 0 8px; flex: none; }
  .mobile-nav-search input { width: 100%; }
  #main-navigation nav a, #main-navigation .nav-section-links a, #main-navigation .nav-section > summary,
  .mobile-nav-results a { min-height: 44px; padding: 9px 10px; font-size: 14px; }
  #main-navigation .nav-favorites-heading button { min-height: 44px; }
  #main-navigation .nav-section-links { grid-template-columns: minmax(0,1fr); }
  #main-navigation.mobile-nav-searching > nav { display: none; }
  .mobile-nav-results { display: grid; gap: 6px; }
  .mobile-nav-results a { display: flex; gap: 10px; align-items: center; background: #f5f7fe; border-radius: 9px; }
  #main-navigation > .aside-note { display: block; padding-top: 24px; }

  .login-screen { display: block; min-height: 100vh; min-height: 100dvh; background: #fff; }
  .login-story { min-height: 0; padding: max(16px,env(safe-area-inset-top)) 20px 16px; }
  .login-story .brand { margin: 0; font-size: 20px; }
  .login-story .brand small { font-size: 12px; }
  .login-story .brand .app-mark { width: 48px; height: 48px; }
  .login-story-copy, .login-story > small { display: none; }
  .login-entry { width: 100%; max-width: 520px; margin-inline: auto; padding: 16px max(20px,env(safe-area-inset-right)) max(20px,env(safe-area-inset-bottom)) max(20px,env(safe-area-inset-left)); }
  .login-card { padding: 0; border: 0; }
  #staff-login, #user-register { gap: 12px; }
  #login-screen .login-card label { margin: 0; gap: 4px; }
  #login-screen .login-card .story-kicker { margin: 0; }
  #login-screen .login-card > p { margin: 0; }
  #login-screen .error-text:empty { display: none; }
  #staff-login h1, #user-register h1 { font-size: 26px; }
  #login-screen .login-card h1 { margin: 0; }
  #staff-login .primary, #user-register .primary { min-height: 48px; font-size: 16px; }
  .auth-switch { margin-bottom: 16px; }
  .installer-entry { margin-top: 20px; padding-top: 8px; }
  .installer-entry summary { display: flex; align-items: center; min-height: 44px; }
  .registration-puzzle { padding: 10px; }
  .registration-puzzle input[type=range] { touch-action: pan-y; }

  .welcome-panel { padding: 14px; gap: 8px; margin-bottom: 10px; }
  .welcome-panel h2 { font-size: 18px; line-height: 1.45; margin-bottom: 4px; }
  .welcome-label { margin-bottom: 4px; }
  .welcome-note { display: none; }
  .welcome-actions { gap: 6px; margin-top: 10px; }
  .welcome-actions > * { flex: 1; }
  .metrics, .billing-metrics, .desk-bi-metrics { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 6px; margin-bottom: 10px; }
  .stat, .billing-metrics > div, .desk-bi-metrics > div { padding: 10px; }
  .stat .number { font-size: 24px; line-height: 1.3; overflow-wrap: anywhere; }
  .metrics > .stat { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 4px 8px; align-items: center; }
  .metrics > .stat > .number { grid-column: 2; grid-row: 1; margin: 0; }
  .metrics > .stat > a { grid-column: 1/-1; display: flex; align-items: center; min-height: 44px; }
  .desk-grid, .customer-cards { grid-template-columns: minmax(0,1fr); gap: 10px; }
  .section-heading { align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
  .section-heading p { margin-top: 2px; line-height: 1.5; }
  .section-heading > div { min-width: 0; max-width: 100%; }
  .section-heading > .manage-actions { width: auto; margin: 0; }
  .manage-actions, .customer-row-actions, .dialog-actions, .form-actions, .opening-footer { flex-wrap: wrap; gap: 6px; max-width: 100%; }
  .customer-row-actions { justify-content: flex-start; }
  .page-tabs, .pricing-tabs { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; flex-wrap: nowrap; }
  .page-tabs > button, .pricing-tabs > button { white-space: nowrap; min-height: 44px; }
  .page-tabs, .pricing-tabs { margin-bottom: 10px; padding-bottom: 6px; }
  .form-grid, .opening-grid, .list-filters, .menu-matrix, #biz-fields,
  .staff-chat-filters, .wechat-picker-filters, #balance-query, #balance-baseline, #upstream-alert,
  .customer-chat-dialog #customer-chat > .form-grid { grid-template-columns: minmax(0,1fr); gap: 10px; }
  .form-grid > label, .opening-grid > label, #biz-fields > label, dialog label { margin-bottom: 0; gap: 4px; }
  .list-filters { margin-bottom: 10px; }
  .customer-filters, .billing-filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: end; margin-block: 0 10px; }
  body .customer-filters > label, body .customer-filters > .customer-keyword,
  body .billing-filters > label { width: auto; flex: 1 1 calc(50% - 6px); max-width: none; min-width: 0; margin: 0; gap: 3px; }
  .customer-filters > .customer-keyword { flex-basis: 100% !important; }
  .customer-filters > button, .billing-filters > button { width: auto; flex: 1 1 44px; height: auto; padding-inline: 10px; }
  .customer-filter-actions { flex: 1 1 100%; }
  .customer-filter-actions > button { flex: 1; }
  .customer-filters.mobile-simple-filters { display: grid; grid-template-columns: minmax(0,1fr) repeat(var(--mobile-filter-actions),44px); gap: 4px; }
  body .customer-filters.mobile-simple-filters > .customer-keyword { display: block; font-size: 0; line-height: 0; }
  .customer-filters.mobile-simple-filters > button { padding-inline: 2px; white-space: nowrap; }
  .customer-filters.mobile-simple-filters input { padding-inline: 8px; }
  .customer-filters.mobile-filterable { gap: 4px; }
  body .customer-filters.mobile-filterable > .customer-keyword { display: block; flex: 1 1 100px !important; font-size: 0; line-height: 0; }
  .customer-filters.mobile-filterable > button { flex: 0 0 auto; padding-inline: 8px; }
  .customer-filters .mobile-filter-toggle { display: inline-flex; gap: 2px; }
  .mobile-filter-toggle::after { content: '⌄'; }
  .mobile-filter-toggle[aria-expanded=true]::after { content: '⌃'; }
  .customer-filters.mobile-filterable > .mobile-filter-field { display: none; order: 2; }
  .customer-filters.mobile-filters-open > .mobile-filter-field { display: flex; flex: 1 1 calc(50% - 4px); margin-top: 4px; }
  .customer-filters input, .customer-filters select, .billing-filters input, .billing-filters select { width: 100%; }
  .customer-advanced > div { left: 0; right: auto; max-width: calc(100vw - 64px); }
  .customer-advanced summary { min-height: 44px; }
  .customer-list-meta, .customer-inline-form, .customer-chat-filters { flex-wrap: wrap; }
  .customer-inline-form { flex-direction: column; align-items: stretch; }
  .customer-inline-form label { min-width: 0 !important; }
  .customer-summary, dl { grid-template-columns: minmax(70px,auto) minmax(0,1fr); gap: 6px 10px; }
  .table-pagination, .customer-management .table-pagination { flex-wrap: wrap; justify-content: flex-end; margin: 6px 0; gap: 4px; }
  .table-pagination > span, .self-service-pagination > span { flex: 1; width: auto; }
  .table-pagination button, .self-service-pagination button { padding-inline: 8px; }
  .self-service-pagination { align-items: center; margin-block: 6px 0; }
  .customer-list-meta, .list-count { margin-block: 6px; }
  .content-area .error-text:empty, dialog .error-text:empty { display: none; }
  #pricing-forms > .page-tabs { padding-right: 0; }
  .pricing-tools { position: static; margin: 0 0 12px; }
  .billing-chart { height: 260px; }
  .entity-picker-head { flex-wrap: wrap; }
  .entity-picker-head > input { flex: 1 1 120px; }
  .entity-options { top: 100%; max-height: 240px; overscroll-behavior: contain; }
  .entity-option { flex-wrap: wrap; }
  .entity-option > [data-choose] { flex-basis: 100%; }
  .entity-option-actions { margin-left: auto; }
  .entity-chips > span { max-width: 100%; overflow-wrap: anywhere; }
  .entity-chips button { flex: none; min-width: 44px; }
  .ss-trigger { font-size: 16px; }
  .ss-options { touch-action: pan-y; }
  .ss-option { display: flex; align-items: center; }

  /* Bottom sheets use the visual viewport, so keyboard and browser chrome cannot cover actions. */
  body dialog, body dialog[class], body #manage-dialog:has(#manage-fields.manage-fields-tabs) {
    position: fixed;
    inset: auto 0 max(0px,calc(100dvh - var(--mobile-viewport-height,100dvh) - var(--mobile-viewport-top,0px))) 0;
    margin: 0 auto;
    width: 100%;
    max-width: 680px;
    max-height: min(94dvh,calc(var(--mobile-viewport-height,100dvh) - 12px));
    padding: 12px max(12px,env(safe-area-inset-right)) max(12px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left));
    border-radius: 14px 14px 0 0;
    overflow: auto;
    overscroll-behavior: contain;
    scroll-padding-block: 20px 90px;
  }
  dialog .section-heading { gap: 8px; margin-bottom: 10px; }
  dialog .section-heading h2 { font-size: 18px; }
  dialog .section-heading > button { flex: none; margin-left: auto; }
  dialog form, dialog label, dialog .form-grid > * { min-width: 0; }
  dialog .dialog-actions, dialog .opening-footer, #manage-dialog .manage-actions, .directory-editor-footer {
    position: sticky;
    bottom: -12px;
    z-index: 3;
    background: #fff;
    padding: 8px 0 max(8px,env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    margin: 10px 0 0;
  }
  dialog .dialog-actions > button, dialog .manage-actions > button { flex: 1; }
  .opening-footer button { width: 100%; }
  .permission-editor-dialog { height: min(94dvh,calc(var(--mobile-viewport-height,100dvh) - 12px)); }
  .permission-layout { grid-template-columns: minmax(0,1fr); grid-template-rows: auto minmax(0,1fr); }
  .permission-sections { flex-direction: row; overflow: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; }
  .permission-sections button { width: auto; flex: none; height: auto; }
  .permission-grid-head { display: none; }
  .permission-row { grid-template-columns: minmax(0,1fr); gap: 8px; padding: 12px; }
  .permission-operations { grid-column: 1/-1; }
  .permission-toolbar { flex-wrap: wrap; }
  .permission-toolbar > label { min-width: 0; flex: 1 1 120px; }
  .permission-toggle, .permission-menu-select { min-height: 44px; }
  .permission-choices { grid-template-columns: minmax(0,1fr); }
  .staff-chat-dialog[open] { overflow: hidden; }
  .staff-message-header { flex-wrap: wrap; }
  .staff-message-source { flex-basis: 100%; }
  .favorites-editor { grid-template-columns: minmax(0,1fr); }
  .favorites-current, .favorites-available { max-height: 28dvh; min-height: 100px; }
  .favorites-row { flex-wrap: wrap; }
  .favorites-row strong { flex-basis: calc(100% - 64px); }
  .favorites-row button { flex: 1; }

  /* Card layout keeps the original cells, buttons and row order intact. */
  .table-wrap { min-width: 0; max-width: 100%; overscroll-behavior-x: contain; }
  body table.mobile-cards, body #customer-keys-card table.mobile-cards { display: block; width: 100%; min-width: 0; border: 0; }
  table.mobile-cards > thead { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); }
  table.mobile-cards > tbody { display: grid; grid-template-columns: minmax(0,1fr); gap: 6px; }
  table.mobile-cards > tbody > tr { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); grid-auto-flow: row dense; gap: 4px 8px; align-items: start; padding: 8px 10px; border: 1px solid #dfe6f2; border-radius: 8px; background: #fff; }
  body table.mobile-cards > tbody > tr > td {
    display: block; position: static; grid-column: span 2; min-width: 0; max-width: none; width: auto; padding: 2px 0;
    border: 0; box-shadow: none; background: transparent; font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; white-space: normal;
  }
  body #customer-keys-card table.mobile-cards > tbody > tr > td { position: static; min-width: 0; max-width: none; padding: 2px 0; box-shadow: none; background: transparent; }
  table.mobile-cards > tbody > tr > td::before { content: attr(data-mobile-label); display: inline; font-size: 12px; font-weight: 400; color: #74829a; margin-right: 6px; }
  body table.mobile-cards > tbody > tr > [data-mobile-kind=primary] { grid-column: 1/-1; font-size: 14px; font-weight: 600; }
  body table.mobile-cards > tbody > .mobile-has-status > [data-mobile-kind=primary] { grid-column: 1/4; }
  body table.mobile-cards > tbody > tr > [data-mobile-kind=status] { grid-column: 4; grid-row: 1; justify-self: end; padding: 2px 7px; border-radius: 5px; background: #f0f4fc; color: #526790; font-size: 12px; text-align: center; }
  table.mobile-cards > tbody > tr > [data-mobile-kind=primary]::before,
  table.mobile-cards > tbody > tr > [data-mobile-kind=status]::before,
  table.mobile-cards > tbody > tr > [data-mobile-kind=actions]::before { display: none; }
  body table.mobile-cards > tbody > tr > [data-mobile-kind=actions] { grid-column: 1/-1; padding: 4px 0 0; border-top: 1px solid #edf0f6; }
  table.mobile-cards > tbody > tr > [data-mobile-kind=status]:has(.badge) { background: transparent; padding: 0; }
  body table.mobile-brief-cards > tbody > .mobile-has-status > [data-mobile-kind=actions] { grid-column: 3/-1; padding: 0; border: 0; text-align: right; }
  table.mobile-brief-cards > tbody > tr > [data-mobile-kind=field] { align-self: center; }
  body table.mobile-cards > tbody > tr > .mobile-wide-cell { grid-column: 1/-1; display: flex; flex-wrap: wrap; align-items: center; gap: 3px 6px; }
  table.mobile-cards > tbody > tr > .mobile-wide-cell::before { margin: 0; }
  table.mobile-cards > tbody > tr > .mobile-wide-cell > small { flex-basis: 100%; max-width: none; margin-top: 0; }
  table.mobile-cards .mobile-wide-cell .staff-chat-links { flex-basis: 100%; margin: 0; gap: 4px; }
  table.mobile-cards .mobile-wide-cell button { margin: 0; }
  table.mobile-cards > tbody > tr > [data-mobile-kind=actions] button { margin: 0 4px 0 0; padding: 4px 10px; }
  table.mobile-cards > tbody > tr > [data-mobile-kind=actions] button:last-child { margin-right: 0; }
  table.mobile-cards .customer-row-actions { max-width: none; flex-wrap: wrap; }
  table.mobile-cards td small, table.mobile-cards td code { max-width: 100%; overflow-wrap: anywhere; }
  table.mobile-cards > tbody > .mobile-spanning-row > td::before { display: none; }
  body table.mobile-cards > tbody > .mobile-spanning-row > td { grid-column: 1/-1; border: 0; padding: 6px 0; }
  body table.mobile-cards > tbody > .mobile-empty-row > td { padding: 14px 0; text-align: center; }
}

@media (max-width: 380px) {
  .page-header { gap: 6px; padding-inline: 10px; }
  .page-heading h1 { font-size: 17px; }
  .toolbar #staff-session { max-width: 68px; }
  .toolbar #refresh { padding-inline: 7px; }
  .content-area .card { padding: 10px; }
  .metrics .stat { padding: 10px; }
  .welcome-actions { flex-direction: column; }
  .billing-filters > label { flex-basis: 100%; }
}

@media (max-width: 900px) and (max-height: 500px), (max-width: 1100px) and (pointer: coarse) and (max-height: 500px) {
  body dialog { border-radius: 0; max-width: none; max-height: calc(var(--mobile-viewport-height,100dvh) - 4px); }
  .page-header { min-height: 52px; padding-block: 4px; }
  .status-bar { display: none; }
}
