/* ===========================================================================================
   OrNsoft Theme — customer portal (client area)

   Scope: body.customers, i.e. every page the client area serves — the sign-in flow, the
   dashboard, projects, sales documents, support, the knowledge base and the account pages.

   Loaded after ornsoft-tokens (design tokens), ornsoft-ui (the component kit that defines
   every .ons-* class) and ornsoft-perfex (the 1.0.0 adaptation of the core markup), so it may
   rely on all three and wins ties by source order. Where a 1.0.0 rule has to be undone, the
   selector here is made more specific rather than editing ornsoft-perfex.css, which belongs
   to the shell work.

   Contents
     a. 1.0.0 sign-in reset · b. Shell · c. Sign-in flow · d. Page content
     e. Legacy Bootstrap blocks · f. Dark mode · g. Responsive
   =========================================================================================== */


/* -------------------------------------------------------------------------------------------
   a. 1.0.0 SIGN-IN RESET

   1.0.0 turned <body> itself into a two-column grid and painted the night hero with a
   body::before, because the sign-in page was still core markup. Since 1.1.0 the hero is real
   markup inside the page (views/themes/perfex/index.php), so the body-level grid has to go —
   it is what squeezed the form into a narrow column and produced the horizontal scrollbar.
   ------------------------------------------------------------------------------------------- */

body.customers.customers_login.ons-portal,
body.customers.register.ons-portal {
  display: block;
  grid-template-columns: none;
  grid-template-rows: none;
  min-height: 100vh;
  background: var(--bg-surface);
}

body.customers.customers_login.ons-portal::before,
body.customers.register.ons-portal::before {
  content: none;
  display: none;
}

body.customers.customers_login.ons-portal > div,
body.customers.register.ons-portal > div {
  grid-column: auto;
  grid-row: auto;
  align-self: auto;
}

body.customers.customers_login.ons-portal .row > div[class*="col-"],
body.customers.register.ons-portal .row > div[class*="col-"] {
  float: none;
  width: auto;
  max-width: none;
  margin: 0;
}


/* -------------------------------------------------------------------------------------------
   b. SHELL — .ons-app grid: brand cell, topbar, sidebar, main

   The grid itself, the 76px nav rows and the collapsed widths all come from the component kit.
   This block only adds what the kit cannot know about: the collapsed state driven from
   <html class="ons-collapsed"> (set before paint by the module's bootstrap script, so the
   sidebar never flashes open), the portal's own topbar controls, and the sidebar foot.
   ------------------------------------------------------------------------------------------- */

body.ons-portal {
  margin: 0;
  background: var(--bg-page);
  color: var(--fg);
  font-family: var(--ons-font-sans);
  overflow-x: hidden;
}

/* Collapsed sidebar, applied from <html> so it is correct on the first paint. The kit's own
   rules key off .is-collapsed on .ons-app, which ornsoft-portal.js mirrors once it runs. */
html.ons-collapsed body.ons-portal .ons-portal-app {
  grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr);
}

html.ons-collapsed body.ons-portal .ons-brand__full,
html.ons-collapsed body.ons-portal .ons-sidebar__toggle span,
html.ons-collapsed body.ons-portal .ons-nav__text,
html.ons-collapsed body.ons-portal .ons-sidebar__endorse,
html.ons-collapsed body.ons-portal .ons-portal-tenant {
  display: none;
}

html.ons-collapsed body.ons-portal .ons-brand__sym {
  display: block;
}

html.ons-collapsed body.ons-portal .ons-sidebar__toggle {
  justify-content: center;
  padding: 0;
}

html.ons-collapsed body.ons-portal .ons-sidebar__burger {
  width: 100%;
}

html.ons-collapsed body.ons-portal .ons-nav__item {
  min-height: 60px;
}

/* --- brand cell ------------------------------------------------------------------------ */

body.ons-portal .ons-brand__sym {
  display: none;
}

body.ons-portal .ons-brand__sym img {
  height: 32px;
}

/* --- topbar ---------------------------------------------------------------------------- */

body.ons-portal .ons-topbar__title {
  /* The client area passes the page title through $title; keep it from pushing the controls
     off the bar on a long document name. */
  min-width: 0;
  max-width: 52%;
}

body.ons-portal .ons-portal-theme-toggle i {
  font-size: 15px;
}

/* Contact menu. The markup is a Bootstrap dropdown so the platform's own bootstrap.js keeps
   opening and closing it; only the trigger and the panel are restyled. */
body.ons-portal .ons-portal-usermenu {
  position: relative;
}

body.ons-portal .ons-portal-usermenu > .ons-user {
  border: 0;
  background: transparent;
}

body.ons-portal .ons-portal-usermenu > .ons-user:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

body.ons-portal .ons-portal-avatar {
  overflow: hidden;
  padding: 0;
  flex: none;
}

body.ons-portal .ons-portal-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

body.ons-portal .ons-portal-usermenu__caret {
  font-size: 11px;
  color: var(--fg-muted);
}

body.ons-portal .ons-portal-usermenu .dropdown-menu {
  min-width: 232px;
  margin-top: 6px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-lg);
}

body.ons-portal .ons-portal-usermenu .dropdown-menu > li > a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--fg-secondary);
  font-size: var(--fs-sm);
  line-height: 1.3;
  white-space: nowrap;
}

body.ons-portal .ons-portal-usermenu .dropdown-menu > li > a > i {
  width: 16px;
  font-size: 13px;
  text-align: center;
  color: var(--fg-muted);
}

body.ons-portal .ons-portal-usermenu .dropdown-menu > li > a:hover,
body.ons-portal .ons-portal-usermenu .dropdown-menu > li > a:focus {
  background: var(--bg-hover);
  color: var(--fg);
}

body.ons-portal .ons-portal-usermenu .dropdown-menu > li.active > a {
  background: var(--accent-soft);
  color: var(--accent-soft-fg);
}

body.ons-portal .ons-portal-usermenu .dropdown-menu > li.divider {
  height: 1px;
  margin: 6px 4px;
  background: var(--border);
}

body.ons-portal .ons-portal-usermenu .dropdown-menu .badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
}

/* --- sidebar --------------------------------------------------------------------------- */

/* The Files / Calendar pair core renders above the content is a <ul> here so the
   before_/after_customers_area_sub_menu hooks keep firing around it; unwrap it so its links
   sit in the nav column like every other item, including anything a module injected. */
body.ons-portal .ons-nav .ons-portal-subnav,
body.ons-portal .ons-nav .ons-portal-subnav > li {
  display: contents;
  margin: 0;
  padding: 0;
  list-style: none;
}

body.ons-portal .ons-nav .ons-portal-subnav > li > a:not(.ons-nav__item) {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 76px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 13px;
  text-align: center;
  line-height: 1.2;
  text-decoration: none;
}

body.ons-portal .ons-nav .ons-portal-subnav > li > a:not(.ons-nav__item) svg {
  width: 24px;
  height: 24px;
}

body.ons-portal .ons-nav .ons-portal-subnav > li > a:not(.ons-nav__item):hover {
  color: var(--fg);
}

body.ons-portal .ons-sidebar__foot {
  gap: 4px;
  text-align: center;
}

body.ons-portal .ons-portal-tenant {
  max-width: 100%;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--fg-secondary);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

/* --- main column ----------------------------------------------------------------------- */

body.ons-portal .ons-main {
  max-width: 100%;
}

/* The page view is wrapped in a Bootstrap .row so views that still open with col-md-* keep
   laying out and clearing; its negative gutters are cancelled so content lines up with the
   shell padding, and the outermost columns lose the padding that would double it. */
body.ons-portal .ons-portal-view {
  min-width: 0;
}

body.ons-portal .ons-portal-view > .row {
  margin-left: 0;
  margin-right: 0;
}

body.ons-portal .ons-portal-view > .row::before,
body.ons-portal .ons-portal-view > .row::after {
  content: " ";
  display: table;
}

body.ons-portal .ons-portal-view > .row::after {
  clear: both;
}

body.ons-portal .ons-portal-view > .row > [class*="col-"] {
  padding-left: 0;
  padding-right: 0;
}

/* Nothing was injected into the hook-only submenu — do not leave an empty bar behind. */
body.ons-portal .ons-portal-hooks-submenu {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* :empty would not match — PHP leaves whitespace text nodes in the wrapper — so the test is
   on the list items themselves: no module injected anything, no bar. */
body.ons-portal .ons-portal-hooks-submenu:not(:has(> li)) {
  display: none;
}

body.ons-portal .ons-portal-hooks-submenu > li > a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: var(--ctl-h-sm);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--bg-surface);
  color: var(--fg-secondary);
  font-size: var(--fs-sm);
}

body.ons-portal .ons-portal-hooks-submenu > li > a:hover {
  border-color: var(--border-strong);
  color: var(--fg);
}

/* --- page foot ------------------------------------------------------------------------- */

body.ons-portal .ons-portal-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: auto 0 0;
  padding: 20px 0 0;
  height: auto;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--fg-faint);
  font-size: var(--fs-xs);
  text-align: center;
}

body.ons-portal .ons-portal-footer a {
  color: var(--fg-muted);
}

body.ons-portal .ons-portal-footer a:hover {
  color: var(--accent-text);
}

body.ons-portal .ons-portal-footer__sep {
  color: var(--fg-faint);
}

body.ons-portal .ons-portal-footer__endorse {
  font-family: var(--ons-font-mono);
}

/* --- standalone document layout (navigation disabled) ---------------------------------- */

body.ons-portal .ons-portal-doc {
  min-height: 100vh;
  padding: 32px 16px 56px;
  background: var(--bg-page);
}

/* The inner column also carries .ons-main so every rule written for the shell's content
   column — legacy panels, tables, DataTables chrome, images — applies here unchanged. */
body.ons-portal .ons-portal-doc__in {
  width: 100%;
  max-width: var(--content-max, 1100px);
  margin: 0 auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}


/* -------------------------------------------------------------------------------------------
   c. SIGN-IN FLOW (sign in, register, forgot password, reset password)

   Same night hero / form column split as the staff sign-in, with the same .ons-auth* class
   names, so the two pages stay one design. The hero is the only place a gradient is allowed.
   ------------------------------------------------------------------------------------------- */

body.ons-portal .ons-auth {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  min-height: 100vh;
}

body.ons-portal .ons-auth__hero {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
  padding: 48px;
  color: var(--ons-paper, #FAFAF8);
  background-color: var(--ons-night);
  background-image: radial-gradient(120% 90% at 20% 10%,
      color-mix(in oklab, var(--p-shade) 70%, var(--ons-midnight)) 0%,
      var(--ons-midnight) 55%,
      var(--ons-night) 100%);
}

body.ons-portal .ons-auth__logo {
  height: 48px;
  width: auto;
  align-self: flex-start;
}

body.ons-portal .ons-auth__pitch .ons-label {
  display: block;
  color: var(--p-light);
}

body.ons-portal .ons-auth__pitch h1 {
  margin: 12px 0 0;
  max-width: 520px;
  font-size: var(--fs-4xl);
  font-weight: var(--fw-extrabold);
  letter-spacing: -.035em;
  line-height: 1.08;
  color: var(--ons-paper, #FAFAF8);
  text-wrap: balance;
}

body.ons-portal .ons-auth__pitch p {
  margin: 14px 0 0;
  max-width: 440px;
  font-size: var(--fs-md);
  color: var(--ons-mist, #B7BDC9);
}

body.ons-portal .ons-auth__legal {
  font-size: 11px;
  color: var(--ons-slate, #8B93A3);
}

body.ons-portal .ons-auth__form {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: var(--bg-surface);
}

body.ons-portal .ons-auth__in {
  width: 100%;
  max-width: 380px;
}

/* The registration form carries far more fields than the sign-in one. */
body.ons-portal.register .ons-auth__in {
  max-width: 560px;
}

body.ons-portal .ons-auth__card {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

body.ons-portal .ons-auth__intro {
  gap: 6px;
}

body.ons-portal .ons-auth__intro .ons-h2,
body.ons-portal .ons-auth__intro .login-heading {
  margin: 0;
  font-size: var(--fs-2xl);
  font-weight: var(--fw-extrabold);
  letter-spacing: var(--ls-h2);
  color: var(--fg);
  text-align: left;
}

body.ons-portal .ons-auth__intro p {
  margin: 0;
}

body.ons-portal .ons-auth__fields {
  gap: 16px;
}

body.ons-portal .ons-auth__fields .ons-input,
body.ons-portal .ons-auth__fields .ons-select {
  height: 44px;
}

body.ons-portal .ons-auth__fields .ons-btn--lg {
  width: 100%;
}

/* form_error() emits <p class="text-danger alert-validation"> (set in the client-area
   constructor); make it read as the kit's field error. */
body.ons-portal .ons-auth__fields .alert-validation,
body.ons-portal .ons-field > .alert-validation {
  margin: 0;
  font-size: var(--fs-xs);
  color: var(--danger);
}

body.ons-portal .ons-auth__note {
  margin: 0;
  text-align: center;
}

/* reCAPTCHA is a fixed-width iframe; let it shrink rather than widen the column. */
body.ons-portal .ons-auth__fields .g-recaptcha {
  max-width: 100%;
  overflow: hidden;
}

/* Below 980px the hero becomes a band above the form, like the staff sign-in. */
@media (max-width: 980px) {
  body.ons-portal .ons-auth {
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
  }

  body.ons-portal .ons-auth__hero {
    gap: 20px;
    padding: 28px 20px;
  }

  body.ons-portal .ons-auth__logo {
    height: 36px;
  }

  body.ons-portal .ons-auth__pitch h1 {
    font-size: var(--fs-2xl);
  }

  body.ons-portal .ons-auth__pitch p,
  body.ons-portal .ons-auth__legal {
    display: none;
  }

  body.ons-portal .ons-auth__form {
    padding: 28px 16px 48px;
  }
}


/* -------------------------------------------------------------------------------------------
   d. PAGE CONTENT — headings and spacing inside .ons-main
   ------------------------------------------------------------------------------------------- */

body.ons-portal .ons-main h1,
body.ons-portal .ons-main h2,
body.ons-portal .ons-main h3,
body.ons-portal .ons-main h4 {
  color: var(--fg);
}

/* Views that are still core markup open with a bare heading; give it the weight the design
   system uses for a section title instead of the browser default. */
body.ons-portal .ons-portal-view > .row > h3:first-child,
body.ons-portal .ons-portal-view > .row > h4:first-child,
body.ons-portal .ons-portal-view .section-heading {
  margin-top: 0;
}

body.ons-portal .ons-main .ons-empty {
  margin: 0;
}

/* Knowledge base search hero (core template part, rendered above the content). */
body.ons-portal .ons-main .kb-search-wrapper,
body.ons-portal .ons-main .knowledge-base-search {
  padding: 0;
  background: transparent;
}


/* -------------------------------------------------------------------------------------------
   e. LEGACY BOOTSTRAP BLOCKS

   Views that have not been rewritten yet still ship Bootstrap markup. 1.0.0 already moved
   buttons, form controls, badges and panels onto the tokens; what is left here is the layout
   work they need to sit correctly inside the shell — and the tables, which are the one thing
   every remaining client page has.
   ------------------------------------------------------------------------------------------- */

body.ons-portal .ons-main .container,
body.ons-portal .ons-main .container-fluid {
  width: 100%;
  max-width: none;
  padding-left: 0;
  padding-right: 0;
}

body.ons-portal .ons-main .panel_s {
  margin-bottom: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

body.ons-portal .ons-main .panel_s + .panel_s,
body.ons-portal .ons-main .panel_s + .ons-card,
body.ons-portal .ons-main .ons-card + .panel_s {
  margin-top: var(--gap);
}

body.ons-portal .ons-main .panel_s > .panel-body {
  padding: var(--card-pad);
}

/* Tables: mono uppercase headers, numbers tabular, hairline rows, hover highlight. */
body.ons-portal .ons-main table.table > thead > tr > th,
body.ons-portal .ons-main .dataTables_wrapper table > thead > tr > th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-strong);
  font-family: var(--ons-font-mono);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--fg-muted);
  white-space: nowrap;
}

body.ons-portal .ons-main table.table > tbody > tr > td {
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: var(--fs-table);
  color: var(--fg-secondary);
  vertical-align: middle;
}

body.ons-portal .ons-main table.table > tbody > tr:hover > td {
  background: var(--bg-hover);
}

body.ons-portal .ons-main table.table > tbody > tr > td a {
  color: var(--fg);
  font-weight: var(--fw-medium);
}

body.ons-portal .ons-main table.table > tbody > tr > td a:hover {
  color: var(--accent-text);
}

/* DataTables chrome: search box, length menu, info line and pager. */
body.ons-portal .ons-main .dataTables_wrapper .dataTables_filter input,
body.ons-portal .ons-main .dataTables_wrapper .dataTables_length select {
  height: var(--ctl-h-sm);
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--bg-surface);
  color: var(--fg);
  font-size: var(--fs-sm);
}

body.ons-portal .ons-main .dataTables_wrapper .dataTables_info,
body.ons-portal .ons-main .dataTables_wrapper .dataTables_length,
body.ons-portal .ons-main .dataTables_wrapper .dataTables_filter {
  color: var(--fg-muted);
  font-size: var(--fs-sm);
}

body.ons-portal .ons-main .dataTables_wrapper .dataTables_paginate .paginate_button {
  min-width: 32px;
  height: 32px;
  margin: 0 2px;
  padding: 0 8px;
  border: 1px solid var(--border) !important;
  border-radius: var(--r-md) !important;
  background: var(--bg-surface) !important;
  color: var(--fg-secondary) !important;
  font-size: var(--fs-sm);
  line-height: 30px;
}

body.ons-portal .ons-main .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--bg-hover) !important;
  color: var(--fg) !important;
}

body.ons-portal .ons-main .dataTables_wrapper .dataTables_paginate .paginate_button.current {
  border-color: var(--accent) !important;
  background: var(--accent-soft) !important;
  color: var(--accent-soft-fg) !important;
  font-weight: var(--fw-semibold);
}

body.ons-portal .ons-main .dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
  opacity: .45;
}

/* A table wider than the column scrolls inside its own box — never the page. */
body.ons-portal .ons-main .table-responsive,
body.ons-portal .ons-main .dataTables_wrapper {
  max-width: 100%;
  overflow-x: auto;
}

/* Core alerts inside the content column. */
body.ons-portal .ons-main .alert {
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
}

/* Announcements banner. */
body.ons-portal .ons-portal-announcements {
  gap: 12px;
}

body.ons-portal .ons-portal-announcement__body {
  flex: 1;
  min-width: 0;
}

body.ons-portal .ons-portal-announcement__meta {
  margin: 2px 0 6px;
}

body.ons-portal .ons-portal-announcement__body .announcement-message p:last-child {
  margin-bottom: 0;
}

body.ons-portal .ons-portal-announcement__close {
  flex: none;
  opacity: 1;
  color: var(--fg-muted);
  text-shadow: none;
  font-size: 14px;
}

body.ons-portal .ons-portal-announcement__close:hover {
  color: var(--fg);
}

/* Charts drawn on a canvas (client dashboard) must not overflow their card. */
body.ons-portal .ons-main canvas {
  max-width: 100%;
}

/* Images inside knowledge-base articles and ticket messages. */
body.ons-portal .ons-main img {
  max-width: 100%;
  height: auto;
}


/* -------------------------------------------------------------------------------------------
   f. DARK MODE — the leftovers 1.0.0 could not reach in the portal shell
   ------------------------------------------------------------------------------------------- */

[data-theme="dark"] body.ons-portal .ons-brand,
[data-theme="dark"] body.ons-portal .ons-sidebar,
[data-theme="dark"] body.ons-portal .ons-topbar {
  background: var(--bg-sidebar);
}

[data-theme="dark"] body.ons-portal .ons-main .panel_s {
  background: var(--bg-surface);
  border-color: var(--border);
}

[data-theme="dark"] body.ons-portal .ons-main .dataTables_wrapper .dataTables_paginate .paginate_button {
  background: var(--bg-surface) !important;
}


/* -------------------------------------------------------------------------------------------
   g. RESPONSIVE

   The component kit already narrows the sidebar to icons below 860px. What is left is keeping
   the topbar usable on a phone and making sure nothing forces a horizontal scrollbar — the
   defect the sign-in page shipped with in 1.0.0.
   ------------------------------------------------------------------------------------------- */

@media (max-width: 1100px) {
  body.ons-portal .ons-topbar__title {
    max-width: 44%;
  }
}

@media (max-width: 860px) {
  html.ons-collapsed body.ons-portal .ons-portal-app,
  body.ons-portal .ons-portal-app {
    grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr);
  }

  body.ons-portal .ons-nav__text,
  body.ons-portal .ons-sidebar__toggle span,
  body.ons-portal .ons-brand__full,
  body.ons-portal .ons-portal-tenant,
  body.ons-portal .ons-user__txt,
  body.ons-portal .ons-portal-usermenu__caret {
    display: none;
  }

  body.ons-portal .ons-brand__sym {
    display: block;
  }

  body.ons-portal .ons-topbar {
    gap: 8px;
    padding: 0 12px;
  }

  body.ons-portal .ons-topbar__title {
    max-width: none;
    font-size: var(--fs-lg);
  }

  body.ons-portal .ons-topbar__right {
    gap: 6px;
  }

  body.ons-portal .ons-portal-usermenu .dropdown-menu {
    /* Bootstrap right-aligns it; keep it inside the viewport on a narrow screen. */
    max-width: calc(100vw - 24px);
  }

  body.ons-portal .ons-portal-doc {
    padding: 20px 12px 40px;
  }
}

@media (max-width: 560px) {
  body.ons-portal .ons-main {
    padding: 16px 12px 40px;
  }
}


/* -------------------------------------------------------------------------------------------
   h. DOCUMENT VIEWS (invoice, estimate, contract, proposal, subscription, consent)

   These pages are opened from an emailed link, by a recipient who may not be signed in, so
   the platform renders them with the navigation disabled and they land in .ons-portal-doc.
   Their markup already carries a [data-sticky] header the core script pins to the top of the
   viewport — it becomes the design system's sticky action bar here, so the download, pay and
   back controls stay reachable however long the document is.
   ------------------------------------------------------------------------------------------- */

body.ons-portal .ons-portal-doc .preview-top-wrapper {
  margin-top: 0;
}

body.ons-portal .ons-portal-doc .invoice-html-logo img,
body.ons-portal .ons-portal-doc .estimate-html-logo img,
body.ons-portal .ons-portal-doc .contract-html-logo img {
  max-height: 44px;
  width: auto;
}

body.ons-portal .ons-portal-doc .preview-top-wrapper .top {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

/* Pinned state: the core script swaps in this class when the bar reaches the top. */
body.ons-portal .ons-portal-doc .preview-sticky-header {
  z-index: 30;
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  border-top: 0;
  box-shadow: var(--shadow-md);
}

body.ons-portal .ons-portal-doc .invoice-html-number,
body.ons-portal .ons-portal-doc .estimate-html-number,
body.ons-portal .ons-portal-doc .proposal-html-number {
  font-family: var(--ons-font-mono);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  letter-spacing: -.01em;
  color: var(--accent-text);
}

/* The overdue / expired notice reads before the document itself. */
body.ons-portal .ons-portal-doc .alert-danger,
body.ons-portal .ons-portal-doc .alert-warning {
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
}

/* Totals block: tabular figures, and the grand total carried by weight, not colour. */
body.ons-portal .ons-portal-doc .invoice-html-total,
body.ons-portal .ons-portal-doc .subtotal,
body.ons-portal .ons-portal-doc .total {
  font-variant-numeric: tabular-nums;
}


/* -------------------------------------------------------------------------------------------
   i. CONTENT DETAILS

   Small adjustments the component kit cannot make on its own, because the platform decides
   what goes inside: photos the helpers render as <img>, and the tabs / progress bars the core
   partials still emit (both already on the tokens in ornsoft-perfex.css — nothing to redo).
   ------------------------------------------------------------------------------------------- */

/* staff_profile_image() and contact_profile_image_url() return an <img>; let it fill the
   avatar circle instead of sitting inside it as a letterbox. */
body.ons-portal .ons-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

body.ons-portal .ons-avatar:has(img) {
  padding: 0;
  overflow: hidden;
}

/* An .ons-badge whose colours come from a status record (project, ticket, invoice) is painted
   inline by the view from the database value; keep the shape rules from fighting it. */
body.ons-portal .ons-main .ons-badge[style] {
  background-clip: padding-box;
}


/* -------------------------------------------------------------------------------------------
   j. FILE INPUTS

   A native <input type="file"> paints its own button from the operating system, so it stays
   light grey whatever the page does — it was the one control left clashing with the dark
   theme (profile picture, ticket attachments, project files). ::file-selector-button lets the
   button itself move onto the tokens, so the control is fixed everywhere at once without
   touching the markup the platform's upload handlers rely on.
   ------------------------------------------------------------------------------------------- */

body.ons-portal input[type="file"] {
  display: block;
  width: 100%;
  min-height: var(--ctl-h);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--bg-surface);
  color: var(--fg-secondary);
  font-family: inherit;
  font-size: var(--fs-sm);
  line-height: calc(var(--ctl-h) - 2px);
  cursor: pointer;
}

body.ons-portal input[type="file"]:hover {
  border-color: var(--fg-faint);
}

body.ons-portal input[type="file"]:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

/* The button inside the control, as a secondary .ons-btn. */
body.ons-portal input[type="file"]::file-selector-button {
  height: calc(var(--ctl-h) - 2px);
  margin: 0 12px 0 0;
  padding: 0 14px;
  border: 0;
  border-right: 1px solid var(--border);
  border-radius: calc(var(--r-md) - 1px) 0 0 calc(var(--r-md) - 1px);
  background: var(--bg-subtle);
  color: var(--fg);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

body.ons-portal input[type="file"]:hover::file-selector-button {
  background: var(--bg-hover);
}

body.ons-portal input[type="file"]:disabled,
body.ons-portal input[type="file"]:disabled::file-selector-button {
  opacity: .55;
  cursor: not-allowed;
}

/* RTL: the button sits on the trailing edge instead. */
body.ons-portal[dir="rtl"] input[type="file"]::file-selector-button {
  margin: 0 0 0 12px;
  border-right: 0;
  border-left: 1px solid var(--border);
  border-radius: 0 calc(var(--r-md) - 1px) calc(var(--r-md) - 1px) 0;
}
