@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --sidebar-width: 268px;
    --sidebar-collapsed-width: 76px;
    --topbar-height: 68px;
    --color-ink: #172033;
    --color-muted: #718096;
    --color-border: #e6ebf2;
    --color-surface: #ffffff;
    --color-canvas: #f7f9fc;
    --color-primary: #2563eb;
    --color-primary-dark: #173a9c;
    --sidebar-transition: width 0.22s ease, transform 0.22s ease;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--color-ink);
    background: var(--color-canvas);
    font-family: Inter, -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- */
/* Auth pages                                                        */
/* ---------------------------------------------------------------- */

.auth-page {
    min-height: 100vh;
    background: #eef3f9;
}

.auth-shell {
    display: grid;
    grid-template-columns: minmax(320px, 0.9fr) minmax(460px, 1.1fr);
    min-height: 100vh;
}

.auth-brand-panel {
    position: relative;
    display: flex;
    align-items: flex-end;
    padding: 64px;
    color: #ffffff;
    background: linear-gradient(145deg, rgba(15, 43, 94, 0.96), rgba(37, 99, 235, 0.88)),
        url('../images/watermark.png') center / cover;
}

.auth-brand-content {
    max-width: 480px;
}

.auth-brand-content .brand-mark {
    margin-bottom: 42px;
    background: rgba(255, 255, 255, 0.16);
    box-shadow: none;
}

.auth-brand-content h1 {
    margin: 10px 0 14px;
    font-size: 38px;
    font-weight: 800;
    letter-spacing: -0.04em;
}

.auth-brand-content p {
    color: rgba(255, 255, 255, 0.75);
    font-size: 14px;
    line-height: 1.7;
}

.auth-form-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.auth-card {
    width: 100%;
    max-width: 430px;
    padding: 40px;
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: 14px;
    box-shadow: 0 18px 50px rgba(23, 32, 51, 0.08);
}

.auth-card h2 {
    margin: 6px 0 8px;
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.auth-intro {
    margin-bottom: 28px;
    color: var(--color-muted);
    line-height: 1.6;
}

.auth-card label {
    color: #4b5870;
    font-size: 11px;
    font-weight: 700;
}

.auth-card .form-control {
    height: 44px;
    border-color: #dfe5ed;
    border-radius: 8px;
    font-size: 13px;
}

@media (max-width: 900px) {
    .auth-shell {
        grid-template-columns: 1fr;
    }

    .auth-brand-panel {
        display: none;
    }
}

/* ---------------------------------------------------------------- */
/* App shell / sidebar                                               */
/* ---------------------------------------------------------------- */

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

.sidebar-backdrop {
    position: fixed;
    z-index: 1035;
    inset: 0;
    display: none;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.sidebar {
    position: fixed;
    z-index: 1040;
    top: 0;
    bottom: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    transition: var(--sidebar-transition);
}

.brand {
    display: flex;
    align-items: center;
    height: var(--topbar-height);
    padding: 0 20px;
    gap: 12px;
    color: var(--color-ink);
    border-bottom: 1px solid var(--color-border);
    text-decoration: none;
    white-space: nowrap;
}

.brand:hover {
    color: var(--color-ink);
    text-decoration: none;
}

.brand-mark {
    display: grid;
    flex: none;
    place-items: center;
    width: 38px;
    height: 38px;
    color: #ffffff;
    background: linear-gradient(145deg, #2563eb, #173a9c);
    border-radius: 11px;
    box-shadow: 0 7px 18px rgba(37, 99, 235, 0.22);
    font-weight: 800;
}

.brand strong,
.brand small,
.topbar-context strong,
.topbar-context span,
.user-chip strong,
.user-chip small {
    display: block;
}

.brand strong {
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
}

.brand small {
    margin-top: 2px;
    overflow: hidden;
    color: #94a3b8;
    font-size: 10px;
    letter-spacing: 0.08em;
    text-overflow: ellipsis;
    text-transform: uppercase;
}

.sidebar-nav {
    padding: 14px 11px 30px;
}

.nav-heading {
    display: block;
    padding: 10px 12px 7px;
    overflow: hidden;
    color: #a3adbd;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.12em;
    white-space: nowrap;
    text-transform: uppercase;
}

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 42px;
    margin: 2px 0;
    padding: 0 12px;
    gap: 11px;
    color: #536176;
    border-radius: 8px;
    cursor: pointer;
    list-style: none;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-item::-webkit-details-marker {
    display: none;
}

.nav-item:hover {
    color: #1f2937;
    background: #f3f6fb;
    text-decoration: none;
}

.nav-item.active {
    color: var(--color-primary);
    background: #edf4ff;
    font-weight: 700;
}

.nav-item.active::before {
    position: absolute;
    top: 8px;
    bottom: 8px;
    left: -11px;
    width: 3px;
    background: var(--color-primary);
    border-radius: 0 3px 3px 0;
    content: '';
}

.nav-item > i:first-child {
    display: grid;
    flex: none;
    place-items: center;
    width: 22px;
    font-size: 19px;
    text-align: center;
}

.nav-item .arrow {
    flex: none;
    margin-left: auto;
    font-size: 15px !important;
    transition: transform 0.2s ease;
}

.nav-group[open] .arrow {
    transform: rotate(180deg);
}

.nav-children {
    margin: 3px 0 7px 22px;
    padding-left: 22px;
    border-left: 1px solid #dfe6ef;
}

.nav-children span,
.nav-children a {
    display: block;
    padding: 7px 8px;
    color: #7c889a;
    font-size: 12px;
    text-decoration: none;
    white-space: nowrap;
}

.nav-children a:hover {
    color: var(--color-primary);
    background: #edf4ff;
    border-radius: 6px;
}

/* Collapsed (icon-rail) desktop mode */
body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .nav-heading,
body.sidebar-collapsed .nav-item span:not(.arrow),
body.sidebar-collapsed .arrow,
body.sidebar-collapsed .nav-children {
    display: none;
}

body.sidebar-collapsed .nav-item {
    justify-content: center;
    padding: 0;
}

body.sidebar-collapsed .brand {
    justify-content: center;
    padding: 0;
}

body.sidebar-collapsed .main-panel {
    margin-left: var(--sidebar-collapsed-width);
}

/* Tooltip shown for collapsed items on hover (desktop only) */
body.sidebar-collapsed .nav-item[data-tooltip]:hover::after {
    position: absolute;
    left: calc(100% + 12px);
    z-index: 1050;
    padding: 6px 10px;
    color: #ffffff;
    white-space: nowrap;
    background: var(--color-ink);
    border-radius: 6px;
    box-shadow: 0 6px 16px rgba(23, 32, 51, 0.25);
    content: attr(data-tooltip);
    font-size: 11px;
    font-weight: 600;
    pointer-events: none;
}

.main-panel {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.22s ease;
}

.topbar {
    position: sticky;
    z-index: 1030;
    top: 0;
    display: flex;
    align-items: center;
    height: var(--topbar-height);
    padding: 0 28px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--color-border);
    backdrop-filter: blur(12px);
}

.menu-toggle,
.icon-button {
    display: grid;
    flex: none;
    place-items: center;
    width: 38px;
    height: 38px;
    color: #657287;
    background: transparent;
    border: 0;
    border-radius: 8px;
    transition: background 0.15s ease, color 0.15s ease;
}

.menu-toggle {
    margin-right: 14px;
    font-size: 21px;
}

.menu-toggle:hover,
.icon-button:hover {
    color: var(--color-primary);
    background: #f3f6fb;
}

.topbar-context strong {
    font-size: 13px;
}

.topbar-context span {
    margin-top: 2px;
    color: #8b97a8;
    font-size: 11px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    margin-left: auto;
    gap: 10px;
}

.icon-button {
    position: relative;
    font-size: 20px;
}

.icon-button span {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 7px;
    height: 7px;
    background: #ef4444;
    border: 2px solid #ffffff;
    border-radius: 50%;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 10px 6px 6px;
    color: inherit;
    background: transparent;
    border: 0;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.user-chip:hover,
.user-chip[aria-expanded='true'] {
    background: #f3f6fb;
}

.user-menu {
    position: relative;
    margin-left: 6px;
}

.user-menu-dropdown {
    position: absolute;
    z-index: 1080;
    top: calc(100% + 9px);
    right: 0;
    display: none;
    width: 190px;
    padding: 7px;
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    box-shadow: 0 16px 35px rgba(23, 32, 51, 0.14);
}

.user-menu-dropdown.show {
    display: block;
}

.user-menu-dropdown a,
.user-menu-dropdown button {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 10px 11px;
    gap: 9px;
    color: #536176;
    background: transparent;
    border: 0;
    border-radius: 7px;
    font-size: 12px;
    text-align: left;
    text-decoration: none;
}

.user-menu-dropdown a:hover,
.user-menu-dropdown button:hover {
    color: var(--color-primary);
    background: #edf4ff;
}

.select2-container {
    width: 100% !important;
}

.form-select {
    display: block;
    width: 100%;
    min-height: 42px;
    padding: 8px 34px 8px 12px;
    color: #495057;
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
}

.select2-container--default .select2-selection--single {
    height: 42px;
    padding: 6px 10px;
    border-color: #dee2e6;
    border-radius: 8px;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: #495057;
    line-height: 28px;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #8b97a8;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 40px;
}

.select2-dropdown {
    z-index: 1090;
    border-color: #dee2e6;
    box-shadow: 0 12px 25px rgba(23, 32, 51, 0.12);
}

.loan-quote-card {
    background: #f8fbff;
    border: 1px solid #dbeafe;
    border-radius: 10px;
}

.avatar {
    display: grid;
    flex: none;
    place-items: center;
    width: 34px;
    height: 34px;
    color: #2463d4;
    background: #e9f1ff;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 800;
}

.user-chip strong {
    font-size: 12px;
}

.user-chip small {
    margin-top: 2px;
    color: #8b97a8;
    font-size: 10px;
}

.content-area {
    flex: 1;
    padding: 28px;
}

.app-footer {
    padding: 15px 28px;
    color: #95a0b0;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    font-size: 11px;
}

.page-heading,
.panel-header,
.metric-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
}

.page-heading {
    align-items: flex-end;
    margin-bottom: 24px;
    gap: 20px;
}

.eyebrow {
    color: #8b97aa;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.page-heading h1 {
    margin: 4px 0 5px;
    font-size: 25px;
    letter-spacing: -0.03em;
}

.page-heading p {
    margin: 0;
    color: var(--color-muted);
}

.heading-actions {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 9px 14px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    transition: filter 0.15s ease, transform 0.1s ease;
}

.btn:active {
    transform: translateY(1px);
}

.btn-light {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
}

.btn-light:hover {
    background: #f7f9fc;
}

.btn-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

.btn-primary:hover {
    filter: brightness(1.06);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 18px;
    gap: 14px;
}

.metric-card,
.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 2px 7px rgba(23, 32, 51, 0.03);
}

.metric-card {
    padding: 17px;
    border-top: 3px solid var(--tone);
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.metric-card:hover {
    box-shadow: 0 10px 24px rgba(23, 32, 51, 0.07);
    transform: translateY(-1px);
}

.metric-top {
    margin-bottom: 15px;
}

.metric-icon {
    display: grid;
    flex: none;
    place-items: center;
    width: 37px;
    height: 37px;
    color: var(--tone);
    background: #f1f5f9;
    border-radius: 9px;
    font-size: 19px;
}

.metric-more {
    color: #a5afbd;
}

.metric-label {
    display: block;
    color: #6e7b8f;
    font-size: 11px;
    font-weight: 700;
}

.metric-value {
    display: block;
    margin: 5px 0;
    font-size: 22px;
    letter-spacing: -0.035em;
}

.metric-value small {
    color: #8793a5;
    font-size: 10px;
    letter-spacing: 0;
}

.metric-caption {
    color: #9ca6b5;
    font-size: 9px;
}

.tone-blue { --tone: #2563eb; }
.tone-violet { --tone: #7c3aed; }
.tone-green { --tone: #059669; }
.tone-cyan { --tone: #0891b2; }
.tone-orange { --tone: #ea580c; }
.tone-yellow { --tone: #d97706; }
.tone-red { --tone: #dc2626; }
.tone-rose { --tone: #e11d48; }

.dashboard-grid {
    display: grid;
    grid-template-columns: 1.35fr 1fr;
    margin-bottom: 18px;
    gap: 18px;
}

.panel {
    padding: 20px;
}

.panel-header {
    margin-bottom: 18px;
}

.panel-header h2 {
    margin: 3px 0 0;
    font-size: 15px;
}

.risk-overview {
    display: flex;
    align-items: center;
    padding: 8px 10px 14px;
    gap: 28px;
}

.donut {
    position: relative;
    display: grid;
    flex: none;
    place-items: center;
    width: 150px;
    height: 150px;
    background: conic-gradient(#ef4444 calc(var(--value) * 1%), #eaf0f7 0);
    border-radius: 50%;
}

.donut::before {
    position: absolute;
    width: 112px;
    height: 112px;
    background: #ffffff;
    border-radius: 50%;
    content: '';
}

.donut div {
    position: absolute;
    text-align: center;
}

.donut strong,
.donut span {
    display: block;
}

.donut strong {
    font-size: 23px;
}

.donut span {
    color: #8b97a8;
    font-size: 10px;
}

.risk-copy h3 {
    font-size: 14px;
}

.risk-copy p {
    max-width: 440px;
    color: #748195;
    font-size: 12px;
    line-height: 1.6;
}

.risk-legend {
    display: flex;
    color: #6f7c90;
    font-size: 10px;
    gap: 18px;
}

.risk-legend i {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 5px;
    border-radius: 50%;
}

.risk-legend .good { background: #eaf0f7; }
.risk-legend .risk { background: #ef4444; }

.quick-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 9px;
}

.quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 85px;
    color: #56647a;
    background: #fbfcfe;
    border: 1px solid var(--color-border);
    border-radius: 9px;
    font-size: 10px;
    font-weight: 700;
    gap: 8px;
    transition: 0.15s ease;
}

.quick-action i {
    color: #3971dd;
    font-size: 23px;
}

.quick-action:hover {
    background: #edf4ff;
    border-color: #cbdcfb;
    transform: translateY(-1px);
}

.table-panel {
    padding: 0;
    overflow: hidden;
}

.table-panel .panel-header {
    padding: 20px 20px 0;
}

.table {
    margin: 0;
}

.table thead th {
    padding: 11px 18px;
    color: #95a0af;
    background: #f8fafc;
    border-color: #edf0f4;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.table tbody td {
    padding: 14px 18px;
    color: #586579;
    border-color: #f0f2f5;
    font-size: 11px;
}

.table tbody tr:hover td {
    background: #fafbfd;
}

.table td strong,
.table td small {
    display: block;
}

.table td small {
    margin-top: 3px;
    color: #9aa5b4;
    font-size: 9px;
}

.reference {
    color: #315fba;
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-weight: 700;
}

.status-badge {
    padding: 4px 8px;
    border-radius: 99px;
    font-size: 9px;
    font-weight: 800;
}

.status-badge.danger {
    color: #dc2626;
    background: #fef2f2;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 38px;
    color: #9aa5b4;
}

.empty-state i {
    color: #43a66d;
    font-size: 30px;
}

.empty-state strong {
    margin: 8px 0 4px;
    color: #536176;
}

.empty-state span {
    font-size: 10px;
}

@media (max-width: 1200px) {
    .metric-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* ---------------------------------------------------------------- */
/* Mobile: sidebar becomes an off-canvas overlay with a backdrop     */
/* ---------------------------------------------------------------- */
@media (max-width: 767px) {
    .sidebar {
        width: var(--sidebar-width) !important;
        box-shadow: 10px 0 30px rgba(23, 32, 51, 0.13);
        transform: translateX(-100%);
    }

    .sidebar .brand-text,
    .sidebar .nav-heading,
    .sidebar .nav-item span:not(.arrow),
    .sidebar .arrow {
        display: block !important;
    }

    .sidebar .nav-item {
        justify-content: flex-start !important;
        padding: 0 12px !important;
    }

    body.sidebar-open .sidebar {
        transform: none;
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
        opacity: 1;
    }

    .main-panel,
    body.sidebar-collapsed .main-panel {
        margin-left: 0;
    }

    .content-area {
        padding: 20px 14px;
    }

    .page-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .metric-grid {
        grid-template-columns: 1fr;
    }

    .quick-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .risk-overview {
        align-items: flex-start;
        flex-direction: column;
    }

    .user-chip > span:last-child {
        display: none;
    }

    .topbar {
        padding: 0 14px;
    }
}