/* Shared sizes: new pages should reuse these tokens and existing action groups. */
:root {
  --ui-page-title-size:24px;
  --ui-body-size:12px;
  --ui-label-size:11px;
  --ui-help-size:11px;
  --ui-control-size:13px;
  --ui-compact-control-size:13px;
  --ui-field-header-height:28px;
  --ui-field-header-gap:4px;
  --ui-field-gap:8px;
  --ui-section-nav-size:12px;
  --ui-preview-title-size:20px;
  --ui-preview-label-size:10px;
  --ui-panel-title-size:14px;
  --ui-section-icon-size:16px;
  --ui-section-nav-number-size:10px;
  --ui-action-size:11px;
}
:is(#view-invoicing,#view-questionnaire,#view-settings,#view-settings-hub,#view-analytics,#view-actions,#view-action-report,#view-planning) :is(.module-header h2,.settings-page-header h1,.invoice-heading h1) {
  font-size:var(--ui-page-title-size); line-height:1.3; letter-spacing:-.025em; overflow-wrap:anywhere;
}
#view-invoicing { font-size:var(--ui-body-size); }
.invoice-controls label { font-size:var(--ui-label-size); }
.invoice-controls :is(input,select) { font-size:var(--ui-control-size); }
.invoice-note { font-size:var(--ui-help-size); }
.invoice-summary,.invoice-table { font-size:var(--ui-body-size); }
.invoice-table th { font-size:var(--ui-label-size); }
:is(#view-analytics,#view-invoicing) .analytics-report-actions button { font-size:var(--ui-action-size); }

/* Constrain native date/month controls and their parents, including iOS. */
body.new-design-ui .view :is(input,select,textarea) { box-sizing:border-box; min-width:0; max-width:100%; }
.view :is(input[type="month"],input[type="date"],input[type="time"]) { min-inline-size:0; max-inline-size:100%; }
.view :is(input[type="month"],input[type="date"],input[type="time"])::-webkit-date-and-time-value { min-width:0; text-align:left; }
#view-questionnaire :is(.qm-fieldset,.qm-scope,.qm-inline-editor,.qm-inline-editor label,.qm-section,.qm-section-body) { box-sizing:border-box; min-width:0; max-width:100%; }
#view-questionnaire .qm-scope { width:100%; }
#view-questionnaire .qm-scope input[type="month"] { display:block; width:100%; max-width:min(240px,100%); min-inline-size:0; -webkit-appearance:none; appearance:none; }
#view-questionnaire .qm-scope p { overflow-wrap:anywhere; }
#view-questionnaire .qm-save-bar > p { min-width:0; }
#view-questionnaire .qm-save-actions { min-width:0; }
#view-questionnaire .qm-save-actions .btn { min-width:0; white-space:normal; overflow-wrap:anywhere; }
#view-questionnaire .qm-page-header { display:grid; grid-template-columns:minmax(0,1fr) 44px; }
.settings-destination-icon .invoice-receipt-icon { color:inherit; }
.settings-destination-icon .settings-choice-icon { color:inherit; }
/* Keep the settings title, cards and return control in one centered workspace. */
#view-settings-hub .settings-destination-grid { width:100%; max-width:none; }
@media(min-width:701px) {
  body.new-design-ui.nd-authenticated > #view-settings-hub.view {
    box-sizing:border-box;
    width:calc(100% - 64px)!important;
    max-width:1120px!important;
    margin:32px auto!important;
    padding:0 0 34px!important;
  }
}
@media(max-width:700px) {
  :root { --ui-page-title-size:22px; --ui-control-size:16px; }
  #view-questionnaire .qm-page-header { grid-template-columns:minmax(0,1fr) 36px; }
}

@media screen {
  /* Clip the existing horizontal overflow without making body a scroll
     container: the header must stick to the document viewport. */
  html:has(body.new-design-ui.nd-authenticated),
  body.new-design-ui.nd-authenticated { overflow-x:clip; }
  html:has(body.new-design-ui.nd-authenticated) {
    scroll-padding-top:calc(var(--app-support-height,0px) + var(--app-topbar-height,86px) + env(safe-area-inset-top,0px) + 20px);
  }
  body.new-design-ui.nd-authenticated > .topbar {
    position:sticky!important;
    top:calc(var(--app-support-height,0px) + var(--ui-safe-top,env(safe-area-inset-top,0px)) + 8px);
    z-index:1400;
    background:#f7f9fa;
    box-shadow:0 3px 12px #3449560d;
    will-change:opacity;
    overflow:visible;
  }
  /* Independent backing below the bar also hides content at its rounded corners. */
  body.new-design-ui.nd-authenticated::before {
    content:"";
    position:fixed;
    top:var(--app-support-height,0px);
    left:0;
    right:0;
    height:calc(env(safe-area-inset-top,0px) + 56px);
    background:linear-gradient(to bottom,#eef2f4 0 calc(100% - 16px),rgba(238,242,244,0) 100%);
    pointer-events:none;
    z-index:899;
  }
  body.nd-view-form #view-form .section-block { scroll-margin-top:12px; }
  #supportBanner { top:env(safe-area-inset-top,0px); }
}
#mobileTopBackdrop { display:none; }
@media screen and (max-width:700px) {
  :root { --ui-floating-bar-gap:8px; }
  /* Let WebKit inset native status/gesture areas; paint their opaque backdrop. */
  html:has(body.new-design-ui),
  body.new-design-ui { background-color:#eef2f4; }
  body.new-design-ui.nd-authenticated::before {
    content:none;
  }
  body.new-design-ui.nd-authenticated > .topbar {
    top:calc(var(--app-support-height,0px) + var(--ui-safe-top,env(safe-area-inset-top,0px)) + var(--ui-floating-bar-gap));
  }
  /* A real, solid edge surface lets native WebKit sample an opaque color. */
  body.new-design-ui.nd-authenticated > #mobileTopBackdrop {
    display:block;
    position:fixed;
    top:0;
    left:0;
    width:100%;
    height:calc(var(--app-support-height,0px) + var(--ui-safe-top,env(safe-area-inset-top,0px)) + var(--ui-floating-bar-gap) + 24px);
    background-color:#eef2f4;
    pointer-events:none;
    z-index:1399;
  }
  body.new-design-ui.nd-authenticated > #mobileTopBackdrop::after {
    content:"";
    position:absolute;
    top:100%;
    left:0;
    width:100%;
    height:16px;
    background:linear-gradient(to bottom,#eef2f4,rgba(238,242,244,0));
  }
}
@media screen and (min-width:701px) {
  body.support-window.new-design-ui .nd-rail {
    top:calc(var(--app-support-height,0px) + env(safe-area-inset-top,0px) + 16px);
  }
}
/* Tablet home: keep all action icons on the logo row, search below. */
@media screen and (min-width:701px) and (max-width:1180px) {
  body.nd-view-home.new-design-ui.nd-authenticated > #topbarRow {
    grid-template-columns:minmax(0,1fr) repeat(5,max-content)!important;
  }
  body.nd-view-home.new-design-ui.nd-authenticated > #topbarRow .nd-topbar-brand {
    grid-column:1; grid-row:1; min-width:0;
  }
  body.nd-view-home.new-design-ui.nd-authenticated > #topbarRow #topbarLogo {
    max-width:min(220px,100%); width:auto!important; height:31px!important; object-fit:contain;
  }
  body.nd-view-home.new-design-ui.nd-authenticated > #topbarRow .topbar-actions > :not(.nd-topbar-search) {
    grid-column:auto; grid-row:1;
  }
  body.nd-view-home.new-design-ui.nd-authenticated > #topbarRow #onlinePresenceWrap { grid-column:2!important; }
  body.nd-view-home.new-design-ui.nd-authenticated > #topbarRow #notificationButton { grid-column:3!important; }
  body.nd-view-home.new-design-ui.nd-authenticated > #topbarRow #settingsOpenButton { grid-column:4!important; }
  body.nd-view-home.new-design-ui.nd-authenticated > #topbarRow #topbarUserWrap { grid-column:5!important; }
  body.nd-view-home.new-design-ui.nd-authenticated > #topbarRow #topbarLogoutButton { grid-column:6!important; }
  body.nd-view-home.new-design-ui.nd-authenticated > #topbarRow .nd-topbar-search {
    grid-column:1/-1; grid-row:2; max-width:none; width:100%;
  }
}
@media screen and (max-width:700px) {
  body.new-design-ui.nd-authenticated > .topbar #notificationPopover {
    top:calc(var(--app-support-height,0px) + var(--app-topbar-height,78px) + env(safe-area-inset-top,0px) + 16px)!important;
    max-height:calc(100dvh - var(--app-support-height,0px) - var(--app-topbar-height,78px) - env(safe-area-inset-top,0px) - 32px);
    box-sizing:border-box;
    overflow-y:auto;
  }
}

/* Audit writing fields share the approved compact text size. */
@media(max-width:700px) {
  body.new-design-ui #view-form .qcard textarea { font-size:var(--ui-compact-control-size,13px); }
  body.new-design-ui #view-form :is(#mandatoryCard,#personelCard) :is(input,select,textarea) { font-size:var(--ui-compact-control-size,13px); }
}

#view-form .qcard .qnote { margin-bottom:var(--ui-field-gap); }
#view-form .qcard .obs-item-header { min-height:var(--ui-field-header-height); margin-bottom:var(--ui-field-header-gap); }
#view-form .qcard .obs-item-remove { width:var(--ui-field-header-height); height:var(--ui-field-header-height); }

/* Writing header and desktop section navigation share the page typography. */
#view-form .form-header { display:grid!important; grid-template-columns:minmax(0,1fr) 44px; align-items:center; gap:16px; }
#view-form .form-header > div { grid-column:1; grid-row:1; min-width:0; display:flex; flex-wrap:wrap; align-items:baseline; gap:6px 16px; }
#view-form .form-header > .ui-back-button { grid-column:2; grid-row:1; justify-self:end; align-self:center!important; margin:0!important; }
#view-form .form-header h2 { font-size:var(--ui-page-title-size); line-height:1.3; overflow-wrap:anywhere; }
#view-form #formMeta { font-family:inherit; font-size:var(--ui-compact-control-size); line-height:1.5; overflow-wrap:anywhere; }
@media(min-width:701px) {
  #view-form .form-header > div { align-items:center; }
  #view-form .nd-audit-steps button { font-size:var(--ui-section-nav-size); font-weight:600; min-height:48px; }
  #view-form .nd-audit-steps button b { font-weight:inherit; }
  #view-form .nd-audit-steps button span { font-family:inherit; font-size:var(--ui-section-nav-number-size); }
}
@media(max-width:700px) {
  #view-form .form-header { grid-template-columns:minmax(0,1fr) 36px; gap:12px; }
  #view-form .form-header h2 { font-size:20px; }
}

/* Matching section icons and compact accordion headings. */
#view-form :is(.nd-step-icon,.nd-panel-icon) { width:var(--ui-section-icon-size); height:var(--ui-section-icon-size); flex:0 0 var(--ui-section-icon-size); fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
#view-form .nd-form-panel > .nd-form-accordion-title { display:flex; align-items:center; gap:8px; font-size:var(--ui-panel-title-size)!important; font-weight:600; line-height:1.35; }
#view-form .nd-form-accordion-title .nd-panel-label { min-width:0; font:inherit; overflow-wrap:anywhere; }
@media(max-width:700px) { #view-form { --ui-panel-title-size:13px; } }

/* One compact header for manager, branch, invoice and KPI PDF previews. */
#view-pdf-preview .module-header { display:grid!important; grid-template-columns:minmax(0,1fr) 44px; align-items:center; gap:12px; padding:14px 16px!important; margin-bottom:14px; border-radius:18px; }
#view-pdf-preview .module-header > div { min-width:0; }
#view-pdf-preview #pdfPreviewTitle { margin:4px 0 0; color:#213b4e; font-family:var(--sans); font-size:var(--ui-preview-title-size); font-weight:600; line-height:1.35; letter-spacing:-.025em; overflow-wrap:anywhere; }
#view-pdf-preview .ui-preview-eyebrow { display:block; color:#7c8f9d; font-size:var(--ui-preview-label-size); font-weight:600; line-height:1.3; letter-spacing:.13em; }
#view-pdf-preview .module-back { align-self:center!important; margin:0!important; }
#view-pdf-preview .pdf-preview-pages { padding:14px; border-radius:18px; }
@media(max-width:700px) {
  #view-pdf-preview { --ui-preview-title-size:18px; }
  #view-pdf-preview .module-header { grid-template-columns:minmax(0,1fr) 36px!important; }
}
