/* ==========================================================================
   Digital Aflevering: the portal's own styles
   ==========================================================================

   normalize.css (loaded first) is the stock base; this file is the design:
   tokens, page layout and components. Form controls are in forms.css.

   Accessibility, built in throughout:
   - Text contrast at least 4.5:1, control borders at least 3:1, on every
     surface the token is used on.
   - Focus is always visible: a yellow fill or ring with a dark edge, shown
     for keyboard use (:focus-visible), on any background.
   - Touch targets at least 44 px; text reflows at 320 px and 200 % zoom.
   - Status is never colour alone: badges always carry their label, and the
     status colours also differ in lightness.
   - Honours prefers-reduced-motion and Windows' forced colours; prints well.
   - System fonts only: nothing is fetched from a third party.
*/

/* --- The portal's own parts stay visible ---------------------------------- */

/* Whatever a Form's look says (docs/adr/0016, 0028): the login menu, the skip link,
   the accessibility statement, the alerts and the form can be restyled, never
   hidden. Important declarations in the first cascade layer outrank every
   later stylesheet's, layered or not, whatever their specificity, so this
   layer is declared before anything else. [hidden] stays the portal's own way
   to hide one of them when it means to, and printing (below) is left alone. */
@layer portal-protect;

@layer portal-protect {
@media screen {
  .skip-link,
  .header-login,
  .user-menu,
  .user-menu summary,
  .user-menu[open] .user-menu-items,
  .user-menu-items li,
  .footer-inner,
  .footer-inner p,
  form.submission,
  form.submission [data-answers],
  .file-chooser:not([hidden]),
  .upload-list,
  .finalize,
  [data-finalize]:not([hidden]),
  [data-stop]:not([hidden]),
  [data-sending]:not([hidden]),
  [data-upload-summary],
  .error-summary:not([hidden]),
  [data-uploader-alert]:not([hidden]),
  .field-error:not([hidden]) {
    visibility: visible !important;
    opacity: 1 !important;
    clip-path: none !important;
    filter: none !important;
    content-visibility: visible !important;
  }

  .header-login,
  .user-menu summary,
  .footer-inner,
  .finalize { display: flex !important; }

  .user-menu { display: block !important; }
  .user-menu[open] .user-menu-items { display: block !important; }

  form.submission { display: block !important; }
  .file-chooser:not([hidden]) { display: flex !important; }

  [data-finalize]:not([hidden]),
  [data-stop]:not([hidden]) { display: inline-flex !important; }
}
}

/* --- Tokens ---------------------------------------------------------------- */

:root {
  --ink: #16202b;          /* text: 16:1 on white */
  --muted: #4b5866;        /* secondary text: 7.3:1 on white, 6.7:1 on surface */
  --accent: #0b5394;       /* links, primary buttons: 7.4:1 on white */
  --accent-dark: #083c6c;  /* hover */
  --accent-soft: #e8f0f9;  /* info banners, menu hover */
  --ground: #ffffff;
  --surface: #f4f6f8;      /* table heads, footer, panels */
  --surface-alt: #fafbfc;  /* every second table row */
  --line: #d5dbe1;         /* dividers */
  --line-strong: #8a96a3;  /* control borders: 3.1:1 on white */
  --focus: #ffbf47;

  --ok: #1d6b3a;           /* 6.6:1 on its soft tint */
  --ok-soft: #e3f1e8;
  --warn: #8a4b00;         /* 5.9:1 on its soft tint */
  --warn-soft: #fdf0dc;
  --err: #b3261e;          /* 6.2:1 on white */
  --err-soft: #fbe7e5;
  --neutral: #2c3743;
  --neutral-soft: #eef1f4;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 6px;
  --radius-lg: 8px;
  --page: 72rem;
  --gutter: 1.5rem;
}

@media (max-width: 40em) {
  :root { --gutter: 1rem; }
}

/* --- Base ------------------------------------------------------------------ */

html {
  color: var(--ink);
  background: var(--ground);
  font-family: var(--font);
  font-size: 100%;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Keep the footer at the bottom of a short page; a long one pushes it down. */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  font-size: 1.0625rem;  /* 17 px */
}

::selection {
  background: var(--accent-soft);
  color: var(--ink);
}

h1, h2, h3 {
  margin: 0 0 .5em;
  line-height: 1.2;
  font-weight: 700;
}

h1 { font-size: clamp(1.75rem, 1.4rem + 1.5vw, 2.25rem); }
h2 { font-size: clamp(1.3rem, 1.2rem + .5vw, 1.5rem); margin-top: 2rem; }
h3 { font-size: 1.2rem; margin-top: 1.5rem; }

p, ul, ol, dl, table, pre, fieldset {
  margin-top: 0;
  margin-bottom: 1rem;
}

/* Readable line lengths for running text. */
main p, main li { max-width: 70ch; }

a {
  color: var(--accent);
  text-decoration-thickness: max(1px, .0625em);
  text-underline-offset: .15em;
}

a:hover { color: var(--accent-dark); text-decoration-thickness: .125em; }

code, pre, kbd, samp { font-family: var(--mono); font-size: .9em; }

code {
  overflow-wrap: anywhere;
  padding: .1em .3em;
  border-radius: 4px;
  background: var(--surface);
}

img, svg, video { max-width: 100%; height: auto; }

/* --- Focus ------------------------------------------------------------------ */

/* One look everywhere: yellow with a dark edge, readable on white, blue or grey. */
:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 0;
  box-shadow: 0 0 0 6px var(--focus);
}

a:focus-visible {
  outline: none;
  color: var(--ink);
  background: var(--focus);
  box-shadow: 0 -2px var(--focus), 0 4px var(--ink);
  text-decoration: none;
}

/* Where the page moves focus itself (the skip link's target, an error summary). */
[tabindex="-1"]:focus { outline: none; box-shadow: none; }

/* --- Skip link ----------------------------------------------------------- */

.skip-link {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 100;
  padding: .75rem 1rem;
  background: var(--focus);
  color: var(--ink);
  font-weight: 700;
  transform: translateY(-120%);
}

.skip-link:focus,
.skip-link:focus-visible { transform: none; }

/* --- Page layout --------------------------------------------------------- */

.page-width {
  width: 100%;
  max-width: var(--page);
  margin-inline: auto;
  padding-inline: var(--gutter);
  box-sizing: border-box;
}

.site-header {
  /* background: var(--ground); */
  background: #0a54977d;
  border-bottom: 4px solid var(--accent);
}

/* A Form's preview: what contrast-check.js found too faint to read. */
.contrast-warning { outline: 3px dashed #b00020 !important; outline-offset: 2px; }
.preview-banner ul { margin-block: .5rem 0; }

/* A Form's own header and footer (docs/adr/0028) take the logo's and the © line's place. */
.look-header { flex: 1 1 auto; min-width: 0; }
.look-footer { flex: 1 1 100%; }

.header-inner {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1rem;
  justify-content: space-between;
  align-items: center;
  padding-block: .75rem;
}

.site-title {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 44px;
  color: var(--ink);
  font-size: 1.1875rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-decoration: none;
  text-transform: uppercase;
}

.site-title:hover { color: var(--ink); text-decoration: underline; }

.site-title img { width: 32px; height: 32px; flex: 0 0 auto; }

@media (max-width: 30em) {
  .site-title { font-size: .95rem; gap: .5rem; }
  .site-title img { width: 28px; height: 28px; }
}

main {
  flex: 1 0 auto;
  padding-block: 2.5rem 4rem;
}

main > :first-child { margin-top: 0; }

.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .9375rem;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 2rem;
  padding-block: 1.5rem;
}

.footer-inner p { margin: 0; }

/* --- Header: login and the user menu ------------------------------------ */

.header-login {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.header-login form { margin: 0; }

/* The logged-in name opens a menu (a <details>: it works without JavaScript). */
.user-menu { position: relative; }

.user-menu summary {
  display: flex;
  align-items: center;
  gap: .6rem;
  max-width: 16rem;
  min-height: 44px;
  padding: 0 .875rem 0 1rem;
  box-sizing: border-box;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.user-menu summary::-webkit-details-marker { display: none; }

.user-menu-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The arrow: points down closed, up open. */
.user-menu summary::after {
  content: "";
  flex: 0 0 auto;
  width: .45rem;
  height: .45rem;
  margin-top: -.25rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.user-menu[open] summary::after { margin-top: .2rem; transform: rotate(-135deg); }

.user-menu summary:hover { border-color: var(--ink); }

.user-menu-items {
  position: absolute;
  right: 0;
  top: calc(100% + .4rem);
  z-index: 10;
  width: max-content;
  min-width: 14rem;
  max-width: calc(100vw - 2 * var(--gutter));
  margin: 0;
  padding: .375rem 0;
  list-style: none;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgb(22 32 43 / 14%);
}

.user-menu-items li { max-width: none; }

/* Logging out sits apart from the pages; on its own (a Citizen's menu), there's nothing to set it apart from. */
.user-menu-items li:last-child:not(:only-child) {
  margin-top: .375rem;
  padding-top: .375rem;
  border-top: 1px solid var(--line);
}

.user-menu-items a,
.user-menu-items button {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: .625rem 1.125rem;
  box-sizing: border-box;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  font-weight: 400;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  box-shadow: none;
}

.user-menu-items a:hover,
.user-menu-items button:hover { background: var(--accent-soft); color: var(--ink); }

.user-menu-items a:focus-visible,
.user-menu-items button:focus-visible {
  outline: none;
  background: var(--focus);
  color: var(--ink);
  box-shadow: inset 0 -4px var(--ink);
}

/* --- Messages --------------------------------------------------------------- */

.banner {
  max-width: none;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  background: var(--accent-soft);
}

/* The warning before a Citizen's login ends for inactivity (main.js). */
.session-warning {
  max-width: min(32rem, calc(100vw - 2rem));
  padding: 1.5rem;
  border: 2px solid var(--accent);
  border-radius: var(--radius-lg);
  background: #fff;
  color: var(--ink);
}
.session-warning::backdrop { background: rgb(0 0 0 / .5); }
.session-warning h2 { margin-top: 0; }

/* A page's own errors (admin), and the alert-style banners. */
.error,
.banner[role="alert"] {
  padding: .875rem 1.125rem;
  border: 2px solid var(--err);
  border-radius: var(--radius-lg);
  background: var(--ground);
  color: var(--ink);
  white-space: pre-line;
}

/* The citizen Form's summary of every error, each linking to its field. */
.error-summary {
  margin-bottom: 2rem;
  padding: 1.125rem 1.25rem;
  border: 3px solid var(--err);
  border-radius: var(--radius-lg);
}

.error-summary > p:first-child {
  margin-bottom: .5rem;
  font-size: 1.1875rem;
  font-weight: 700;
}

.error-summary ul { margin: 0; padding: 0; list-style: none; }
.error-summary li { margin-top: .25rem; }
.error-summary a { color: var(--err); font-weight: 600; }
.error-summary a:focus-visible { color: var(--ink); }

/* --- Status badges ------------------------------------------------------ */

.status {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .2rem .75rem;
  border-radius: 999px;
  background: var(--neutral-soft);
  color: var(--neutral);
  font-size: .9375rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.status::before {
  content: "";
  flex: 0 0 auto;
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  background: currentColor;
}

.status-released, .status-active { background: var(--ok-soft); color: var(--ok); }
.status-needs_review { background: var(--warn-soft); color: var(--warn); }
.status-quarantined { background: var(--err-soft); color: var(--err); }
.status-erased { background: var(--ink); color: var(--ground); }

td .status { font-size: .875rem; }

/* --- Tables ---------------------------------------------------------------- */

/* Wide tables scroll inside their own box, never the whole page. */
.table-wrap {
  max-width: 100%;
  margin-bottom: 1.5rem;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.table-wrap:focus-visible { box-shadow: 0 0 0 6px var(--focus); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
}

.table-wrap table { margin: 0; }

th, td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

thead th {
  background: var(--surface);
  font-weight: 700;
  white-space: nowrap;
}

tbody tr:nth-child(even) { background: var(--surface-alt); }
tbody tr:last-child > * { border-bottom: 0; }

td.number, th.number { text-align: right; font-variant-numeric: tabular-nums; }

/* The last column holds a row's actions, set to the right. */
td:last-child:has(> a, > form) { text-align: right; white-space: nowrap; }
td > form { display: inline; margin: 0 0 0 .5rem; }

/* --- Definition lists: answers and a Submission's details -------------------- */

main dl {
  display: grid;
  grid-template-columns: minmax(9rem, 16rem) minmax(0, 1fr);
  max-width: 56rem;
  border-top: 1px solid var(--line);
}

main dt,
main dd {
  margin: 0;
  padding: .625rem 0;
  border-bottom: 1px solid var(--line);
}

main dt { padding-right: 1rem; font-weight: 600; }
main dd { overflow-wrap: anywhere; }

@media (max-width: 40em) {
  main dl { display: block; }
  main dt { padding-bottom: 0; border-bottom: 0; color: var(--muted); font-weight: 400; font-size: .9375rem; }
  main dd { padding-top: 0; font-weight: 600; }
}

/* --- Pagination, back links --------------------------------------------- */

.pagination {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
}

.pagination a { min-width: 8rem; }

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-weight: 600;
}

.back-link::before { content: "← "; white-space: pre; }

/* Heading with an action beside it, such as "Ny formular". */
.page-heading {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.page-heading h1 { margin: 0; }

/* --- Citizen pages -------------------------------------------------------- */

.page-intro { max-width: 46rem; margin-bottom: 2rem; }
.page-intro p { margin-bottom: .5rem; }


/* The Receipt's confirmation. */
.confirmation {
  max-width: 56rem;
  margin-bottom: 1.5rem;
  padding: 1.75rem 2rem;
  border-radius: var(--radius-lg);
  background: var(--ok);
  color: #ffffff;
}

.confirmation h1 { margin-bottom: .75rem; }
.confirmation p { margin-bottom: .5rem; }
.confirmation .reference { margin: 0; font-size: 1.375rem; font-weight: 700; }

.keep-receipt {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1.25rem;
  align-items: center;
  max-width: 56rem;
  padding: 1.25rem;
  box-sizing: border-box;
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.keep-receipt p { flex: 1 1 20rem; margin: 0; }

/* --- The uploader (upload.js) -------------------------------------------- */

.uploader { max-width: 46rem; }

.file-chooser {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .5rem;
  margin-bottom: 1rem;
  padding: 1.5rem;
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-alt);
}

.file-chooser label { font-weight: 600; }
.file-chooser input[type="file"] { max-width: 100%; font: inherit; font-size: 1rem; }

[data-upload-summary] { margin-bottom: .5rem; font-weight: 600; }

.upload-list {
  margin: 0 0 1.5rem;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.upload-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .375rem 1rem;
  align-items: center;
  max-width: none;
  padding: .875rem 0;
  border-bottom: 1px solid var(--line);
}

.upload-name { font-weight: 600; overflow-wrap: anywhere; }
.upload-size { margin-left: .5rem; color: var(--muted); font-weight: 400; }

.upload-actions { display: flex; gap: .25rem; }

.upload-actions button {
  min-height: 44px;
  padding: 0 .75rem;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 1rem;
  text-decoration: underline;
  text-underline-offset: .15em;
}

.upload-actions button:hover { color: var(--accent-dark); background: none; }

.upload-progress {
  grid-column: 1 / -1;
  width: 100%;
  height: .625rem;
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: #e3e8ed;
  color: var(--accent);
  overflow: hidden;
}

.upload-progress::-webkit-progress-bar { background: #e3e8ed; border-radius: 999px; }
.upload-progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
.upload-progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

.upload-status { grid-column: 1 / -1; color: var(--muted); font-size: .9375rem; }

/* Each File's state, set by upload.js; the status text always says it too. */
.upload-list li[data-state="uploaded"] .upload-status { color: var(--ok); font-weight: 600; }
.upload-list li[data-state="uploaded"] .upload-progress::-webkit-progress-value { background: var(--ok); }
.upload-list li[data-state="uploaded"] .upload-progress::-moz-progress-bar { background: var(--ok); }
.upload-list li[data-state="missing"] .upload-progress::-webkit-progress-value { background: var(--line-strong); }
.upload-list li[data-state="missing"] .upload-progress::-moz-progress-bar { background: var(--line-strong); }

.upload-list li[data-state="failed"],
.upload-list li[data-state="refused"] {
  margin-block: .5rem;
  padding-inline: 1rem;
  border: 2px solid var(--err);
  border-radius: var(--radius-lg);
}

.upload-list li[data-state="failed"] .upload-status,
.upload-list li[data-state="refused"] .upload-status { color: var(--err); font-weight: 600; }
.upload-list li[data-state="refused"] .upload-progress { display: none; }

/* While sending: the reminder and the overall progress. */
.sending { max-width: 46rem; }
.sending .banner { margin-bottom: .75rem; font-weight: 600; }

.overall-progress {
  width: 100%;
  height: 1rem;
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: #e3e8ed;
  color: var(--accent);
  overflow: hidden;
}

.overall-progress::-webkit-progress-bar { background: #e3e8ed; border-radius: 999px; }
.overall-progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
.overall-progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

[data-upload-summary] { max-width: 46rem; }

/* Chosen, not sent yet: no progress to show. */
.upload-list li[data-state="chosen"] .upload-progress { display: none; }

.finalize {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1rem;
  align-items: center;
}

.finalize p { margin: 0; color: var(--muted); font-size: .9375rem; }

.session-discard {
  max-width: 46rem;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

/* --- Admin: a User's dashboard ------------------------------------------------ */

.dashboard-card {
  margin-block: 1.5rem;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.dashboard-card h2 { margin-top: 0; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  column-gap: 1.5rem;
}

.dashboard-grid .dashboard-card { margin-block: 0 1.5rem; }

.task-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }

/* --- Admin: review --------------------------------------------------------- */

.review-panel {
  max-width: 56rem;
  margin-block: 2rem;
  padding: 1.5rem 1.75rem;
  border: 2px solid var(--warn);
  border-radius: var(--radius-lg);
}

.review-panel h2 { margin-top: 0; }

.review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: flex-end;
}

.review-actions form { margin: 0; }

.review-reject {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  padding-left: 1.5rem;
  border-left: 1px solid var(--line);
}

@media (max-width: 40em) {
  .review-panel { padding: 1.25rem; }
  .review-reject { padding-left: 0; border-left: 0; }
}

.decisions { padding-left: 1.25rem; }

/* Links side by side, such as a Submission's answers in each format. */
.inline-links { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; padding: 0; list-style: none; }

/* Version history and the FormTemplate source. */
.template-source {
  width: 100%;
  min-height: 24rem;
  font-family: var(--mono);
  font-size: .9375rem;
  line-height: 1.5;
  tab-size: 2;
}

pre {
  max-width: 100%;
  overflow-x: auto;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

/* --- Preferences ------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Windows high contrast and other forced colours: keep edges and focus. */
@media (forced-colors: active) {
  :focus-visible { outline: 3px solid Highlight; box-shadow: none; }
  a:focus-visible { outline: 3px solid Highlight; }
  .status, .banner, .confirmation, .review-panel, .table-wrap, .file-chooser { border: 1px solid CanvasText; }
  .status::before { background: CanvasText; forced-color-adjust: none; }
  .user-menu summary::after { border-color: CanvasText; }
}

/* --- Print: the Receipt above all ------------------------------------------ */

@media print {
  body { font-size: 11pt; }
  .skip-link, .header-login, .site-footer, .no-print, .keep-receipt button { display: none !important; }
  .site-header { border-bottom: 2px solid #000; }
  .confirmation { border: 2px solid #000; background: none !important; color: #000 !important; padding: 1rem; }
  .table-wrap { overflow: visible; border: 0; }
  thead th { background: none !important; }
  code { background: none; }
  main { padding-block: 1rem; }
}
