:root {
    /* Subtle cool-grey page background (Tailwind gray-50) */
    --d2d-page-bg: #f9fafb;
    --d2d-overlay: rgba(255, 255, 255, 0.7);
    --d2d-stripe: rgba(0, 0, 0, 0.02);
    --d2d-add-row: rgba(0, 0, 0, 0.075);
    --d2d-pill-bg: #fff;
    --d2d-pill-bg-striped: #fafafa;
    --d2d-pill-fg: #6c757d;
    --d2d-column-bg: #f0f7ff;
    --d2d-column-bg-alt: #e4edf8;
    --d2d-column-add-bg: #e8f0fb;
    --d2d-column-name: #5a7da8;
    --d2d-column-desc: #6b7f99;
    --d2d-column-handle: #7a94b0;
}

[data-bs-theme="dark"] {
    --d2d-page-bg: #181b1e;
    --d2d-overlay: rgba(33, 37, 41, 0.7);
    --d2d-stripe: rgba(255, 255, 255, 0.03);
    --d2d-add-row: rgba(255, 255, 255, 0.06);
    --d2d-pill-bg: #2b3035;
    --d2d-pill-bg-striped: #2b3035;
    --d2d-pill-fg: #adb5bd;
    --d2d-column-bg: #1a2533;
    --d2d-column-bg-alt: #1f2c3d;
    --d2d-column-add-bg: #1c2838;
    --d2d-column-name: #8fb0d6;
    --d2d-column-desc: #9aaac0;
    --d2d-column-handle: #8ea6c2;
}

body {
    background-color: var(--d2d-page-bg);
}

[data-bs-theme="dark"] footer.bg-dark {
    border-top: 1px solid var(--bs-border-color);
}

/* Blazor validation integration with Bootstrap */
.valid.modified:not([type=checkbox]) {
    border-color: var(--bs-success);
}

.invalid {
    border-color: var(--bs-danger);
}

/* Remove focus outline on headings (set by FocusOnNavigate for accessibility) */
h1:focus,
h2:focus,
h3:focus,
h4:focus,
h5:focus,
h6:focus {
    outline: none;
}

/* Blazor error boundary styling */
.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA9?Bu==) no-repeat 1rem/1.8rem, var(--bs-danger);
    padding: 1rem 1rem 1rem 3.7rem;
  color: white;
    border-radius: 0.375rem;
    margin: 1rem 0;
}

.blazor-error-boundary::after {
    content: "An error has occurred."
}

/* Auto-expanding textarea */
textarea.auto-expand {
    field-sizing: content;
    min-height: calc(1.5em + 0.5rem + 2px);
    overflow: hidden;
    resize: none;
}

/* Drag-and-drop ghost row */
.sortable-ghost {
    opacity: 0.4;
    background-color: var(--bs-primary-bg-subtle);
}

.reorder-overlay {
    position: absolute;
    inset: 0;
    background: var(--d2d-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.busy-button {
    position: relative;
}

.busy-button-spinner {
    position: absolute;
    inset: 0;
    margin: auto;
}

.busy-button:has(.busy-button-spinner) .busy-button-label {
    visibility: hidden;
}

/* Field grid layout */
.fields-container {
    overflow-x: auto;
}

.field-grid {
    display: grid;
    grid-template-columns: 36px 22% 120px 1fr 100px;
    align-items: center;
    min-width: 650px;
}

.field-grid > div {
    padding: 0.35rem 0.5rem;
    min-width: 0;
}

/*
 * Two header treatments, chosen by where a table sits rather than per page:
 *   - A top-level list (Templates, Workflows, Grants, SFTP) stands on the page and uses table-dark.
 *   - A table inside a card section is a sub-level view and takes the Fields grid's light header,
 *     which is the reference design. A dark bar directly under a light card header is what looked
 *     wrong on the workflow steps and Usage pages.
 */
.field-grid-header,
.card .table > thead {
    font-weight: 600;
    border-bottom: 2px solid var(--bs-border-color);
}

.card .table > thead th {
    background-color: transparent;
    color: inherit;
    border-bottom: 0;
}

.field-grid-header > div {
    padding: 0.5rem;
}

.field-grid-row {
    border-bottom: 1px solid var(--bs-border-color);
}

.field-grid-error {
    padding: 0.125rem 0.5rem 0.35rem calc(36px + 1rem);
    border-bottom: 1px solid var(--bs-border-color);
}

/* Field striping */
.field-group:nth-child(odd) > .field-grid-row {
    background-color: var(--d2d-stripe);
}

/* Hide columns while dragging fields */
.fields-dragging .column-container {
    display: none !important;
}

/* Column container styling */
.column-container {
    border-left: 3px solid var(--bs-primary);
}

/* Column count pill — tight, muted, overlaps icon */
.column-count-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 1;
    min-width: 12px;
    height: 12px;
    padding: 0 2px;
    border-radius: 6px;
    background-color: var(--d2d-pill-bg);
    color: var(--d2d-pill-fg);
    margin-left: -6px;
    position: relative;
    top: 4px;
}

.field-group:nth-child(odd) .column-count-pill {
    background-color: var(--d2d-pill-bg-striped);
}

/* Column row hierarchy — subordinate styling */
.column-row {
    background-color: var(--d2d-column-bg);
}

.column-row:nth-child(even) {
    background-color: var(--d2d-column-bg-alt);
}

.column-edit-row {
    background-color: var(--d2d-column-bg);
}

.column-row .column-field-name {
    color: var(--d2d-column-name);
    font-family: var(--bs-font-monospace);
    font-weight: 400;
    font-size: 0.875rem;
}

.column-row .column-desc {
    color: var(--d2d-column-desc);
}

.column-row .col-drag-handle i {
    color: var(--d2d-column-handle) !important;
}

.col-drag-handle {
    cursor: grab;
}

.add-column-row {
    background-color: var(--d2d-column-add-bg);
}

.add-column-row > div {
    padding-bottom: 0.75rem;
}

.add-field-row {
    background-color: var(--d2d-add-row);
    border-bottom: 1px solid var(--bs-border-color);
}

.components-reconnect-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: flex-start;
    justify-content: center;
    padding-top: 20vh;
}

.components-reconnect-modal.components-reconnect-show,
.components-reconnect-modal.components-reconnect-failed,
.components-reconnect-modal.components-reconnect-rejected {
    display: flex;
}

.components-reconnect-card {
    margin: 0 auto;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.75rem;
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.5), 0 0.25rem 0.75rem rgba(0, 0, 0, 0.3);
    padding: 2rem 2.5rem;
    max-width: 460px;
    width: calc(100% - 2rem);
}

.components-reconnect-content {
    display: flex;
    align-items: center;
}

/* Hide all states by default */
.components-reconnect-show,
.components-reconnect-failed,
.components-reconnect-rejected {
    display: none;
}

/* Show appropriate state based on modal class */
.components-reconnect-modal.components-reconnect-show .components-reconnect-show {
    display: flex;
    align-items: center;
}

.components-reconnect-modal.components-reconnect-failed .components-reconnect-failed {
    display: flex;
    align-items: center;
}

.components-reconnect-modal.components-reconnect-rejected .components-reconnect-rejected {
    display: flex;
    align-items: center;
}

/* JSON editor (CodeMirror 6) --------------------------------------------------------------- */

.json-editor {
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    overflow: hidden;
}

.json-editor .cm-editor {
    /* Tall enough for a small config document without a scrollbar, and bounded so a large one
       scrolls inside the editor rather than pushing the form's buttons off screen. */
    max-height: 22rem;
    font-size: 0.875rem;
}

.json-editor .cm-editor.cm-focused {
    outline: none;
}

.json-editor:focus-within {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25);
}

.json-editor--readonly .cm-editor {
    background-color: var(--bs-secondary-bg);
    /* A result is read, not filled in, so it gets the room a form field cannot have. */
    max-height: 40rem;
}

.jobs-table .job-row {
    cursor: pointer;
}

.jobs-table .job-error {
    max-width: 18rem;
}

.job-steps .job-step-current {
    background-color: var(--bs-tertiary-bg);
}

.job-filters .job-filter-label {
    min-width: 3.5rem;
    font-size: .8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--bs-secondary-color);
}

.job-details dd {
    min-width: 0;
}

/*
 * The field editors become cards on a phone, the same way Corely.IAM.Web's .table-cards turns table
 * rows into cards. The shared roles (.cell-title, .cell-badge, .cell-sub, .cell-actions, .cell-hide,
 * .cell-only), .row-actions and .detail-cards come from iam-web.css; only the grids are ours.
 */
@media (max-width: 767.98px) {
    .fields-container .field-grid-header,
    .fields-container .cell-hide {
        display: none !important;
    }

    .fields-container .field-grid {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        column-gap: 0.75rem;
        row-gap: 0.25rem;
        align-items: start;
        min-width: 0;
    }

    .fields-container .field-grid-row,
    .fields-container .workflow-step-grid-row {
        margin: 0 0 0.75rem;
        padding: 0.75rem;
        border: 1px solid var(--bs-border-color);
        border-radius: var(--bs-border-radius);
        background-color: var(--bs-body-bg);
    }

    /* Striping marks rows in a table; between separate cards it only reads as a colour change. */
    .fields-container .field-group > .field-grid-row,
    .fields-container .workflow-step-grid-row {
        margin: 0.5rem;
        background-color: var(--bs-body-bg);
    }

    .fields-container .field-grid > div {
        grid-column: 1 / -1;
        padding: 0;
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .fields-container .cell-title {
        grid-column: 1;
        grid-row: 1;
        font-weight: 600;
    }

    .fields-container .cell-badge {
        grid-column: 2;
        grid-row: 1;
        justify-self: end;
    }

    .fields-container .cell-actions {
        display: flex;
        justify-content: flex-end;
        margin-top: 0.25rem;
    }

    /* Move up / move down sit apart from edit and delete, on the left of the same line. */
    .reorder-buttons {
        display: inline-flex;
        gap: 0.25rem;
        margin-right: auto;
    }

    /* Dragging is a pointer-precision gesture; on a phone the arrows replace the handles. */
    .fields-container .drag-handle,
    .fields-container .col-drag-handle {
        display: none !important;
    }

    /* A table field's columns: smaller cards tucked under their field. */
    .fields-container .column-container {
        margin: -0.25rem 0.5rem 0.5rem 1.25rem;
        border-left-width: 2px;
    }

    .fields-container .column-row {
        padding: 0.5rem 0.75rem;
        border-bottom: 1px solid var(--bs-border-color-translucent);
    }

    /* The add and inline-edit rows are forms: one input per line. */
    .fields-container :is(.add-field-row, .add-column-row, .column-edit-row) {
        padding: 0.75rem;
    }

    .fields-container .field-group > .column-container + .column-container {
        margin-top: 0.75rem;
    }

    .site-footer .container-lg {
        flex-wrap: wrap;
        gap: 0.25rem 1rem;
    }
}
