:root {
    --oct-brand: #067ea8;
    --oct-brand-dark: #045f7f;
    --oct-sidebar-bg: #0f2231;
    --oct-sidebar-fg: #c7d3dc;
    /* Loan-type palette, matching texaslending.com */
    --oct-purchase: #1980a6;
    --oct-refinance: #84246c;
    --oct-home-equity: #577f3e;
    --oct-heloc: #e02d2d;
    --oct-sidebar-width: 240px;
    --bs-primary: var(--oct-brand);
    --bs-primary-rgb: 6, 126, 168;
    --bs-link-color: var(--oct-brand);
    --bs-link-hover-color: var(--oct-brand-dark);
    --bs-body-bg: #f4f6f8;
}

.btn-primary {
    --bs-btn-bg: var(--oct-brand);
    --bs-btn-border-color: var(--oct-brand);
    --bs-btn-hover-bg: var(--oct-brand-dark);
    --bs-btn-hover-border-color: var(--oct-brand-dark);
    --bs-btn-active-bg: var(--oct-brand-dark);
    --bs-btn-active-border-color: var(--oct-brand-dark);
}

.btn-outline-primary {
    --bs-btn-color: var(--oct-brand);
    --bs-btn-border-color: var(--oct-brand);
    --bs-btn-hover-bg: var(--oct-brand);
    --bs-btn-hover-border-color: var(--oct-brand);
    --bs-btn-active-bg: var(--oct-brand);
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

.app-sidebar {
    width: var(--oct-sidebar-width);
    flex: 0 0 var(--oct-sidebar-width);
    background: var(--oct-sidebar-bg);
    color: var(--oct-sidebar-fg);
    padding: 1rem 0.75rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease, flex-basis 0.2s ease;
}

.sidebar-brand {
    display: block;
    padding: 0.5rem 0.75rem 1.25rem;
    color: #fff;
    text-decoration: none;
}

.sidebar-brand img {
    display: block;
    width: 100%;
    height: auto;
    filter: brightness(0) invert(1);
}

.sidebar-brand-mini {
    display: none;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-align: center;
}

.sidebar-collapse {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-bottom: 0.5rem;
    padding: 0.35rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.5rem;
    background: transparent;
    color: #7f93a3;
    font-size: 0.85rem;
}

.sidebar-collapse:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.06);
}

/* Collapsed (icon-only) sidebar on desktop; class is set on <html> before paint from localStorage */
@media (min-width: 992px) {
    html.sidebar-collapsed .app-sidebar {
        --oct-sidebar-width: 68px;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    html.sidebar-collapsed .sidebar-brand {
        padding-left: 0;
        padding-right: 0;
    }

    html.sidebar-collapsed .sidebar-brand img,
    html.sidebar-collapsed .sidebar-section,
    html.sidebar-collapsed .app-sidebar .nav-link span {
        display: none;
    }

    html.sidebar-collapsed .sidebar-brand-mini {
        display: block;
    }

    html.sidebar-collapsed .app-sidebar .nav {
        margin-top: 0.75rem;
    }

    html.sidebar-collapsed .app-sidebar .nav-link {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }

    html.sidebar-collapsed .sidebar-collapse .bi {
        transform: rotate(180deg);
    }
}

.sidebar-section {
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #7f93a3;
    padding: 0.75rem 0.75rem 0.25rem;
}

.sidebar-version {
    margin-top: auto;
    padding: 1rem 0.75rem 0;
    font-size: 0.7rem;
    color: #5f7382;
    text-align: center;
}

.app-sidebar .nav-link {
    color: var(--oct-sidebar-fg);
    border-radius: 0.5rem;
    padding: 0.55rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-size: 0.925rem;
}

.app-sidebar .nav-link .bi {
    font-size: 1.05rem;
    width: 1.25rem;
    text-align: center;
}

.app-sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.app-sidebar .nav-link.active {
    background: var(--oct-brand);
    color: #fff;
}

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

.app-topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid #e3e8ee;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.topbar-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0;
}

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

.app-footer {
    padding: 0.75rem 1.5rem;
    border-top: 1px solid #e3e8ee;
}

.sidebar-toggle {
    font-size: 1.5rem;
    padding: 0;
    color: var(--oct-brand);
}

@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        z-index: 1040;
        left: calc(-1 * var(--oct-sidebar-width));
        transition: left 0.2s ease;
    }

    .app-shell.sidebar-open .app-sidebar {
        left: 0;
    }

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

/* Cards and KPIs */
.card {
    border: 1px solid #e3e8ee;
    border-radius: 0.75rem;
}

.kpi {
    padding: 1rem 1.25rem;
}

.kpi-label {
    font-size: 0.8rem;
    color: #6c7a89;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.kpi-value {
    font-size: 1.65rem;
    font-weight: 600;
    line-height: 1.2;
}

.kpi-sub {
    font-size: 0.8rem;
    color: #6c7a89;
}

.filter-bar {
    background: #fff;
}

th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

th.sortable .bi {
    font-size: 0.7rem;
    opacity: 0.4;
}

th.sortable.is-sorted .bi {
    opacity: 1;
}

.filter-bar .filter-layout.has-hint {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(16rem, 24rem);
    gap: 0.75rem 1.5rem;
    align-items: center;
}

.filter-bar .filter-controls {
    width: 100%;
}

.filter-bar .filter-hint {
    line-height: 1.45;
}

@media (max-width: 991.98px) {
    .filter-bar .filter-layout.has-hint {
        grid-template-columns: 1fr;
    }
}

.filter-bar .sftp-note {
    display: block;
    width: 100%;
    margin: 0.75rem 0 0;
    padding: 0.4rem 0.75rem;
    border-radius: 0.375rem;
    background: #f08c2e;
    color: #3a2208;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.4;
}

/* Bucket colouring */
.bucket-purchase {
    --bucket-color: var(--oct-purchase);
}

.bucket-refinance {
    --bucket-color: var(--oct-refinance);
}

.bucket-home-equity {
    --bucket-color: var(--oct-home-equity);
}

.bucket-heloc {
    --bucket-color: var(--oct-heloc);
}

.bucket-heading {
    border-left: 4px solid var(--bucket-color, var(--oct-brand));
    padding-left: 0.75rem;
}

.bucket-badge {
    background: var(--bucket-color, var(--oct-brand));
    color: #fff;
    font-weight: 500;
}

.bucket-text {
    color: var(--bucket-color, inherit);
    font-weight: 600;
}

/* Tables */
.table-report {
    font-size: 0.9rem;
    margin-bottom: 0;
}

.table-report th {
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #55636f;
    background: #f8fafc;
    white-space: nowrap;
    vertical-align: bottom;
}

.table-report td.num,
.table-report th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.table-report tr.total-row td {
    font-weight: 600;
    background: #f8fafc;
}

.table-report .stage-name {
    font-weight: 500;
    white-space: nowrap;
}

.muted {
    color: #8a97a3;
}

.progress-thin {
    height: 6px;
}

/* Reconciliation flow */
.flow {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
}

.flow-step {
    background: #fff;
    border: 1px solid #e3e8ee;
    border-radius: 0.75rem;
    padding: 0.9rem 1rem;
    position: relative;
}

.flow-step .flow-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6c7a89;
}

.flow-step .flow-value {
    font-size: 1.5rem;
    font-weight: 600;
}

.flow-step .flow-sub {
    font-size: 0.78rem;
    color: #6c7a89;
}

.flow-step.is-good {
    border-top: 3px solid #2ca25f;
}

.flow-step.is-warn {
    border-top: 3px solid #f0ad4e;
}

.flow-step.is-bad {
    border-top: 3px solid #d9534f;
}

.flow-step.is-info {
    border-top: 3px solid var(--oct-brand);
}

a.flow-step {
    color: inherit;
    text-decoration: none;
    display: block;
}

a.flow-step:hover {
    border-color: var(--oct-brand);
}

a.flow-step.is-selected {
    border-color: var(--oct-brand);
    box-shadow: 0 0 0 1px var(--oct-brand);
    background: #f4fafc;
}

.table-report .num-link {
    appearance: none;
    background: none;
    border: 0;
    box-shadow: none;
    padding: 0;
    margin: 0;
    font: inherit;
    line-height: inherit;
    vertical-align: baseline;
    color: var(--bs-link-color);
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.table-report .num-link:hover,
.table-report .num-link:focus-visible {
    color: var(--bs-link-hover-color);
}

.purpose-toggle .bi {
    display: inline-block;
    margin-right: 0.35rem;
    transition: transform 0.15s ease;
}

.purpose-toggle[aria-expanded="true"] .bi {
    transform: rotate(90deg);
}

.purpose-breakdown {
    background: #f7f9fb;
    padding: 0.75rem 1rem 0.75rem 2rem;
}

tr.purpose-host:not(:has(.collapsing)):not(:has(.show)) {
    display: none;
}

/* Status badges */
.badge-status {
    font-weight: 500;
    text-transform: capitalize;
}

.status-pending { background: #e8eef3; color: #3e4c59; }
.status-uploaded { background: #dcf3e6; color: #1c6b3d; }
.status-duplicate { background: #e4f0f6; color: #1f5f7c; }
.status-skipped { background: #fff3cd; color: #7a5b00; }
.status-failed { background: #fbe0df; color: #9b2c28; }
.badge-sftp {
    background: #f08c2e;
    color: #3a2208;
    font-weight: 600;
    text-transform: none;
    white-space: normal;
    text-align: left;
    line-height: 1.35;
}
.status-expired { background: #ececec; color: #5b5b5b; }
.status-success, .status-SUCCESS { background: #dcf3e6; color: #1c6b3d; }
.status-PARTIAL_SUCCESS { background: #fff3cd; color: #7a5b00; }
.status-FAILED { background: #fbe0df; color: #9b2c28; }
.status-PROCESSING, .status-UNKNOWN { background: #e8eef3; color: #3e4c59; }

/* System health banner */
.status-banner {
    border-left: 5px solid #adb5bd;
}

.status-banner.is-healthy { border-left-color: #2ca25f; }
.status-banner.is-alert { border-left-color: #d9534f; }

.status-icon {
    font-size: 2rem;
    line-height: 1;
    color: #adb5bd;
}

.is-healthy .status-icon { color: #2ca25f; }
.is-alert .status-icon { color: #d9534f; }

.status-stats .stat-value {
    font-size: 1.35rem;
    font-weight: 600;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.status-stats .stat-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6c7a89;
}

.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot-good { background: #2ca25f; }
.dot-bad { background: #d9534f; }

.card-header-tabs .nav-link {
    color: #55636f;
    font-weight: 500;
}

.card-header-tabs .nav-link.active {
    color: var(--oct-brand);
}

/* Notes */
.note-box {
    white-space: pre-wrap;
    font-size: 0.9rem;
    background: #fffdf3;
    border: 1px solid #f1e6b8;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    max-height: 220px;
    overflow: auto;
}

/* Timeline */
.timeline {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.timeline li {
    position: relative;
    padding-left: 1.5rem;
    padding-bottom: 0.9rem;
    border-left: 2px solid #e3e8ee;
    margin-left: 0.5rem;
}

.timeline li::before {
    content: "";
    position: absolute;
    left: -7px;
    top: 0.3rem;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--oct-brand);
}

.timeline li.is-bad::before { background: #d9534f; }
.timeline li.is-warn::before { background: #f0ad4e; }
.timeline li.is-good::before { background: #2ca25f; }

/* Login */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #0f2231 0%, #123c52 60%, var(--oct-brand) 100%);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    border: none;
    border-radius: 1rem;
}

.auth-logo {
    display: block;
    width: 100%;
    max-width: 260px;
    height: auto;
    margin: 0 auto;
}

/* Misc */
.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85em;
}

.chart-box {
    position: relative;
    height: 260px;
}

.log-pane {
    max-height: 60vh;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.help {
    cursor: help;
    border-bottom: 1px dotted #8a97a3;
}

.infinity-lead + .infinity-lead {
    margin-top: 0.45rem;
    padding-top: 0.45rem;
    border-top: 1px solid #eef2f5;
}

.infinity-detail-value {
    word-break: break-word;
}

@media print {
    .app-sidebar, .app-topbar, .filter-bar, .app-footer, .no-print {
        display: none !important;
    }

    .app-content {
        padding: 0;
    }
}
