/*
 * Tankhaheto PWA platform foundation.
 * iOS/iPadOS first: dynamic viewport, safe areas, portrait-only UX and adaptive widths.
 * Feature visuals intentionally stay in the existing PWA theme files.
 */
:root {
  --pwa-visual-height: 100dvh;
  --pwa-safe-top: env(safe-area-inset-top, 0px);
  --pwa-safe-right: env(safe-area-inset-right, 0px);
  --pwa-safe-bottom: env(safe-area-inset-bottom, 0px);
  --pwa-safe-left: env(safe-area-inset-left, 0px);
  --pwa-shell-max: 760px;
  --pwa-dialog-max: 620px;
  --pwa-touch-target: 44px;
}

html,
body,
#app,
.app-shell {
  min-width: 100%;
  width: 100%;
  min-height: 100svh;
  height: var(--pwa-visual-height, 100dvh);
  max-height: var(--pwa-visual-height, 100dvh);
}

html {
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  background: var(--bg, #f4f7fa);
}

body {
  touch-action: manipulation;
  padding-left: var(--pwa-safe-left);
  padding-right: var(--pwa-safe-right);
}

button,
[role="button"],
input,
select,
textarea {
  min-height: var(--pwa-touch-target);
}

input[type="checkbox"],
input[type="radio"],
input[type="file"] {
  min-height: 0;
}

.main-app,
.bottom-nav,
.app-dock-v3,
.auth-screen > * {
  max-width: var(--pwa-shell-max);
}

.sheet-dialog,
.detail-dialog,
#confirm-dialog,
#simple-dialog,
#document-datepicker-dialog {
  max-width: min(var(--pwa-dialog-max), calc(100vw - 24px));
}

/* Keeps iOS home-indicator and camera-island areas out of tappable content. */
.bottom-nav,
.app-dock-v3 {
  padding-bottom: max(7px, var(--pwa-safe-bottom));
}

.topbar,
.pwa-header,
.settings-sticky-header {
  padding-top: max(8px, var(--pwa-safe-top));
}

/* iPhone mini / compact portrait */
@media (max-width: 374px) and (orientation: portrait) {
  :root {
    --pwa-touch-target: 42px;
  }
  .main-app {
    padding-inline: 10px;
  }
  .topbar {
    margin-inline: -10px;
  }
  .summary-grid {
    grid-auto-columns: minmax(128px, 1fr);
  }
  .document-card {
    padding-inline: 9px;
  }
}

/* Standard / Pro / Pro Max phones */
@media (min-width: 430px) and (max-width: 767px) and (orientation: portrait) {
  :root {
    --pwa-shell-max: 720px;
  }
  .main-app {
    padding-inline: clamp(16px, 4vw, 24px);
  }
  .topbar {
    margin-inline: calc(clamp(16px, 4vw, 24px) * -1);
    padding-inline: clamp(16px, 4vw, 24px);
  }
  .sheet-dialog {
    width: min(92vw, 620px);
  }
}

/* iPad mini / Air / Pro portrait. Preserve the phone visual language but use space. */
@media (min-width: 768px) and (orientation: portrait) {
  :root {
    --pwa-shell-max: min(94vw, 980px);
    --pwa-dialog-max: 720px;
  }
  .main-app {
    max-width: var(--pwa-shell-max);
    padding-inline: clamp(22px, 4vw, 44px);
    padding-bottom: calc(112px + var(--pwa-safe-bottom));
  }
  .topbar {
    margin-inline: calc(clamp(22px, 4vw, 44px) * -1);
    padding-inline: clamp(22px, 4vw, 44px);
  }
  .bottom-nav,
  .app-dock-v3 {
    width: min(760px, calc(100vw - 72px));
  }
  .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
  }
  .form-grid.single,
  .report-filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .settings-content,
  .management-settings-screen,
  .profile-panel,
  #view-reports > .panel {
    width: 100%;
  }
  .sheet-dialog {
    width: min(78vw, 720px);
    max-height: min(88dvh, 920px);
  }
  .document-form-scroll {
    max-height: min(76dvh, 860px);
  }
}

/* Large iPad Pro portrait */
@media (min-width: 1024px) and (orientation: portrait) {
  :root {
    --pwa-shell-max: 1040px;
  }
  .main-app {
    padding-inline: 48px;
  }
  .topbar {
    margin-inline: -48px;
    padding-inline: 48px;
  }
  .document-list {
    gap: 9px;
  }
  .document-card {
    padding: 11px 15px;
  }
}

/* Portrait-only contract. Browsers that cannot physically lock orientation never expose app UI in landscape. */
#portrait-lock-screen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  padding: max(24px, var(--pwa-safe-top)) max(24px, var(--pwa-safe-right)) max(24px, var(--pwa-safe-bottom)) max(24px, var(--pwa-safe-left));
  background: #0f172a;
  color: #fff;
  place-items: center;
  text-align: center;
}

#portrait-lock-screen .portrait-lock-card {
  width: min(86vw, 420px);
  display: grid;
  justify-items: center;
  gap: 12px;
}

#portrait-lock-screen i {
  font-size: 44px;
}

#portrait-lock-screen strong {
  font-size: 19px;
}

#portrait-lock-screen small {
  color: #cbd5e1;
  line-height: 1.9;
}

@media (orientation: landscape) {
  body > :not(#portrait-lock-screen) {
    visibility: hidden !important;
    pointer-events: none !important;
  }
  #portrait-lock-screen {
    display: grid !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }
}

/* Dynamic keyboard viewport on iOS. */
html.pwa-keyboard-open .bottom-nav,
html.pwa-keyboard-open .app-dock-v3 {
  transform: translate(-50%, calc(100% + var(--pwa-safe-bottom) + 14px));
  pointer-events: none;
}

html.pwa-keyboard-open .sheet-dialog[open],
html.pwa-keyboard-open .detail-dialog[open] {
  max-height: calc(var(--pwa-visual-height) - 16px);
}

/* Installed mode avoids accidental browser-like edge artifacts. */
html.pwa-standalone,
html.pwa-standalone body {
  overscroll-behavior: none;
}

html.pwa-ios body {
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
  html.pwa-keyboard-open .bottom-nav,
  html.pwa-keyboard-open .app-dock-v3 {
    transition: none !important;
  }
}

.offline-queue-status {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--amber, #f59e0b) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--amber, #f59e0b) 28%, transparent);
}
.offline-queue-status b { font-size: 13px; }
.offline-queue-status small { color: var(--muted, #667085); line-height: 1.7; }

.documents-status-tabs {
  position: sticky;
  top: calc(var(--topbar-height, 58px) + 4px);
  z-index: 12;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 7px 0 10px;
  padding: 4px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--card, #fff) 88%, transparent);
  border: 1px solid var(--line, #dce3eb);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
}
.documents-status-tabs button {
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted, #667085);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.documents-status-tabs button.active {
  background: var(--dark, #111827);
  color: #fff;
}

/* v3.1.0.31 — iOS browser install education + iOS standalone chrome hardening. */
#ios-status-bar-surface{display:none}
html[data-ios-standalone="true"] #ios-status-bar-surface,
html.pwa-ios.pwa-standalone #ios-status-bar-surface{
  display:block;
  position:fixed;
  z-index:2147483647;
  top:0;
  right:0;
  left:0;
  width:100%;
  height:11px;
  pointer-events:none;
  opacity:1!important;
  visibility:visible!important;
  background-color:#fff!important;
  -webkit-background-clip:text!important;
  background-clip:text!important;
  -webkit-backdrop-filter:none!important;
  backdrop-filter:none!important;
  filter:none!important;
  transform:none!important;
  mix-blend-mode:normal!important;
}
:root[data-theme="dark"][data-ios-standalone="true"] #ios-status-bar-surface,
:root[data-theme="dark"].pwa-ios.pwa-standalone #ios-status-bar-surface{background-color:#111827!important}

/* iOS 27 can draw a progressive status-bar blur over standalone PWAs.
   Keep the app header itself solid; the fixed color-extension sentinel above is
   invisible to paint but visible to WebKit's edge sampler. */
html.pwa-ios.pwa-standalone .topbar.app-header-v3,
html[data-ios-standalone="true"] .topbar.app-header-v3{
  background:#111827!important;
  -webkit-backdrop-filter:none!important;
  backdrop-filter:none!important;
  filter:none!important;
}
:root[data-theme="light"].pwa-ios.pwa-standalone .topbar.app-header-v3,
:root[data-theme="light"][data-ios-standalone="true"] .topbar.app-header-v3{background:#fff!important}

/* The floating dock should visually meet the physical bottom edge. Controls stay
   above the home indicator because the safe inset is kept inside the app surface. */
html.pwa-standalone .app-shell > .bottom-nav.app-dock-v3{
  bottom:0!important;
}

/* Documents header: currency lives directly below the page title on the RTL side. */
.app-header-v3__title > .app-header-v3__link{
  justify-self:end;
  justify-content:flex-start;
  text-align:right;
}

/* iOS keyboard: keep the whole OTP/auth card inside the VisualViewport and give
   enough scroll tail so the confirmation card is never cut by the keyboard. */
html.pwa-ios .auth-screen.keyboard-open,
html.pwa-ios .auth-screen:focus-within{
  position:fixed!important;
  top:var(--pwa-visual-offset-top,0px)!important;
  right:0!important;
  bottom:auto!important;
  left:0!important;
  width:100%!important;
  height:var(--pwa-visual-height,100dvh)!important;
  max-height:var(--pwa-visual-height,100dvh)!important;
  padding-top:max(18px,var(--pwa-safe-top))!important;
  padding-bottom:max(112px,calc(var(--pwa-safe-bottom) + 80px))!important;
  scroll-padding-top:max(18px,var(--pwa-safe-top))!important;
  scroll-padding-bottom:148px!important;
}
html.pwa-ios .auth-screen.keyboard-open .auth-form,
html.pwa-ios .auth-screen:focus-within .auth-form{margin-bottom:28px}

/* Safari install tutorial, intentionally page-like instead of a tiny toast. */
.ios-install-guide{
  position:fixed;
  z-index:2147483600;
  inset:0;
  overflow:auto;
  overscroll-behavior:contain;
  background:#fff;
  color:#111827;
  padding:max(56px,calc(var(--pwa-safe-top) + 28px)) max(24px,var(--pwa-safe-right)) max(28px,calc(var(--pwa-safe-bottom) + 20px)) max(24px,var(--pwa-safe-left));
}
.ios-install-guide.hidden{display:none!important}
.ios-install-guide__content{
  width:min(100%,520px);
  min-height:calc(100% - 8px);
  margin:0 auto;
  display:flex;
  flex-direction:column;
  align-items:stretch;
  text-align:center;
}
.ios-install-guide__brand{margin:12vh auto 26px;width:92px;height:92px;border-radius:20px;overflow:hidden;box-shadow:0 14px 34px rgba(15,23,42,.12)}
.ios-install-guide__brand img{width:100%;height:100%;display:block;object-fit:cover}
.ios-install-guide h2{margin:0 auto 10px;font-size:25px;line-height:1.6;max-width:430px}
.ios-install-guide>*,.ios-install-guide p{font-family:inherit}
.ios-install-guide__content>p{margin:0 auto 28px;color:#667085;line-height:1.9;max-width:430px}
.ios-install-guide__steps{list-style:none;margin:0;padding:20px 0;border-top:1px solid #eef2f7;display:grid;gap:21px;text-align:right}
.ios-install-guide__steps li{display:grid;grid-template-columns:42px minmax(0,1fr);gap:13px;align-items:center;color:#475467;line-height:1.9}
.ios-install-guide__step-icon{width:42px;height:42px;display:grid;place-items:center;color:#4f67ff;font-size:24px}
.ios-install-guide__step-icon--text{font-size:15px;font-weight:800}
.ios-install-guide__dismiss{margin-top:auto;min-height:58px;border:0;border-radius:13px;background:#16a34a;color:#fff;font-size:18px;font-weight:900;padding:12px 18px}
:root[data-theme="dark"] .ios-install-guide{background:#0f1f31;color:#f8fafc}
:root[data-theme="dark"] .ios-install-guide__content>p,
:root[data-theme="dark"] .ios-install-guide__steps li{color:#b8c5d3}
:root[data-theme="dark"] .ios-install-guide__steps{border-top-color:#27384c}
@media(max-height:720px){
  .ios-install-guide__brand{margin-top:3vh;width:72px;height:72px}
  .ios-install-guide h2{font-size:21px}
  .ios-install-guide__steps{gap:12px;padding-block:14px}
}

/* v3.1.0.120 — iOS standalone solid chrome + physical-bottom safe area.
 * Loaded last on purpose so older glass/floating overrides cannot win. */
html.pwa-standalone:not(.pwa-keyboard-open),
html.pwa-standalone:not(.pwa-keyboard-open) body,
html.pwa-standalone:not(.pwa-keyboard-open) #app,
html.pwa-standalone:not(.pwa-keyboard-open) .app-shell {
  height:100dvh!important;
  min-height:100dvh!important;
  max-height:100dvh!important;
  background:var(--bg,#f4f7fa)!important;
}

html.pwa-ios.pwa-standalone #pwa-header.topbar.app-header-v3 {
  background-color:#111827!important;
  background-image:none!important;
  -webkit-backdrop-filter:none!important;
  backdrop-filter:none!important;
  filter:none!important;
  opacity:1!important;
}
:root[data-theme="light"].pwa-ios.pwa-standalone #pwa-header.topbar.app-header-v3 {
  background-color:#fff!important;
}

html.pwa-standalone .app-shell > .bottom-nav.app-dock-v3 {
  bottom:0!important;
  padding-bottom:calc(7px + env(safe-area-inset-bottom,0px))!important;
}

html.pwa-standalone .main-app {
  padding-bottom:calc(96px + env(safe-area-inset-bottom,0px))!important;
}
@media (min-width:768px) and (orientation:portrait) {
  html.pwa-standalone .main-app {
    padding-bottom:calc(112px + env(safe-area-inset-bottom,0px))!important;
  }
}


/* v3.1.0.121 — iOS standalone chrome hard-reset follow-up.
 * The header already lives in the first grid row; keeping it sticky can still
 * trigger WebKit's scroll-edge compositor. Make it a normal opaque grid item.
 * The dock keeps the same controls, but its surface itself now includes the
 * complete bottom safe area so the Home Indicator is painted by the dock. */
html.pwa-ios.pwa-standalone #pwa-header.pwa-header,
html.pwa-ios.pwa-standalone #pwa-header.topbar.app-header-v3 {
  position:relative!important;
  top:auto!important;
  inset-block-start:auto!important;
  background-color:#111827!important;
  background-image:none!important;
  -webkit-backdrop-filter:none!important;
  backdrop-filter:none!important;
  filter:none!important;
  box-shadow:none!important;
  opacity:1!important;
  transform:none!important;
  will-change:auto!important;
}
:root[data-theme="light"].pwa-ios.pwa-standalone #pwa-header.pwa-header,
:root[data-theme="light"].pwa-ios.pwa-standalone #pwa-header.topbar.app-header-v3 {
  background-color:#fff!important;
}
html.pwa-ios.pwa-standalone #pwa-header.pwa-header *,
html.pwa-ios.pwa-standalone #pwa-header.topbar.app-header-v3 * {
  -webkit-backdrop-filter:none!important;
  backdrop-filter:none!important;
  filter:none!important;
  text-shadow:none!important;
}

html.pwa-ios.pwa-standalone .app-shell > .bottom-nav.app-dock-v3 {
  bottom:0!important;
  height:auto!important;
  min-height:calc(72px + var(--pwa-safe-bottom))!important;
  padding:5px 5px max(8px,var(--pwa-safe-bottom))!important;
  border-bottom-left-radius:0!important;
  border-bottom-right-radius:0!important;
  margin-bottom:0!important;
}
html.pwa-ios.pwa-standalone .app-shell > .bottom-nav.app-dock-v3 .fab {
  bottom:calc(var(--pwa-safe-bottom) + 1px)!important;
}
@media(max-width:420px){
  html.pwa-ios.pwa-standalone .app-shell > .bottom-nav.app-dock-v3 {
    min-height:calc(68px + var(--pwa-safe-bottom))!important;
  }
  html.pwa-ios.pwa-standalone .app-shell > .bottom-nav.app-dock-v3 .fab {
    bottom:calc(var(--pwa-safe-bottom) + 1px)!important;
  }
}

/* v3.1.0.125 — iOS standalone real-device correction, rebased on exported v3.1.0.122.
 * Keep the dashboard/documents header sticky while avoiding WebKit's glass/raster
 * path. Restore the original floating dock dimensions after v121's safe-area
 * inflation, and keep the app-owned background painted beneath the Home Indicator. */
html.pwa-ios.pwa-standalone #pwa-header.topbar.app-header-v3 {
  position:sticky!important;
  top:0!important;
  inset-block-start:0!important;
  z-index:24!important;
  background:#111827!important;
  background-color:#111827!important;
  background-image:none!important;
  -webkit-backdrop-filter:none!important;
  backdrop-filter:none!important;
  filter:none!important;
  box-shadow:none!important;
  opacity:1!important;
  transform:none!important;
  perspective:none!important;
  mix-blend-mode:normal!important;
  will-change:auto!important;
  contain:none!important;
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
}
:root[data-theme="light"].pwa-ios.pwa-standalone #pwa-header.topbar.app-header-v3 {
  background:#fff!important;
  background-color:#fff!important;
}

/* Sticky inside an explicitly composited momentum-scroll layer is the path that
 * produced the soft/rasterized header on the affected iPhone. Modern iOS does
 * not need the legacy touch-scroller compositor for momentum scrolling. */
html.pwa-ios.pwa-standalone .main-app {
  -webkit-overflow-scrolling:auto!important;
  transform:none!important;
  perspective:none!important;
  filter:none!important;
  background:var(--bg,#f4f7fa)!important;
}

/* Every visible header control is opaque. Do not leave an rgba fill that can be
 * mistaken for / promoted to a glass material by WebKit. */
html.pwa-ios.pwa-standalone #pwa-header .app-header-v3__filter,
html.pwa-ios.pwa-standalone #pwa-header .app-header-v3__icon {
  background:#1f2937!important;
  background-color:#1f2937!important;
  background-image:none!important;
  border-color:#344054!important;
  -webkit-backdrop-filter:none!important;
  backdrop-filter:none!important;
  filter:none!important;
  box-shadow:none!important;
  opacity:1!important;
}
html.pwa-ios.pwa-standalone #pwa-header .app-header-v3__filter:active,
html.pwa-ios.pwa-standalone #pwa-header .app-header-v3__icon:active {
  background:#273449!important;
  background-color:#273449!important;
}
:root[data-theme="light"].pwa-ios.pwa-standalone #pwa-header .app-header-v3__filter,
:root[data-theme="light"].pwa-ios.pwa-standalone #pwa-header .app-header-v3__icon {
  background:#f2f4f7!important;
  background-color:#f2f4f7!important;
  border-color:#d0d5dd!important;
}
:root[data-theme="light"].pwa-ios.pwa-standalone #pwa-header .app-header-v3__filter:active,
:root[data-theme="light"].pwa-ios.pwa-standalone #pwa-header .app-header-v3__icon:active {
  background:#e4e7ec!important;
  background-color:#e4e7ec!important;
}
html.pwa-ios.pwa-standalone #pwa-header,
html.pwa-ios.pwa-standalone #pwa-header * {
  -webkit-backdrop-filter:none!important;
  backdrop-filter:none!important;
  filter:none!important;
  text-shadow:none!important;
  mix-blend-mode:normal!important;
  opacity:1;
}

/* Undo v121's enlarged safe-area dock without changing the established glass
 * capsule/FAB design. The actual system Home Indicator remains iOS-owned UI. */
html.pwa-ios.pwa-standalone .app-shell > .bottom-nav.app-dock-v3 {
  bottom:0!important;
  height:72px!important;
  min-height:72px!important;
  padding:5px!important;
  border-radius:999px!important;
  margin-bottom:0!important;
  overflow:visible!important;
}
html.pwa-ios.pwa-standalone .app-shell > .bottom-nav.app-dock-v3 .fab {
  bottom:1px!important;
}
@media(max-width:420px){
  html.pwa-ios.pwa-standalone .app-shell > .bottom-nav.app-dock-v3 {
    height:68px!important;
    min-height:68px!important;
    padding:5px!important;
    border-radius:999px!important;
  }
  html.pwa-ios.pwa-standalone .app-shell > .bottom-nav.app-dock-v3 .fab {
    bottom:1px!important;
  }
}

/* Full-viewport paint contract. This does not and cannot hide the iOS Home
 * Indicator itself; it guarantees there is no browser-transparent strip under it. */
html.pwa-ios.pwa-standalone,
html.pwa-ios.pwa-standalone body,
html.pwa-ios.pwa-standalone #app,
html.pwa-ios.pwa-standalone .app-shell {
  width:100%!important;
  min-height:100dvh!important;
  height:100dvh!important;
  max-height:100dvh!important;
  background:var(--bg,#f4f7fa)!important;
  background-color:var(--bg,#f4f7fa)!important;
}
html.pwa-ios.pwa-standalone .app-shell::after {
  content:"";
  position:fixed;
  z-index:1;
  left:0;
  right:0;
  bottom:0;
  height:max(1px,var(--pwa-safe-bottom));
  pointer-events:none;
  background:var(--bg,#f4f7fa);
}

/* v3.1.0.126/v133 — legacy edge-to-edge geometry guard.
 * 100vh is retained only for installations that actually expose a non-zero
 * safe-area-inset-top (the old edge-to-edge/black-translucent install contract).
 * Fresh v133 installs keep the non-edge-to-edge viewport and therefore stay on
 * the 100dvh rule above, avoiding WebKit's known 100vh mismatch in that mode. */
html.pwa-ios.pwa-standalone.pwa-edge-to-edge:not(.pwa-keyboard-open),
html.pwa-ios.pwa-standalone.pwa-edge-to-edge:not(.pwa-keyboard-open) body,
html.pwa-ios.pwa-standalone.pwa-edge-to-edge:not(.pwa-keyboard-open) #app,
html.pwa-ios.pwa-standalone.pwa-edge-to-edge:not(.pwa-keyboard-open) .app-shell {
  min-height:100vh!important;
  height:100vh!important;
  max-height:100vh!important;
  background:var(--bg,#f4f7fa)!important;
  background-color:var(--bg,#f4f7fa)!important;
}

/* The dock itself stays the original floating capsule. With a correctly installed
 * edge-to-edge viewport, bottom:0 now means the physical display bottom instead of
 * the inset standalone viewport that produced the visible strip in v125. */
html.pwa-ios.pwa-standalone:not(.pwa-keyboard-open) .app-shell > .bottom-nav.app-dock-v3 {
  bottom:0!important;
  margin-bottom:0!important;
}

/* v125's paint bridge is no longer needed once the installed viewport is truly
 * edge-to-edge. Leaving an extra fixed strip can make the safe-area look like a
 * separate footer, so explicitly disable it. */
html.pwa-ios.pwa-standalone .app-shell::after {
  content:none!important;
  display:none!important;
}

/* v3.1.0.128 — recovery from v127 header-layout regression.
 * Restore the known-good v126 iOS standalone header/fullscreen geometry exactly.
 * Keep only the two user-requested layout refinements that were safe in v127:
 * compact page-content gutters and a slightly higher floating dock. Header and
 * dock horizontal geometry are intentionally untouched. */
html.pwa-ios.pwa-standalone:not(.pwa-keyboard-open) .app-shell > .bottom-nav.app-dock-v3 {
  bottom:13px!important;
  margin-bottom:0!important;
}

/* Phone content gutter: approximately 5px outer spacing for top-level views.
 * Do not alter the primary header or bottom dock widths/margins. */
@media (max-width:374px) {
  #main-app > .view { margin-inline:-5px!important; }
}
@media (min-width:375px) and (max-width:429px) {
  #main-app > .view { margin-inline:-9px!important; }
}
@media (min-width:430px) and (max-width:767px) {
  #main-app > .view { margin-inline:calc(5px - clamp(16px,4vw,24px))!important; }
}


/* v3.1.0.130 — iOS 27 standalone top-edge blur root fix.
 * The visible app header is now a direct .app-shell grid sibling of .main-app,
 * not a sticky descendant of the momentum scroll surface. This removes the
 * WebKit scroll-edge compositor path that was still rasterizing/softening the
 * page title and month text even though backdrop-filter itself was disabled. */
.app-shell > #pwa-header.pwa-header.topbar.app-header-v3 {
  position:relative!important;
  grid-column:1!important;
  grid-row:1!important;
  top:auto!important;
  right:auto!important;
  bottom:auto!important;
  left:auto!important;
  inset-block-start:auto!important;
  z-index:24!important;
  width:100%!important;
  max-width:var(--pwa-shell-max,760px)!important;
  height:auto!important;
  min-height:calc(58px + var(--pwa-safe-top))!important;
  margin:0 auto!important;
  background:#111827!important;
  background-color:#111827!important;
  background-image:none!important;
  -webkit-backdrop-filter:none!important;
  backdrop-filter:none!important;
  filter:none!important;
  box-shadow:none!important;
  transform:none!important;
  perspective:none!important;
  mix-blend-mode:normal!important;
  opacity:1!important;
  will-change:auto!important;
  contain:none!important;
  isolation:auto!important;
  backface-visibility:visible!important;
}
:root[data-theme="light"] .app-shell > #pwa-header.pwa-header.topbar.app-header-v3 {
  background:#fff!important;
  background-color:#fff!important;
}
.app-shell > #pwa-header.pwa-header.topbar.app-header-v3,
.app-shell > #pwa-header.pwa-header.topbar.app-header-v3 * {
  -webkit-backdrop-filter:none!important;
  backdrop-filter:none!important;
  filter:none!important;
  text-shadow:none!important;
  mix-blend-mode:normal!important;
  will-change:auto!important;
}

/* The scrolling content owns only the second grid row. Header visibility is
 * controlled by the existing sibling rules in header.css for auth/settings. */
.app-shell > .main-app:not(.hidden):not(.settings-root):not(.settings-detail-mode) {
  grid-row:2!important;
  min-height:0!important;
  padding-top:8px!important;
}

/* On iOS standalone specifically, forbid any later legacy sticky override from
 * pulling the header back into WebKit's scroll-edge material/compositor. */
html.pwa-ios.pwa-standalone .app-shell > #pwa-header.pwa-header.topbar.app-header-v3 {
  position:relative!important;
  top:auto!important;
  inset-block-start:auto!important;
  -webkit-backdrop-filter:none!important;
  backdrop-filter:none!important;
  filter:none!important;
  transform:none!important;
  contain:none!important;
}

/* The documents tabs are now sticky inside the second grid row. Because the
 * primary header no longer belongs to that scroll container, its height must
 * not be added to the sticky offset. */
.app-shell > .main-app .documents-status-tabs {
  top:4px!important;
}


/* v3.1.0.133 — iOS 27 WebKit fixed-color-extension workaround.
 * The install-time black-translucent contract can keep _obscuredInsets.top at
 * zero and makes WebKit's top color-extension path unavailable. Fresh installs
 * therefore do not opt into black-translucent. For non-edge-to-edge installs,
 * the 11px fixed sentinel is present before first paint, spans >90% of the
 * viewport, stays above the 0.1 opacity threshold, and exposes a solid computed
 * background-color while background-clip:text prevents visible pixels. */
html[data-ios-standalone="true"] #ios-status-bar-surface,
html.pwa-ios.pwa-standalone #ios-status-bar-surface{
  display:block!important;
  position:fixed!important;
  inset:0 0 auto 0!important;
  width:100%!important;
  height:11px!important;
  z-index:2147483647!important;
  pointer-events:none!important;
  opacity:1!important;
  visibility:visible!important;
  background-color:#fff!important;
  -webkit-background-clip:text!important;
  background-clip:text!important;
}
:root[data-theme="dark"][data-ios-standalone="true"] #ios-status-bar-surface,
:root[data-theme="dark"].pwa-ios.pwa-standalone #ios-status-bar-surface{
  background-color:#111827!important;
}
/* v3.1.0.136 — iOS 27 install-contract correction.
 * The top fixed-color extension only becomes available when iOS owns an
 * obscured top inset. Existing legacy black-translucent Home Screen installs
 * are detected through their non-zero safe-area top and receive a one-time
 * reinstall guide; fresh installs declare status-bar-style=default. */
html[data-ios-standalone="true"] #ios-status-bar-surface,
html.pwa-ios.pwa-standalone #ios-status-bar-surface{
  min-width:100vw!important;
  max-width:none!important;
  contain:none!important;
  isolation:auto!important;
}
html.pwa-ios.pwa-standalone.pwa-legacy-edge-install #ios-status-bar-surface{
  /* Kept harmlessly present, but WebKit cannot use the extension path until
     the old install-time edge-to-edge contract is replaced by reinstalling. */
  pointer-events:none!important;
}



/* v3.1.0.137 — auth shell + OTP keyboard contract.
 * The dock is application navigation and must never render while the authenticated
 * main surface is hidden (startup/login/register/channel/OTP). */
.app-shell > #main-app.hidden ~ .bottom-nav.app-dock-v3 {
  display:none!important;
}

/* When the OTP reaches six digits, JS blurs the native one-time-code input before
 * verification. Keep auth layout from retaining keyboard-only spacing after blur. */
html:not(.pwa-keyboard-open) .auth-screen:not(:focus-within) {
  --pwa-auth-keyboard-dismissed:1;
}

/* v170: iPhone status strip matches the splash until it leaves the DOM. */
html:has(#startup-screen:not(.hidden)) #ios-status-bar-surface{background:#f4f7fa!important;background-color:#f4f7fa!important}
html[data-theme="dark"]:has(#startup-screen:not(.hidden)) #ios-status-bar-surface{background:#111827!important;background-color:#111827!important}
