/* Shared mobile layout rules. Kept after module styles so every screen uses the same small-screen behavior. */
.purchase-scan-controls { display:flex; align-items:center; flex-wrap:wrap; gap:12px; }
.purchase-scan-controls input[type="file"] { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; clip-path:inset(50%); border:0; }
.purchase-scan-controls input[type="file"]:focus-visible + button { outline:3px solid var(--focus); outline-offset:2px; }
.purchase-scan-error { color:var(--danger); }
.purchase-page-actions { display:flex; align-items:center; gap:14px; flex-shrink:0; }
.purchase-camera input[type="file"] { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0,0,0,0); clip-path:inset(50%); }
.purchase-camera-button { display:grid; width:46px; height:46px; place-items:center; border:1px solid var(--line); border-radius:10px; background:var(--surface); color:var(--ink); cursor:pointer; }
.purchase-camera-button:hover { background:var(--surface-soft); }
.purchase-camera-button svg { width:23px; height:23px; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
.purchase-camera-button[aria-disabled="true"] { opacity:.6; pointer-events:none; }
.purchase-camera .sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); clip-path:inset(50%); white-space:nowrap; border:0; }
@media (max-width: 720px) {
  html { -webkit-text-size-adjust: 100%; }
  body { min-width: 320px; overflow-x: hidden; font-size: 15px; }
  .workspace { display: block; min-height: 100svh; }
  .workspace-main { width: 100%; min-width: 0; margin: 0 !important; }
  .workspace-content { width: 100%; max-width: none; margin: 0; padding: 22px 16px 36px; }
  .workspace-content > h1, .page-heading h1, .crm-heading h1 { font-size: clamp(25px, 7vw, 31px); line-height: 1.2; overflow-wrap: anywhere; }
  .workspace-header { min-height: 60px; height: auto; padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  .header-navigation { gap: 9px; }
  .sidebar-toggle { width: 44px; height: 44px; }
  .workspace-header > .header-organization { order: 3; flex: 1 0 100%; min-width: 0; margin: 0; }
  .header-organization label { display: none; }
  .header-organization > div, .header-organization select { width: 100%; max-width: none; min-width: 0; }
  .profile-dropdown { margin-left: auto; }
  .profile-dropdown > summary { max-width: min(48vw, 190px); min-height: 44px; }
  .workspace-content > :is(.form-section, .dashboard-panel, .module-card, .invoice-paper) { min-width: 0; }
  .page-heading { align-items: stretch; gap: 8px; }
  .page-heading > .primary-button { width: 100%; min-height: 46px; margin: 0 0 16px; justify-content: center; }
  .purchase-page-actions { width:100%; align-items:center; justify-content:flex-end; gap:14px; }
  .purchase-page-actions > a { min-height:44px; justify-content:center; }
  .section-heading { align-items: flex-start; gap: 10px; flex-wrap: wrap; }
  .mobile-module-nav { flex-wrap: nowrap; gap: 18px; overflow-x: auto; overscroll-behavior-x: contain; white-space: nowrap; padding: 12px 16px; scrollbar-width: thin; }
  .mobile-module-nav a { min-height: 36px; display: inline-flex; align-items: center; flex: 0 0 auto; }

  .form-section { min-width: 0; padding: 18px 14px; margin-bottom: 14px; border-radius: 9px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); gap: 15px; }
  .form-grid > *, .record-form, .registry-form-layout, .record-details, .table-scroll { min-width: 0; }
  .record-form input:not([type=hidden]), .record-form select, .record-form textarea,
  .registry-filters input, .registry-filters select, .header-organization select,
  .crm-activity-composer input, .crm-activity-composer select, .crm-activity-composer textarea,
  .crm-form input, .crm-form select, .crm-form textarea {
    min-height: 44px; font-size: 16px; scroll-margin-block: 80px;
  }
  .record-form textarea, .crm-activity-composer textarea, .crm-form textarea { min-height: 90px; }
  .form-actions { align-items: stretch; flex-wrap: wrap; gap: 10px; }
  .purchase-scan-controls > * { flex:1 1 100%; width:100%; justify-content:center; text-align:center; }
  .form-actions > * { max-width: 100%; }
  .form-actions .primary-button, .record-form > .form-actions .primary-button { min-height: 46px; }
  .alert, .success-alert { padding: 12px 14px; margin: 14px 0; overflow-wrap: anywhere; }

  .registry-filters { align-items: stretch; gap: 12px; padding: 14px; margin-bottom: 18px; }
  .registry-filters > div, .registry-filters .search-field { flex: 1 1 100%; min-width: 0; }
  .registry-filters .primary-button { width: 100%; min-height: 44px; justify-content: center; }
  .table-scroll { max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; }
  .registry-table { min-width: 620px; }
  .registry-table th, .registry-table td { padding: 12px 10px; }
  .pagination { align-items: center; gap: 14px; flex-wrap: wrap; }
  .pagination a { min-height: 44px; display: inline-flex; align-items: center; }
  .record-details dl { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .record-details dd { margin: 0 0 10px; overflow-wrap: anywhere; }

  .invoice-tools, .invoice-tools nav { display: flex; flex-wrap: nowrap; gap: 18px; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  .invoice-tools a { min-height: 42px; display: inline-flex; align-items: center; flex: 0 0 auto; }
  .invoice-form .invoice-row { position: relative; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: auto; gap: 12px 10px; padding: 42px 12px 14px; margin: 14px 0; }
  .invoice-form .invoice-row > .row-description { grid-column: 1 / -1; grid-row: auto; }
  .invoice-form .invoice-row > div:nth-child(2), .invoice-form .invoice-row > div:nth-child(3),
  .invoice-form .invoice-row > div:nth-child(n+4) { grid-column: auto; grid-row: auto; align-self: end; }
  .invoice-form .invoice-row > div:nth-child(10) { grid-column: 1 / -1; }
  .invoice-form .invoice-row > .remove-row { position: absolute !important; top: 8px; right: 10px; grid-column: auto !important; grid-row: auto !important; width: 36px; height: 36px; }
  .invoice-form .invoice-row label { font-size: 12px; }
  .invoice-form .invoice-row input:not([type=hidden]), .invoice-form .invoice-row select { min-height: 44px; height: 44px; padding: 8px 9px; font-size: 16px; }
  .invoice-form .unit-picker { width: 100%; max-width: 100%; }
  .invoice-summary { width: 100%; max-width: none; margin: 22px 0; }
  .invoice-summary p { gap: 10px; font-size: 15px; }
  .invoice-paper { padding: 18px 14px; margin: 14px 0; border-radius: 10px; }
  .invoice-paper .page-heading { align-items: flex-start; flex-wrap: wrap; gap: 8px; }
  .invoice-paper .record-details { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .invoice-lines { min-width: 620px; }
  .invoice-paper .table-scroll { overflow-x: auto; }
  .invoice-paper .table-scroll, .extended-paper { overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; }

  .dashboard-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .dashboard-aside { display: flex; flex-direction: column; gap: 12px; }
  .calendar, .dashboard-events, .dashboard-counter { grid-column: auto; grid-row: auto; }
  .dashboard-panel { padding: 16px; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .quick-tile { min-width: 0; min-height: 126px; padding: 14px 11px; overflow-wrap: anywhere; }
  .dashboard-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .dashboard-stats > a { min-width: 0; padding: 14px 11px; overflow-wrap: anywhere; }
  .dashboard-stats strong { font-size: clamp(19px, 6vw, 25px); }
  .billing-months > a { grid-template-columns: 48px minmax(0, 1fr) auto; gap: 8px; }

  .crm-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 16px 0 22px; }
  .crm-metrics article { min-width: 0; padding: 13px 11px; overflow-wrap: anywhere; }
  .crm-metrics strong { font-size: clamp(20px, 6vw, 27px); }
  .crm-columns { display: grid; grid-auto-columns: minmax(80vw, 1fr); grid-auto-flow: column; grid-template-columns: none; gap: 10px; overflow-x: auto; padding: 0 0 10px; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
  .crm-column { min-width: 0; scroll-snap-align: start; }
  .crm-customer-search { padding: 14px; }
  .crm-customer-search > form { flex-wrap: wrap; }
  .crm-customer-search > form input:not([type=hidden]) { flex: 1 1 100%; min-width: 0; min-height: 44px; font-size: 16px; }
  .crm-customer-search > form .primary-button { flex: 1; justify-content: center; min-height: 44px; }
  .crm-search-results article { align-items: flex-start; flex-direction: column; gap: 6px; }
  .crm-result-action { display: inline-flex; align-items: center; min-height: 40px; }

  .intra-payment-list, .intra-payment-list .table-scroll { max-width: 100%; overflow-x: auto; }
  .intra-payment-list .registry-table { min-width: 850px; }
  .intra-payment-entry-panel { padding: 12px; }
  .intra-payment-entry-panel .form-grid, .intra-payment-entry-panel .form-grid[data-entry-kind="credit"] { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .intra-payment-entry-panel .form-grid .full-width, .intra-payment-save { grid-column: auto; }
  .intra-payment-save .primary-button { width: 100%; min-height: 44px; }

  .auth-layout { display: block; min-height: 100svh; }
  .story-panel { min-height: 0; padding: 18px 20px; }
  .story-copy, .story-footer { display: none; }
  .form-panel { min-height: calc(100svh - 72px); padding: 20px; }
  .form-content { max-width: 460px; margin: 28px auto; }
  .form-content h2 { font-size: clamp(27px, 8vw, 34px); }
  .auth-form input, .setup-box input { min-height: 48px; font-size: 16px; }
  .primary-button { min-height: 46px; }
}

@media (max-width: 720px) {
  .workspace.sidebar-collapsed .sidebar { display: none; }
  .workspace:not(.sidebar-collapsed) .sidebar { display: flex; position: fixed; inset: 0 auto 0 0; width: min(280px, 84vw); height: 100svh; padding: 20px 14px; overflow-y: auto; box-shadow: 12px 0 36px #0f172a55; z-index: 100; }
  .workspace:not(.sidebar-collapsed) .sidebar .brand { display: flex; width: 100%; max-width: 190px; margin: 0 auto; }
  .workspace:not(.sidebar-collapsed)::before { content: ""; position: fixed; inset: 0; z-index: 90; background: #10141bcc; }
  .workspace:not(.sidebar-collapsed) .sidebar .nav-caption { margin: 28px 12px 12px; }
  .workspace:not(.sidebar-collapsed) .sidebar .sidebar-label { display: inline; }
  .workspace:not(.sidebar-collapsed) .sidebar .nav-item { justify-content: flex-start; min-height: 48px; padding: 10px 12px; }
  .workspace:not(.sidebar-collapsed) .sidebar .sidebar-bottom { justify-content: flex-start; padding-inline: 12px; }
  .workspace-header { min-height: 56px; padding: 6px 10px; }
  .profile-dropdown > summary { max-width: 45vw; padding: 3px; }
  .profile-dropdown > summary > span:nth-child(2) { max-width: 25vw; }
  .workspace-content { padding: 18px 12px 30px; }
  .mobile-module-nav { padding-inline: 12px; }
  .invoice-collapse > summary { gap: 10px; padding: 16px 14px; font-size: 15px; }
  .invoice-collapse > .collapse-content { padding: 16px 13px 18px; }
  .invoice-form .invoice-row { gap: 10px 8px; padding-inline: 9px; }
  .registry-stats, .crm-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-actions > .primary-button, .form-actions > button { flex: 1 1 100%; width: 100%; justify-content: center; }
  .form-actions > .text-button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .recovery-grid { grid-template-columns: 1fr; padding: 14px; }
}

@media (max-width: 380px) {
  .quick-grid, .dashboard-stats, .crm-metrics, .registry-stats { grid-template-columns: minmax(0, 1fr); }
  .invoice-form .invoice-row { grid-template-columns: minmax(0, 1fr); }
  .invoice-form .invoice-row > .row-description, .invoice-form .invoice-row > div:nth-child(10) { grid-column: 1; }
  .workspace-header > .header-organization { flex-basis: 100%; }
  .mobile-module-nav { gap: 14px; font-size: 12px; }
}
