/* ==========================================================================
   TechForge ETD portals — shared stylesheet for both Razor portals
   (Pages/Portal/* tenant portal and Pages/Admin/* admin portal).

   Structured as design tokens + components. Every colour, radius, shadow and
   easing is a custom property declared once in :root, so a theme change is a
   token edit rather than a sweep through the rules. The dark palette is the
   same token names redefined under prefers-color-scheme, which is why no
   component rule below mentions a literal colour.

   Class names are the contract with the .cshtml pages and are deliberately
   unchanged from the original stylesheet — restyling happens here, not in
   markup. Two constraints from the CSP set by Middleware/SecurityHeadersMiddleware:
   `font-src 'self'` rules out webfonts from Google/CDNs (hence the system font
   stack), and `img-src 'self' data:` rules out remote imagery.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root {
    color-scheme: light;

    /* Brand, sampled from wwwroot/img/techforge-logo.png: the gear is #0e858d
       and the wordmark #1a5a7e. Accent text uses the darker teal so it clears
       WCAG AA on white — the logo teal alone is 3.6:1 and fails for body copy. */
    --brand-teal: #0e858d;
    --brand-teal-strong: #0b6c73;
    --brand-navy: #1a5a7e;
    --brand-navy-deep: #123f59;

    --accent: var(--brand-teal-strong);
    --accent-hover: #095b61;
    --accent-on: #ffffff;
    --accent-soft: #e6f4f5;

    /* Neutrals */
    --bg: #f4f7f9;
    --bg-gradient: radial-gradient(1200px 600px at 15% -10%, #e8f2f4 0%, transparent 60%),
                   radial-gradient(900px 500px at 100% 0%, #eaf0f5 0%, transparent 55%);
    --surface: #ffffff;
    --surface-2: #f8fafb;
    --surface-3: #eef2f5;
    --border: #e2e8ed;
    --border-strong: #cbd6df;
    --text: #10202b;
    --text-muted: #5a6b79;
    --text-faint: #8496a3;

    /* Semantic pairs. Each status renders as a tinted pill: soft background,
       saturated foreground, hairline ring — instead of the old solid fills,
       which turned a table of badges into a colour chart. */
    --ok-bg: #e7f6ed;      --ok-fg: #15703f;   --ok-br: #b9e3ca;
    --warn-bg: #fdf3e0;    --warn-fg: #8a5a08; --warn-br: #f2ddb4;
    --bad-bg: #fdeaea;     --bad-fg: #a51f1f;  --bad-br: #f5c9c9;
    --crit-bg: #f8e3e3;    --crit-fg: #7c1a1a; --crit-br: #eab8b8;
    --info-bg: #eaf0f6;    --info-fg: #3d5162; --info-br: #d3dee7;
    --purple-bg: #f2eafb;  --purple-fg: #6b25b0; --purple-br: #ddc9f3;

    /* Elevation. Kept shallow and layered — a modern card reads as a hairline
       border plus a hint of shadow, not a drop shadow doing the work alone. */
    --shadow-xs: 0 1px 2px rgba(16, 32, 43, 0.04);
    --shadow-sm: 0 1px 2px rgba(16, 32, 43, 0.05), 0 2px 6px rgba(16, 32, 43, 0.04);
    --shadow-md: 0 2px 4px rgba(16, 32, 43, 0.05), 0 8px 24px rgba(16, 32, 43, 0.07);
    --shadow-lg: 0 12px 40px rgba(16, 32, 43, 0.12);

    --radius: 14px;
    --radius-md: 10px;
    --radius-sm: 8px;
    --radius-pill: 999px;

    --ring: 0 0 0 3px rgba(14, 133, 141, 0.28);
    --ease: cubic-bezier(0.4, 0, 0.2, 1);

    /* Height of the sticky nav. The sticky table header offsets by this, so a
       long submissions list keeps its column labels visible below the bar
       rather than scrolling underneath it. */
    --nav-h: 56px;

    --nav-bg: linear-gradient(100deg, #123f59 0%, #17566f 55%, #0e6b74 100%);
    --nav-fg: #ffffff;
    --nav-fg-dim: rgba(255, 255, 255, 0.72);
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;

        --accent: #2ea3ac;
        --accent-hover: #3fb9c2;
        --accent-on: #04222b;
        --accent-soft: rgba(46, 163, 172, 0.14);

        --bg: #0c141a;
        --bg-gradient: radial-gradient(1200px 600px at 15% -10%, rgba(14, 133, 141, 0.10) 0%, transparent 60%),
                       radial-gradient(900px 500px at 100% 0%, rgba(26, 90, 126, 0.14) 0%, transparent 55%);
        --surface: #141e26;
        --surface-2: #18242d;
        --surface-3: #1e2c36;
        --border: #253643;
        --border-strong: #33495a;
        --text: #e7eef4;
        --text-muted: #9db0bf;
        --text-faint: #7b8fa0;

        --ok-bg: rgba(34, 160, 90, 0.16);    --ok-fg: #63d296;    --ok-br: rgba(34, 160, 90, 0.34);
        --warn-bg: rgba(200, 130, 20, 0.16); --warn-fg: #ecb457;  --warn-br: rgba(200, 130, 20, 0.34);
        --bad-bg: rgba(200, 50, 50, 0.16);   --bad-fg: #f28b8b;   --bad-br: rgba(200, 50, 50, 0.34);
        --crit-bg: rgba(150, 30, 30, 0.22);  --crit-fg: #e57373;  --crit-br: rgba(150, 30, 30, 0.42);
        --info-bg: rgba(120, 150, 175, 0.14);--info-fg: #a9bccb;  --info-br: rgba(120, 150, 175, 0.3);
        --purple-bg: rgba(140, 80, 200, 0.18); --purple-fg: #c39bef; --purple-br: rgba(140, 80, 200, 0.36);

        --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.25);
        --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.35);
        --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);

        --ring: 0 0 0 3px rgba(46, 163, 172, 0.35);

        --nav-bg: linear-gradient(100deg, #0d2733 0%, #123c4c 55%, #0d4b52 100%);
        --nav-fg: #eef6f8;
        --nav-fg-dim: rgba(238, 246, 248, 0.66);
    }
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text",
                 "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background-color: var(--bg);
    background-image: var(--bg-gradient);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.15s var(--ease);
}
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* One visible focus treatment for everything, so keyboard navigation is usable
   on the forms that rotate keys and reverse documents. :focus-visible keeps it
   off mouse clicks. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

h1 {
    font-size: 1.6rem;
    line-height: 1.25;
    letter-spacing: -0.018em;
    font-weight: 650;
    margin: 0 0 1.1rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem;
}
h2 {
    font-size: 1.02rem;
    letter-spacing: -0.008em;
    font-weight: 650;
    margin: 0;
}

.hint-text {
    color: var(--text-muted);
    font-size: 0.86rem;
    margin: 0 0 1.15rem;
    max-width: 78ch;
}
h1 + .hint-text { margin-top: -0.7rem; }
/* A hint that annotates a single field sits below it, tight and unconstrained
   by the reading-width cap. */
.form-row .hint-text {
    margin: 0.35rem 0 0;
    font-size: 0.8rem;
    max-width: none;
}

/* Money and counts line up column-wise only with tabular figures; the default
   proportional digits make a right-aligned N2 column look ragged. */
.num, .totals-value, .mono-small, .etdui-link, .payload-pre {
    font-variant-numeric: tabular-nums;
}

.mono-small {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.79rem;
    word-break: break-all;
    color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   3. Top navigation
   -------------------------------------------------------------------------- */

.portal-nav {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    padding: 0.6rem 1.5rem;
    background: var(--nav-bg);
    color: var(--nav-fg);
    box-shadow: var(--shadow-md);
}
.portal-nav a { color: var(--nav-fg); }
.portal-nav a:hover { color: var(--nav-fg); text-decoration: none; }

.portal-nav-brand a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-weight: 650;
    letter-spacing: -0.01em;
    font-size: 1.02rem;
}
/* The wordmark is navy-on-transparent, which sinks into the dark nav. A light
   plate behind it restores the contrast the logo was drawn for. */
.portal-logo {
    height: 30px;
    width: auto;
    padding: 3px 7px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.94);
}

.portal-nav-user {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.2rem;
}
.portal-nav-user .user-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--nav-fg-dim);
    margin-right: 0.6rem;
    padding: 0.2rem 0.7rem 0.2rem 0;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
}
.portal-nav .btn-link {
    background: none;
    border: 1px solid transparent;
    color: var(--nav-fg-dim);
    font-weight: 550;
    font-size: 0.875rem;
    text-decoration: none;
    padding: 0.4rem 0.7rem;
    border-radius: var(--radius-sm);
    transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.portal-nav .btn-link:hover {
    background: rgba(255, 255, 255, 0.14);
    color: var(--nav-fg);
    text-decoration: none;
}
/* Current section, set by the layouts from RouteData. */
.portal-nav .btn-link.is-active {
    background: rgba(255, 255, 255, 0.17);
    border-color: rgba(255, 255, 255, 0.22);
    color: var(--nav-fg);
}

/* --------------------------------------------------------------------------
   4. Page shell
   -------------------------------------------------------------------------- */

.portal-main {
    flex: 1;
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
    padding: 1.75rem 1.5rem 3rem;
}

.portal-footer {
    padding: 1.25rem 1.5rem 1.75rem;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-faint);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 1rem;
    font-size: 0.88rem;
    font-weight: 550;
    color: var(--text-muted);
}
.back-link:hover { color: var(--accent); text-decoration: none; }

/* --------------------------------------------------------------------------
   5. Auth pages (login / register / verify / reset)
   -------------------------------------------------------------------------- */

/* Set by the layouts on <body> when nobody is signed in, so the signed-out
   screens get a centred, quieter canvas than the data pages. */
.auth-page .portal-main {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 2.5rem;
}

/* Auth screens that are a whole form rather than a single card (register) wrap
   their content in this. `.auth-page .portal-main` is a flex row, so without a
   single wrapping item the <h1>, the <form> and the "already have an account"
   link become side-by-side, vertically-centred columns. */
.auth-stack {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
}

.login-box {
    width: 100%;
    max-width: 400px;
    margin: 2rem auto;
    padding: 2.25rem 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
/* Pages that embed the card in a normal flow (e.g. a section of a wider page)
   opt out of the centring margin. */
.narrow-box { margin: 0; }

.login-logo {
    display: block;
    max-width: 190px;
    height: auto;
    margin: 0 auto 1.35rem;
}
.login-box h1 {
    justify-content: center;
    text-align: center;
    font-size: 1.3rem;
    margin-bottom: 1.4rem;
}
.login-box .form-row { margin-bottom: 0.95rem; }
/* Same exclusion as .form-card below: a stretched radio or checkbox centres its glyph in
   the full row width and pushes its label to the far right. */
.login-box .form-row input:not([type="radio"]):not([type="checkbox"]),
.login-box .form-row select { width: 100%; }
/* The primary action on an auth card is the only action — full width reads as
   the obvious next step and gives a comfortable tap target. */
.login-box .btn-primary { width: 100%; margin-top: 0.35rem; padding: 0.6rem 1rem; }

.login-box h1 + .hint-text { text-align: center; margin-bottom: 1.3rem; }

.login-links {
    margin-top: 1.25rem;
    padding-top: 1.1rem;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.87rem;
    color: var(--text-muted);
}
.login-alt {
    text-align: center;
    margin-top: 1.1rem;
    font-size: 0.85rem;
}

/* --------------------------------------------------------------------------
   6. Forms
   -------------------------------------------------------------------------- */

.form-row {
    display: flex;
    flex-direction: column;
    margin-bottom: 0.85rem;
    min-width: 165px;
}
.form-row label {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.005em;
    margin-bottom: 0.3rem;
    color: var(--text-muted);
}

.form-row input,
.form-row select,
.form-row textarea {
    padding: 0.48rem 0.65rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 0.92rem;
    line-height: 1.4;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.form-row input::placeholder { color: var(--text-faint); }
.form-row input:hover,
.form-row select:hover,
.form-row textarea:hover { border-color: var(--text-faint); }
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--ring);
}
/* File inputs (PFX upload) never take the padding well — give them room and a
   styled browse button instead. */
.form-row input[type="file"] { padding: 0.4rem; font-size: 0.85rem; }
.form-row input[type="file"]::file-selector-button {
    margin-right: 0.7rem;
    padding: 0.32rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    color: var(--text);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.filter-form { margin-bottom: 1.25rem; }
.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem 1.1rem;
    align-items: flex-end;
}
.filter-actions {
    margin: 0 0 0.85rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding-top: 0.15rem;
}
/* Each status filter is a selectable chip rather than a bare checkbox — same
   input, but it reads as a filter control and gets a real hit area. */
.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 500;
    font-size: 0.85rem;
    padding: 0.32rem 0.7rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill);
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}
.checkbox-label:hover { border-color: var(--accent); }
.checkbox-label:has(input:checked) {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}
.checkbox-label input { accent-color: var(--accent); margin: 0; }

/* A stacked radio choice inside a form. Distinct from .checkbox-label above, which is a
   filter chip — small, pill-shaped and sized to its own text, so it reads wrong (and
   stretches badly) as one of two full-width options in a form card. Here the whole row is
   the hit area and the option text reads at body size. */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.85rem;
}
.radio-option {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    background: var(--surface);
    cursor: pointer;
    /* Overrides .form-row label, which is a small muted field caption. This is the
       option's own text, not a caption above a field. */
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0;
    transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}
.radio-option:hover { border-color: var(--accent); }
.radio-option:has(input:checked) {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}
.radio-option input {
    /* Belt and braces against any width rule that reaches in here — see the note on
       .form-card .form-row input above. */
    width: auto;
    flex: 0 0 auto;
    margin: 0;
    accent-color: var(--accent);
}

.form-actions {
    margin: 1.1rem 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-width: 640px;
}

/* --------------------------------------------------------------------------
   7. Buttons
   -------------------------------------------------------------------------- */

.btn-primary, .btn-secondary, .btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 0.48rem 0.95rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.35;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease),
                box-shadow 0.15s var(--ease), transform 0.08s var(--ease);
}
.btn-primary:hover, .btn-secondary:hover, .btn-danger:hover { text-decoration: none; }
.btn-primary:active, .btn-secondary:active, .btn-danger:active { transform: translateY(1px); }

.btn-primary {
    background: var(--accent);
    color: var(--accent-on);
    box-shadow: var(--shadow-xs);
}
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-on); box-shadow: var(--shadow-sm); }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: var(--surface-3); color: var(--text); border-color: var(--text-faint); }

/* Destructive actions (document reversal, key rotation). Also used on an <a>,
   which needs the inline-flex/no-underline reset that <button> gets for free. */
.btn-danger {
    background: var(--bad-fg);
    color: #fff;
    box-shadow: var(--shadow-xs);
}
.btn-danger:hover { background: var(--crit-fg); color: #fff; }
a.btn-primary, a.btn-secondary, a.btn-danger { text-decoration: none; }

/* Link-style button. Base is a visible accent link; the nav re-colours it via
   the more specific `.portal-nav .btn-link` rule above. (A bare light colour
   here rendered every non-nav .btn-link invisible on white backgrounds.) */
.btn-link {
    background: none;
    border: none;
    padding: 0;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 550;
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}
.btn-link:hover { color: var(--accent-hover); }
.btn-link.danger { color: var(--bad-fg); }

button:disabled, .btn-primary:disabled, .btn-secondary:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* --------------------------------------------------------------------------
   8. Alerts
   -------------------------------------------------------------------------- */

.alert {
    padding: 0.7rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    border-left-width: 3px;
    margin-bottom: 1.15rem;
    font-size: 0.9rem;
}
.alert a { text-decoration: underline; color: inherit; }
.alert-error   { background: var(--bad-bg);  color: var(--bad-fg);  border-color: var(--bad-br); }
.alert-success { background: var(--ok-bg);   color: var(--ok-fg);   border-color: var(--ok-br); }
.alert-warn    { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-br); }

/* --------------------------------------------------------------------------
   9. Surfaces: stat bar, cards, detail grid, payload panels
   -------------------------------------------------------------------------- */

/* KPI strip above the submission and billing tables. Hairline dividers between
   items instead of raw gaps, so it reads as one instrument panel. */
.totals-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.35rem 0.5rem;
    margin-bottom: 1.15rem;
    box-shadow: var(--shadow-sm);
}
.totals-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.7rem 1.35rem;
    border-right: 1px solid var(--border);
}
.totals-item:last-of-type { border-right: none; }
.totals-label {
    font-size: 0.68rem;
    font-weight: 650;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.totals-value {
    font-size: 1.32rem;
    font-weight: 680;
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.totals-bar-action { margin: auto 0.5rem auto auto; }

/* Card wrapper for admin forms/sections. The <h2> is the first child of the
   card, so the shared `h2 { margin: 0 }` no longer collides with preceding
   content. */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.4rem 1.6rem;
    margin-bottom: 1.15rem;
    box-shadow: var(--shadow-sm);
    max-width: 640px;
}
.form-card h2 {
    margin: 0 0 1.1rem;
    padding-bottom: 0.7rem;
    border-bottom: 1px solid var(--border);
}
.form-card .hint-text { margin: 0 0 1rem; }
/* Radios and checkboxes are excluded: they are fixed-size glyphs, and stretching one to
   the row width centres the glyph in a full-width box and shoves its label to the far
   right. Everything else in a card form fills the row. */
.form-card .form-row input:not([type="radio"]):not([type="checkbox"]),
.form-card .form-row select,
.form-card .form-row textarea { width: 100%; }
.form-card .filter-row { align-items: flex-end; }
/* Drop the form-row's bottom margin inside a filter-row so `align-items:flex-end`
   lines the button's bottom up with the dropdown's bottom (the margin otherwise
   pushed it ~0.85rem low). */
.form-card .filter-row .form-row { margin-bottom: 0; }
.form-card .filter-actions { margin-bottom: 0; }
.form-card .form-actions { margin-bottom: 0; }

.detail-grid {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.85rem 1.6rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    font-size: 0.9rem;
}
/* Hairline between rows: the border goes on both cells of a row, and the two
   :last-of-type rules drop it on the final pair so the card doesn't end on a
   stray line. */
.detail-grid dt, .detail-grid dd {
    padding: 0.42rem 0;
    border-bottom: 1px solid var(--border);
}
.detail-grid dt:last-of-type, .detail-grid dd:last-of-type { border-bottom: none; }
.detail-grid dt, .detail-grid .kv-key {
    padding-right: 1.5rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}
.detail-grid dd { margin: 0; }

.payload-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem 1.5rem 1.35rem;
    margin-bottom: 1.15rem;
    box-shadow: var(--shadow-sm);
}
.payload-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem;
}
.payload-section .hint-text { margin: 0.7rem 0 1rem; }
.payload-actions { display: flex; gap: 0.5rem; }
.payload-pre {
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 420px;
    overflow: auto;
    background: #0c1620;
    color: #d7e3ec;
    border: 1px solid #1b2b38;
    padding: 1rem 1.1rem;
    border-radius: var(--radius-md);
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.78rem;
    line-height: 1.55;
    margin-top: 0.85rem;
    scrollbar-width: thin;
}

/* One-time API key reveal panel */
.api-key-reveal { max-width: 640px; }
.api-key-reveal .payload-pre { max-height: none; }

/* --------------------------------------------------------------------------
   10. Tables
   -------------------------------------------------------------------------- */

.submissions-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    font-size: 0.875rem;
}
/* `overflow: hidden` would clip the corner cells to the table's radius, but it
   also makes the table a (non-scrolling) scroll container, which silently
   disables the sticky header inside it. Round the corner cells instead. */
.submissions-table thead th:first-child { border-top-left-radius: var(--radius); }
.submissions-table thead th:last-child { border-top-right-radius: var(--radius); }
.submissions-table tbody tr:last-child > :first-child { border-bottom-left-radius: var(--radius); }
.submissions-table tbody tr:last-child > :last-child { border-bottom-right-radius: var(--radius); }
.submissions-table th,
.submissions-table td {
    padding: 0.62rem 0.85rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}
.submissions-table thead th {
    position: sticky;
    top: var(--nav-h);
    z-index: 1;
    background: var(--surface-3);
    font-size: 0.72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    white-space: nowrap;
}
.submissions-table tbody tr:last-child td { border-bottom: none; }
.submissions-table tbody tr { transition: background-color 0.12s var(--ease); }
.submissions-table tbody tr:hover { background: var(--surface-2); }
/* The fee-breakdown table on the details page closes with a <th> total row. */
.submissions-table tbody th {
    border-bottom: none;
    background: var(--surface-2);
    font-weight: 650;
}
.submissions-table td.num, .submissions-table th.num { text-align: right; }

.submissions-table .empty-row, .empty-row {
    text-align: center;
    color: var(--text-faint);
    padding: 2.5rem !important;
    font-size: 0.9rem;
}

.etdui-link {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.8rem;
    letter-spacing: -0.01em;
}
/* Keep the ETDUI and its lookup icon on one line — the number is 44 chars and
   would otherwise wrap away from the icon on narrow viewports. */
.etdui-cell { white-space: nowrap; }
.qr-link {
    display: inline-flex;
    align-items: center;
    margin-left: 0.4rem;
    color: var(--text-faint);
    vertical-align: middle;
    transition: color 0.15s var(--ease);
}
.qr-link:hover { color: var(--accent); }

/* A test document's would-be fee: shown, but visibly not a real charge. */
.fee-estimate { color: var(--text-faint); font-style: italic; }
.fee-estimate-legend { margin: 1rem 0 0; }
.fee-estimate-note {
    display: inline-block;
    margin-left: 0.5rem;
    color: var(--text-faint);
    font-size: 0.8rem;
    font-style: italic;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: center;
    margin: 1.25rem 0 0;
    font-size: 0.87rem;
    color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   11. Badges
   -------------------------------------------------------------------------- */

.status-badge, .env-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.16rem 0.6rem;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    font-size: 0.73rem;
    font-weight: 650;
    letter-spacing: 0.01em;
    white-space: nowrap;
    text-transform: capitalize;
}
/* Leading dot: the status is legible from shape and position, not colour alone
   — the table is scanned, and 5% of readers cannot separate the red from the
   green pill. */
.status-badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}

.status-authorized { background: var(--ok-bg);     color: var(--ok-fg);     border-color: var(--ok-br); }
.status-rejected   { background: var(--bad-bg);    color: var(--bad-fg);    border-color: var(--bad-br); }
.status-error      { background: var(--crit-bg);   color: var(--crit-fg);   border-color: var(--crit-br); }
.status-queued     { background: var(--warn-bg);   color: var(--warn-fg);   border-color: var(--warn-br); }
.status-pending    { background: var(--info-bg);   color: var(--info-fg);   border-color: var(--info-br); }
/* Not a SubmissionStatus — an authorized document voided by a 050 cancellation event. */
.status-reversed   { background: var(--purple-bg); color: var(--purple-fg); border-color: var(--purple-br); }

.env-production { background: var(--bad-bg);  color: var(--bad-fg);  border-color: var(--bad-br); }
.env-test       { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-br); }

/* h1 carries a status badge on the submission details page; keep it from
   inheriting the heading's size. */
h1 .status-badge { font-size: 0.75rem; vertical-align: middle; }

/* --------------------------------------------------------------------------
   12. Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
    .portal-nav { padding: 0.55rem 1rem; }
    .portal-nav-user .user-label { width: 100%; border-right: none; margin: 0; padding: 0; }
    .portal-main { padding: 1.25rem 1rem 2.5rem; }

    /* Wide tables (the submissions grid is 11 columns) scroll inside themselves
       rather than forcing the whole page sideways. Scoped to narrow viewports so
       the desktop layout is untouched. */
    .submissions-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        scrollbar-width: thin;
    }
    .submissions-table thead th { position: static; }

    .totals-item { padding: 0.6rem 1rem; }
    .totals-value { font-size: 1.15rem; }
    .detail-grid { grid-template-columns: 1fr; gap: 0; padding: 0.85rem 1.15rem; }
    .detail-grid dt { border-bottom: none; padding-bottom: 0; }
    .detail-grid dd { padding-top: 0.1rem; }
    .form-card, .payload-section { padding: 1.1rem 1.15rem; }
}

/* The logo is drawn for a light ground: navy wordmark, teal gear. On a dark
   card the wordmark loses most of its contrast, so it keeps a light plate —
   the same treatment .portal-logo gets against the dark nav. */
@media (prefers-color-scheme: dark) {
    .login-logo {
        padding: 0.75rem 1rem;
        border-radius: var(--radius-md);
        background: rgba(255, 255, 255, 0.94);
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* --------------------------------------------------------------------------
   Long-form legal text (Pages/Portal/Terms.cshtml)

   The only page in either portal that is prose rather than a form or a table,
   so it needs a measure and a vertical rhythm nothing else here provides. It
   renders signed-out, where <body> carries `auth-page` and centres its child —
   hence the explicit max-width and auto margins rather than relying on the
   surrounding layout. Kept in the same token vocabulary as everything else so
   a theme change still reaches it.
   -------------------------------------------------------------------------- */

.legal-doc {
    width: 100%;
    max-width: 52rem;
    margin: 0 auto;
    /* `.auth-page .portal-main` is a centred flex row. A document taller than the viewport
       centred on the cross axis overflows past the top of the scroll container, putting the
       first screen of text out of reach — so this one aligns to the start instead. */
    align-self: flex-start;
    padding: 2rem 2.25rem 2.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    /* Prose reads better slightly looser than the form-dense pages. */
    line-height: 1.65;
    text-align: left;
}

.legal-doc h1 { margin: 0 0 0.35rem; font-size: 1.5rem; }
.legal-doc h2 {
    margin: 2rem 0 0.6rem;
    font-size: 1.1rem;
    color: var(--accent);
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
}
.legal-doc h3 { margin: 1.35rem 0 0.4rem; font-size: 0.98rem; color: var(--text); }
.legal-doc p { margin: 0 0 0.9rem; color: var(--text); }
.legal-doc ul, .legal-doc ol { margin: 0 0 1rem; padding-left: 1.35rem; color: var(--text); }
.legal-doc li { margin-bottom: 0.5rem; }
.legal-doc code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.88em;
    background: var(--surface-3);
    border-radius: var(--radius-sm);
    padding: 0.08em 0.35em;
}

/* Version line and sign-off — the same muted caption at both ends of the document. */
.legal-doc .legal-meta { font-size: 0.85rem; color: var(--text-muted); }
.legal-doc .legal-lede {
    margin: 1.25rem 0 0.5rem;
    padding: 0.9rem 1.1rem;
    background: var(--surface-2);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
}

/* The registration form's acceptance row. Wider hit area than a bare checkbox,
   and the checkbox is excluded from the .form-card full-width input rule the
   same way the radios are. */
.consent-row {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.85rem 0.95rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text);
}
.consent-row:hover { border-color: var(--accent); }
.consent-row:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.consent-row input {
    width: auto;
    flex: 0 0 auto;
    /* Nudged down onto the first line of the label rather than the box's top edge. */
    margin: 0.22rem 0 0;
    accent-color: var(--accent);
}

@media (max-width: 720px) {
    .legal-doc { padding: 1.35rem 1.15rem 1.75rem; border-radius: var(--radius-md); }
    .legal-doc h1 { font-size: 1.3rem; }
}
