/* ══════════════════════════════════════
   LOANMS — Design System (Screenshot Match)
   Purple accent, dark navy sidebar
══════════════════════════════════════ */

/* ── Global overflow prevention ── */
html, body {
    max-width: 100%;
    overflow-x: hidden !important;
}
*, *::before, *::after {
    max-width: 100%;
}
img, video, iframe, embed, object { max-width: 100%; height: auto; }

:root {
    --primary:       #7c3aed;          /* Purple */
    --primary-dark:  #5b21b6;
    --primary-light: #ede9fe;
    --navy:          #1a1d2e;          /* Dark sidebar */
    --navy-hover:    rgba(255,255,255,.06);
    --success:       #10b981;
    --warning:       #f59e0b;
    --danger:        #ef4444;
    --info:          #3b82f6;
    --light-bg:      #f5f6fa;
    --card-bg:       #ffffff;
    --text-primary:  #111827;
    --text-muted:    #6b7280;
    --border:        #e5e7eb;
    --sidebar-width: 260px;
    --topbar-h:      68px;
    --radius-lg:     16px;
    --radius-md:     12px;
    --radius-sm:     8px;
    --shadow-sm:     0 1px 4px rgba(0,0,0,.06);
    --shadow-md:     0 4px 16px rgba(0,0,0,.08);
    --shadow-lg:     0 8px 32px rgba(0,0,0,.12);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html  { overflow-x: hidden; scroll-behavior: smooth; }
body  {
    font-family: 'Inter', 'Segoe UI', Tahoma, sans-serif;
    background: var(--light-bg);
    color: var(--text-primary);
    overflow-x: hidden;
    font-size: 14px;
    line-height: 1.5;
}

/* ══════════════════════════════════════
   AUTH PAGES
══════════════════════════════════════ */
.auth-wrapper {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1a1d2e 0%, #7c3aed 100%);
    padding: 20px;
}
.auth-card {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    width: 100%; max-width: 460px;
    box-shadow: var(--shadow-lg);
}
@media (max-width: 480px) { .auth-card { padding: 28px 20px; } }
.auth-card .brand { text-align: center; margin-bottom: 28px; }
.auth-card .brand h1 { font-size: 1.8rem; color: var(--navy); font-weight: 800; }
.auth-card .brand p  { color: var(--text-muted); font-size: .9rem; }
.auth-card .form-label { font-weight: 600; color: #374151; }
.auth-card .btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none; width: 100%; padding: 12px;
    font-size: 1rem; border-radius: var(--radius-sm);
    margin-top: 8px; transition: opacity .2s;
}
.auth-card .btn-primary:hover { opacity: .9; }

/* ══════════════════════════════════════
   SIDEBAR
══════════════════════════════════════ */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--navy);
    color: #fff;
    flex-shrink: 0;
    display: flex; flex-direction: column;
    position: fixed; height: 100vh;
    overflow-y: auto; overflow-x: hidden;
    z-index: 1000;
    transition: transform .3s ease;
}

/* Brand */
.sidebar-brand { padding: 22px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.06); }
.brand-flex { display: flex; align-items: center; gap: 12px; }
.brand-logo {
    width: 38px; height: 38px;
    background: linear-gradient(135deg, var(--primary), #9f67fa);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 1.1rem; color: #fff;
    flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; }
.main-title { font-weight: 700; font-size: 1rem; letter-spacing: .5px; color: #fff; }
.sub-title   { font-size: .72rem; color: #6b7280; }

/* Nav */
.sidebar-nav { flex: 1; padding: 10px 12px; overflow-y: auto; }

.nav-header {
    font-size: .65rem; font-weight: 700; letter-spacing: 1.2px;
    color: #4b5563; text-transform: uppercase;
    padding: 18px 10px 8px;
}

.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px;
    color: #9ca3af;
    text-decoration: none;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    font-size: .88rem; font-weight: 500;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--navy-hover); color: #e5e7eb; }
.nav-item.active {
    background: linear-gradient(135deg, var(--primary), #9f67fa);
    color: #fff !important;
    box-shadow: 0 4px 12px rgba(124,58,237,.4);
}
.nav-icon  { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }
.nav-label { flex: 1; }
.chevron   { font-size: .6rem; opacity: .4; }

/* Footer */
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.06);
}
.user-pill {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 10px; font-size: .85rem; color: #d1d5db;
}
.logout-link {
    color: #f87171; text-decoration: none;
    font-size: .82rem; display: block;
    padding: 6px 0;
    transition: color .15s;
}
.logout-link:hover { color: #fca5a5; }

/* Overlay for mobile */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.5); z-index: 999;
}
.sidebar-overlay.active { display: block; }

/* ══════════════════════════════════════
   MAIN CONTENT
══════════════════════════════════════ */
.app-layout {
    display: flex; min-height: 100vh;
    overflow-x: hidden;
    max-width: 100vw;
}
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex; flex-direction: column;
    min-height: 100vh;
    min-width: 0;
    overflow-x: hidden;
    width: 0; /* combined with flex:1 this correctly fills remaining space */
    max-width: calc(100vw - var(--sidebar-width));
}

/* ── Topbar ── */
.topbar {
    background: #fff;
    height: var(--topbar-h);
    padding: 0 20px;
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: var(--shadow-sm);
    position: sticky; top: 0; z-index: 50;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    width: 100%; overflow: hidden;
}

/* Search */
.topbar-search {
    flex: 1; max-width: 480px;
    display: flex; align-items: center;
    background: var(--light-bg);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 0 14px;
    gap: 8px;
    height: 42px;
    transition: border-color .2s;
}
.topbar-search:focus-within { border-color: var(--primary); }
.topbar-search .search-icon { color: var(--text-muted); font-size: 1rem; }
.topbar-search input {
    border: none; background: none; outline: none;
    font-size: .9rem; color: var(--text-primary);
    flex: 1; min-width: 0;
}
.topbar-search input::placeholder { color: #9ca3af; }

/* Topbar right actions */
.topbar-actions {
    display: flex; align-items: center; gap: 14px; flex-shrink: 0;
}
.topbar-btn-new {
    display: inline-flex; align-items: center; gap: 7px;
    background: linear-gradient(135deg, var(--primary), #9f67fa);
    color: #fff; border: none;
    padding: 10px 18px; border-radius: 10px;
    font-size: .88rem; font-weight: 600;
    cursor: pointer; text-decoration: none;
    box-shadow: 0 4px 12px rgba(124,58,237,.35);
    transition: opacity .2s, transform .15s;
    white-space: nowrap;
}
.topbar-btn-new:hover { opacity: .9; transform: translateY(-1px); color: #fff; }

.topbar-bell {
    position: relative; cursor: pointer;
    color: var(--text-muted); font-size: 1.2rem;
    text-decoration: none;
    display: flex; align-items: center;
}
.topbar-bell .bell-dot {
    position: absolute; top: -2px; right: -2px;
    width: 9px; height: 9px; border-radius: 50%;
    background: #ef4444; border: 2px solid #fff;
}

.topbar-user {
    display: flex; align-items: center; gap: 10px;
    cursor: pointer;
}
.topbar-user-name { line-height: 1.2; text-align: right; }
.topbar-user-name .uname { font-size: .88rem; font-weight: 600; color: var(--text-primary); display: block; }
.topbar-user-name .urole { font-size: .75rem; color: var(--text-muted); display: block; }
.topbar-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #9f67fa);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: .85rem;
    flex-shrink: 0;
}
/* Legacy user-avatar */
.user-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: .9rem;
    flex-shrink: 0;
}

/* ── Page body ── */
.page-body {
    padding: 30px;
    flex: 1;
    overflow-x: hidden;
    max-width: 1400px;
    width: 100%;
    box-sizing: border-box;
    margin-left: auto;
    margin-right: auto;
}

/* Page header section */
.page-heading {
    display: flex; align-items: flex-start; justify-content: space-between;
    flex-wrap: wrap; gap: 16px;
    margin-bottom: 24px;
}
.page-heading .page-title h2 {
    font-size: 1.5rem; font-weight: 800; color: var(--text-primary);
    display: flex; align-items: center; gap: 10px;
}
.page-heading .page-title p { color: var(--text-muted); font-size: .88rem; margin-top: 4px; }
.btn-purple {
    display: inline-flex; align-items: center; gap: 7px;
    background: linear-gradient(135deg, var(--primary), #9f67fa);
    color: #fff !important; border: none;
    padding: 11px 20px; border-radius: 10px;
    font-size: .9rem; font-weight: 600;
    cursor: pointer; text-decoration: none;
    box-shadow: 0 4px 12px rgba(124,58,237,.3);
    transition: opacity .2s, transform .15s;
    white-space: nowrap;
}
.btn-purple:hover { opacity: .9; transform: translateY(-1px); }

/* ══════════════════════════════════════
   STAT CARDS
══════════════════════════════════════ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 22px 20px;
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    transition: transform .15s, box-shadow .15s;
    gap: 12px;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.stat-body { flex: 1; min-width: 0; }
.stat-label { font-size: .8rem; color: var(--text-muted); font-weight: 500; margin-bottom: 6px; }
.stat-value { font-size: 1.7rem; font-weight: 800; color: var(--text-primary); line-height: 1; }
.stat-sub   { font-size: .78rem; color: var(--text-muted); margin-top: 6px; }
.stat-sub.positive { color: var(--success); }
.stat-sub.negative { color: var(--danger); }

.stat-icon-box {
    width: 52px; height: 52px; border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem; flex-shrink: 0;
}
.stat-icon-box.purple  { background: #ede9fe; }
.stat-icon-box.green   { background: #d1fae5; }
.stat-icon-box.orange  { background: #fef3c7; }
.stat-icon-box.blue    { background: #dbeafe; }
.stat-icon-box.red     { background: #fee2e2; }
.stat-icon-box.dark    { background: #e5e7eb; }

/* Legacy .stat-card layout (for backward compat) */
.stat-card > .stat-icon {
    width: 48px; height: 48px; border-radius: 12px;
    background: var(--primary-light); flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
}
.stat-card > .stat-info h3 { font-size: 1.5rem; font-weight: 800; color: var(--text-primary); }
.stat-card > .stat-info p  { font-size: .78rem; color: var(--text-muted); margin: 0; }

/* ══════════════════════════════════════
   CARDS
══════════════════════════════════════ */
.card {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 20px;
    border: 1px solid var(--border);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 8px;
}
.card-header h5 { font-weight: 700; color: var(--text-primary); margin: 0; font-size: .96rem; }
.card-body  { padding: 20px; }

/* ══════════════════════════════════════
   TABLES
══════════════════════════════════════ */
.table-responsive {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    max-width: 100%; width: 100%;
}
table { width: 100%; border-collapse: collapse; }
table th {
    background: #f9fafb;
    padding: 10px 14px;
    text-align: left;
    font-size: .74rem; text-transform: uppercase; letter-spacing: .5px;
    color: #6b7280; font-weight: 700; white-space: nowrap;
    border-bottom: 1px solid var(--border);
}
table td {
    padding: 12px 14px;
    border-bottom: 1px solid #f3f4f6;
    font-size: .88rem; vertical-align: middle;
}
table tr:last-child td { border-bottom: none; }
table tr:hover td { background: #f9fafb; }
/* Tables inside cards: scroll horizontally within their wrapper only */
.card-body .table-responsive,
.card > .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
}

/* ══════════════════════════════════════
   FORMS
══════════════════════════════════════ */
.form-label { font-weight: 600; font-size: .85rem; color: #374151; margin-bottom: 5px; }
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    padding: 9px 12px;
    font-size: .9rem;
    transition: border .2s, box-shadow .2s;
    width: 100%;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(124,58,237,.12);
    outline: none;
}
.form-text { font-size: .78rem; color: var(--text-muted); margin-top: 4px; }
textarea.form-control { resize: vertical; }

/* ══════════════════════════════════════
   BUTTONS
══════════════════════════════════════ */
.btn { border-radius: var(--radius-sm); font-weight: 600; font-size: .88rem; padding: 8px 16px; transition: all .15s; }
.btn-primary   { background: linear-gradient(135deg, var(--primary), #9f67fa); border: none; color: #fff; }
.btn-primary:hover { opacity: .9; color: #fff; }
.btn-success   { background: var(--success);  border-color: var(--success); }
.btn-danger    { background: var(--danger);   border-color: var(--danger); }
.btn-warning   { background: var(--warning);  border-color: var(--warning); color: #fff; }
.btn-secondary { background: #6b7280; border-color: #6b7280; color: #fff; }
.btn-outline-secondary { border-color: #d1d5db; color: #374151; background: transparent; }
.btn-outline-secondary:hover { background: #f3f4f6; }
.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }

/* ══════════════════════════════════════
   BADGES
══════════════════════════════════════ */
.badge { padding: 4px 9px; border-radius: 6px; font-size: .74rem; font-weight: 600; }
.bg-primary   { background: var(--primary) !important; }
.bg-success   { background: var(--success) !important; }
.bg-danger    { background: var(--danger) !important; }
.bg-warning   { background: var(--warning) !important; }
.bg-info      { background: var(--info) !important; }
.bg-dark      { background: #374151 !important; }
.bg-secondary { background: #6b7280 !important; }

/* ══════════════════════════════════════
   ALERTS
══════════════════════════════════════ */
.alert { border-radius: var(--radius-md); padding: 14px 18px; font-size: .9rem; border: none; }
.alert-info    { background: #eff6ff; color: #1e40af; }
.alert-success { background: #f0fdf4; color: #166534; }
.alert-warning { background: #fffbeb; color: #92400e; }
.alert-danger  { background: #fef2f2; color: #991b1b; }

/* ══════════════════════════════════════
   LOAN CARD (CLIENT)
══════════════════════════════════════ */
.loan-card {
    background: #fff;
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 14px;
    border-left: 4px solid var(--primary);
    box-shadow: var(--shadow-sm);
    border-top: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.loan-card.active    { border-left-color: var(--info); }
.loan-card.completed { border-left-color: var(--success); }
.loan-card.pending   { border-left-color: var(--warning); }
.loan-card.rejected  { border-left-color: var(--danger); }
.loan-card.approved  { border-left-color: var(--primary); }

.progress { height: 6px; border-radius: 3px; background: #e5e7eb; }
.progress-bar { background: linear-gradient(90deg, var(--primary), #9f67fa); border-radius: 3px; }

/* ══════════════════════════════════════
   STEP BADGE
══════════════════════════════════════ */
.step-badge {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; border-radius: 50%;
    background: var(--primary); color: #fff;
    font-size: .75rem; font-weight: 700; margin-right: 8px; flex-shrink: 0;
}

/* ══════════════════════════════════════
   COLLATERAL
══════════════════════════════════════ */
.collateral-item {
    background: #f9fafb; border: 1.5px solid var(--border);
    border-radius: var(--radius-md); padding: 16px; margin-bottom: 12px; position: relative;
}
.collateral-item .remove-btn { position: absolute; top: 10px; right: 10px; }

/* ══════════════════════════════════════
   BOOTSTRAP ROW OVERFLOW FIX
   Bootstrap rows use negative margins; contain them so they
   never push content wider than the viewport.
══════════════════════════════════════ */
.row {
    margin-left: 0 !important;
    margin-right: 0 !important;
}
.row > * {
    padding-left: 12px !important;
    padding-right: 12px !important;
}
/* Ensure Bootstrap columns never exceed their parent */
[class*="col-"] {
    min-width: 0;
    max-width: 100%;
}

/* ══════════════════════════════════════
   LANDING PAGE
══════════════════════════════════════ */
.landing-hero {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--navy) 0%, var(--primary) 100%);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: #fff; text-align: center; padding: 40px 20px;
}
.landing-hero h1 { font-size: 2.5rem; font-weight: 900; margin-bottom: 16px; }
.landing-hero p  { font-size: 1.1rem; opacity: .85; max-width: 600px; margin-bottom: 36px; }
.landing-btns { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.landing-btns a {
    padding: 12px 28px; border-radius: 10px;
    font-size: 1rem; font-weight: 700;
    text-decoration: none; transition: transform .2s, box-shadow .2s;
}
.landing-btns a:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.btn-white         { background: #fff; color: var(--primary); }
.btn-outline-white { border: 2px solid #fff; color: #fff; background: transparent; }

.features { background: #fff; padding: 60px 20px; text-align: center; }
.features h2 { color: var(--text-primary); margin-bottom: 40px; font-size: 1.8rem; font-weight: 800; }
.features-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 24px; max-width: 1000px; margin: 0 auto; }
.feature-item { padding: 24px 18px; border-radius: var(--radius-md); background: var(--light-bg); transition: transform .2s; }
.feature-item:hover { transform: translateY(-4px); }
.feature-item .icon { font-size: 2.2rem; margin-bottom: 12px; }
.feature-item h4 { color: var(--text-primary); font-weight: 700; margin-bottom: 8px; }
.feature-item p  { color: var(--text-muted); font-size: .88rem; }

/* ══════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════ */
@media (max-width: 1023px) {
    :root { --sidebar-width: 220px; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
    .page-body { padding: 18px; }
    .topbar-search { max-width: 280px; }
}

@media (max-width: 768px) {
    :root { --sidebar-width: 260px; }

    /* Sidebar becomes a fixed drawer that slides in from left */
    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        height: 100%;
        z-index: 1000;
        transition: left .3s ease;
        box-shadow: none;
    }
    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 20px rgba(0,0,0,.3);
    }

    /* Main content takes full width — sidebar is overlaid, not pushing */
    .main-content {
        margin-left: 0;
        max-width: 100%;
        width: 100%;
    }

    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card  { padding: 14px 12px; }
    .stat-value { font-size: 1.3rem; }
    .stat-icon-box { width: 40px; height: 40px; font-size: 1rem; }

    .topbar { padding: 0 12px; gap: 8px; }
    .topbar-search { display: none; }
    .topbar-user-name { display: none; }
    .topbar-btn-new { padding: 8px 12px; font-size: .8rem; }

    .page-body { padding: 14px; }
    .card-body  { padding: 14px; overflow-x: hidden; }
    .card-header { padding: 12px 14px; }

    /* Tables scroll inside wrapper only */
    .table-responsive { width: 100%; max-width: 100%; overflow-x: auto; }

    .btn-mobile-full { width: 100% !important; }

    .row.g-3 > [class*="col-md"],
    .row.g-4 > [class*="col-md"],
    .row.g-2 > [class*="col-md"] { flex: 0 0 100%; max-width: 100%; }
    .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8 { flex: 0 0 100%; max-width: 100%; }

    .landing-hero h1 { font-size: 1.8rem; }
    .page-heading { flex-direction: column; align-items: flex-start; gap: 10px; }
    .page-heading .btn-purple { align-self: flex-start; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-value  { font-size: 1.15rem; }
    .topbar-btn-new span { display: none; }
}

@media (max-width: 360px) {
    .stats-grid { grid-template-columns: 1fr; }
    .badge { font-size: .7rem; padding: 3px 7px; }
}
