
    /* Focus visible accessibility rules */
    button:focus-visible,
    a:focus-visible,
    input:focus-visible,
    select:focus-visible,
    textarea:focus-visible {
      outline: 2.5px solid #009FE3 !important;
      outline-offset: 2px !important;
    }
    button:focus:not(:focus-visible),
    a:focus:not(:focus-visible),
    input:focus:not(:focus-visible),
    select:focus:not(:focus-visible),
    textarea:focus:not(:focus-visible) {
      outline: none !important;
    }

    /* Visually hidden label class for screen reader accessibility */
    .sr-only {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
      white-space: nowrap;
      border: 0;
    }

    /* Support for users with prefers-reduced-motion active */
    @media (prefers-reduced-motion: reduce) {
      * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
      }
    }

    :root {
      --blue: #009FE3; --blue-dark: #005A87; --blue-mid: #0076B3; --blue-tint: #E8F6FD; --blue-glow: rgba(0,159,227,.15);
      --amber: #F8AF41; --amber-dark: #C8841A; --amber-tint: rgba(248,175,65,.12);
      --ink: #0F1D2E; --ink-2: #1C2D42; --slate: #4A5E73; --muted: #7B93A8; --line: #DDE8F2; --paper: #F3F7FB; --white: #fff;
      --green: #22C55E; --green-tint: rgba(34,197,94,.1); --red: #EF4444; --red-tint: rgba(239,68,68,.08);
      --display: 'Space Grotesk', sans-serif;
      --sans: 'IBM Plex Sans', sans-serif;
      --mono: 'IBM Plex Mono', monospace;
      --r-sm: 10px; --r-md: 16px; --r-lg: 22px; --r-xl: 28px;
      --shadow-sm: 0 1px 3px rgba(15,29,46,.06), 0 1px 2px rgba(15,29,46,.04);
      --shadow-md: 0 4px 16px rgba(15,29,46,.08), 0 2px 6px rgba(15,29,46,.04);
      --shadow-lg: 0 20px 50px rgba(15,29,46,.12), 0 8px 20px rgba(15,29,46,.06);
      --sidebar-w: 260px;
    }
    *, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
    html { font-size: 14px; }
    body { font-family: var(--sans); background: var(--paper); color: var(--ink-2); -webkit-font-smoothing: antialiased; min-height: 100vh; overflow-x: hidden; }
    button, input, select, textarea { font-family: inherit; font-size: inherit; }
    a { text-decoration: none; }

    /* ─── SCROLLBAR ─────────────────────── */
    ::-webkit-scrollbar { width: 4px; height: 4px; }
    ::-webkit-scrollbar-track { background: transparent; }
    ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
    ::-webkit-scrollbar-thumb:hover { background: var(--muted); }

    /* ─── LOGIN SCREEN ──────────────────── */
    .screen-login {
      min-height: 100vh; display: flex; align-items: stretch;
      background: var(--ink);
    }
    .login-left {
      flex: 1; display: flex; flex-direction: column; justify-content: center;
      padding: 70px 68px; position: relative; overflow: hidden;
      background: linear-gradient(135deg, var(--blue-dark) 0%, #0A1628 100%);
    }
    .login-left::before {
      content: ''; position: absolute; inset: 0;
      background: radial-gradient(ellipse 60% 60% at 20% 80%, rgba(0,159,227,.2) 0%, transparent 70%),
                  radial-gradient(ellipse 40% 40% at 80% 20%, rgba(248,175,65,.08) 0%, transparent 70%);
    }
    .login-grid {
      position: absolute; inset: 0; opacity: .04;
      background-image: linear-gradient(rgba(255,255,255,.8) 1px, transparent 1px),
                        linear-gradient(90deg, rgba(255,255,255,.8) 1px, transparent 1px);
      background-size: 40px 40px;
    }
    .login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 52px; position: relative; z-index: 1; }
    .login-brand-name { font-size: 24px; font-weight: 700; color: #fff; letter-spacing: -.01em; }
    .login-headline { font-size: clamp(36px, 3.5vw, 52px); font-weight: 800; color: #fff; line-height: 1.1; margin-bottom: 20px; position: relative; z-index: 1; letter-spacing: -.02em; }
    .login-headline em { color: var(--amber); font-style: normal; display: block; }
    .login-sub { font-size: 15.5px; color: rgba(255,255,255,.58); line-height: 1.7; position: relative; z-index: 1; max-width: 400px; }
    .login-badges { display: flex; flex-direction: column; gap: 14px; margin-top: 52px; position: relative; z-index: 1; }
    .login-badge { display: flex; align-items: center; gap: 14px; font-size: 13.5px; color: rgba(255,255,255,.72); font-weight: 500; }
    .login-badge-icon { width: 38px; height: 38px; border-radius: 10px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12); display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
    .login-right {
      width: 500px; flex-shrink: 0; background: var(--white);
      display: flex; flex-direction: column; justify-content: center;
      padding: 64px 56px;
    }
    .login-form-title { font-size: 30px; font-weight: 800; color: var(--ink); margin-bottom: 8px; letter-spacing: -.02em; }
    .login-form-sub { font-size: 14px; color: var(--muted); margin-bottom: 36px; line-height: 1.5; }
    .field { margin-bottom: 20px; }
    .field-label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--slate); margin-bottom: 8px; }
    .field-input { width: 100%; padding: 13px 16px; border: 1.5px solid var(--line); border-radius: var(--r-sm); font-size: 14.5px; color: var(--ink); background: var(--paper); transition: border-color .2s, box-shadow .2s; }
    .field-input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-glow); background: var(--white); }
    .field-input::placeholder { color: var(--muted); }
    .btn-login { width: 100%; padding: 15px; background: var(--ink); color: #fff; border: none; border-radius: var(--r-sm); font-size: 15px; font-weight: 700; letter-spacing: .03em; cursor: pointer; transition: background .2s, transform .1s; margin-top: 6px; }
    .btn-login:hover { background: var(--blue-dark); }
    .btn-login:active { transform: scale(.99); }
    .login-error { background: var(--red-tint); border: 1px solid rgba(239,68,68,.3); color: var(--red); padding: 11px 15px; border-radius: var(--r-sm); font-size: 13px; font-weight: 600; margin-bottom: 16px; display: none; }
    .login-creds { margin-top: 28px; padding: 20px; background: var(--paper); border-radius: var(--r-sm); border: 1px solid var(--line); }
    .login-creds-title { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 14px; }
    .cred-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
    .cred-row:last-child { border-bottom: none; }
    .cred-role { font-size: 12px; color: var(--slate); font-weight: 600; }
    .cred-val { font-family: var(--mono); font-size: 11px; color: var(--blue-dark); background: var(--blue-tint); padding: 3px 9px; border-radius: 5px; cursor: pointer; transition: all .15s; border: 1px solid transparent; }
    .cred-val:hover { background: var(--blue); color: #fff; border-color: var(--blue); }
    @keyframes fadeUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }
    .login-right { animation: fadeUp .45s ease; }
    @media (max-width: 860px) {
      .login-left { display: none; }
      .login-right { width: 100%; padding: 40px 28px; }
    }

    /* ─── APP SHELL ─────────────────────── */
    .app { display: none; flex-direction: column; min-height: 100vh; }
    .app.visible { display: flex; }

    /* ─── TOPBAR ─────────────────────────── */
    .topbar {
      height: 56px; background: var(--white); border-bottom: 1px solid var(--line);
      display: flex; align-items: center; padding: 0 24px; gap: 16px;
      position: sticky; top: 0; z-index: 100; flex-shrink: 0;
      box-shadow: var(--shadow-sm);
    }
    .topbar-logo { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; color: var(--ink); flex-shrink: 0; }
    .topbar-divider { width: 1px; height: 24px; background: var(--line); flex-shrink: 0; }
    .topbar-breadcrumb { font-size: 13px; color: var(--muted); font-weight: 500; flex: 1; }
    .topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
    .topbar-user { display: flex; align-items: center; gap: 8px; }
    .topbar-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0; }
    .topbar-user-name { font-size: 13px; font-weight: 600; color: var(--ink); }
    .topbar-user-role { font-family: var(--mono); font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
    .btn-topbar { padding: 6px 14px; border-radius: 20px; font-size: 11.5px; font-weight: 600; border: 1px solid var(--line); background: transparent; color: var(--slate); cursor: pointer; transition: all .18s; font-family: var(--mono); text-transform: uppercase; }
    .btn-topbar:hover { background: var(--red-tint); border-color: var(--red); color: var(--red); }

    /* ─── BODY SHELL ─────────────────────── */
    .body-shell { display: flex; flex: 1; overflow: hidden; }

    /* ─── SIDEBAR ─────────────────────────── */
    .sidebar {
      width: var(--sidebar-w); flex-shrink: 0;
      background: var(--white); border-right: 1px solid var(--line);
      display: flex; flex-direction: column;
      overflow-y: auto; padding-bottom: 24px;
    }
    .sidebar-header { padding: 22px 20px 16px; border-bottom: 1px solid var(--line); }
    .sidebar-role-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px; font-family: var(--mono); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
    .sidebar-role-badge.admin { background: rgba(248,175,65,.15); color: var(--amber-dark); border: 1px solid rgba(248,175,65,.3); }
    .sidebar-role-badge.client { background: var(--blue-tint); color: var(--blue-dark); border: 1px solid rgba(0,159,227,.2); }
    .sidebar-role-badge.investor { background: var(--green-tint); color: #166534; border: 1px solid rgba(34,197,94,.2); }
    .sidebar-section-title { padding: 18px 20px 6px; font-family: var(--mono); font-size: 9.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
    .nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 20px; font-size: 13px; font-weight: 500; color: var(--slate); cursor: pointer; transition: all .15s; position: relative; border: none; background: transparent; width: 100%; text-align: left; border-radius: 0; }
    .nav-item:hover { background: var(--paper); color: var(--ink); }
    .nav-item.active { background: var(--blue-tint); color: var(--blue-dark); font-weight: 600; }
    .nav-item.active::before { content: ''; position: absolute; left: 0; top: 4px; bottom: 4px; width: 3px; background: var(--blue); border-radius: 0 3px 3px 0; }
    .nav-item .nav-icon { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }
    .nav-badge { margin-left: auto; background: var(--blue); color: #fff; font-family: var(--mono); font-size: 9px; font-weight: 700; padding: 1px 6px; border-radius: 10px; }
    .sidebar-back-link { margin: 16px; padding: 10px 14px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-sm); display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); cursor: pointer; transition: all .18s; }
    .sidebar-back-link:hover { background: var(--blue-tint); color: var(--blue-dark); border-color: rgba(0,159,227,.3); }

    /* ─── MAIN CONTENT ──────────────────── */
    .main { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
    .main-inner { padding: 28px 32px; flex: 1; animation: fadeIn .25s ease; }
    @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
    @keyframes pulse {
      0% { transform: scale(1); opacity: 1; }
      50% { transform: scale(1.03); opacity: 0.9; }
      100% { transform: scale(1); opacity: 1; }
    }
    .page-header { margin-bottom: 26px; }
    .page-title { font-size: 22px; font-weight: 700; color: var(--ink); }
    .page-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }

    /* ─── STATS GRID ─────────────────────── */
    .stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }
    .stat-card {
      background: var(--white); border: 1px solid var(--line); border-radius: var(--r-lg);
      padding: 20px 22px; box-shadow: var(--shadow-sm);
      display: flex; flex-direction: column; gap: 6px;
      transition: box-shadow .2s, transform .2s;
    }
    .stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
    .stat-top { display: flex; justify-content: space-between; align-items: flex-start; }
    .stat-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
    .stat-icon.blue { background: var(--blue-tint); }
    .stat-icon.amber { background: var(--amber-tint); }
    .stat-icon.green { background: var(--green-tint); }
    .stat-icon.red { background: var(--red-tint); }
    .stat-icon.purple { background: rgba(168,85,247,.15); color: #a855f7; }
    .stat-label { font-family: var(--mono); font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
    .stat-value { font-size: 24px; font-weight: 700; color: var(--ink); }
    .stat-delta { font-size: 11.5px; color: var(--muted); }
    .stat-delta.up { color: var(--green); }

    /* ─── CARDS ──────────────────────────── */
    .card { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
    .card-header { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
    .card-title { font-size: 14px; font-weight: 700; color: var(--ink); }
    .card-body { padding: 0; }
    .card-padded { padding: 22px; }

    /* ─── BUTTONS ─────────────────────────── */
    .btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--r-sm); font-size: 12px; font-weight: 700; font-family: var(--mono); text-transform: uppercase; letter-spacing: .04em; border: none; cursor: pointer; transition: all .18s; white-space: nowrap; }
    .btn-primary { background: var(--blue); color: #fff; }
    .btn-primary:hover { background: var(--blue-dark); }
    .btn-amber { background: var(--amber); color: var(--ink); }
    .btn-amber:hover { background: var(--amber-dark); color: #fff; }
    .btn-ghost { background: transparent; color: var(--slate); border: 1px solid var(--line); }
    .btn-ghost:hover { background: var(--paper); color: var(--ink); }
    .btn-danger { background: var(--red-tint); color: var(--red); border: 1px solid rgba(239,68,68,.2); }
    .btn-danger:hover { background: var(--red); color: #fff; }
    .btn-sm { padding: 5px 10px; font-size: 10px; border-radius: 6px; }
    .btn-icon { width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; border: none; background: transparent; cursor: pointer; transition: all .18s; font-size: 14px; }
    .btn-icon:hover { background: var(--paper); }
    .btn-icon.danger:hover { background: var(--red-tint); color: var(--red); }

    /* ─── BADGES / TAGS ─────────────────── */
    .badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-family: var(--mono); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
    .badge-blue { background: var(--blue-tint); color: var(--blue-dark); }
    .badge-amber { background: var(--amber-tint); color: var(--amber-dark); }
    .badge-green { background: var(--green-tint); color: #166534; }
    .badge-red { background: var(--red-tint); color: var(--red); }
    .badge-slate { background: var(--paper); color: var(--slate); border: 1px solid var(--line); }

    /* ─── TABLE ──────────────────────────── */
    .data-table { width: 100%; border-collapse: collapse; }
    .data-table th { font-family: var(--mono); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
    .data-table td { padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
    .data-table tr:last-child td { border-bottom: none; }
    .data-table tbody tr { cursor: pointer; transition: background .12s; }
    .data-table tbody tr:hover td { background: var(--paper); }
    .data-table tbody tr.selected td { background: var(--blue-tint); }
    .empty-state { text-align: center; padding: 48px 20px; color: var(--muted); font-size: 13px; }

    /* ─── CHARTS ─────────────────────────── */
    .charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 24px; }
    .chart-card { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px; box-shadow: var(--shadow-sm); }
    .chart-label { font-family: var(--mono); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 16px; }
    .donut-wrap { display: flex; align-items: center; gap: 20px; }
    .donut-legend { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
    .legend-row { display: flex; align-items: center; gap: 7px; font-size: 12px; }
    .legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
    .legend-name { color: var(--slate); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .legend-val { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--ink); }
    .bar-grid { display: flex; flex-direction: column; gap: 10px; }
    .bar-item { display: flex; align-items: center; gap: 10px; }
    .bar-name { font-size: 11px; font-weight: 600; color: var(--slate); width: 80px; flex-shrink: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .bar-track { flex: 1; height: 8px; background: var(--paper); border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
    .bar-fill { height: 100%; border-radius: 4px; transition: width .7s cubic-bezier(.25,.8,.25,1); }
    .bar-amount { font-family: var(--mono); font-size: 10px; color: var(--muted); width: 64px; text-align: right; }

    /* ─── PROGRESS BAR ──────────────────── */
    .progress-bar { height: 8px; background: var(--paper); border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
    .progress-fill { height: 100%; border-radius: 4px; transition: width .6s ease; background: var(--blue); }
    .progress-fill.amber { background: linear-gradient(90deg, var(--blue), var(--amber)); }

    /* ─── DETAIL PANEL ──────────────────── */
    .two-col { display: grid; grid-template-columns: 1fr 1.1fr; gap: 20px; align-items: start; }
    .detail-panel { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
    .detail-header { background: linear-gradient(135deg, var(--ink) 0%, var(--blue-dark) 100%); padding: 22px 24px; position: relative; overflow: hidden; }
    .detail-header::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse 80% 80% at 80% -20%, rgba(0,159,227,.25) 0%, transparent 60%); }
    .detail-header-content { position: relative; z-index: 1; }
    .detail-op-type { font-family: var(--mono); font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--amber); margin-bottom: 6px; }
    .detail-name { font-size: 20px; font-weight: 700; color: #fff; margin-bottom: 4px; }
    .detail-ruc { font-family: var(--mono); font-size: 11px; color: rgba(255,255,255,.5); }
    .detail-actions { display: flex; gap: 8px; margin-top: 14px; }
    .detail-btn { padding: 7px 14px; border-radius: 20px; font-family: var(--mono); font-size: 10.5px; font-weight: 700; text-transform: uppercase; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.08); color: rgba(255,255,255,.9); cursor: pointer; transition: all .18s; }
    .detail-btn:hover { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.4); }
    .detail-btn.danger { border-color: rgba(239,68,68,.4); color: rgba(239,68,68,.9); background: rgba(239,68,68,.08); }
    .detail-btn.danger:hover { background: var(--red); color: #fff; }
    .detail-body { padding: 20px 24px; }

    /* ─── MINI METRICS ROW ──────────────── */
    .mini-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
    .mini-metric { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; }
    .mini-label { font-family: var(--mono); font-size: 9px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 4px; }
    .mini-value { font-size: 15px; font-weight: 700; color: var(--ink); }

    /* ─── AMORT SECTION ─────────────────── */
    .amort-section { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 16px; margin-bottom: 18px; }
    .amort-title { font-size: 12px; font-weight: 700; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
    .amort-pct { font-family: var(--mono); font-size: 13px; font-weight: 700; color: var(--blue); }
    .amort-meta { display: flex; justify-content: space-between; margin-top: 8px; font-family: var(--mono); font-size: 10.5px; color: var(--muted); }

    /* ─── SPLIT BARS (interest vs capital) ── */
    .split-bars { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
    .split-bar-item { }
    .split-bar-label { font-family: var(--mono); font-size: 9.5px; color: var(--muted); text-transform: uppercase; margin-bottom: 4px; }
    .split-bar-val { font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 4px; }

    /* ─── PAYMENTS HISTORY ──────────────── */
    .payments-section { margin-bottom: 18px; }
    .section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
    .section-title { font-size: 12px; font-weight: 700; color: var(--ink); }
    .payments-scroll { max-height: 170px; overflow-y: auto; }

    /* ─── DOCUMENTS ─────────────────────── */
    .docs-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
    .doc-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-sm); transition: border-color .15s; }
    .doc-row:hover { border-color: var(--blue); }
    .doc-ext { width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; font-family: var(--mono); flex-shrink: 0; }
    .doc-ext.pdf { background: rgba(239,68,68,.1); color: var(--red); }
    .doc-ext.img { background: var(--green-tint); color: #166534; }
    .doc-ext.doc { background: var(--blue-tint); color: var(--blue-dark); }
    .doc-ext.xls { background: var(--green-tint); color: #166534; }
    .doc-name { flex: 1; min-width: 0; font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .doc-meta { font-family: var(--mono); font-size: 9.5px; color: var(--muted); }
    .doc-btns { display: flex; gap: 4px; flex-shrink: 0; }

    /* ─── DROPZONE ──────────────────────── */
    .dropzone { border: 1.5px dashed var(--line); background: var(--paper); border-radius: var(--r-sm); padding: 16px; text-align: center; cursor: pointer; transition: all .2s; position: relative; }
    .dropzone:hover { border-color: var(--blue); background: var(--blue-tint); }
    .dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
    .dropzone-icon { font-size: 20px; margin-bottom: 4px; }
    .dropzone-text { font-size: 11.5px; color: var(--muted); line-height: 1.4; }
    .dropzone-text strong { color: var(--blue); }

    /* ─── MODAL ──────────────────────────── */
    .modal-bg { display: none; position: fixed; inset: 0; background: rgba(10,20,36,.5); z-index: 500; backdrop-filter: blur(6px); align-items: center; justify-content: center; padding: 20px; }
    .modal-bg.open { display: flex; }
    .modal { background: var(--white); border-radius: var(--r-xl); padding: 34px; max-width: 600px; width: 100%; box-shadow: var(--shadow-lg); animation: fadeUp .3s ease; max-height: 90vh; overflow-y: auto; }
    .modal-title { font-size: 20px; font-weight: 700; margin-bottom: 22px; display: flex; align-items: center; gap: 10px; }
    .modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
    .modal-footer { display: flex; gap: 10px; margin-top: 24px; }
    .modal-footer .btn { flex: 1; justify-content: center; padding: 13px; font-size: 12.5px; }

    /* ─── CONFIRM DIALOG ─────────────────── */
    .confirm-bg { display: none; position: fixed; inset: 0; background: rgba(10,20,36,.55); z-index: 600; backdrop-filter: blur(8px); align-items: center; justify-content: center; }
    .confirm-bg.open { display: flex; }
    .confirm-box { background: var(--white); border-radius: var(--r-xl); padding: 36px 40px; max-width: 400px; width: 90%; text-align: center; box-shadow: var(--shadow-lg); }
    .confirm-icon { font-size: 42px; margin-bottom: 14px; }
    .confirm-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
    .confirm-msg { font-size: 13.5px; color: var(--muted); line-height: 1.6; margin-bottom: 26px; }
    .confirm-buttons { display: flex; gap: 10px; }
    .confirm-buttons .btn { flex: 1; justify-content: center; padding: 12px; }

    /* ─── TOAST ──────────────────────────── */
    .toast { position: fixed; bottom: 24px; right: 24px; background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 12px; font-family: var(--mono); font-size: 12px; font-weight: 600; z-index: 900; box-shadow: var(--shadow-lg); transform: translateY(80px); opacity: 0; transition: all .3s cubic-bezier(.25,.8,.25,1); display: flex; align-items: center; gap: 8px; }
    .toast.show { transform: translateY(0); opacity: 1; }
    .toast.ok { background: #166534; }
    .toast.err { background: var(--red); }

    /* ─── CLIENT: AMORT TABLE ────────────── */
    .amort-table-scroll { max-height: 360px; overflow-y: auto; }

    /* ─── EMPTY DETAIL ───────────────────── */
    .empty-detail { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 20px; color: var(--muted); text-align: center; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--white); }
    .empty-detail-icon { font-size: 48px; margin-bottom: 14px; opacity: .4; }
    .empty-detail-text { font-size: 14px; }

    @media (max-width: 900px) {
      .sidebar { display: none; }
      .main-inner { padding: 20px; }
      .two-col { grid-template-columns: 1fr; }
    }
  
    
    
    
    
    
    /* ─── NOISE GRAIN AND CARD LIFTS ─────── */
    body::before {
      content: "";
      position: fixed;
      top: 0; left: 0; width: 100%; height: 100%;
      background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.012'/%3E%3C/svg%3E");
      pointer-events: none;
      z-index: 9999;
    }
    
    .card {
      border: 1px solid rgba(0,159,227,0.12);
      border-radius: var(--r-md);
      transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s ease, border-color 0.3s ease;
    }
    .card:hover {
      box-shadow: var(--shadow-md);
      border-color: rgba(0,159,227,0.25);
    }
    
    .stat-card {
      border: 1px solid rgba(0,159,227,0.12);
      border-radius: var(--r-md);
      transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s ease, border-color 0.3s ease;
    }
    .stat-card:hover {
      transform: translateY(-3px);
      box-shadow: var(--shadow-md);
      border-color: rgba(0,159,227,0.25);
    }

    /* ─── PREMIUM SVG SIDEBAR ICONS ─────── */
    .sidebar-svg-icon {
      stroke: var(--slate);
      transition: stroke 0.22s ease, transform 0.22s ease;
      vertical-align: middle;
      display: inline-block;
    }
    .nav-item.active .sidebar-svg-icon {
      stroke: var(--blue-dark);
    }
    .nav-item:hover .sidebar-svg-icon {
      stroke: var(--ink);
      transform: translateX(1px);
    }
    
    .data-table th {
      font-family: var(--mono);
      font-size: 10.5px;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--muted);
      border-bottom: 2px solid var(--line);
    }

    /* ─── CRM KANBAN BOARD STYLES ────────── */
    .crm-board-wrapper {
      width: 100%;
    }
    .crm-board {
      display: flex;
      gap: 16px;
      padding-bottom: 8px;
    }
    .crm-col {
      flex: 1;
      min-width: 250px;
      max-width: 320px;
      background: #fff;
      border: 1px solid var(--line);
      border-radius: var(--r-md);
      display: flex;
      flex-direction: column;
      height: 600px;
      box-shadow: var(--shadow-sm);
    }
    .crm-col-header {
      padding: 14px 16px;
      background: #fafbfc;
      border-bottom: 1px solid var(--line);
      border-top-left-radius: var(--r-md);
      border-top-right-radius: var(--r-md);
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .crm-col-body {
      flex: 1;
      overflow-y: auto;
      padding: 12px;
      display: flex;
      flex-direction: column;
      gap: 10px;
      background: var(--paper);
      border-bottom-left-radius: var(--r-md);
      border-bottom-right-radius: var(--r-md);
      transition: background 0.2s ease;
    }
    .crm-card {
      background: #fff;
      border: 1px solid var(--line);
      border-radius: var(--r-sm);
      padding: 14px 16px;
      box-shadow: 0 1px 3px rgba(0,0,0,0.02);
      cursor: pointer;
      transition: all 0.2s ease;
    }
    .crm-card:hover {
      transform: translateY(-2px);
      box-shadow: var(--shadow-md);
      border-color: var(--blue);
    }
    .crm-card.dragging {
      opacity: 0.4;
      border: 2.5px dashed var(--blue);
    }

    /* ============ PORTAL UNIFIED RESPONSIVE SYSTEM ============ */
    html { overflow-x: hidden; }
    body { overflow-x: hidden; width: 100vw; max-width: 100%; position: relative; }
    *, *::before, *::after { box-sizing: border-box; }

    .portal-mobile-nav { display: none; }

    /* ─── TABLET / MOBILE COMMON (< 1024px) ─── */
    @media (max-width: 1023px) {
      /* REMOVE VIEWPORT LOCKING ON MOBILE TO ALLOW NATURAL SCROLLING DOWN TO THE BOTTOM */
      .app {
        height: auto !important;
        min-height: 100dvh !important;
        overflow: visible !important;
      }
      .body-shell {
        flex-direction: column !important;
        height: auto !important;
        overflow: visible !important;
      }
      .sidebar {
        display: none !important;
      }
      .main {
        padding-bottom: 90px !important;
        overflow-y: visible !important;
        height: auto !important;
      }
      .main-inner {
        padding: clamp(12px, 3vw, 24px) !important;
      }
      
      /* Topbar scaling to prevent text overlap */
      .topbar {
        padding: 0 clamp(10px, 2vw, 20px) !important;
        gap: clamp(8px, 1.5vw, 16px) !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 100 !important;
      }
      .topbar-breadcrumb {
        display: none !important; /* Hide 'Portal' breadcrumb text */
      }
      .topbar-user-name, .topbar-user-role {
        display: none !important; /* Hide user text, keep avatar only */
      }
      .btn-topbar {
        padding: 5px 10px !important;
        font-size: 10.5px !important;
      }

      /* Grid collapses and spacing adjustments */
      .two-col,
      .portal-main-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
      }

      /* CRITICAL FIX: Force grid child columns to not expand past viewport width.
         This prevents tables from stretching the card width out of the screen boundaries. */
      .portal-main-grid > div,
      .two-col > div {
        min-width: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
      }
      
      /* Excel mapping and import grids */
      .modal-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
      }

      /* Double columns for stats and charts on large screens, single column on small mobile */
      .stats-grid,
      .portal-stats-grid,
      .grid-accounts,
      div[style*="grid-template-columns: repeat(5, 1fr)"] {
        grid-template-columns: 1fr 1fr !important;
        gap: 14px !important;
      }
      
      .charts-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
      }

      /* Disable scrolling on parent card containers to avoid scroll locks */
      .card-padded, .card-body {
        overflow-x: visible !important;
      }
      
      /* Dedicate scrolling ONLY to the scroll wrapper container */
      .table-scroll-container,
      .amort-table-scroll,
      .payments-scroll,
      div[style*="overflow-x: auto"] {
        width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        display: block !important;
        margin-bottom: 8px !important;
      }
      
      /* Force a minimum width on tables inside the scroll container to ensure scrollability */
      .table-scroll-container table,
      .amort-table-scroll table,
      .payments-scroll table,
      .data-table {
        display: table !important;
        width: auto !important;
        min-width: 800px !important; /* Ensures the table spans naturally past mobile viewport */
      }
      
      .data-table th, .data-table td, table th, table td {
        padding: 8px 12px !important;
        white-space: nowrap !important; /* Prevent text wrapping inside tables, forces scrollbar */
      }

      /* Next payment card layout stacking on mobile & tablets */
      .next-payment-body {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 16px !important;
        width: 100% !important;
        padding: 20px 16px !important;
      }
      
      .card-title {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
      }
      
      .card-upload-container {
        width: 100% !important;
        max-width: 100% !important;
        margin-top: 10px !important;
      }
      
      .btn-card-upload {
        width: 100% !important;
        max-width: 100% !important;
        padding: 12px 16px !important;
        font-size: 12.5px !important;
        text-align: center !important;
        background: var(--blue-dark) !important;
        color: #fff !important;
        border-radius: 8px !important;
        display: block !important;
        border: none !important;
        font-weight: 700 !important;
      }

      /* Portal mobile bottom navigation bar */
      .portal-mobile-nav {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 60px !important;
        background: rgba(255, 255, 255, 0.98) !important;
        backdrop-filter: blur(20px) !important;
        border-top: 1px solid var(--line) !important;
        box-shadow: 0 -4px 20px rgba(10, 27, 46, 0.06) !important;
        z-index: 9999 !important;
        justify-content: space-around !important;
        align-items: center !important;
        padding-bottom: env(safe-area-inset-bottom, 0) !important;
      }
      .portal-mobile-nav-item {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        color: var(--slate) !important;
        font-size: 9.5px !important;
        font-family: var(--sans) !important;
        font-weight: 500 !important;
        text-decoration: none !important;
        flex: 1 !important;
        height: 100% !important;
        transition: color 0.2s !important;
        cursor: pointer !important;
      }
      .portal-mobile-nav-item.active {
        color: var(--blue) !important;
        font-weight: 700 !important;
      }
      .portal-mobile-icon {
        font-size: 18px !important;
        margin-bottom: 2px !important;
      }

      /* Chart height constraints */
      div[style*="height: 320px"] {
        height: 250px !important;
      }

      /* Detail actions wrap */
      .detail-actions {
        flex-wrap: wrap !important;
        gap: 8px !important;
      }

      /* Modals */
      .modal {
        width: calc(100vw - 32px) !important;
        margin: 16px !important;
        max-height: calc(100vh - 32px) !important;
        overflow-y: auto !important;
        padding: 24px 20px !important;
      }
    }

    /* ─── SMALL MOBILE ONLY (< 480px) ─── */
    @media (max-width: 479px) {
      /* Force all grids to 1 column on small phones */
      .stats-grid,
      .portal-stats-grid,
      .grid-accounts,
      .excel-buttons-grid,
      div[style*="grid-template-columns: repeat(5, 1fr)"],
      div[style*="grid-template-columns:1fr 1fr"],
      div[style*="grid-template-columns: 1fr 1fr"],
      .mini-metrics,
      .split-bars,
      .confirm-buttons,
      form div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
      }
      
      /* Keep the table upload buttons small and clean! Do not force 100% width on row buttons */
      .row-upload-container {
        width: auto !important;
        display: inline-block !important;
      }
      .row-upload-container .btn-topbar {
        width: auto !important;
        padding: 4px 8px !important;
        font-size: 10px !important;
      }

      /* Opportunities list auto-fit grid (Line 1957) */
      div[style*="minmax(320px"] {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
      }

      /* Login card padding */
      .login-right {
        padding: 32px 20px !important;
      }
      .login-headline {
        font-size: 28px !important;
      }

      /* Donut charts stack vertically to prevent text overlap */
      .donut-wrap {
        flex-direction: column !important;
        align-items: center !important;
        gap: 16px !important;
      }
      .donut-legend {
        width: 100% !important;
        text-align: center !important;
        align-items: center !important;
      }
    }
  
  