/* CE Readings operational portal — cohesive production stylesheet.
   Contract notes:
   - Preserve legacy template classes; extend with source/status semantics.
   - .table-scroll owns horizontal scrolling for wide technical tables.
   - Bare tables remain scroll-safe until templates use the wrapper. */

/* 1. Design tokens and base ------------------------------------------------ */
:root {
    --ink-950: #102239;
    --ink-900: #17283e;
    --ink-800: #24364d;
    --ink-700: #3c5068;
    --ink-600: #566a80;
    --ink-500: #6d7f93;
    --canvas: #f3f6f8;
    --surface: #ffffff;
    --surface-muted: #f7f9fb;
    --line: #d9e1e8;
    --line-strong: #c3ced8;
    --teal-800: #14565b;
    --teal-700: #176b70;
    --teal-600: #1b7b80;
    --teal-100: #dff1f0;
    --blue-800: #24517e;
    --blue-100: #e5f0fb;
    --green-800: #185c45;
    --green-100: #e2f3ea;
    --amber-900: #77440d;
    --amber-700: #a9600b;
    --amber-100: #fff1d6;
    --red-800: #922c35;
    --red-700: #b4232f;
    --red-100: #fde8e9;
    --shadow-sm: 0 1px 2px rgba(16, 34, 57, 0.06);
    --shadow-md: 0 8px 24px rgba(16, 34, 57, 0.08);
    --radius-sm: 5px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --focus-ring: 0 0 0 3px rgba(23, 107, 112, 0.22);
    --portal-sidebar-width: 240px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--canvas);
    color-scheme: light;
}

body {
    min-height: 100vh;
    margin: 0;
    background:
        linear-gradient(180deg, rgba(226, 237, 242, 0.58) 0, rgba(243, 246, 248, 0) 220px),
        var(--canvas);
    color: var(--ink-800);
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.55;
}

h1,
h2,
h3 {
    color: var(--ink-900);
    line-height: 1.22;
}

h1 {
    margin: 0;
    font-size: clamp(1.7rem, 3vw, 2.35rem);
    font-weight: 680;
    letter-spacing: -0.035em;
}

h2 {
    margin: 1.75rem 0 0.8rem;
    font-size: 1.15rem;
    font-weight: 680;
    letter-spacing: -0.015em;
}

p {
    margin-top: 0;
}

a {
    color: var(--blue-800);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.16em;
}

a:hover {
    color: var(--teal-800);
}

button,
input,
select,
textarea {
    font: inherit;
}

:focus-visible {
    outline: 2px solid var(--teal-700);
    outline-offset: 2px;
}

::selection {
    background: #cbe7e5;
    color: var(--ink-950);
}

.container {
    width: min(100%, 1480px);
    min-width: 0;
    margin: 0 auto;
    padding: 30px clamp(18px, 3vw, 42px) 72px;
}

.container > * {
    min-width: 0;
}

.text-right {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.text-center {
    text-align: center;
}

.text-error {
    color: var(--red-700);
}

.text-warning {
    color: var(--amber-900);
}

.full-width {
    width: 100%;
}

/* 2. Shared portal navigation --------------------------------------------- */
/* Compact layout is the resilient baseline: native details remain usable
   without JavaScript. The permanent rail is applied from 901px upward. */
.portal-navbar.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: clamp(14px, 2.4vw, 28px);
    min-height: 64px;
    padding: 9px clamp(14px, 3vw, 34px);
    background: var(--ink-950);
    border-bottom: 1px solid #2d4259;
    box-shadow: 0 8px 24px rgba(16, 34, 57, 0.16);
    color: #fff;
}

.nav-brand {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
    color: #fff;
    line-height: 1.15;
    text-decoration: none;
}

.nav-brand:hover {
    color: #fff;
    text-decoration: none;
}

.nav-brand-name,
.nav-brand > span:first-child {
    overflow: hidden;
    max-width: 34ch;
    font-size: 1rem;
    font-weight: 680;
    letter-spacing: -0.015em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-brand small {
    color: #aebdcb;
    font-size: 0.64rem;
    font-weight: 650;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.portal-nav-collapse {
    position: relative;
    flex: 0 0 auto;
    min-width: 0;
}

.portal-nav-collapse > summary {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 38px;
    padding: 8px 11px;
    border: 1px solid #455b72;
    border-radius: var(--radius-sm);
    background: #22374d;
    color: #fff;
    cursor: pointer;
    font-size: 0.84rem;
    font-weight: 650;
    list-style: none;
}

.portal-nav-collapse > summary::before {
    width: 14px;
    height: 10px;
    border-top: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    content: "";
}

.portal-nav-collapse > summary::after {
    content: "⌄";
    color: #b7c6d3;
}

.portal-nav-collapse[open] > summary::after {
    content: "⌃";
}

.portal-nav-collapse > summary::-webkit-details-marker,
.nav-system > summary::-webkit-details-marker {
    display: none;
}

.portal-nav-panel {
    position: absolute;
    top: calc(100% + 9px);
    right: 0;
    z-index: 3;
    display: none;
    width: min(430px, calc(100vw - 28px));
    max-height: calc(100dvh - 82px);
    padding: 9px;
    overflow-y: auto;
    background: var(--ink-950);
    border: 1px solid #3b536b;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.portal-nav-collapse[open] > .portal-nav-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-links {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    min-width: 0;
}

.nav-links > a,
.nav-system > summary,
.nav-section {
    display: block;
    min-width: 0;
    padding: 9px 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: #cbd7e2;
    font-size: 0.875rem;
    font-weight: 540;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
}

.nav-links > a:hover,
.nav-system > summary:hover,
.nav-links > a.active,
.nav-links > a[aria-current="page"],
.nav-system[data-active="true"] > summary {
    background: #2b4057;
    border-color: #455c73;
    color: #fff;
    text-decoration: none;
}

.nav-links > a.active,
.nav-links > a[aria-current="page"] {
    border-left-color: #55b4b1;
    box-shadow: inset 3px 0 0 var(--teal-600);
}

.nav-system {
    min-width: 0;
}

.nav-system > summary {
    cursor: pointer;
    list-style: none;
}

.nav-system > summary::after {
    content: "⌄";
    margin-left: 6px;
    color: #94a9ba;
    font-size: 0.78rem;
}

.nav-system[open] > summary::after {
    content: "⌃";
}

.nav-system[data-active="true"] > summary::after {
    color: #bfe4e1;
}

.nav-system-links {
    display: grid;
    gap: 3px;
    min-width: 0;
    margin: 4px 0 4px 14px;
    padding: 3px 0 3px 9px;
    border-left: 1px solid #3b536b;
}

.nav-system-links a {
    display: block;
    min-width: 0;
    padding: 7px 9px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: #d7e1e9;
    font-size: 0.84rem;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.nav-system-links a:hover,
.nav-system-links a[aria-current="page"] {
    background: #2b4057;
    border-color: #455c73;
    color: #fff;
}

.nav-system-links a[aria-current="page"] {
    box-shadow: inset 3px 0 0 var(--teal-600);
}

.nav-account {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
    padding: 9px 3px 2px;
    border-top: 1px solid #30465d;
}

.nav-user {
    display: block;
    min-width: 0;
    overflow: hidden;
    color: #b8c5d1;
    font-size: 0.8rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-account .btn,
.nav-account .btn-sm,
.nav-logout {
    color: #fff;
    background: #2b4057;
    border: 1px solid #455c73;
}

.nav-account .btn:hover,
.nav-account .btn-sm:hover,
.nav-logout:hover {
    color: #fff;
    background: #3a536d;
}

.nav-section {
    color: #9fcbd0;
}

@media screen and (min-width: 901px) {
    .portal-navbar.navbar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 100;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 0;
        width: var(--portal-sidebar-width);
        height: 100vh;
        height: 100dvh;
        min-height: 0;
        padding: 0;
        overflow-x: hidden;
        overflow-y: auto;
        border-right: 1px solid #30465d;
        border-bottom: 0;
        box-shadow: 8px 0 24px rgba(16, 34, 57, 0.1);
        scrollbar-color: #455c73 var(--ink-950);
        scrollbar-width: thin;
    }

    .portal-navbar .nav-brand {
        flex: 0 0 auto;
        padding: 23px 18px 18px;
        border-bottom: 1px solid #30465d;
    }

    .portal-navbar .nav-brand > span:first-child {
        max-width: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .portal-nav-collapse {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        min-height: 0;
        overflow-y: auto;
        scrollbar-color: #455c73 var(--ink-950);
        scrollbar-width: thin;
    }

    .portal-nav-collapse > summary {
        display: none;
    }

    .portal-nav-panel {
        position: static;
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        gap: 14px;
        width: auto;
        max-height: none;
        min-height: calc(100dvh - 91px);
        padding: 17px 12px 14px;
        overflow: visible;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .portal-nav-panel .nav-links {
        grid-template-columns: minmax(0, 1fr);
        gap: 5px;
    }

    .portal-nav-panel .nav-links > a,
    .portal-nav-panel .nav-system > summary {
        width: 100%;
        padding: 11px 11px;
        font-size: 0.91rem;
        white-space: normal;
    }

    .portal-nav-panel .nav-links > a:hover,
    .portal-nav-panel .nav-system > summary:hover {
        background: #243a51;
    }

    .portal-nav-panel .nav-system-links {
        margin: 5px 0 5px 14px;
        padding-left: 10px;
    }

    .portal-nav-panel .nav-account {
        flex-direction: column;
        align-items: stretch;
        gap: 9px;
        margin-top: auto;
        padding: 15px 4px 3px;
    }

    .portal-nav-panel .nav-user {
        max-width: 100%;
        line-height: 1.4;
        text-align: center;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .portal-nav-panel .nav-logout {
        width: 100%;
        text-align: center;
    }

    .portal-navbar ~ .container {
        width: min(calc(100% - var(--portal-sidebar-width)), 1480px);
        max-width: 1480px;
        margin-right: auto;
        margin-left: var(--portal-sidebar-width);
    }
}

.nav-sub {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-bottom: 22px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.nav-sub a {
    padding: 6px 11px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink-700);
    font-size: 0.875rem;
    font-weight: 550;
    text-decoration: none;
}

.nav-sub a:hover,
.nav-sub a.active,
.nav-sub a[aria-current="page"] {
    border-color: var(--ink-800);
    background: var(--ink-800);
    color: #fff;
}

/* 3. Page hierarchy and panels -------------------------------------------- */
.page-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px 28px;
    margin: 0 0 26px;
}

.page-heading > * {
    min-width: 0;
}

.page-heading h1 {
    margin: 3px 0 5px;
}

.page-heading .results-info {
    margin-bottom: 0;
}

.eyebrow {
    margin: 0;
    color: var(--ink-600);
    font-size: 0.71rem;
    font-weight: 720;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.section-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: -8px 0 26px;
}

.section-meta,
.results-info {
    color: var(--ink-600);
    font-size: 0.9rem;
}

.results-info {
    margin-bottom: 13px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
    gap: 12px;
    margin: 0 0 30px;
}

.stat-card {
    position: relative;
    min-width: 0;
    padding: 18px 18px 16px;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.stat-card::before {
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    height: 3px;
    background: #a9bfce;
    content: "";
}

.stat-value {
    overflow-wrap: anywhere;
    color: var(--ink-950);
    font-size: clamp(1.45rem, 2.5vw, 2rem);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    letter-spacing: -0.035em;
    line-height: 1.2;
}

.stat-label {
    margin-top: 5px;
    color: var(--ink-600);
    font-size: 0.83rem;
    font-weight: 560;
    line-height: 1.35;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 285px), 1fr));
    gap: 0;
    margin: 20px 0;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    padding: 16px 18px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.detail-item strong {
    color: var(--ink-600);
    font-size: 0.71rem;
    font-weight: 720;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.detail-item span {
    color: var(--ink-900);
    font-size: 0.94rem;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.detail-item.full-width {
    grid-column: 1 / -1;
    border-right: 0;
}

.source-panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr));
    gap: 14px;
    margin: 14px 0 30px;
}

.source-panel {
    min-width: 0;
    padding: 22px 24px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 4px solid #6f92b5;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.source-panel:nth-child(2) {
    border-left-color: var(--teal-600);
}

.source-panel h2 {
    margin: 10px 0 6px;
}

.source-panel p {
    margin-bottom: 18px;
    color: var(--ink-600);
}

.source-panels-compact {
    gap: 10px;
}

.source-panels-compact .source-panel {
    padding: 17px 20px;
}

.source-panels-compact .source-panel h2 {
    margin: 7px 0 4px;
}

.source-panels-compact .source-panel p {
    margin-bottom: 8px;
}

/* 4. Filters, controls, and forms ----------------------------------------- */
.filter-form {
    min-width: 0;
    margin-bottom: 20px;
    padding: 18px 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.filter-form > .btn {
    margin-top: 3px;
}

.filter-grid,
.filter-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
    gap: 13px;
    align-items: end;
}

.filter-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.form-group {
    min-width: 0;
    margin-bottom: 15px;
}

.form-group > label,
.form-group > .label {
    display: block;
    margin-bottom: 5px;
    color: var(--ink-800);
    font-size: 0.84rem;
    font-weight: 650;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group input[type="datetime-local"],
.form-group input:not([type]),
.form-group select,
.form-group textarea,
select {
    width: 100%;
    min-height: 40px;
    padding: 8px 11px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    color: var(--ink-900);
    font-size: 0.93rem;
    line-height: 1.35;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.form-group input::placeholder,
textarea::placeholder {
    color: #7b8b9b;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
select:focus {
    border-color: var(--teal-700);
    box-shadow: var(--focus-ring);
    outline: none;
}

.form-group input:disabled,
.form-group select:disabled,
.form-group textarea:disabled,
button:disabled,
.btn[disabled],
.btn[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.58;
}

.form-group input[type="checkbox"] {
    width: auto;
    min-height: 0;
    margin: 4px 7px 0 0;
    accent-color: var(--teal-700);
}

.form-group label:has(input[type="checkbox"]) {
    display: inline-flex;
    align-items: flex-start;
}

/* 5. Buttons --------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 38px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--ink-800);
    color: #fff;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 650;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.btn:hover {
    color: #fff;
    text-decoration: none;
}

.btn-primary,
.btn-primary:hover,
.btn-primary:focus {
    background: var(--teal-700);
    color: #fff;
}

.btn-primary:hover {
    background: var(--teal-800);
}

.btn-secondary,
.btn-secondary:hover {
    background: var(--surface);
    border-color: var(--line-strong);
    color: var(--ink-800);
}

.btn-secondary:hover {
    background: var(--surface-muted);
    border-color: #9eacb9;
    color: var(--ink-950);
}

.btn-danger,
.btn-danger:hover,
.btn-danger:focus,
.btn-sm.btn-danger,
.btn-sm.btn-danger:hover {
    background: var(--red-700);
    border-color: var(--red-700);
    color: #fff;
}

.btn-danger:hover,
.btn-sm.btn-danger:hover {
    background: #92212b;
    border-color: #92212b;
}

.btn-sm {
    min-height: 31px;
    padding: 5px 10px;
    font-size: 0.79rem;
}

.btn-sm:not(.btn-danger):not(.btn-primary):not(.btn-secondary),
.btn-sm:not(.btn-danger):not(.btn-primary):not(.btn-secondary):hover {
    background: #edf3f7;
    border-color: #d2dee7;
    color: var(--ink-800);
}

.btn-sm:not(.btn-danger):not(.btn-primary):not(.btn-secondary):hover {
    background: #e1ebf1;
    border-color: #bac9d4;
    color: var(--ink-950);
}

/* 6. Dense tables ---------------------------------------------------------- */
.table-scroll {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    scrollbar-color: #aebdca var(--surface-muted);
    scrollbar-width: thin;
}

.table-scroll > table {
    display: table;
    width: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    scrollbar-color: #aebdca var(--surface-muted);
    scrollbar-width: thin;
}

thead,
tbody,
tr {
    min-width: max-content;
}

th,
td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    background: #edf2f5;
    color: #3c5068;
    font-size: 0.74rem;
    font-weight: 720;
    letter-spacing: 0.025em;
    line-height: 1.3;
    text-transform: uppercase;
    white-space: nowrap;
}

td {
    color: var(--ink-800);
    font-size: 0.88rem;
    line-height: 1.4;
    white-space: nowrap;
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover {
    background: #f8fafb;
}

.table-scroll tbody tr:hover {
    background: #f8fafb;
}

td.wrap-text {
    min-width: 180px;
    max-width: 300px;
    white-space: normal;
    overflow-wrap: anywhere;
}

/* Descriptive site and person names wrap; technical values and actions do not. */
table td:has(> .site-name),
table td.description {
    min-width: 180px;
    max-width: 300px;
    white-space: normal;
    overflow-wrap: anywhere;
}

.text-center:empty {
    color: var(--ink-600);
}

/* 7. Status and source presentation --------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    padding: 2px 7px;
    border: 1px solid transparent;
    border-radius: 4px;
    font-size: 0.71rem;
    font-weight: 720;
    letter-spacing: 0.025em;
    line-height: 1.35;
    text-transform: uppercase;
    vertical-align: middle;
    white-space: nowrap;
}

.badge-valid,
.badge-processed,
.badge-success {
    background: var(--green-100);
    border-color: #b9ddca;
    color: var(--green-800);
}

.badge-invalid,
.badge-failed,
.badge-rejected {
    background: var(--red-100);
    border-color: #f1bdc1;
    color: var(--red-800);
}

.badge-missing,
.badge-partially_processed,
.badge-partial {
    background: var(--amber-100);
    border-color: #efd49e;
    color: var(--amber-900);
}

.badge-received,
.badge-duplicate {
    background: #e8edf2;
    border-color: #ccd6df;
    color: #3f566d;
}

.badge-source-elvaco {
    background: var(--blue-100);
    border-color: #bfd7ed;
    color: var(--blue-800);
}

.badge-source-cme3100 {
    background: var(--teal-100);
    border-color: #b7ddda;
    color: var(--teal-800);
}

.badge-source-elvaco,
.badge-source-cme3100 {
    padding-top: 3px;
    padding-bottom: 3px;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.025em;
    text-transform: none;
    white-space: nowrap;
}

/* 8. Notices and diagnostics ---------------------------------------------- */
.alert,
.notice {
    position: relative;
    margin: 0 0 18px;
    padding: 13px 16px 13px 19px;
    border: 1px solid;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
}

.alert::before,
.notice::before {
    position: absolute;
    inset: -1px auto -1px -1px;
    width: 4px;
    border-radius: var(--radius-md) 0 0 var(--radius-md);
    content: "";
}

.alert {
    background: #f6f8fa;
    border-color: var(--line-strong);
    color: var(--ink-800);
}

.alert::before {
    background: var(--ink-600);
}

.alert-error {
    background: var(--red-100);
    border-color: #edb9bd;
    color: #7d2029;
}

.alert-error::before {
    background: var(--red-700);
}

.alert-warning {
    background: var(--amber-100);
    border-color: #e8c47e;
    color: var(--amber-900);
}

.alert-warning::before {
    background: var(--amber-700);
}

.alert-success {
    background: var(--green-100);
    border-color: #b8ddc9;
    color: var(--green-800);
}

.alert-success::before {
    background: #267457;
}

.alert p,
.notice p {
    margin-bottom: 0.35rem;
}

.alert ul,
.notice ul {
    margin: 0.3rem 0 0.4rem;
    padding-left: 1.2rem;
}

.notice {
    background: var(--blue-100);
    border-color: #c2d8ec;
    color: var(--blue-800);
}

.notice::before {
    background: #3f75a5;
}

/* 9. Raw payloads and login ----------------------------------------------- */
.raw-json {
    max-height: 520px;
    margin: 12px 0 22px;
    padding: 15px 17px;
    overflow: auto;
    background: #14263a;
    border: 1px solid #2d455d;
    border-radius: var(--radius-md);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    color: #dce6ee;
    font-family: Consolas, "SFMono-Regular", "Liberation Mono", monospace;
    font-size: 0.8rem;
    line-height: 1.55;
    white-space: pre;
}

.login-page {
    display: grid;
    min-height: 100vh;
    padding: 28px 18px;
    place-items: center;
    background:
        linear-gradient(135deg, rgba(23, 107, 112, 0.08), transparent 46%),
        linear-gradient(315deg, rgba(36, 81, 126, 0.08), transparent 44%),
        var(--canvas);
}

.login-container {
    width: min(100%, 410px);
    padding: 34px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-top: 4px solid var(--teal-700);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.login-container h1 {
    margin-bottom: 6px;
    font-size: 1.5rem;
    text-align: center;
}

.login-container > p {
    color: var(--ink-600);
    font-size: 0.9rem;
    text-align: center;
}

.login-container .btn {
    width: 100%;
    min-height: 43px;
    margin-top: 4px;
    font-size: 0.94rem;
}

.microsoft-login-form { margin-top: 24px; }
.btn-microsoft {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--ink-900);
    background: var(--surface);
    border: 1px solid var(--ink-600);
}
.btn-microsoft:hover:not(:disabled) { background: var(--canvas); }
.btn-microsoft:disabled { cursor: not-allowed; opacity: 0.65; }
.microsoft-mark { display: grid; grid-template-columns: repeat(2, 9px); gap: 2px; flex: 0 0 auto; }
.microsoft-mark span { width: 9px; height: 9px; background: #f25022; }
.microsoft-mark span:nth-child(2) { background: #7fba00; }
.microsoft-mark span:nth-child(3) { background: #00a4ef; }
.microsoft-mark span:nth-child(4) { background: #ffb900; }
.login-help { color: var(--ink-600); font-size: 0.82rem; line-height: 1.5; margin: 10px 0 0; text-align: center; }
.login-divider { display: flex; align-items: center; gap: 10px; margin: 22px 0; color: var(--ink-600); font-size: 0.82rem; }
.login-divider::before, .login-divider::after { content: ''; height: 1px; flex: 1; background: var(--line); }

/* 10. Pagination ----------------------------------------------------------- */
.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px 14px;
    margin-top: 18px;
}

.page-info {
    color: var(--ink-600);
    font-size: 0.88rem;
    font-variant-numeric: tabular-nums;
}

.pagination a,
.pagination .btn {
    white-space: nowrap;
}

/* 11. Tablet --------------------------------------------------------------- */
@media (max-width: 900px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filter-grid,
    .filter-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* 12. Mobile ---------------------------------------------------------------- */
@media (max-width: 600px) {
    .container {
        padding: 22px 14px 56px;
    }

    h2 {
        margin-top: 1.5rem;
    }

    .page-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .page-heading .btn {
        width: 100%;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 16px;
    }

    .detail-item {
        padding: 14px 15px;
    }

    .filter-form {
        padding: 15px;
    }

    .filter-grid,
    .filter-row {
        grid-template-columns: 1fr;
    }

    .filter-actions .btn,
    .section-actions .btn {
        flex: 1 1 auto;
    }

    .nav-links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .nav-user {
        max-width: 22ch;
    }

    .nav-account {
        flex-wrap: wrap;
    }

    .source-panel {
        padding: 19px;
    }

    .login-container {
        padding: 27px 22px;
    }

    th,
    td {
        padding: 9px 10px;
    }

    .badge {
        font-size: 0.68rem;
    }
}

/* 13. Motion and print ----------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

@media print {
    .portal-navbar,
    .btn,
    .filter-form,
    .pagination {
        display: none !important;
    }

    body,
    .container {
        background: #fff;
    }

    .container {
        width: 100%;
        max-width: none;
        margin-right: 0;
        margin-left: 0;
        padding: 0;
    }
}
