/* ==========================================================================
   Design tokens
   ==========================================================================
   Kept intentionally small; every component below pulls from these so we
   don't scatter magic numbers. Change a token here and the whole page follows.
   ========================================================================== */
:root {
    /* color */
    --color-bg: #f5f7fa;
    --color-surface: #ffffff;
    --color-surface-alt: #f9fafb;
    --color-border: #d1d5db;
    --color-border-strong: #9ca3af;
    --color-text: #111827;
    --color-text-muted: #6b7280;
    --color-primary: #1d4ed8;
    --color-primary-hover: #1e40af;
    --color-primary-soft: rgba(29, 78, 216, 0.12);
    --color-danger: #dc2626;
    --color-danger-hover: #b91c1c;
    --color-accent: #047857;
    --color-disabled-bg: #f3f4f6;

    /* radius + shadow */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.05);
    --shadow-md: 0 4px 12px rgba(17, 24, 39, 0.08);

    /* spacing scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;

    /* type scale */
    --font-size-xs: 12px;
    --font-size-sm: 14px;
    --font-size-md: 16px;
    --font-size-lg: 18px;
    --font-size-xl: 22px;
    --font-size-2xl: 28px;

    /* controls */
    --control-height: 42px;
}

/* ==========================================================================
   Reset + base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
                 Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: var(--font-size-md);
    line-height: 1.55;
    color: var(--color-text);
    background-color: var(--color-bg);
    /* Guard against any single block (e.g. a wide response table) forcing a
       document-wide horizontal scrollbar and pulling the centered #content
       visually off-axis. */
    overflow-x: hidden;
}

hr {
    border: 0;
    border-top: 1px solid var(--color-border);
    margin: var(--space-5) 0;
}

img {
    max-width: 200px;
    height: auto;
    border-radius: var(--radius-sm);
}

/* ==========================================================================
   Layout shell
   ========================================================================== */
#content {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--space-5) var(--space-4) var(--space-7);
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   Typography
   ========================================================================== */
h1 {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    text-align: center;
    margin: 0 0 var(--space-5);
    letter-spacing: -0.01em;
}

h2 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin: 0 0 var(--space-4);
    color: var(--color-text);
}

.card > h2:first-child,
.mDL-document > h2:first-child { margin-top: 0; }

/* ==========================================================================
   Form controls (shared baseline)
   ========================================================================== */
#items-request-selection-form {
    margin: 0;
}

label {
    font-size: var(--font-size-md);
    color: var(--color-text);
    line-height: 1.45;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select,
textarea {
    font: inherit;
    font-size: var(--font-size-md);
    height: var(--control-height);
    padding: 0 var(--space-3);
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select {
    min-width: 200px;
    padding-right: var(--space-4);
    cursor: pointer;
}

textarea {
    height: auto;
    min-height: 120px;
    padding: var(--space-2) var(--space-3);
    resize: vertical;
    line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}

/* Checkbox + radio: accent-color brings the native look in line with --color-primary. */
input[type="radio"],
input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--color-primary);
    vertical-align: middle;
    cursor: pointer;
    flex-shrink: 0;
}

/* Override legacy 40x40 size from the old rule */
#items-request-selection-form input[type="checkbox"],
#items-request-selection-form input[type="radio"] {
    width: 18px;
    height: 18px;
}

/* Label + control row (product info, referrer policy, curves, ...)
   Scoped to an explicit class so it doesn't leak into .radio-options-wrapper
   or other direct-div children of a .card. */
.form-field {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.form-field:last-child { margin-bottom: 0; }

.form-field > label {
    font-size: var(--font-size-md);
    font-weight: 500;
    color: var(--color-text);
}

/* Short-label variant (Vendor / Product): reserve space so inputs line up. */
.form-field--compact > label { min-width: 90px; }

#items-request-selection-form input[type="text"] {
    flex: 1;
    min-width: 220px;
    max-width: 480px;
    height: var(--control-height);
    font-size: var(--font-size-md);
}

.error-text {
    color: var(--color-danger);
    font-size: var(--font-size-sm);
    flex-basis: 100%;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn,
button[type="submit"],
#add-document-button,
.add-button,
.add-bigger-button,
.remove-button,
#downloadButton {
    font: inherit;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: var(--control-height);
    padding: 0 var(--space-4);
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s ease, border-color 0.15s ease,
                color 0.15s ease, box-shadow 0.15s ease;
}

.btn:focus-visible,
button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.btn:disabled,
button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Primary (submit, add, download) */
#items-request-selection-form button[type="submit"],
#add-document-button,
.add-button,
.add-bigger-button,
#downloadButton,
.btn--primary {
    background: var(--color-primary);
    color: #ffffff;
    border-color: var(--color-primary);
    font-weight: 600;
}

#items-request-selection-form button[type="submit"]:hover,
#add-document-button:hover,
.add-button:hover,
.add-bigger-button:hover,
#downloadButton:hover,
.btn--primary:hover {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

#items-request-selection-form button[type="submit"] {
    min-width: 180px;
    margin-top: var(--space-4);
    padding: 0 var(--space-5);
    font-size: var(--font-size-md);
}

/* Destructive icon button (the per-doc "X" and per-row "X") */
.remove-button {
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: var(--font-size-sm);
    font-weight: 600;
    background: transparent;
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
    border-radius: var(--radius-sm);
    line-height: 1;
    margin: 0;
}

.remove-button:hover {
    background: var(--color-danger);
    color: #ffffff;
}

/* Inline "+ Add ..." buttons get a slightly smaller padding */
.add-button {
    padding: 0 var(--space-4);
    font-size: var(--font-size-md);
}

.add-bigger-button {
    padding: 0 var(--space-5);
    font-size: var(--font-size-md);
}

/* The little "+" button in Add Document row */
#add-document-button {
    min-width: 48px;
    height: var(--control-height);
    padding: 0 var(--space-4);
    font-size: var(--font-size-lg);
    font-weight: 700;
    line-height: 1;
}

/* ==========================================================================
   Engagement Technology + other radio groups
   ========================================================================== */
.radio-options-wrapper {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.radio-options-wrapper > label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px 0;
    cursor: pointer;
    font-size: var(--font-size-md);
    color: var(--color-text);
}

/* Inline selects within a radio row (e.g. "Age Over [21]") should be compact,
   not sprawl to the shared 200px min-width. */
.radio-options-wrapper select {
    min-width: 80px;
    height: 36px;
    padding: 0 var(--space-2);
    margin-left: var(--space-2);
    font-size: var(--font-size-md);
}

.radio-options-wrapper > label:has(input[type="radio"]:checked) {
    color: var(--color-primary);
}

/* ==========================================================================
   Per-document fragment (document.html) — the "card" version
   ========================================================================== */
.mDL-document {
    position: relative;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-sm);
}

.mDL-document > .remove-button {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    margin: 0;
}

.inline-wrapper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin: 0 0 var(--space-4);
    padding-right: var(--space-6); /* keep clear of the absolute "X" */
}

.content-left {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin: 0;
}

.content-right {
    display: flex;
    align-items: center;
    margin: 0;
}

.doc-type-label {
    color: var(--color-accent);
    font-size: var(--font-size-sm);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.data-request-heading {
    margin: 0;
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.checkbox-wrapper {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
}

.checkbox-wrapper > label { font-size: var(--font-size-md); color: var(--color-text-muted); }

/* ==========================================================================
   Add-document row + submit area
   ========================================================================== */
#add-document-section {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    background: var(--color-surface);
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
}

#add-document-section label {
    font-weight: 500;
    color: var(--color-text-muted);
}

#document-type-select {
    min-width: 260px;
    width: auto;
    height: var(--control-height);
}

/* Curve / referrer selects: keep them inline with their label in the card */
#referrer-policy,
#algorithm-session-encryption,
#algorithm-reader-authentication {
    width: auto;
    min-width: 220px;
    height: var(--control-height);
    font-size: var(--font-size-md);
}

/* ==========================================================================
   CUSTOM popup dropdown (multi-select of data elements)
   ========================================================================== */
.custom-options-container {
    position: relative;
    display: inline-block;
    margin-top: var(--space-3);
}

.custom-options-toggle {
    font: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    height: var(--control-height);
    min-width: 240px;
    padding: 0 var(--space-3);
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
}

.custom-options-toggle:hover { background: var(--color-surface-alt); }
.custom-options-toggle:focus-visible {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.custom-options-toggle .caret {
    float: none;
    margin-left: var(--space-2);
    font-size: 12px;
    color: var(--color-text-muted);
}

.custom-options-popup {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 100;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    padding: var(--space-2) 0;
    min-width: 320px;
    max-height: 360px;
    overflow-y: auto;
}

.custom-options-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px var(--space-3);
    font-size: var(--font-size-md);
    cursor: pointer;
    white-space: nowrap;
}

.custom-options-row:hover { background: var(--color-surface-alt); }

.custom-options-row input[type="checkbox"] { width: 18px; height: 18px; }

/* ==========================================================================
   Engagement text (the redirect link) + response display
   ========================================================================== */
#mDL-reader-engagement-text {
    overflow-wrap: break-word;
    width: auto;
    max-width: 100%;
    padding: var(--space-4) 0;
    font-size: var(--font-size-md);
    color: var(--color-text);
}

#mDL-reader-engagement-text a {
    color: var(--color-primary);
    word-break: break-all;
}

/* Response area: long CBOR / base64 values must wrap so they never push
   the table wider than the page (which otherwise causes a body-level
   horizontal scrollbar and makes the rest of the page look off-center). */
#response-display {
    padding: 0;
    margin: 0;
    max-width: 100%;
    min-width: 0;
}

#response-display table {
    table-layout: fixed;
    width: 100%;
    max-width: 100%;
}

/* Aggressive wrapping for value cells only — these hold the long hex /
   base64 / CBOR strings. Keys stay readable (see first-child rule below). */
#response-display table td:not(:first-child),
#response-display table th {
    overflow-wrap: anywhere;
    word-break: break-word;
}

#response-display img {
    max-width: 100%;
    height: auto;
}

/* ==========================================================================
   Download row
   ========================================================================== */
#downloadContainer {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-top: var(--space-4);
}

#checkboxContainer {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    height: var(--control-height);
    font-size: var(--font-size-md);
    margin: 0;
}

#checkboxContainer label { display: inline-flex; align-items: center; gap: var(--space-2); }

#includeLogCheckBox { width: 18px; height: 18px; }

/* Download status banner — shown above #downloadContainer while the PDF
   is being generated. Block-level with explicit padding so the full text
   is always visible regardless of the surrounding flex row. */
#loadingSpinner {
    display: block;
    color: var(--color-primary);
    background: var(--color-primary-soft);
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-md);
    font-weight: 600;
    padding: var(--space-3) var(--space-4);
    margin: var(--space-4) 0;
}

/* ==========================================================================
   Session expiration modal
   ========================================================================== */
.notification-container {
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    inset: 0;
    background-color: rgba(17, 24, 39, 0.6);
    z-index: 1000;
}

.notification {
    background: var(--color-surface);
    color: var(--color-text);
    padding: var(--space-5) var(--space-6);
    border-radius: var(--radius-md);
    text-align: center;
    max-width: 80%;
    box-shadow: var(--shadow-md);
}

.notification p {
    margin: var(--space-2) 0;
    font-size: var(--font-size-md);
}

#session-expiration-notification {
    overflow-wrap: break-word;
    font-size: var(--font-size-md);
    color: var(--color-text);
    padding: 0;
    border-radius: 0;
}

/* ==========================================================================
   Disclaimer
   ========================================================================== */
.disclaimer-container {
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
    padding: var(--space-4) var(--space-5);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    max-width: 100%;
    margin: 0 0 var(--space-5);
    box-shadow: var(--shadow-sm);
}

.disclaimer-text {
    font-size: var(--font-size-sm);
    line-height: 1.55;
    margin: 0 0 var(--space-3);
    color: var(--color-text);
}

.disclaimer-container ol,
.disclaimer-container ul {
    margin: 0 0 var(--space-3) var(--space-5);
    padding: 0;
    font-size: var(--font-size-sm);
}

.disclaimer-container li {
    margin-bottom: 6px;
    line-height: 1.55;
}

/* ==========================================================================
   Tables (response display + selective-disclosure)
   ==========================================================================
   ResponseToHtmlService emits <table class="odd-table|even-table"> with
   <td>key:</td><td>value</td> rows and no <thead>. Keep those classes.
   ========================================================================== */
table {
    width: 100%;
    margin: 0 0 var(--space-4);
    border-collapse: collapse;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--color-surface);
    font-size: var(--font-size-md);
}

table th,
table td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    font-size: var(--font-size-md);
    vertical-align: top;
    line-height: 1.5;
}

table th {
    background: var(--color-surface-alt);
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

table tr:last-child td { border-bottom: 0; }

table tbody tr:hover td { background: rgba(29, 78, 216, 0.04); }

/* Response-display tables key column (key cells are the first <td>).
   - No `white-space: nowrap`: in a fixed-layout table it would push the
     text into the value column instead of wrapping it.
   - `overflow-wrap: break-word; word-break: normal` keeps labels readable:
     breaks happen only at word boundaries (or as a last resort), never
     mid-word like `un_distinguishin...g_sign`.
   - Wider column + heavier weight + full text color so labels scan easily. */
#response-display table td:first-child {
    color: var(--color-text);
    font-weight: 600;
    font-size: var(--font-size-md);
    width: 36%;
    padding-right: var(--space-4);
    vertical-align: top;
    overflow-wrap: break-word;
    word-break: normal;
    hyphens: none;
}

/* Namespace rows (emitted by ResponseToHtmlService as <td class="bold-key">)
   keep the pre-refactor bold treatment. Selector is weighted so it wins
   against the generic first-child rule above. */
#response-display table td.bold-key,
table td.bold-key {
    color: var(--color-text);
    font-weight: 700;
}

/* Response zebra alternates per table (not per row) — preserve existing API */
.odd-table { background: var(--color-surface); }
.even-table { background: var(--color-surface-alt); }

/* ==========================================================================
   Selective disclosure fragment
   ========================================================================== */
#sd-config-container {
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
}

#sd-config-container h2 {
    font-size: var(--font-size-lg);
    margin: var(--space-5) 0 var(--space-3);
}

#sd-config-container p {
    font-size: var(--font-size-md);
    line-height: 1.55;
    margin-bottom: var(--space-3);
}

#sd-config-container table {
    margin-bottom: var(--space-3);
    font-size: var(--font-size-md);
}

#sd-config-container th,
#sd-config-container td {
    font-size: var(--font-size-md);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    text-align: left;
    vertical-align: middle;
}

#sd-config-container input[type="text"],
#sd-config-container select,
#sd-config-container select:disabled {
    font-size: var(--font-size-md) !important;
    height: var(--control-height) !important;
    padding: 0 var(--space-3) !important;
    box-sizing: border-box !important;
    width: 100% !important;
}

#sd-config-container select:disabled {
    background-color: var(--color-disabled-bg);
    color: var(--color-text-muted);
    opacity: 1;
}

/* Column widths */
.claim-id { width: 60%; }
.claim-docType { width: 100%; }
.claim-namespace,
.claim-element { width: 80%; }

.claim-set-group,
.cred-set-group {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-3);
}

.claim-set-group input[type="text"],
.cred-set-group input[type="text"] {
    flex: 1;
    max-width: 420px;
    padding: 0 var(--space-3);
    height: var(--control-height);
    font-size: var(--font-size-md);
}

#sd-config-container .doc-type-select {
    width: 260px !important;
    max-width: 260px !important;
}

#sd-config-container .cred-id-input {
    width: 160px !important;
    max-width: 160px !important;
}

#sd-config-container .claim-set-group input[type="text"],
#sd-config-container .cred-set-group input[type="text"] {
    flex: 1;
    max-width: 320px;
    width: auto;
}

#sd-config-container .cred-set-group label.inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#sd-config-container .credential {
    padding: var(--space-4) var(--space-5);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    margin-bottom: var(--space-4);
}

#sd-config-container .credential .claims-table { margin-top: var(--space-3); }

/* Title row for a credential card — heading on the left, remove button
   pinned to the top-right so the action feels attached to the card. */
#sd-config-container .credential-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

#sd-config-container .credential-title-row h2 {
    margin: 0;
}

/* Credential ID + DocType inputs sit on a single line via flex and wrap
   cleanly when the viewport is too narrow. */
#sd-config-container .credential-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-3) var(--space-4);
    margin-bottom: var(--space-3);
}

#sd-config-container .credential-header .credential-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
}

#sd-config-container .credential-header .credential-field label {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-muted);
}

/* Lock these two controls to their designed widths. Selectors are
   intentionally more specific than the generic `input[type=text]` /
   `select` rules further up so the 100%-width default doesn't win. */
#sd-config-container .credential-header input.cred-id-input {
    width: 180px !important;
    max-width: 100%;
    flex: 0 0 auto;
}

#sd-config-container .credential-header select.doc-type-select {
    width: 260px !important;
    max-width: 100%;
    flex: 0 0 auto;
}

/* Claims table: lock columns so the <select> elements can't blow the
   table past the card / viewport width. table-layout: fixed is the
   piece that keeps things in check even when option text is long. */
#sd-config-container .claims-table {
    width: 100%;
    max-width: 100%;
    table-layout: fixed;
}

/* Claim id values are short but the text input still needs enough room
   to not visually overflow its column (default <input> intrinsic width
   is ~180px). Namespace + Data Element still uses most of the place. */
#sd-config-container .claims-table th:nth-child(1),
#sd-config-container .claims-table td:nth-child(1) { width: 15%; }
#sd-config-container .claims-table th:nth-child(2),
#sd-config-container .claims-table td:nth-child(2) { width: 37%; }
#sd-config-container .claims-table th:nth-child(3),
#sd-config-container .claims-table td:nth-child(3) { width: 40%; }
#sd-config-container .claims-table th:nth-child(4),
#sd-config-container .claims-table td:nth-child(4) { width: 8%; }

/* With table-layout: fixed the td widths above are authoritative, but
   inputs/selects carry an intrinsic min-width (from their default size
   attribute) that can push them past a narrow column. Forcing min-width:0
   lets them actually shrink to their 100% width. */
#sd-config-container .claims-table input[type="text"],
#sd-config-container .claims-table select {
    min-width: 0;
}

#sd-config-container .claims-table td:last-child,
#sd-config-container .claims-table th:last-child { text-align: center; }

/* ==========================================================================
   Utilities
   ========================================================================== */
.hidden { display: none !important; }
.bold-key { font-weight: 600; }

/* ==========================================================================
   Responsive (single-column below 720px)
   ========================================================================== */
@media (max-width: 720px) {
    #content { padding: var(--space-4) var(--space-3) var(--space-6); }
    .card,
    .mDL-document,
    #add-document-section { padding: var(--space-4); }

    h1 { font-size: var(--font-size-xl); }
    h2 { font-size: var(--font-size-md); }

    #items-request-selection-form input[type="text"] {
        max-width: none;
        flex: 1 1 100%;
    }

    .inline-wrapper {
        flex-direction: column;
        align-items: flex-start;
        padding-right: var(--space-5);
    }

    .content-right { align-self: flex-start; }

    #add-document-section,
    #downloadContainer { flex-direction: column; align-items: stretch; }

    #add-document-section > * ,
    #downloadContainer > * { width: 100%; }

    #document-type-select,
    .custom-options-toggle,
    .custom-options-popup { min-width: 0; width: 100%; }

    #items-request-selection-form button[type="submit"] { width: 100%; }

    /* Give the response key column a bit more breathing room on mobile so
       long labels like `un_distinguishing_sign` or `issuer Data Authentication`
       don't get crammed into a narrow strip. */
    #response-display table td:first-child { width: 42%; }

    /* Credential header stacks on narrow screens: each field on its own
       line (remove button already lives in the title row above). */
    #sd-config-container .credential-header {
        flex-direction: column;
        align-items: stretch;
    }

    #sd-config-container .credential-header .credential-field {
        width: 100%;
    }

    #sd-config-container .credential-header input.cred-id-input,
    #sd-config-container .credential-header select.doc-type-select {
        width: 100% !important;
        max-width: 100%;
    }

    /* Claims table -> stacked card layout so it never overflows the
       viewport. Each <tr> becomes a card with the remove button pinned
       to the top-right; <td>s are labeled fields (label comes from the
       data-label attribute set in the JS template). */
    #sd-config-container .claims-table,
    #sd-config-container .claims-table tbody,
    #sd-config-container .claims-table tr,
    #sd-config-container .claims-table td {
        display: block;
        width: 100%;
    }

    /* Override the desktop column widths on mobile. The :nth-child
       selectors above have higher specificity than the plain `td` rule
       here, so without this block the tds keep inheriting 15%/37%/40%/8%
       and the stacked selects render way too narrow. */
    #sd-config-container .claims-table td:nth-child(1),
    #sd-config-container .claims-table td:nth-child(2),
    #sd-config-container .claims-table td:nth-child(3),
    #sd-config-container .claims-table td:nth-child(4) {
        width: 100%;
    }

    #sd-config-container .claims-table thead { display: none; }

    #sd-config-container .claims-table tr {
        position: relative;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-sm);
        background: var(--color-bg);
        padding: var(--space-3);
        padding-right: calc(var(--space-3) + 40px); /* room for absolute X */
        margin-bottom: var(--space-3);
    }

    #sd-config-container .claims-table td {
        border: none;
        padding: var(--space-1) 0;
    }

    #sd-config-container .claims-table td:first-child { padding-top: 0; }
    #sd-config-container .claims-table td:last-child { padding-bottom: 0; }

    #sd-config-container .claims-table td::before {
        content: attr(data-label);
        display: block;
        font-size: var(--font-size-sm);
        font-weight: 600;
        color: var(--color-text-muted);
        margin-bottom: 2px;
    }

    /* Claim ID values are short — don't stretch the input across the full
       card width on mobile; it reads better as a compact field. */
    #sd-config-container .claims-table td[data-label="ID"] input[type="text"] {
        width: 160px !important;
        max-width: 100%;
    }

    /* Pin the X button to the top-right of the card so the action is
       attached to the card it affects, not stranded below the fields. */
    #sd-config-container .claims-table td.claim-actions {
        position: absolute;
        top: var(--space-2);
        right: var(--space-2);
        width: auto;
        padding: 0;
        margin: 0;
    }

    #sd-config-container .claims-table td.claim-actions::before { content: none; }
}
