/* Assessment geometry only. Colours, exercise content and timing remain in
   the original stylesheet and runtime. Loaded after the assessment styles. */

html,
body {
  max-width: 100%;
}

#sc-app.active {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  max-width: 100%;
  overflow: hidden;
}

#sc-app > .topbar {
  position: relative;
  flex: 0 0 auto;
  min-width: 0;
  gap: .45rem .8rem;
}

#sc-app .brandmark {
  min-width: 0;
}

#sc-app #whoami {
  flex: 0 1 20rem;
  min-width: 0;
  max-width: 20rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#sc-app #save-status {
  min-width: 0;
  overflow-wrap: anywhere;
}

#sc-app .timer,
#sc-app #themebtn {
  flex: 0 0 auto;
  white-space: nowrap;
}

#sc-app > .layout {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  align-items: stretch;
  overflow: hidden;
}

#sc-app .nav {
  flex: 0 0 232px;
  width: 232px;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

#mainarea {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-bottom: 1.5rem;
  -webkit-overflow-scrolling: touch;
  container-type: size;
}

.view,
.split > *,
.pagehead > *,
.card,
.linebox,
.notice,
.doc,
fieldset {
  min-width: 0;
}

.pagehead p,
.kv dt,
.kv dd,
.doc .meta dt,
.doc .meta dd,
.doc .addr,
.notice,
.policy,
.radio-row label {
  overflow-wrap: anywhere;
}

.grid2 {
  grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr));
}

.kv,
.doc .meta {
  grid-template-columns: fit-content(40%) minmax(0, 1fr);
}

/* Each long table owns both scroll axes. This makes the existing sticky
   column headings stick to the table viewport instead of leaving the page. */
.tablewrap {
  position: relative;
  isolation: isolate;
  min-width: 0;
  max-width: 100%;
  max-height: min(38rem, 65vh);
  max-height: min(38rem, 65dvh);
  overflow: auto;
  overscroll-behavior: contain;
  scroll-padding-top: 4rem;
  -webkit-overflow-scrolling: touch;
}

.tablewrap thead th {
  top: 0;
}

/* Bound tables by the actual content pane, including wrapped header controls.
   The viewport cap above remains the fallback for introductory screens. */
#sc-app .tablewrap {
  max-height: min(38rem, calc(100cqh - 1rem));
}

.tablewrap tbody button,
.tablewrap tbody a {
  scroll-margin-top: 4rem;
}

#v-billing .tablewrap > table {
  min-width: 78rem;
}

#v-purchases .tablewrap > table {
  min-width: 56rem;
}

#v-coa .tablewrap > table {
  min-width: 36rem;
}

/* Contacts has one table at a time: keep its heading and tabs visible while
   the table fills the rest of the main pane, including short viewports. */
#v-contacts.active {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

#v-contacts > h1,
#v-contacts > .tabs {
  flex: 0 0 auto;
}

#v-contacts > [role="tabpanel"]:not([hidden]) {
  display: flex;
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
}

#v-contacts > [role="tabpanel"] > .tablewrap {
  flex: 1 1 0;
  min-height: 0;
  max-height: none;
}

/* Source documents can contain wide invoice lines. Keep their horizontal
   scrolling local too, without clipping the figures on a phone. */
.doc {
  max-width: min(720px, 100%);
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.doc > table {
  min-width: 24rem;
}

.doc.receipt > table {
  min-width: 18rem;
}

.modal {
  padding: max(.75rem, env(safe-area-inset-top))
    max(.75rem, env(safe-area-inset-right))
    max(.75rem, env(safe-area-inset-bottom))
    max(.75rem, env(safe-area-inset-left));
  overflow: hidden;
}

.modal .box {
  min-width: 0;
  max-height: calc(100vh - 1.5rem);
  max-height: calc(100dvh - max(.75rem, env(safe-area-inset-top)) - max(.75rem, env(safe-area-inset-bottom)));
  overflow: auto;
  overscroll-behavior: contain;
  overflow-wrap: anywhere;
  -webkit-overflow-scrolling: touch;
}

.modal .box > p:last-child {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

@media (max-width: 820px) {
  #pc1 .tablewrap > table {
    min-width: 76rem;
  }

  #pc2 .tablewrap > table {
    min-width: 42rem;
  }

  #sc-app > .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: .25rem .6rem;
    padding: .5rem .75rem;
  }

  #sc-app .topbar > .spacer {
    display: none;
  }

  #sc-app .brandmark {
    grid-column: 1;
    grid-row: 1;
  }

  #sc-app #brandname {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  #sc-app #timer {
    grid-column: 2;
    grid-row: 1;
  }

  #sc-app #themebtn {
    grid-column: 3;
    grid-row: 1;
  }

  #sc-app #whoami {
    grid-column: 1 / -1;
    grid-row: 2;
    max-width: 100%;
    font-size: .78rem;
  }

  #sc-app #save-status {
    grid-column: 1 / 3;
    grid-row: 3;
    max-width: 100%;
    font-size: .75rem;
  }

  #sc-app #focuslabel {
    grid-column: 3;
    grid-row: 3;
    justify-self: end;
    align-self: start;
    font-size: .72rem;
  }

  #sc-app > .layout {
    flex-direction: column;
  }

  #sc-app .nav {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: .25rem;
    width: 100%;
    padding: .45rem .6rem;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-gutter: auto;
    scrollbar-width: thin;
    scroll-padding-inline: .6rem;
  }

  #sc-app .nav h2 {
    display: none;
  }

  #sc-app .nav a {
    flex: 0 0 auto;
    white-space: nowrap;
    font-size: .86rem;
    padding: .5em .65em;
  }

  #mainarea {
    padding: 1rem;
  }

  .card,
  .doc {
    padding: 1rem;
  }
}

@media (max-width: 420px) {
  #sc-app > .topbar {
    gap: .25rem .45rem;
  }

  #sc-app .brandmark {
    gap: .35rem;
    font-size: .9rem;
  }

  #sc-app #themebtn {
    font-size: .78rem;
  }

  #sc-app #timer {
    font-size: 1rem;
    padding-inline: .5em;
  }

  #mainarea {
    padding: .75rem;
  }

  .card,
  .doc,
  .modal .box {
    padding: .85rem;
  }
}

@media (max-width: 820px) and (max-height: 500px) {
  #mainarea {
    padding: .5rem .75rem;
  }

  #v-contacts.active {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: .375rem .75rem;
  }

  #v-contacts > h1 {
    margin: 0;
    align-self: center;
    font-size: 1.05rem;
  }

  #v-contacts > .tabs {
    min-width: 0;
    margin: 0;
  }

  #v-contacts > .tabs button {
    padding: .4em .65em;
    font-size: .8rem;
  }

  #v-contacts > [role="tabpanel"]:not([hidden]) {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

@media print {
  #sc-app.active,
  #sc-app > .layout,
  #mainarea,
  #v-contacts.active,
  #v-contacts > [role="tabpanel"]:not([hidden]) {
    display: block;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
  }

  #mainarea {
    padding: 0;
    container-type: normal;
  }

  .tablewrap,
  #sc-app .tablewrap,
  #v-contacts > [role="tabpanel"] > .tablewrap,
  .doc {
    height: auto;
    max-height: none;
    overflow: visible;
    break-inside: auto;
  }

  #sc-app .tablewrap > table,
  .doc > table,
  .doc.receipt > table {
    min-width: 0;
    width: 100%;
  }

  .tablewrap th,
  .tablewrap td {
    min-width: 0;
    padding: .3em .35em;
    font-size: 8pt;
    overflow-wrap: anywhere;
  }

  .tablewrap .nowrap {
    white-space: normal;
  }

  .gridtable td.acttd,
  .gridtable td:nth-child(12),
  .gridtable th:nth-child(12) {
    min-width: 0;
  }

  .tablewrap thead th,
  .gridtable thead th:last-child,
  .gridtable td:last-child {
    position: static;
    box-shadow: none;
  }

  .tablewrap thead {
    display: table-header-group;
  }

  .modal {
    display: none !important;
  }
}
