/* ============================================================
   GBS Loan — Shared App Stylesheet
   Ported from the hr-saas design system (teal + gold, Inter).
   Single source of truth, loaded on every authenticated page.
   ============================================================ */

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
img, svg { display: block; max-width: 100%; }

/* ── Variables ──────────────────────────────────────────────── */
:root {
    /* Brand — teal + gold. --maroon is the historical variable name for the
       PRIMARY brand colour (kept for parity with hr-saas component CSS). */
    --maroon:        #0E6B61;
    --maroon-dark:   #093F39;
    --maroon-light:  rgba(14,107,97,0.08);
    --secondary:     #C9A227;
    --secondary-dark:#977a1d;
    --cream:         #FAF6F0;
    --cream-dark:    #F0E9DD;
    --bg:            #f0ede9;
    --card:          #fff;
    --text:          #1a1a1a;
    --text-muted:    #888;
    --border:        #e8e5e0;
    --green:         #16a34a;
    --red:           #dc2626;
    --amber:         #a05a00;
    --sky:           #1a4f8a;
    --violet:        #5b2faa;

    --shadow:        0 2px 8px rgba(0,0,0,0.05);
    --shadow-lift:   0 12px 28px -10px color-mix(in srgb, var(--maroon) 18%, transparent), 0 2px 6px rgba(0,0,0,.04);
    --app-bg:
        radial-gradient(ellipse at 0% 0%,    color-mix(in srgb, var(--maroon) 7%, transparent) 0%, transparent 55%),
        radial-gradient(ellipse at 100% 0%,  rgba(201,162,39,0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 100% 100%, color-mix(in srgb, var(--maroon) 5%, transparent) 0%, transparent 55%),
        linear-gradient(160deg, #f7faf9 0%, #eef4f2 40%, #e7efec 100%);

    --sb-collapsed:  72px;
    --sb-expanded:   240px;

    --transition-in:  .22s cubic-bezier(.4,0,.2,1);
    --transition-out: .32s cubic-bezier(.4,0,.2,1);
    --transition:     .28s cubic-bezier(.4,0,.2,1);

    --tone-rose-bg:    #fde7ec;  --tone-rose-fg:    #9a1a35;
    --tone-amber-bg:   #fff1d6;  --tone-amber-fg:   #a05a00;
    --tone-emerald-bg: #dff6e6;  --tone-emerald-fg: #0e6a3b;
    --tone-sky-bg:     #e1eefe;  --tone-sky-fg:     #1a4f8a;
    --tone-violet-bg:  #ece1fb;  --tone-violet-fg:  #5b2faa;
    --tone-slate-bg:   #e6e8ec;  --tone-slate-fg:   #34455c;
}

/* ── Body & global ──────────────────────────────────────────── */
body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text);
    min-height: 100vh;
    background: var(--app-bg);
    background-attachment: fixed;
    overflow-x: hidden;
}

/* ── Accent bar ─────────────────────────────────────────────── */
.accent-bar {
    position: fixed; top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--maroon), var(--secondary), var(--maroon-dark));
    z-index: 200;
}

/* ── Sidebar overlay (mobile) ───────────────────────────────── */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 99; }
.sidebar-overlay.active { display: block; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
    position: fixed; left: 0; top: 3px; bottom: 0;
    width: var(--sb-collapsed);
    background: linear-gradient(180deg, #ffffff 0%, #f3f8f6 50%, #e9f2ef 100%);
    border-right: none; border-radius: 0 28px 28px 0;
    box-shadow: 6px 0 32px color-mix(in srgb, var(--maroon) 10%, transparent);
    overflow: hidden; display: flex; flex-direction: column; z-index: 100;
    transition: width var(--transition-in), transform .3s ease;
}
.sidebar:hover                      { width: var(--sb-expanded); transition: width var(--transition-in); }
.sidebar.expanded                   { width: var(--sb-expanded); }
.sidebar:not(:hover):not(.expanded) { transition: width var(--transition-out); }

.sb-brand {
    padding: 20px 0; display: flex; align-items: center; justify-content: center;
    gap: 10px; border-bottom: 1px solid var(--border); min-height: 68px; overflow: hidden; flex-shrink: 0;
}
.sb-brand-icon {
    width: 36px; height: 36px; flex-shrink: 0;
    background: linear-gradient(135deg, var(--maroon), var(--maroon-dark)); border-radius: 10px;
    display: flex; align-items: center; justify-content: center; font-size: 16px; color: #fff;
}
.sb-brand-text { overflow: hidden; white-space: nowrap; opacity: 0; width: 0; transition: opacity var(--transition-in), width var(--transition-in); }
.sb-brand-text h2    { font-size: 14px; font-weight: 700; color: var(--maroon); }
.sb-brand-text small { font-size: 10px; color: var(--text-muted); display: block; }

.sb-toggle {
    position: absolute; top: 50%; right: -14px; transform: translateY(-50%);
    width: 28px; height: 28px; background: var(--card); border: 1.5px solid var(--border);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 10px; color: var(--text-muted); cursor: pointer; z-index: 101;
    transition: all .2s; box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.sb-toggle:hover { background: var(--maroon); color: #fff; border-color: var(--maroon); }

/* Drawer close (×) — only shown when the sidebar is a slide-in drawer (mobile). */
.sb-close { display: none; }

.sb-nav { flex: 1; padding: 10px 8px; overflow-y: auto; overflow-x: hidden; }
.sb-nav::-webkit-scrollbar       { width: 3px; }
.sb-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.nav-sec { display: flex; align-items: center; justify-content: center; height: 22px; margin: 8px 0 4px; overflow: hidden; padding: 0 6px; }
.nav-sec-label { font-size: 10px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .8px; white-space: nowrap; opacity: 0; transition: opacity var(--transition); }
.nav-sec::before { content: ''; display: block; height: 1px; background: var(--border); flex: 1; margin: 0 4px; transition: margin var(--transition); }

.nav-item {
    display: flex !important; flex-direction: column !important; align-items: center !important; justify-content: center !important;
    gap: 3px !important; padding: 6px 6px !important; border-radius: 12px; text-decoration: none; color: #666;
    transition: background .15s, color .15s, gap var(--transition), padding var(--transition);
    margin-bottom: 2px; overflow: hidden; min-height: 58px !important; max-height: 58px !important; position: relative; width: 100%;
}
.nav-item i { font-size: 17px !important; flex-shrink: 0; width: 22px !important; text-align: center; line-height: 1 !important; }
.nav-label {
    display: block !important; font-size: 9px !important; font-weight: 600; line-height: 1.1 !important; letter-spacing: .2px;
    color: inherit; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center !important;
    max-height: 14px !important; width: 100%; padding: 0 2px; transition: font-size var(--transition), text-align var(--transition); opacity: 1 !important;
}
.nav-item:hover             { background: var(--cream); color: var(--maroon); }
.nav-item.active            { background: var(--maroon-light); color: var(--maroon); }
.nav-item.active .nav-label { font-weight: 700; }
.sidebar:not(:hover):not(.expanded) .nav-label { display: none !important; }

.sb-footer { padding: 10px 8px; border-top: 1px solid var(--border); flex-shrink: 0; }
.sb-user { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px; border-radius: 10px; background: linear-gradient(135deg, #eef4f2, #ddeae6); border: 1px solid var(--maroon-light); overflow: hidden; }
.sb-avatar { width: 32px; height: 32px; flex-shrink: 0; border-radius: 8px; background: var(--maroon); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; }
.sb-user-info { overflow: hidden; white-space: nowrap; opacity: 0; width: 0; transition: opacity var(--transition), width var(--transition); }
.sb-uname { font-size: 12px; font-weight: 600; }
.sb-urole { font-size: 10px; color: var(--text-muted); }
.sb-logout { margin-top: 8px; }
.sb-logout a { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px; border-radius: 10px; background: #fee2e2; color: var(--red); border: 1px solid #fca5a5; text-decoration: none; font-size: 12px; font-weight: 600; overflow: hidden; white-space: nowrap; }
.sb-logout a:hover { background: var(--red); color: #fff; border-color: var(--red); }
.sidebar:not(:hover):not(.expanded) .sb-logout .sb-logout-label { display: none; }

.sidebar.expanded, .sidebar:hover { box-shadow: 12px 0 48px color-mix(in srgb, var(--maroon) 18%, transparent), 0 0 1px rgba(0,0,0,.04); }
.sidebar.expanded .sb-brand,     .sidebar:hover .sb-brand      { padding: 20px 18px; justify-content: flex-start; }
.sidebar.expanded .sb-brand-text,.sidebar:hover .sb-brand-text { opacity: 1; width: auto; }
.sidebar.expanded .nav-sec,      .sidebar:hover .nav-sec       { justify-content: flex-start; padding-left: 14px; }
.sidebar.expanded .nav-sec::before,.sidebar:hover .nav-sec::before { margin: 0 0 0 8px; }
.sidebar.expanded .nav-sec-label,.sidebar:hover .nav-sec-label { opacity: 1; }
.sidebar.expanded .nav-item,     .sidebar:hover .nav-item {
    flex-direction: row !important; min-height: 58px !important; max-height: 58px !important;
    padding: 0 14px !important; justify-content: flex-start !important; gap: 12px !important;
}
.sidebar.expanded .nav-label, .sidebar:hover .nav-label { font-size: 13px !important; font-weight: 500; text-align: left !important; max-height: 24px !important; line-height: 1 !important; width: auto; padding: 0; }
.sidebar.expanded .sb-user,   .sidebar:hover .sb-user      { justify-content: flex-start; }
.sidebar.expanded .sb-user-info,.sidebar:hover .sb-user-info{ opacity: 1; width: auto; }

/* ── Main layout (overlay mode) ─────────────────────────────── */
.main { margin-left: var(--sb-collapsed) !important; min-height: 100vh; }
body:has(.sidebar:hover) .main, body:has(.sidebar.expanded) .main { margin-left: var(--sb-collapsed) !important; }

.content, .main > .content, .main .content {
    max-width: none !important; width: auto !important; margin-left: 0 !important; margin-right: 0 !important;
    padding-top: 28px !important; padding-bottom: 40px !important;
    padding-left: clamp(16px, 2.4vw, 40px) !important; padding-right: clamp(16px, 2.4vw, 40px) !important; box-sizing: border-box;
}
.topbar { padding-left: clamp(16px, 2.4vw, 40px) !important; padding-right: clamp(16px, 2.4vw, 40px) !important; }
@media (max-width: 640px) {
    .content, .main > .content, .main .content { padding-top: 18px !important; padding-bottom: 28px !important; padding-left: 14px !important; padding-right: 14px !important; }
    .topbar { padding-left: 14px !important; padding-right: 14px !important; }
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
    position: sticky; top: 3px; z-index: 50; padding: 14px 28px;
    background: linear-gradient(90deg, rgba(255,248,242,.94) 0%, rgba(250,238,228,.94) 100%);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(220,200,185,.5);
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.menu-toggle { display: none; background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; padding: 4px; }
.crumbs { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 0; flex-wrap: wrap; }
.crumbs a { color: var(--maroon); text-decoration: none; font-weight: 500; }
.crumbs a:hover { text-decoration: underline; }
.crumbs span { margin: 0 5px; opacity: .5; }
.page-title { font-size: 19px; font-weight: 700; margin-top: 2px; display: flex; align-items: center; gap: 9px; }
.page-title i { color: var(--maroon); font-size: 17px; }
.page-desc { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; line-height: 1.45; }
.topbar-action { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topbar-date { font-size: 12px; font-weight: 600; color: var(--maroon); background: var(--maroon-light); padding: 7px 12px; border-radius: 20px; display: inline-flex; align-items: center; gap: 6px; }

.beta-pill { font-size: 11px; background: linear-gradient(135deg, #a05a00, #d6892b); color: #fff; padding: 2px 6px; border-radius: 5px; letter-spacing: .6px; font-weight: 700; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; border: none; transition: all .15s; text-decoration: none; font-family: inherit; }
.btn-primary { background: var(--maroon); color: #fff; }
.btn-primary:hover { background: var(--maroon-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--cream); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-gold { background: var(--secondary); color: #fff; }
.btn-gold:hover { background: var(--secondary-dark); }
.btn-danger { background: #fee2e2; color: var(--red); border: 1px solid #fca5a5; }
.btn-danger:hover { background: var(--red); color: #fff; border-color: var(--red); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { filter: brightness(.94); }

/* ── Cards ──────────────────────────────────────────────────── */
.card { background: rgba(255,255,255,0.96); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); transition: box-shadow .25s; }
.card:hover { box-shadow: var(--shadow); }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.card-title { font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-title i { color: var(--maroon); }
.card-body { padding: 16px 18px; }

/* ── Stat / KPI cards ───────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card { background: rgba(255,255,255,.96); border: 1px solid var(--border); border-radius: 16px; padding: 18px 18px 16px; display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden; animation: fadeUp .42s both; }
.stat-card::after { content: ''; position: absolute; inset: 0 0 auto auto; width: 88px; height: 88px; background: radial-gradient(circle at 100% 0%, var(--tone-bg, var(--maroon-light)) 0%, transparent 70%); }
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-ico { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; background: var(--tone-bg, var(--maroon-light)); color: var(--tone-fg, var(--maroon)); }
.stat-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.stat-value { font-size: 24px; font-weight: 800; letter-spacing: -.5px; }
.stat-sub { font-size: 11.5px; color: var(--text-muted); }
.tone-maroon  { --tone-bg: var(--maroon-light); --tone-fg: var(--maroon); }
.tone-gold    { --tone-bg: #fbf2d6; --tone-fg: var(--secondary-dark); }
.tone-emerald { --tone-bg: var(--tone-emerald-bg); --tone-fg: var(--tone-emerald-fg); }
.tone-sky     { --tone-bg: var(--tone-sky-bg); --tone-fg: var(--tone-sky-fg); }
.tone-rose    { --tone-bg: var(--tone-rose-bg); --tone-fg: var(--tone-rose-fg); }
.tone-violet  { --tone-bg: var(--tone-violet-bg); --tone-fg: var(--tone-violet-fg); }
.tone-slate   { --tone-bg: var(--tone-slate-bg); --tone-fg: var(--tone-slate-fg); }

/* ── Badges ─────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; text-transform: uppercase; letter-spacing: .3px; background: var(--tone-slate-bg); color: var(--tone-slate-fg); }
.badge.emerald { background: var(--tone-emerald-bg); color: var(--tone-emerald-fg); }
.badge.sky     { background: var(--tone-sky-bg); color: var(--tone-sky-fg); }
.badge.rose    { background: var(--tone-rose-bg); color: var(--tone-rose-fg); }
.badge.amber   { background: var(--tone-amber-bg); color: var(--tone-amber-fg); }
.badge.violet  { background: var(--tone-violet-bg); color: var(--tone-violet-fg); }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 14px; padding: 16px 18px; }
.form-grid.cols-3 { grid-template-columns: repeat(3,1fr); }
.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: span 3; }
label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=email], input[type=tel], input[type=password], select, textarea {
    padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit; outline: none; background: #fff; width: 100%; color: var(--text);
}
input:focus, select:focus, textarea:focus { border-color: var(--maroon); box-shadow: 0 0 0 3px var(--maroon-light); }
textarea { resize: vertical; min-height: 64px; }
.req { color: var(--red); }

.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.toggle input { display: none; }
.toggle-track { width: 36px; height: 20px; border-radius: 20px; background: #ddd; position: relative; transition: background .2s; }
.toggle-track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle input:checked + .toggle-track { background: var(--maroon); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }
.toggle-label { font-size: 13px; font-weight: 600; }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 9px 16px; font-size: 10px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; text-align: left; background: linear-gradient(90deg, #fff6ec, #fff1e4); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 11px 16px; font-size: 13px; font-weight: 500; border-top: 1px solid var(--border); }
tr:hover td { background: #fffaf5; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Toasts / alerts ────────────────────────────────────────── */
.toast { position: fixed; top: 20px; right: 20px; padding: 12px 18px; border-radius: 10px; font-size: 13px; font-weight: 600; z-index: 999; animation: tIn .25s ease; transition: opacity .35s ease; box-shadow: var(--shadow-lift); }
.toast-success { background: #dcfce7; color: var(--green); border: 1px solid #86efac; }
.toast-error   { background: #fee2e2; color: var(--red); border: 1px solid #fca5a5; }
.toast-warn    { background: #fff1d6; color: var(--amber); border: 1px solid #fde68a; }
.error-msg { color: var(--red); background: #fee2e2; padding: 10px 14px; border-radius: 8px; font-size: 13px; margin: 0 0 12px; border: 1px solid #fca5a5; }

/* ── Empty state ────────────────────────────────────────────── */
.empty-state { padding: 50px 20px; text-align: center; color: var(--text-muted); }
.empty-state i { font-size: 36px; margin-bottom: 12px; color: var(--border); display: block; }
.empty-state h4 { color: var(--text); font-size: 15px; font-weight: 700; margin-bottom: 6px; }

/* ── Animations ─────────────────────────────────────────────── */
@keyframes tIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Footer ─────────────────────────────────────────────────── */
.app-footer { padding: 18px 28px 24px; text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 30px; border-top: 1px solid var(--border); background: rgba(255,255,255,0.4); backdrop-filter: blur(8px); }
.app-footer a { color: var(--maroon); text-decoration: none; font-weight: 600; }
.app-footer a:hover { text-decoration: underline; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1024px) { .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; } }
/* App mode = tablet / iPad / phone (≤1024px): hide the rail and navigate
   through the slide-in drawer (tap the hamburger / brand). No bottom bar.
   Desktop (>1024px) is untouched. */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); border-radius: 0 22px 22px 0; width: min(86vw, var(--sb-expanded)); box-shadow: 14px 0 48px rgba(0,0,0,.22); }
    .sidebar.open { transform: translateX(0); }
    .sidebar:hover { width: min(86vw, var(--sb-expanded)); }
    .sidebar-overlay.active { display: block; }
    body:has(.sidebar:hover) .main { margin-left: 0; }
    .main { margin-left: 0 !important; }
    .topbar { padding: 12px 16px; }
    .menu-toggle { display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; padding: 0; margin-left: -8px; }
    .sb-toggle { display: none; }
    .sb-close { display: flex; align-items: center; justify-content: center;
        position: absolute; top: 13px; right: 12px; width: 40px; height: 40px; z-index: 102;
        border-radius: 10px; border: 1px solid var(--border); background: #fff; color: var(--text-muted); font-size: 16px; cursor: pointer; }
    .sb-close:hover { background: var(--cream); color: var(--maroon); }
    /* Open slide-in sidebar shows full labelled rows, not the icon rail. */
    .sidebar .nav-label, .sidebar .sb-logout-label, .sidebar .nav-sec-label, .sidebar .sb-brand-text, .sidebar .sb-user-info { opacity: 1 !important; width: auto !important; display: block !important; }
    .sidebar:not(:hover):not(.expanded) .nav-label { display: block !important; }
    .sidebar .nav-item { flex-direction: row !important; align-items: center !important; justify-content: flex-start !important; gap: 13px !important; padding: 0 16px !important; min-height: 48px !important; max-height: none !important; }
    .sidebar .nav-item i { width: 22px !important; }
    .sidebar .nav-label { font-size: 13.5px !important; font-weight: 500; text-align: left !important; max-height: none !important; line-height: 1.15 !important; padding: 0 !important; }
    .sidebar .sb-brand { padding: 18px 58px 18px 18px !important; justify-content: flex-start !important; }
    .sidebar .nav-sec { justify-content: flex-start !important; padding-left: 14px !important; }
    .sidebar .nav-sec::before { margin: 0 0 0 8px !important; }
    .sidebar .sb-user { justify-content: flex-start !important; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ── Two-column work pages (issue / loan view): stack on app screens ────── */
.split-grid { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }

/* ── App-mode chrome: header brand (rail hidden, drawer-only nav) ────────── */
.topbar-brand { display: none; }

@media (max-width: 1024px) {
    .split-grid { grid-template-columns: 1fr; }
    .split-grid .sticky-aside { position: static !important; top: auto !important; }

    /* Brand mark in the header (the rail sidebar is hidden here). Tap = home; the hamburger opens the drawer. */
    .topbar-brand { display: inline-flex; align-items: center; justify-content: center;
        width: 34px; height: 34px; border-radius: 9px; overflow: hidden; flex-shrink: 0;
        background: linear-gradient(135deg, var(--maroon), var(--maroon-dark)); color: #fff; font-size: 15px; }
    .topbar-brand img { width: 100%; height: 100%; object-fit: contain; background: #fff; }

    /* No bottom bar in app mode — navigation lives in the slide-in drawer. */
    .main { padding-bottom: env(safe-area-inset-bottom) !important; }
    .app-footer { display: none; }
    .table-wrap { -webkit-overflow-scrolling: touch; }
}
@media (max-width: 560px) {
    th, td { padding-left: 11px; padding-right: 11px; }
    .stat-value { font-size: 21px; }
}

/* ── Responsive utilities (single source, used across pages) ────────────── */
.grid-2-1 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1024px) { .grid-2-1 { grid-template-columns: 1fr; } }

/* Detail page: fixed-width left rail (profile/summary) + fluid body; stacks on app screens. */
.detail-grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1024px) { .detail-grid { grid-template-columns: 1fr; } }

/* Hide a block on phones / small tablets (e.g. KPI summary strips). */
@media (max-width: 768px) { .hide-mobile { display: none !important; } }
/* Hide a single table column on phones (mark matching th + td). */
@media (max-width: 700px) { .hide-phone { display: none !important; } }

/* Turn a wide table into stacked, labelled cards on phones — tap-friendly.
   Label pins left, value(s) group on the right (handles multi-line cells). */
@media (max-width: 700px) {
    table.rtable, table.rtable tbody { display: block; width: 100%; }
    table.rtable thead, table.rtable tfoot { display: none; }
    table.rtable tr { display: block; border: 1px solid var(--border); border-radius: 13px;
        margin: 0 0 10px; background: #fff; padding: 2px 2px; box-shadow: var(--shadow); }
    table.rtable tr:hover td { background: transparent; }
    table.rtable td { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center;
        gap: 4px 10px; padding: 9px 14px; border: none; text-align: right; font-size: 13.5px; }
    table.rtable td + td { border-top: 1px solid var(--border); }
    table.rtable td::before { content: attr(data-label); margin-right: auto; font-size: 10px; font-weight: 700;
        text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); text-align: left; }
    table.rtable td:not([data-label])::before { content: none; }
    table.rtable td.rt-action { padding: 11px 14px; }
    table.rtable td.rt-action .btn { width: 100%; justify-content: center; }
}

/* ── Mobile stepped wizard (multi-section forms, e.g. New Loan) ──────────────
   Desktop renders the whole form; on phones JS adds `.wiz-on` to a `.split-grid`
   and `wiz-active` to <body>, then shows one `[data-wiz]` section at a time with
   a progress header (`.wiz-head`) and a fixed Back/Next bar (`.wiz-foot`). */
.wiz-head, .wiz-foot { display: none; }
@media (max-width: 768px) {
    .split-grid.wiz-on { display: block; }
    .split-grid.wiz-on > div { width: auto; }
    .split-grid.wiz-on .sticky-aside { margin: 0; }
    /* On the review step the fixed footer owns the actions — hide the in-card ones. */
    .split-grid.wiz-on .sticky-aside #reviewBtn,
    .split-grid.wiz-on .sticky-aside a.btn { display: none !important; }

    .wiz-head { display: block; margin: 0 0 14px; }
    .wiz-head-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
    .wiz-x { width: 34px; height: 34px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
        border-radius: 9px; border: 1px solid var(--border); background: #fff; color: var(--maroon); font-size: 15px; text-decoration: none; }
    .wiz-head-mid { flex: 1; text-align: center; min-width: 0; }
    .wiz-title { font-size: 15px; font-weight: 800; letter-spacing: -.01em; }
    .wiz-sub { font-size: 11.5px; color: var(--text-muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .wiz-bar { display: flex; gap: 5px; }
    .wiz-bar span { flex: 1; height: 5px; border-radius: 99px; background: var(--cream-dark); transition: background .25s; }
    .wiz-bar span.on { background: var(--secondary); }

    .wiz-foot { display: flex; gap: 10px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
        padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
        background: rgba(255,255,255,.97); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
        border-top: 1px solid var(--border); box-shadow: 0 -4px 22px rgba(14,107,97,.10); }
    .wiz-foot .btn { padding: 12px 16px; font-size: 14px; }
    .wiz-foot #wizNext { flex: 1; justify-content: center; }
    body.wiz-active .content { padding-bottom: calc(78px + env(safe-area-inset-bottom)) !important; }
}

/* ── Login page ─────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; background: rgba(255,255,255,.97); border: 1px solid var(--border); border-radius: 20px; box-shadow: 0 24px 60px -20px color-mix(in srgb, var(--maroon) 30%, transparent); padding: 34px 30px; animation: fadeUp .4s both; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-logo { width: 56px; height: 56px; border-radius: 16px; background: linear-gradient(135deg, var(--maroon), var(--maroon-dark)); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 24px; box-shadow: 0 8px 20px -6px color-mix(in srgb, var(--maroon) 50%, transparent); }
.login-title { font-size: 20px; font-weight: 800; color: var(--maroon); }
.login-sub { font-size: 12.5px; color: var(--text-muted); margin-top: -6px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form .btn-primary { justify-content: center; padding: 11px; font-size: 14px; }
.login-foot { text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 18px; }
