/* Platform behavior: zoom stays available; controls provide their own press feedback. */
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; scroll-padding-top: var(--sticky-header-height, 0px); }
button, a, summary, [role="button"] { touch-action: manipulation; }
button, .button, summary, [role="button"], .rail a { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
button:not(:disabled):active, .button:active, summary:active { filter: brightness(.9); }
/* The review photo is left out on purpose: CSS cannot tell a finger from a wheel, and a contained photo traps a
   swipe on any touch screen. Once the photo has no more to scroll, a swipe or wheel moves the page to the form. */
.table-wrap, .issuer-options, .rail { overscroll-behavior: contain; }
.table-wrap { position: relative; min-width: 0; max-width: 100%; }
.navigation-shell { display: contents; }
.drawer-backdrop, .drawer-close, .header-menu-toggle, .record-toggle { display: none; }
.header-menu { min-width: 0; max-width: 50%; }
.header-menu .actions { justify-content: flex-end; }
.header-menu .company-details { flex-basis: 100%; order: 1; overflow-wrap: anywhere; }
.content-header { padding-top: max(1rem, env(safe-area-inset-top, 0px)); padding-left: max(1.5rem, env(safe-area-inset-left, 0px)); padding-right: max(1.5rem, env(safe-area-inset-right, 0px)); }
.rail { padding-top: max(1.25rem, env(safe-area-inset-top, 0px)); padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px)); padding-left: max(1rem, env(safe-area-inset-left, 0px)); }
#document-editor .review-actions, .cdoc-form-actions { padding-bottom: calc(.75rem + env(safe-area-inset-bottom, 0px)); }
.public-bar { padding-top: max(.9rem, env(safe-area-inset-top, 0px)); padding-left: max(clamp(1rem, 5vw, 4rem), env(safe-area-inset-left, 0px)); padding-right: max(clamp(1rem, 5vw, 4rem), env(safe-area-inset-right, 0px)); }
.public-login { flex: 0 0 auto; }

/* Camera controls wrap by content; the viewfinder keeps its own viewport space. */
@media (max-width: 30rem) {
  .camera-controls { grid-template-columns: minmax(0, 1fr) var(--camera-shutter-size); }
  .camera-dialog .camera-add-page { justify-self: stretch; }
  .camera-dialog .camera-done { grid-column: 1 / -1; justify-self: stretch; }
}
@media (max-height: 30rem) and (min-width: 36rem) {
  .camera-dialog[open] { grid-template-columns: minmax(0, 1fr) minmax(16rem, 35%); grid-template-rows: auto minmax(0, 1fr) auto; }
  .camera-dialog-bar { grid-column: 1 / -1; }
  .camera-stage { grid-column: 1; grid-row: 2; }
  .camera-strip { grid-column: 1; grid-row: 3; padding-bottom: max(.75rem, env(safe-area-inset-bottom, 0px)); }
  .camera-controls { grid-column: 2; grid-row: 2 / 4; grid-template-columns: minmax(0, 1fr) var(--camera-shutter-size); max-height: none; }
  .camera-dialog .camera-add-page { justify-self: stretch; }
  .camera-dialog .camera-done { grid-column: 1 / -1; justify-self: stretch; }
}

@media (any-pointer: coarse) {
  /* Override component font inheritance: Safari zooms focused fields below 16px. */
  #main input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]), #main select, #main textarea { font-size: max(1rem, 16px); }
  #main button:not(.camera-shutter), .button, .rail a, summary { min-height: 2.75rem; }
  #main .info-tip { width: 2.75rem; height: 2.75rem; min-height: 2.75rem; }
  .admin-workspace .data-table td a { display: inline-flex; align-items: center; min-height: 2.75rem; }
  .invoice-sheet .invoice-sheet-terms :is(input:not([type="checkbox"]), select, textarea) { min-height: 2.75rem; }
  .field > .info-tip { top: 0; }
  .public-nav a { display: inline-flex; align-items: center; min-height: 2.75rem; padding-inline: .25rem; }
}

@media (max-width: 1200px) {
  /* Login is outside the scrolling secondary navigation, always in view. */
  .public-bar { flex-wrap: wrap; row-gap: .35rem; }
  .public-nav { order: 3; width: 100%; gap: 1rem; overflow-x: auto; scrollbar-width: thin; padding-bottom: .25rem; }
  .public-nav > a { flex: 0 0 auto; }
}

@media (max-width: 768px) {
  /* CSS also hides the closed drawer before its deferred script runs. */
  .navigation-shell { display: block; position: fixed; inset: 0; z-index: 20; visibility: hidden; pointer-events: none; }
  .navigation-shell:has(.rail.open) { visibility: visible; pointer-events: auto; }
  .drawer-backdrop { display: block; position: absolute; inset: 0; background: #0008; }
  .rail { inset: 0 auto 0 0; height: 100dvh; width: min(20rem, calc(100% - 3rem)); max-width: 100%; }
  .drawer-close { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 2.75rem; margin: 0 0 .5rem auto; background: #ffffff1f; }
  .drawer-close svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 2; }
  html.navigation-open, html.navigation-open body { overflow: hidden; overscroll-behavior: none; }
  .content-header { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: .5rem; padding: max(.5rem, env(safe-area-inset-top, 0px)) max(.75rem, env(safe-area-inset-right, 0px)) .5rem max(.75rem, env(safe-area-inset-left, 0px)); }
  /* The support entry point is a fourth child; it takes its own column so the actions menu keeps the
     right edge and its dropdown, anchored there, stays inside the viewport. */
  .content-header:has(> .header-support) { grid-template-columns: auto minmax(0, 1fr) auto auto; }
  .drawer-toggle { min-height: 2.75rem; padding: .65rem .75rem; }
  .content-context { grid-template-columns: minmax(0, 1fr); }
  .company-context > span { min-width: 0; }
  .content-title, .company-context > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .content-title { font-size: .95rem; }
  .header-menu { position: relative; max-width: none; }
  .header-menu-toggle { display: inline-grid; place-items: center; width: 2.75rem; height: 2.75rem; padding: 0; font-size: 1.5rem; }
  .header-menu .actions { display: none; }
  .header-menu.open .actions { display: flex; position: absolute; top: calc(100% + .5rem); right: 0; width: min(20rem, calc(100vw - 2rem)); padding: 1rem; border: 1px solid var(--border); border-radius: .65rem; background: var(--surface); box-shadow: 0 .75rem 2rem #0002; }
  .header-menu .company-details { order: 0; }
  .header-menu .actions > .button, .header-menu .actions form { flex: 1 1 auto; text-align: center; }
  .header-menu .actions form button { width: 100%; }
  main { padding-left: max(1rem, env(safe-area-inset-left, 0px)); padding-right: max(1rem, env(safe-area-inset-right, 0px)); padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); }
  .cdoc-stat { padding: .65rem .5rem; }
  .cdoc-stats { gap: .5rem; }

  /* Same cells and permissions as desktop; secondary cells expand per record. */
  .mobile-records-wrap { overflow: visible; max-height: none; border: 0; background: transparent; box-shadow: none; }
  .mobile-records, .mobile-records tbody { display: block; }
  .mobile-records thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .mobile-records tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; margin-bottom: .75rem; padding: 1rem; border: 1px solid var(--border); border-radius: .7rem; background: var(--surface); }
  .mobile-records tbody td { display: block; min-width: 0; padding: 0; border: 0; white-space: normal; text-align: left; overflow-wrap: anywhere; }
  .mobile-records tbody td::before { content: attr(data-label); display: block; margin-bottom: .25rem; font-size: .75rem; font-weight: 650; color: var(--muted); }
  .mobile-records tbody .col-wide { grid-column: 1 / -1; }
  .mobile-records tbody td > .cell { min-width: 0; max-width: 100%; }
  .mobile-records td[data-mobile-secondary] { display: none; }
  .mobile-records .record-expanded td[data-mobile-secondary] { display: block; }
  .mobile-records tbody tr[aria-current="true"] { border-left: 3px solid var(--primary); }
  .mobile-records tbody tr[aria-current="true"] > :first-child { box-shadow: none; }
  .mobile-records .table-empty { grid-column: 1 / -1; }
  .mobile-records caption { display: block; padding: 0 0 .75rem; }
  .mobile-records tfoot { display: block; }
  .mobile-records tfoot tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem .75rem; margin-bottom: .75rem; padding: 1rem; border: 1px solid var(--border); border-radius: .7rem; background: #f3f8f8; font-weight: 600; }
  .mobile-records tfoot :is(th, td) { display: block; min-width: 0; padding: 0; border: 0; text-align: left; overflow-wrap: anywhere; }
  .mobile-records tfoot td:empty { display: none; }
  .record-toggle { display: block; width: 100%; margin-top: .35rem; padding: .5rem; font-size: .8rem; background: #e7eeee; color: #173839; }
  .mobile-records .record-toggle-cell { grid-column: 1 / -1; }
  .mobile-records .record-toggle-cell::before { display: none; }
  .record-toggle[aria-expanded="true"] { background: #cde5e3; }
}

@media (prefers-reduced-motion: reduce) {
  button, .button, .rail { transition: none; }
}
/* Disclosure occupies no column in the unchanged desktop table. */
@media (min-width: 769px) {
  .record-toggle-cell { display: none; }
}
.mobile-table-sort { display: none; }
@media (max-width: 768px) {
  .mobile-table-sort { display: flex; flex-wrap: wrap; align-items: end; gap: .5rem; margin-block: 1rem; }
  .mobile-table-sort label { flex: 1 1 8rem; min-width: 0; }
  .mobile-records tbody .col-num { grid-column: 1 / -1; overflow-wrap: normal; }
  /* Internal accounts: amounts pair up two per row; a row heading (opening balance, subtotal) sits beside its amount. */
  .internal-records tbody .col-num { grid-column: auto; }
  .internal-records tbody th[scope="row"] { padding: 0; border: 0; font-size: .875rem; }
}
