/* Step 7: screen-only overrides. Desktop and printed documents retain their cascade. */
@media screen and (max-width: 900px) {
  html { scroll-padding-block: 12px; }
  body:has(.top-row) { height: auto; min-height: 100dvh; display: flex; flex-direction: column; }
  .brand-row { height: auto; min-height: 76px; display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
  .brand-left { position: static; width: 56px; height: 56px; flex: none; }
  .doctor-logo { max-width: 56px; max-height: 56px; }
  .brand-name { position: static; transform: none; font-size: clamp(24px, 5vw, 36px); line-height: 1.2; white-space: normal; }
  .top-row { height: auto; flex-wrap: wrap; gap: 4px; padding: 6px 12px; }
  .top-row .menu { width: auto; height: auto; margin: 0 auto 0 0; padding: 10px 16px; }
  .top-row .account { order: 1; width: 100%; max-width: none; margin: 0; padding: 10px 0; text-align: left; }
  .account span { white-space: normal; overflow-wrap: anywhere; overflow: visible; }
  .top-row .bell, .top-row .language-switch { min-width: 44px; }
  aside { position: static; width: 100%; max-height: none; border-right: 0; border-bottom: 1px solid #e8e8e8; }
  .side-title, .side-sub { padding: 14px 20px; }
  main, body.sidebar-hidden main, .business-page main {
    position: static; width: 100%; min-width: 0; overflow: visible; padding: 12px; order: 1;
  }
  .app-version { position: static; order: 2; margin: 12px; padding-bottom: env(safe-area-inset-bottom, 0px); background: transparent; }
  main h1 { margin: 12px 0 20px; font-size: 26px; overflow-wrap: anywhere; }
  h2 { height: auto; min-height: 54px; padding: 13px 16px; line-height: 1.3; overflow-wrap: anywhere; }
  .panel { min-width: 0; overflow: visible; }
  #customer-main > .panel { margin-right: 0; }
  .toolbar, .bottom-toolbar, .toolbar-right, .detail-actions, .result-tools, .result-footer,
  .export-buttons, .pager, .search-actions, .dialog-actions, .receipt-email-buttons {
    height: auto; flex-wrap: wrap; gap: 8px;
  }
  .toolbar, .detail-actions { padding: 12px; }
  .customer-issue-fields, .general-grid, .totals-grid, .search-grid, .detail-fields {
    min-width: 0; padding: 20px 12px; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .general-grid > *, .totals-grid > *, .detail-fields > * { grid-column: auto !important; }
  .general-grid .span6, .general-grid .checks, .totals-grid .payable { grid-column: 1 / -1 !important; }
  .customer-issue-actions { padding: 0 12px 20px; }
  .checks, .checks label { flex-wrap: wrap; white-space: normal; }
  .totals-grid .payable { flex-wrap: wrap; }
  .totals-grid .payable input { max-width: 100%; }
  input:not([type=checkbox]):not([type=radio]), select, textarea {
    min-width: 0; max-width: 100%; font-size: 16px !important; line-height: 1.4;
  }
  input:not([type=checkbox]):not([type=radio]), select { min-height: 44px; }
  button, .alternative, .remember, .business-check, .business-terms { min-height: 44px; touch-action: manipulation; }
  button { white-space: normal; }
  .row-expand { width: 44px; height: 44px; line-height: 44px; }
  .history-suggestions .history-remove { flex-basis: 44px; }
  .table-scroll { min-width: 0; max-width: 100%; margin: 16px 12px; overflow: auto; overscroll-behavior-x: contain; }
  .table-scroll > table { min-width: 720px; }
  .results-panel .table-scroll > table { min-width: 900px; }
  .stats-table-wrap { overflow: auto; }
  .stats-table-wrap > table { min-width: 560px; }
  .result-tools, .result-footer { padding: 12px; }
  .result-actions button { min-width: 44px; }
  .period-buttons { width: auto; margin: 0 0 20px; flex-wrap: wrap; border-radius: 12px; }
  .stats-heading { display: block; }
  .metric-grid, .chart-grid, .important-grid { grid-template-columns: minmax(0, 1fr); }
  .stats-section { min-width: 0; }
  .stats-chart.expanded, .important-grid .stats-section.expanded { inset: 12px; }
  .detail-identifiers { padding: 12px; }
  #detail-totals .detail-payable { flex-wrap: wrap; justify-content: flex-start; }
  .business-toolbar { min-height: 0; padding: 0 0 12px; }
  .business-form { padding: 16px 12px; }
  .business-file-row { height: auto; flex-wrap: wrap; }
  .business-file-row span { min-width: 0; overflow-wrap: anywhere; }
  .business-terms { flex-wrap: wrap; }
  dialog, dialog.line-dialog, dialog.classification-dialog, dialog.receipt-email, dialog.receipt-success, #detail-row-dialog {
    box-sizing: border-box; position: fixed; top: calc(var(--dr-mobile-top, 0px) + 12px);
    bottom: auto; left: 12px; right: 12px; margin: 0 auto;
    width: calc(100% - 24px); max-width: 760px; height: auto;
    max-height: calc(var(--dr-mobile-height, 100dvh) - 24px); overflow: auto;
    overscroll-behavior: contain; scroll-padding-block: 12px;
  }
  dialog.compact-dialog, dialog.confirm-delete, dialog.required-actions-dialog, dialog.preview-errors, dialog.receipt-email { max-width: 410px; }
  dialog.receipt-success { width: min(400px, calc(100vw - 24px)); transform: none; }
  dialog h3, .line-dialog h3 { height: auto; padding: 18px 52px 18px 16px; line-height: 1.35; overflow-wrap: anywhere; }
  .line-dialog .dialog-close { top: 6px; right: 8px; min-width: 44px; }
  .line-dialog #dialog-content, .line-dialog .line-dialog-content { height: auto; max-height: none; overflow: visible; }
  .line-dialog-grid { padding: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .line-dialog-grid > label, .line-dialog-grid .line-quarter, .line-dialog-grid .vat-start, .line-dialog-grid .rec-start { grid-column: auto; margin-bottom: 0; }
  .line-dialog-grid .line-full, .line-dialog-grid .line-half { grid-column: 1 / -1; }
  .line-totals-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .line-totals-row > label, .line-totals-row > label:nth-child(1), .line-totals-row > label:nth-child(3) { grid-column: auto; }
  .discount-input-group { height: auto; min-height: 44px; }
  .discount-input-group button { flex-basis: 44px; }
  .line-dialog .classification-editor { margin: 16px 0 0; overflow: auto; }
  .classification-editor .classification-row, .classification-editor .classification-list { min-width: 620px; }
  .classification-editor .classification-list .classification-row { min-width: 0; }
  .issued-classification-table { min-width: 620px; }
  .classification-form label:last-child { width: 100%; }
  .dialog-actions { padding: 12px; }
  .line-dialog .dialog-actions button, .classification-dialog .dialog-actions button { height: auto; min-height: 44px; }
  #detail-row-fields { max-height: none; padding: 16px; }
  .preview-details { grid-template-columns: minmax(0, 1fr); }
  .preview-details dd { margin: 0 0 12px; overflow-wrap: anywhere; }
  .preview-table { table-layout: fixed; white-space: normal; }
  .preview-table th, .preview-table td { padding: 6px 2px; overflow-wrap: anywhere; }
  .receipt-email:has(.history-suggestions:not([hidden])) { overflow: auto; }
  .receipt-email .history-suggestions { position: static; max-height: 180px; overflow-y: auto; }
  .receipt-email input { min-height: 44px; }
  .top-business-fields { grid-template-columns: minmax(0, 1fr); }
  .top-popover { top: calc(var(--dr-mobile-top, 0px) + 12px) !important; left: 12px !important; right: 12px;
    max-height: calc(var(--dr-mobile-height, 100dvh) - 24px); overflow-y: auto; }
  .delivery-reverse-row, .delivery-route-row, .delivery-address-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calendar-days button { min-height: 44px; }
  .search-calendar { top: calc(var(--dr-mobile-top, 0px) + 12px) !important; left: 12px !important;
    max-height: calc(var(--dr-mobile-height, 100dvh) - 24px); overflow-y: auto; }
  body[data-login-mode] { min-height: 100dvh; padding: 44px 12px 20px; }
  body[data-login-mode] .card { width: 570px; max-width: 100%; }
  body[data-login-mode] .login-html { padding: 32px 16px; }
  body[data-login-mode] form { width: 360px; max-width: 100%; }
  body[data-login-mode] input:not([type=checkbox]) { padding-inline: 8px; }
  body[data-login-mode] .mobile-field-label { display: block; margin: 0 0 8px; color: white; font: 600 14px/20px Arial, sans-serif; }
  body[data-login-mode]:has(.mobile-field-label) #doctorReceiptsPassword::placeholder { color: transparent; }
  body[data-login-mode] .alternative { height: auto; min-height: 54px; }
  body[data-login-mode] .language { top: 10px; right: 16px; min-width: 44px; }
  #error { overflow-wrap: anywhere; }
  body:has(#document) { min-height: 100dvh; height: 100dvh; }
  body:has(#document) nav { flex-wrap: wrap; gap: 8px; }
  body:has(#document) nav strong, body:has(#document) nav #status { flex: 1 1 100%; overflow-wrap: anywhere; }
  body:has(#document) nav button { min-height: 44px; }
  body:has(#document) iframe { min-height: 160px; }
}

@media screen and (max-width: 600px) {
  .customer-issue-fields, .general-grid, .totals-grid, .search-grid, .detail-fields,
  .dialog-grid, .line-dialog-grid, .line-totals-row, #detail-row-fields,
  .delivery-reverse-row, .delivery-route-row, .delivery-address-row, .detail-identifiers { grid-template-columns: minmax(0, 1fr); }
  .general-grid > *, .totals-grid > *, .detail-fields > * { grid-column: 1 / -1 !important; }
  .line-dialog-grid > label, .line-dialog-grid .line-quarter, .line-dialog-grid .vat-start, .line-dialog-grid .rec-start,
  .line-totals-row > label, .line-totals-row > label:nth-child(1), .line-totals-row > label:nth-child(3) { grid-column: 1 / -1; }
  .announcement-header { height: auto; flex-wrap: wrap; }
  .announcement-footer { flex-wrap: wrap; }
}
