/*
 * Design layer for the operator UI. Everything is expressed as CSS custom properties on :root and, where
 * Bootstrap already owns a component, by overriding Bootstrap's own variables rather than fighting its
 * selectors — that keeps the stock components (forms, modals, alerts) consistent without a build step.
 */

:root {
    --ink-900: #0f172a;
    --ink-700: #334155;
    --ink-500: #64748b;
    --ink-300: #cbd5e1;
    --ink-100: #e2e8f0;
    --ink-050: #f1f5f9;
    --surface: #ffffff;
    --canvas: #f6f8fb;

    --brand-600: #2563eb;
    --brand-700: #1d4ed8;

    --sidebar-bg: #111827;
    --sidebar-bg-hover: #1f2937;
    --sidebar-fg: #9ca3af;
    --sidebar-fg-active: #ffffff;
    --sidebar-width: 15rem;

    --radius: 0.625rem;
    --radius-sm: 0.375rem;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, .07);

    /* Status accents — the single hue per status, reused by rows, badges and stat cards. */
    --status-pending: #2563eb;
    --status-processing: #d97706;
    --status-integrated: #059669;
    --status-failed: #dc2626;
    --status-skipped: #ea580c;
    --status-compensation-incomplete: #7f1d1d;
    --status-cancelled: #64748b;

    /* Bootstrap overrides. */
    --bs-body-bg: var(--canvas);
    --bs-body-color: var(--ink-700);
    --bs-border-color: var(--ink-100);
    --bs-primary: var(--brand-600);
    --bs-link-color: var(--brand-700);
    --bs-link-hover-color: var(--brand-600);
    --bs-border-radius: var(--radius-sm);
    --bs-font-sans-serif: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

html {
    font-size: 15px;
}

body {
    background: var(--canvas);
    color: var(--ink-700);
    font-family: var(--bs-font-sans-serif);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--ink-900);
    font-weight: 600;
    letter-spacing: -.01em;
}

/* ---------- Shell ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: 1.125rem 1.25rem;
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    letter-spacing: .02em;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}

.app-brand:hover {
    color: #fff;
}

.app-brand-mark {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: var(--radius-sm);
    background: var(--brand-600);
    display: grid;
    place-items: center;
    font-size: .75rem;
    font-weight: 700;
}

.app-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.app-brand-sub {
    font-size: .6875rem;
    font-weight: 400;
    color: var(--sidebar-fg);
}

.app-nav {
    padding: .75rem .625rem;
    display: flex;
    flex-direction: column;
    gap: .125rem;
    flex: 1 1 auto;
    overflow-y: auto;
}

.app-nav-label {
    font-size: .6875rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #6b7280;
    padding: .75rem .75rem .375rem;
}

.app-nav-link {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .5rem .75rem;
    border-radius: var(--radius-sm);
    color: var(--sidebar-fg);
    text-decoration: none;
    font-size: .9375rem;
    transition: background-color .12s ease, color .12s ease;
}

.app-nav-link:hover {
    background: var(--sidebar-bg-hover);
    color: #e5e7eb;
}

.app-nav-link.active {
    background: var(--brand-600);
    color: var(--sidebar-fg-active);
    font-weight: 500;
}

.app-nav-icon {
    width: 1.125rem;
    text-align: center;
    opacity: .9;
}

.app-sidebar-footer {
    padding: .75rem .625rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, .07);
}

.app-user {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .5rem .75rem;
    color: #e5e7eb;
    font-size: .875rem;
}

.app-avatar {
    width: 1.875rem;
    height: 1.875rem;
    border-radius: 50%;
    background: var(--sidebar-bg-hover);
    display: grid;
    place-items: center;
    font-size: .75rem;
    font-weight: 600;
    color: #fff;
    text-transform: uppercase;
}

.app-signout {
    background: none;
    border: 0;
    padding: .5rem .75rem;
    width: 100%;
    text-align: left;
    color: var(--sidebar-fg);
    font-size: .875rem;
    border-radius: var(--radius-sm);
}

.app-signout:hover {
    background: var(--sidebar-bg-hover);
    color: #e5e7eb;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--ink-100);
    padding: .875rem 1.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.app-topbar h1 {
    font-size: 1.125rem;
    margin: 0;
}

.app-content {
    padding: 1.5rem 1.75rem 3rem;
    flex: 1 1 auto;
}

@media (max-width: 991.98px) {
    .app-shell {
        flex-direction: column;
    }

    .app-sidebar {
        width: 100%;
        flex-basis: auto;
        height: auto;
        position: static;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
    }

    .app-brand {
        border-bottom: 0;
        border-right: 1px solid rgba(255, 255, 255, .07);
        white-space: nowrap;
    }

    .app-nav {
        flex-direction: row;
        padding: .5rem;
    }

    /* Only the section captions go: the footer holds Sign out, and hiding it strands the operator. */
    .app-nav-label {
        display: none;
    }

    .app-sidebar-footer {
        display: flex;
        align-items: center;
        gap: .25rem;
        padding: .5rem;
        border-top: 0;
        border-left: 1px solid rgba(255, 255, 255, .07);
        margin-left: auto;
    }

    /* Kept visible: it is the only hint that the username is the way to the password page. */
    .app-user .app-brand-sub {
        font-size: .625rem;
    }

    .app-user, .app-signout {
        white-space: nowrap;
        width: auto;
    }

    .app-content {
        padding: 1.25rem 1rem 2rem;
    }
}

/* Sign-in / change-password shell: no sidebar, the form centred on the canvas. */
.auth-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: linear-gradient(160deg, #0f172a 0%, #1e293b 55%, #334155 100%);
    background-attachment: fixed;
}

.auth-card {
    width: 100%;
    max-width: 24rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 18px 40px rgba(15, 23, 42, .35);
    padding: 2rem;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: .625rem;
    margin-bottom: 1.5rem;
    color: var(--ink-900);
    font-weight: 600;
}

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--ink-100);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--ink-100);
    padding: .875rem 1.125rem;
    font-weight: 600;
    color: var(--ink-900);
}

.card-body {
    padding: 1.125rem;
}

/*
 * Section headings are what the eye jumps between on a long detail page, so they are darker and heavier than
 * the labels inside a section. Uppercase micro-grey for both levels was the reason the page read as one flat
 * wall: nothing outranked anything else.
 */
.section-title {
    font-size: .875rem;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    color: var(--ink-900);
    margin: 0 0 .625rem;
}

/* ---------- Status stat cards (also the per-status navigation) ---------- */

/* auto-fit + a smaller floor: auto-fill kept reserving a column that was not there, which clipped the last card. */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
    gap: .75rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--ink-100);
    border-left: 3px solid var(--ink-300);
    border-radius: var(--radius);
    padding: .75rem .875rem;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow-sm);
    transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}

.stat-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    color: inherit;
}

.stat-card.active {
    border-color: var(--ink-300);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, .18), var(--shadow-sm);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 650;
    color: var(--ink-900);
    line-height: 1.1;
}

.stat-label {
    font-size: .8125rem;
    color: var(--ink-500);
    overflow-wrap: anywhere;
}

.stat-card-pending { border-left-color: var(--status-pending); }
.stat-card-processing { border-left-color: var(--status-processing); }
.stat-card-integrated { border-left-color: var(--status-integrated); }
.stat-card-failed { border-left-color: var(--status-failed); }
.stat-card-skipped { border-left-color: var(--status-skipped); }
.stat-card-compensation-incomplete { border-left-color: var(--status-compensation-incomplete); }
.stat-card-cancelled { border-left-color: var(--status-cancelled); }
.stat-card-all { border-left-color: var(--ink-500); }

/* A status that needs attention only shouts when it actually has rows. */
.stat-card.stat-alert .stat-value {
    color: var(--status-failed);
}

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

.table {
    --bs-table-bg: transparent;
    margin-bottom: 0;
    color: var(--ink-700);
}

.table > thead th {
    background: var(--ink-050);
    color: var(--ink-500);
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .045em;
    border-bottom: 1px solid var(--ink-100);
    padding: .625rem .75rem;
    white-space: nowrap;
}

.table > tbody td {
    padding: .625rem .75rem;
    border-bottom: 1px solid var(--ink-050);
    vertical-align: middle;
}

.table-card {
    background: var(--surface);
    border: 1px solid var(--ink-100);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.table-card .table > tbody tr:last-child td {
    border-bottom: 0;
}

.num {
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

.muted {
    color: var(--ink-500);
}

.cell-sub {
    display: block;
    font-size: .8125rem;
    color: var(--ink-700);
}

/* Rows in the audit tables are long and uniform; a hover cue is what keeps the eye on one line. */
.table-card tbody tr:hover {
    background-color: var(--ink-050);
}

/*
 * An audit row is one row. The request/response used to expand into a second full-width row under it, which
 * doubled the grid and left every other line half empty — the bodies now open in the shared log dialog.
 */
.log-row {
    cursor: pointer;
}

.log-open-col {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.log-open {
    font-weight: 500;
}

/* A Bulut360 URL is long and repetitive; capping it keeps the columns that carry meaning in view. */
.log-url {
    max-width: 22rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/*
 * Status on a row is a left accent bar, not a full fill: a coloured background across eleven columns makes
 * the text fight the colour, and every row then competes for attention. The accent + badge reads faster.
 */
.status-row-pending,
.status-row-processing,
.status-row-integrated,
.status-row-failed,
.status-row-skipped,
.status-row-compensation-incomplete,
.status-row-cancelled {
    box-shadow: inset 3px 0 0 0 var(--row-accent, transparent);
}

.status-row-pending { --row-accent: var(--status-pending); }
.status-row-processing { --row-accent: var(--status-processing); background-color: #fffbeb; }
.status-row-integrated { --row-accent: var(--status-integrated); }
.status-row-failed { --row-accent: var(--status-failed); background-color: #fef2f2; }
.status-row-skipped { --row-accent: var(--status-skipped); }
.status-row-compensation-incomplete { --row-accent: var(--status-compensation-incomplete); background-color: #fee2e2; }
.status-row-cancelled { --row-accent: var(--status-cancelled); }

tbody tr.refund-row:hover {
    background-color: var(--ink-050);
}

.refund-row {
    cursor: pointer;
}

.refund-error-cell {
    max-width: 18rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--status-failed);
    font-size: .8125rem;
}

/* ---------- Badges ---------- */

.badge {
    font-weight: 600;
    font-size: .6875rem;
    letter-spacing: .02em;
    padding: .3em .6em;
    border-radius: 999px;
}

.status-badge-pending { background-color: #dbeafe; color: #1e40af; }
.status-badge-processing { background-color: #fef3c7; color: #92400e; }
.status-badge-integrated { background-color: #d1fae5; color: #065f46; }
.status-badge-failed { background-color: #fee2e2; color: #991b1b; }
.status-badge-skipped { background-color: #ffedd5; color: #9a3412; }
.status-badge-compensation-incomplete { background-color: #7f1d1d; color: #ffffff; }
.status-badge-cancelled { background-color: var(--ink-100); color: var(--ink-700); }

/* ---------- Forms, buttons, misc ---------- */

.form-label {
    font-size: .8125rem;
    font-weight: 500;
    color: var(--ink-500);
    margin-bottom: .25rem;
}

.form-control, .form-select {
    border-color: var(--ink-300);
    border-radius: var(--radius-sm);
}

.form-control:focus, .form-select:focus {
    border-color: var(--brand-600);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.btn {
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.btn:focus-visible {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .3);
}

.filter-bar {
    background: var(--surface);
    border: 1px solid var(--ink-100);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: .875rem 1.125rem;
    margin-bottom: 1.25rem;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
    margin-bottom: .875rem;
}

.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--ink-500);
}

.empty-state-title {
    font-weight: 600;
    color: var(--ink-700);
    margin-bottom: .25rem;
}

.alert {
    border: 0;
    border-left: 3px solid transparent;
    border-radius: var(--radius-sm);
}

.alert-success { border-left-color: var(--status-integrated); }
.alert-danger { border-left-color: var(--status-failed); }
.alert-warning { border-left-color: var(--status-processing); }
.alert-info { border-left-color: var(--status-pending); }

/* Log request/response bodies: monospace, scroll-capped so one huge payload cannot push the page away. */
.log-body {
    background: var(--ink-900);
    color: #e2e8f0;
    border-radius: var(--radius-sm);
    padding: .75rem .875rem;
    font-size: .8125rem;
    line-height: 1.5;
    max-height: 22rem;
    overflow: auto;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.log-body-failed {
    border-left: 3px solid var(--status-failed);
}

/* The queue panel still expands its result lines in place — they are a handful of short lines, not a payload. */
details.log-details > summary {
    cursor: pointer;
    font-size: .8125rem;
    color: var(--brand-700);
    padding: .25rem 0;
}

/*
 * The queue panel's own header is its disclosure control. The native marker is dropped rather than styled:
 * a flex summary already hides it in Chrome, so keeping it would mean two different headers depending on the
 * browser. The caret in the markup is the one indicator, in every browser.
 */
#queue-panel > summary {
    cursor: pointer;
    list-style: none;
}

#queue-panel > summary::-webkit-details-marker {
    display: none;
}

.queue-caret {
    display: inline-block;
    margin-right: .5rem;
    color: var(--ink-500);
    transition: transform .15s ease;
}

#queue-panel[open] > summary .queue-caret {
    transform: rotate(90deg);
}

/* ---------- Log dialog ---------- */

.log-dialog-header {
    align-items: flex-start;
    gap: 1rem;
}

/*
 * Bootstrap's modal header does not justify its children; it relies on .btn-close carrying margin-left:auto.
 * Wrapping the close button together with the fullscreen toggle takes that rule out of the header's own flex
 * row, so the group has to claim the free space itself — otherwise both buttons sit glued to the title.
 */
.log-dialog-actions {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-left: auto;
}

.log-dialog-meta {
    font-size: .8125rem;
    color: var(--ink-500);
}

.log-dialog-section + .log-dialog-section {
    margin-top: 1rem;
}

.log-dialog-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: .375rem;
}

.log-dialog-hint {
    margin-right: auto;
    font-size: .8125rem;
    color: var(--status-failed);
}

/* Fullscreen is for reading one long payload, so the body — not the page — is what scrolls. */
.modal-fullscreen .log-body {
    max-height: none;
}

.pagination {
    --bs-pagination-color: var(--ink-700);
    --bs-pagination-active-bg: var(--brand-600);
    --bs-pagination-border-color: var(--ink-100);
}

.page-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    font-size: .875rem;
    color: var(--ink-500);
}

/* ---------- Refund detail ---------- */

/*
 * Labels stay quiet but must still be legible: .75rem uppercase micro-grey was below the size at which
 * letter-spacing helps, so it read as noise around the values instead of naming them.
 */
.detail-term {
    display: block;
    font-size: .8125rem;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    color: var(--ink-500);
    margin-bottom: .125rem;
}

/* The identity strip at the top of a refund: what it is, then the four facts that identify it. */
.detail-head {
    background: var(--surface);
    border: 1px solid var(--ink-100);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.125rem;
    margin-bottom: 1rem;
}

.detail-head-id {
    display: flex;
    align-items: center;
    gap: .625rem;
    margin-bottom: .875rem;
}

.detail-head-label {
    font-size: .8125rem;
    font-weight: 600;
    color: var(--ink-500);
}

.detail-head-no {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--ink-900);
    line-height: 1;
}

.detail-head-facts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: .875rem 1.5rem;
}

.detail-head-value {
    display: block;
}

.detail-head-sub {
    display: block;
    font-weight: 400;
    font-size: .8125rem;
    color: var(--ink-500);
}

.detail-groups {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.detail-group-title {
    font-size: .875rem;
    font-weight: 600;
    color: var(--ink-900);
    margin: 0 0 .75rem;
}

/* Term left, value right: a two-column list is read line by line, unlike a grid of label-over-value tiles. */
.detail-list {
    display: grid;
    grid-template-columns: minmax(7rem, auto) 1fr;
    gap: .5rem 1.25rem;
    margin: 0;
}

/* The same list across a full-width card: two term/value pairs per line once there is room for them. */
@media (min-width: 62em) {
    .detail-list-wide {
        grid-template-columns: minmax(9rem, auto) 1fr minmax(9rem, auto) 1fr;
    }
}

.detail-list dt {
    font-size: .8125rem;
    font-weight: 600;
    color: var(--ink-500);
}

/*
 * A value belongs next to its label. `.num` right-aligns inside table cells, where a column of figures should
 * line up; in a term/value list it would fling the number to the far edge and break the pairing, so the list
 * keeps the tabular figures and drops the alignment.
 */
.detail-list dd,
.detail-head-value {
    margin: 0;
    text-align: left;
    color: var(--ink-900);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.detail-note {
    font-weight: 400;
    font-size: .8125rem;
    color: var(--ink-500);
}

.detail-doc-empty td {
    color: var(--ink-500);
}

.detail-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-left: 3px solid var(--status-failed);
    border-radius: var(--radius);
    padding: .875rem 1.125rem;
    margin-bottom: 1rem;
}

.detail-error-title {
    font-size: .8125rem;
    font-weight: 600;
    color: #991b1b;
    margin: 0 0 .375rem;
}

.detail-error-body {
    margin: 0;
    font-size: .875rem;
    color: var(--ink-900);
    white-space: pre-wrap;
    word-break: break-word;
}
