/* Keep the existing visual design; only the content, not the app frame, scrolls. */
:root {
  --app-viewport-height: 100dvh;
  --app-viewport-top: 0px;
}
html:has(#appShell:not([hidden])),
html:has(#appShell:not([hidden])) body {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
}
#appShell:not([hidden]) {
  display: flex;
  flex-direction: column;
  height: var(--app-viewport-height);
  min-height: 0;
  padding: 0;
  top: var(--app-viewport-top);
  overflow: hidden;
}
#appShell > .topbar {
  position: relative;
  top: auto;
  height: auto;
  min-height: calc(76px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  flex: 0 0 auto;
}
#appContent {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  scroll-padding: 20px;
  scrollbar-gutter: stable;
}
#appContent > .view {
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
  overflow-wrap: anywhere;
}
#appShell > .bottom-nav {
  position: relative;
  bottom: auto;
  left: auto;
  transform: none;
  width: 100%;
  height: auto;
  min-height: calc(70px + env(safe-area-inset-bottom));
  flex: 0 0 auto;
}
.bottom-nav button { min-height: 48px; cursor: pointer; }
.bottom-nav .nav-label { font-size: 11px; line-height: 16px; }
body[data-role="subcontractor"] #appContent { padding-bottom: env(safe-area-inset-bottom); }
html:has(dialog[open]) #appContent,
dialog.app-dialog.app-dialog-suspended > .app-dialog-body { overflow: hidden; }

/* A non-scrolling dialog bar and one clearly bounded scrolling body. */
dialog.app-dialog {
  padding: 0;
  max-width: calc(100vw - 32px);
  max-height: calc(var(--app-viewport-height) - 32px);
  top: calc(var(--app-viewport-top) + var(--app-viewport-height) / 2);
  bottom: auto;
  margin: 0 auto;
  transform: translateY(-50%);
  overflow: hidden;
  overscroll-behavior: none;
}
dialog.app-dialog[open] { display: flex; flex-direction: column; }
.app-dialog-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  min-height: 60px;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.app-dialog-bar .dialog-close,
.app-dialog-back {
  position: static;
  width: auto;
  height: auto;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: #edf2f0;
  color: var(--green);
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  flex: 0 0 auto;
}
.app-dialog-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 800;
}
.app-dialog-body {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  padding: 24px;
  overflow: auto;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  overflow-wrap: anywhere;
  scroll-padding: 20px;
}
.app-dialog-body > :first-child { margin-top: 0; }
.app-dialog-body form { min-width: 0; }
.mail-body, .workproof-source-text, .source-data-content {
  overscroll-behavior: contain;
}
.app-dialog-back:focus-visible, .app-dialog-bar .dialog-close:focus-visible,
.bottom-nav button:focus-visible {
  outline: 3px solid var(--green2);
  outline-offset: -3px;
}
@media (max-width: 620px) {
  dialog.app-dialog {
    top: var(--app-viewport-top);
    bottom: auto;
    left: 0;
    right: 0;
    margin: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
    height: var(--app-viewport-height);
    max-height: var(--app-viewport-height);
    border-radius: 0;
  }
  .app-dialog-bar {
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  .app-dialog-body {
    padding: 20px max(18px, env(safe-area-inset-right))
      calc(24px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  }
  /* Prevent iPhone auto-zoom when entering text; keep user pinch-zoom enabled. */
  #appShell input:not([type="checkbox"]):not([type="radio"]),
  #appShell select, #appShell textarea,
  dialog.app-dialog input:not([type="checkbox"]):not([type="radio"]),
  dialog.app-dialog select, dialog.app-dialog textarea { font-size: 16px; }
  .acceptance-preview-document iframe { min-height: 180px; height: 55dvh; }
}
/* Tablet touch screens only: widen the order, not other dialogs or laptops.
   Both dimensions exclude phones in landscape; fine-pointer laptops keep 520px. */
@media (min-width: 621px) and (min-height: 621px) and (max-width: 1400px) and (hover: none) and (pointer: coarse) {
  dialog#jobDialog.app-dialog {
    width: min(1100px, calc(100vw - 48px));
    max-width: calc(100vw - 48px);
  }
}
@media (prefers-reduced-motion: reduce) {
  #appContent, .app-dialog-body { scroll-behavior: auto; }
}
