/* Responsive repairs. Loaded after the legacy desktop layout. */
html { scroll-padding-top: calc(var(--topbar-h, 72px) + 16px); }
button, input, select, textarea { touch-action: manipulation; }
.user-chip { font: inherit; cursor: pointer; }
.more-sheet:not(.open) { visibility: hidden; }
.more-sheet.open { visibility: visible; }
.import-file-label { display: block; font-weight: 700; margin-top: 18px; }
.excel-import { min-width: 0; }
.import-batch-list { max-height: 440px; overflow: auto; margin-top: 12px; }
.import-batch-list th[scope="row"] { min-width: 180px; max-width: 320px; overflow-wrap: anywhere; white-space: normal; }
.import-batch-list td { white-space: normal; vertical-align: top; }
.import-batch-list td:nth-child(3) { min-width: 130px; }
.import-batch-list td:last-child { min-width: 180px; overflow-wrap: anywhere; }
.import-batch-list tr[aria-current="step"] { background: var(--surface-2); font-weight: 700; }
.import-actions [hidden] { display: none !important; }
.excel-import input[type="file"] { display: block; max-width: 100%; width: 100%; margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.import-file-info { overflow-wrap: anywhere; font-size: 14px; color: var(--ink-3); margin: 8px 0 16px; }
.import-help { line-height: 1.8; font-size: 14px; color: var(--ink-2); }
.import-help a { color: var(--teal-dark); text-underline-offset: 3px; }
.import-steps { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 12px 0 18px; padding-left: 22px; font-weight: 700; color: var(--teal-dark); font-size: 14px; }
.import-steps li { padding-left: 2px; }
.import-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.import-actions .btn { min-height: 46px; }
.import-feedback { margin-top: 12px; min-width: 0; }
.import-result { line-height: 1.7; overflow-wrap: anywhere; }
.import-result p { margin: 4px 0; }
.import-table-scroll { overflow-x: auto; margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; }
.import-result-table { min-width: 650px; font-size: 14px; table-layout: auto; }
.import-result-table th, .import-result-table td { padding: 10px; }
.import-result-table th[scope="row"] { position: static; text-align: left; }
.import-result-table details { min-width: 180px; }
.import-result-table summary { min-height: 32px; }
.report-box, .report-grid, .report-actions, .head-actions { min-width: 0; }
.report-actions .btn { white-space: normal; overflow-wrap: anywhere; }
.manual-hub p { font-size: 14px; line-height: 1.8; }
.manual-settings-links { display: flex; flex-wrap: wrap; gap: 10px; }
.manual-settings-links .btn { min-height: 44px; }
.import-setup-guide { margin: 16px 0 24px; padding: 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.import-setup-guide h4 { margin: 0 0 10px; font-size: 18px; }
.import-setup-guide p { font-size: 14px; line-height: 1.8; margin: 8px 0 14px; }
.import-setup-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 12px; list-style: none; margin: 16px 0; padding: 0; }
.import-setup-steps li { min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: var(--surface, #fff); }
.import-setup-steps strong { font-size: 16px; }
.import-setup-steps p { margin-bottom: 0; }
.import-setup-steps .btn { margin-top: 14px; }
.import-setup-guide .btn { white-space: normal; overflow-wrap: anywhere; }
.modal, .wizard { max-height: calc(100dvh - 32px); display: flex; flex-direction: column; overflow: hidden; }
.modal-head, .wz-head { flex-shrink: 0; }
.modal-body, .wz-body { min-height: 0; flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; }
.modal-foot, .wz-foot { flex-shrink: 0; }
.wz-progress { min-width: 0; }
.wz-dots { flex-wrap: wrap; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 3px; }
main:focus { outline: none; }

/* Identifiers and short status labels must remain readable at desktop zoom. */
@media (min-width: 1100px) {
  #mf-screen .mf-frame > .mf-row:first-of-type { flex-wrap: wrap; }
  #mf-screen .mf-frame > .mf-row:first-of-type > .mf-w-no { flex: 0 0 210px; width: 210px; min-width: 210px; max-width: 210px; }
  #mf-screen .mf-susp > .mf-w-state { flex: 0 0 220px; width: 220px; min-width: 220px; }
}

/* Fixed columns need a scrollable table between the card and desktop breakpoints. */
@media (min-width: 721px) and (max-width: 1099px) {
  .table-wrap { max-width: 100%; overflow: auto; }
  .rec-table, .pay-table { min-width: 1040px; }
  .cp-table { min-width: 1000px; }
  .report-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Keep the existing desktop form, but reflow all fields on tablets and phones.
   IDs intentionally beat the accumulated desktop width overrides. */
@media (max-width: 1099px) {
  .app-main.mf-wrap { width: 100%; max-width: 100%; margin: 0; padding: 12px !important; }
  #mf-screen { width: 100%; min-width: 0; zoom: 1; margin: 0; padding: 12px; transform: none; }
  #mf-screen .mf-titlebar { flex-wrap: wrap; gap: 10px; }
  #mf-screen .mf-apptitle { font-size: 20px; white-space: normal; width: auto; flex: 1 1 200px; }
  #mf-screen .mf-date { font-size: 13px; }
  #mf-screen .mf-x { flex: none; min-width: 44px; min-height: 44px; margin-left: auto; }
  #mf-screen .mf-minitabs { order: 3; width: 100%; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
  #mf-screen .mf-tab { min-height: 44px; font-size: 14px; padding: 8px 10px; white-space: normal; flex: 1 1 110px; }
  #mf-screen .mf-toprow { flex-wrap: wrap; padding: 12px 0; }
  #mf-screen .mf-searchrow { flex: 1 1 100%; width: 100%; }
  #mf-screen .mf-search-input { min-width: 0; width: 100%; font-size: 16px; }
  #mf-screen .mf-body, #mf-screen .mf-idblock, #mf-screen .mf-lower { flex-direction: column; gap: 14px; }
  #mf-screen .mf-bodymain, #mf-screen .mf-idmain, #mf-screen .mf-addrstack { width: 100%; min-width: 0; }
  #mf-screen .mf-row, #mf-screen .mf-telline { flex-wrap: wrap; gap: 10px; }
  #mf-screen .mf-frame { padding: 16px 10px 10px; min-width: 0; gap: 12px; }
  #mf-screen .mf-frame > .mf-row:first-of-type > .mff,
  #mf-screen .mf-row > .mff,
  #mf-screen .mf-susp > .mff { flex: 1 1 calc(50% - 10px); width: auto !important; min-width: 0; max-width: 100%; overflow: visible; }
  #mf-screen .mf-row-name, #mf-screen .mf-row-tel { flex-direction: column; align-items: stretch; }
  #mf-screen .mf-w-name { width: 100%; flex: 1 1 auto; }
  #mf-screen .mff-l { flex: 0 0 76px; width: 76px; font-size: 14px; white-space: normal; }
  #mf-screen .mff-v { font-size: 16px; min-width: 0; min-height: 40px; max-width: 100%; width: auto; }
  #mf-screen .mf-w-name .mff-v { flex: 1; width: auto; min-width: 0; padding: 8px 12px; }
  #mf-screen .mf-name { font-size: 25px; overflow-wrap: anywhere; white-space: normal; }
  #mf-screen .mf-addrstack .mff-v { white-space: normal; overflow-wrap: anywhere; height: auto; max-height: none; }
  #mf-screen .mf-w-tel, #mf-screen .mf-w-telnote { flex: 1 1 calc(50% - 10px); width: auto !important; min-width: 0; }
  #mf-screen .mf-actionrail { width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #mf-screen .mf-btn { min-height: 44px; font-size: 14px; white-space: normal; padding: 9px 12px; }
  #mf-screen .mf-noteline { align-items: flex-start; gap: 8px; }
  #mf-screen .mf-noteline .mff-l { flex: 0 0 76px; width: 76px; padding-top: 8px; }
  #mf-screen .mf-notebox { font-size: 16px; white-space: normal; overflow-wrap: anywhere; max-height: none; height: auto; min-height: 40px; line-height: 1.6; }
  #mf-screen .mf-monthbar { flex-wrap: wrap; gap: 8px; }
  #mf-screen .mf-bigmonth { padding: 6px 10px; }
  #mf-screen .mf-bigmonth b { font-size: 22px; }
  #mf-screen .mf-mcell { min-height: 48px; padding: 6px 10px; }
  #mf-screen .mf-limit { width: 100%; text-align: left; font-size: 14px; }
  #mf-screen .mf-listrow { white-space: normal; overflow-wrap: anywhere; font-size: 16px; }
  #mf-screen .mf-money { width: 100%; padding: 12px; flex: 0 0 auto; }
  #mf-screen .mf-money > .mf-mrow { grid-template-columns: minmax(0, 1fr) minmax(120px, 1fr); flex: none; gap: 12px; }
  #mf-screen .mf-ml { font-size: 16px; white-space: normal; }
  #mf-screen .mf-mv { font-size: 26px; min-height: 48px; }
  #mf-screen .mf-mrow-bill .mf-mv { font-size: 30px; }
  #mf-screen .mf-mactions { margin-top: 12px !important; grid-template-columns: minmax(0, 1fr) auto auto; }
}

@media (max-width: 720px) {
  .app-main { padding-left: 14px; padding-right: 14px; padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  .app-main.mf-wrap { padding: 8px 8px calc(88px + env(safe-area-inset-bottom)) !important; }
  #mf-screen { padding: 10px; }
  #mf-screen .mf-frame > .mf-row:first-of-type > .mff,
  #mf-screen .mf-row > .mff, #mf-screen .mf-susp > .mff,
  #mf-screen .mf-w-tel, #mf-screen .mf-w-telnote { flex-basis: 100%; }
  .section-head .head-actions { width: 100%; display: flex; flex-wrap: wrap; }
  .head-actions .btn { flex: 1 1 160px; white-space: normal; }
  .report-grid, .report-actions { grid-template-columns: minmax(0, 1fr); }
  .report-box { padding: 16px; }
  .import-steps { flex-direction: column; gap: 6px; }
  .import-actions .btn { width: 100%; }
  .rec-filters .searchbox { flex: 1 1 100%; min-width: 0; width: 100%; }
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { max-width: 100%; font-size: 16px; }
  .modal-overlay, .wizard-overlay { padding: 10px; }
  .modal, .wizard { max-height: calc(100dvh - 20px); width: 100%; }
  .modal-body, .wz-body { padding: 16px; min-height: 0; }
  .modal-foot, .wz-foot { padding: 12px 16px; gap: 8px; }
  .modal-foot .btn, .wz-foot .btn { min-height: 44px; }
  .pk-qbtn, .btn-icon { min-width: 44px; min-height: 44px; }
  .pack-modal .btn-sm { min-height: 44px; }
  .login-card { width: 100%; padding: 22px 18px; }
  .login-screen { min-height: 100dvh; padding: 18px; }
}
/* Persistent save-conflict notice, with a full surface rather than an accent bar. */
.shared-conflict-notice {
  position: fixed; z-index: 20000; bottom: 16px; right: 16px;
  max-width: min(520px, calc(100vw - 32px)); max-height: 45vh; overflow: auto;
  padding: 16px; border: 1px solid #d1d5db; border-radius: 12px;
  background: #fff7e6; color: #422006; box-shadow: 0 4px 20px #0002;
}
.shared-conflict-notice p { margin: 0 0 12px; line-height: 1.6; }
.shared-live-notice {
  position: fixed; z-index: 19999; bottom: 16px; right: 16px;
  max-width: min(520px, calc(100vw - 32px)); max-height: 40vh; overflow: auto;
  padding: 16px; border: 1px solid #d1d5db; border-radius: 12px;
  background: #eef6ff; color: #17324f; box-shadow: 0 4px 20px #0002;
}
.shared-live-notice p { margin: 0 0 12px; line-height: 1.6; }
.data-reset-panel { margin-bottom: 20px; }
.data-reset-panel p { line-height: 1.75; }
.data-reset-panel .report-actions { margin-top: 12px; }
.data-reset-warning { padding: 12px; border-radius: 10px; background: #fff1f2; color: #9f1239; line-height: 1.7; }
.data-reset-host { overflow-wrap: anywhere; }
.data-reset-counts { margin: 16px 0; }
.data-reset-counts > div { display: flex; justify-content: space-between; gap: 16px; padding: 5px 0; }
.data-reset-counts dt { min-width: 0; overflow-wrap: anywhere; }
.data-reset-counts dd { margin: 0; white-space: nowrap; font-variant-numeric: tabular-nums; }
.data-reset-preserved summary { cursor: pointer; padding: 10px 0; font-weight: 700; }
.data-reset-ack { display: flex; gap: 10px; align-items: flex-start; margin: 16px 0; cursor: pointer; line-height: 1.7; }
.data-reset-ack input { flex: 0 0 auto; width: 20px; height: 20px; margin-top: 4px; }
.data-reset-label { display: block; margin-bottom: 8px; font-weight: 700; }
.data-reset-input { width: 100%; min-width: 0; min-height: 44px; padding: 10px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 16px; }
/* Legacy workbook conversion: plain surfaces, no decorative accent bars. */
.legacy-import { overflow-wrap: anywhere; }
.legacy-import [hidden] { display: none !important; }
.legacy-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 16px; margin: 16px 0; }
.legacy-fields label { display: grid; align-content: start; gap: 6px; font-weight: 600; }
.legacy-fields input, .legacy-fields select { width: 100%; min-width: 0; min-height: 44px; box-sizing: border-box; }
.legacy-check { display: flex; align-items: flex-start; gap: 10px; margin: 16px 0; line-height: 1.7; cursor: pointer; }
.legacy-check input { flex: 0 0 auto; width: 20px; height: 20px; margin-top: 4px; }
.legacy-import details { margin: 12px 0; }
.legacy-import summary { cursor: pointer; padding: 8px 0; font-weight: 600; }
.legacy-import li { margin: 6px 0; }
/* Runtime identification uses text, icons and full surfaces, never accent bars. */
.runtime-badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 6px; font-size: 12px; font-weight: 800; line-height: 1.35; white-space: nowrap; }
.runtime-web { background: #e3edff; color: #163f78; }
.runtime-portable { background: #dcf4e7; color: #135c39; }
.runtime-notice { padding: 14px 16px; margin: 0 0 18px; background: #f1f5f9; border-radius: 10px; color: #26374b; }
.runtime-notice p { margin: 7px 0 0; line-height: 1.65; }
.ai-converter [hidden] { display: none !important; }
.ai-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 14px; margin: 16px 0; }
.ai-fields label { display: flex; flex-direction: column; gap: 7px; font-size: 13px; font-weight: 700; min-width: 0; }
.ai-fields input, .ai-fields select { width: 100%; min-width: 0; min-height: 42px; padding: 8px; font: inherit; border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--text); }
.ai-converter .report-actions { margin: 14px 0; flex-wrap: wrap; }
.ai-converter summary { cursor: pointer; padding: 10px 0; font-weight: 700; }
.ai-check { display: flex; gap: 10px; align-items: flex-start; margin: 16px 0; }
.ai-check input { flex-shrink: 0; width: 20px; height: 20px; margin: 2px 0 0; }
.ai-warning { padding: 14px; background: #fff5d9; border-radius: 8px; color: #65460a; }
.ai-table-scroll { overflow: auto; max-height: 440px; }
.ai-table-scroll small { display: block; color: #526174; }
.ai-table-scroll td { white-space: pre-wrap; min-width: 110px; overflow-wrap: anywhere; }
#ai-message:not(:empty) { padding: 12px 0; font-weight: 700; }
#ai-progress { width: 100%; }
.app-topbar .brand { flex-wrap: wrap; max-width: 100%; }
@media (min-width: 900px) and (max-width: 1500px) { .app-topbar .brand .brand-text { display: none; } }
@media (max-width: 600px) {
  .app-topbar .brand { gap: 7px; min-width: 0; flex: 1; }
  .app-topbar .brand .brand-text { display: none; }
  .runtime-badge { font-size: 12px; padding: 6px 8px; }
}

/* PC: use the reclaimed workspace for readable controls, without scaling printouts. */
.report-subheading { margin: 0 0 6px; font-size: 13px; }
@media screen and (min-width: 901px) {
  .app-main { font-size: 16px; line-height: 1.6; }
  .app-main .section-head h2 { font-size: 24px; }
  .app-main .section-head .sub { font-size: 14px; }
  .app-main .btn, .app-main:not(.mf-wrap) .btn, .modal .btn, .wizard .btn {
    min-height: 46px; font-size: 16px; padding: 10px 16px;
    white-space: normal; overflow-wrap: anywhere; justify-content: center;
  }
  .app-main .btn-sm, .app-main:not(.mf-wrap) .btn-sm, .modal .btn-sm, .wizard .btn-sm {
    font-size: 16px !important; padding: 10px 16px !important;
  }
  .app-main .btn-icon { min-width: 40px; min-height: 40px; font-size: 16px; }
  .app-main .form-row > label, .modal-body .form-row > label { font-size: 16px; }
  .app-main :is(.form-row, .rec-filters, .pay-filters, .report-box) :where(input:not([type="checkbox"]):not([type="radio"]), select, textarea),
  .modal-body :where(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
    min-height: 46px; font-size: 16px;
  }
  .app-main :is(.rec-table, .data-table, .prod-table) { font-size: 15px; }
  .app-main .report-box { padding: 20px; }
  .app-main .report-box h3 { font-size: 20px; }
  .app-main .report-box .sm, .app-main .report-reprint-help,
  .app-main .report-total-scope, .app-main .numbering-panel summary { font-size: 16px; }
  .app-main #numbering-summary { font-size: 17px; }
  .app-main .report-subheading { font-size: 18px; }
  .app-main .report-scope-controls {
    display: grid; grid-template-columns: minmax(230px, 1.1fr) repeat(2, minmax(0, .8fr)) minmax(220px, 1.2fr);
    gap: 20px; align-items: start;
  }
  .app-main .report-scope-controls > * { min-width: 0; }
  .app-main .report-scope-controls label { font-size: 18px; }
  .app-main .report-box .report-scope-controls :is(input, select) { width: 100%; min-height: 56px; font-size: 18px; }
  .app-main .report-month-control #rep-month { min-height: 64px; font-size: 28px; }
  .app-main .report-month-shortcuts > .btn { flex: 1; padding-inline: 8px; }
  .app-main .report-output-summary { font-size: 22px; }
  .app-main .report-actions { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
  .app-main > .numbering-panel .numbering-downloads { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .app-main .report-card .rc-num { font-size: 32px; }
  .app-main .report-card .rc-lbl { font-size: 16px; }
}
