:root {
    --primary: #6D4CE0;
    --primary-dark: #5636C9;
    --primary-darker: #4A2AB8;
    --primary-light: #EFEAFC;
    --surface: #FFFFFF;
    --bg: #F4F5FA;
    --text: #241F3D;
    --text-muted: #8B8AA3;
    --border: #ECEBF3;
    --success: #1FAE6E;
    --success-bg: #E1F7EC;
    --danger: #E5484D;
    --danger-bg: #FDEAEA;
    --warning: #F2A93B;
    --warning-bg: #FEF3E0;
    --shell-width: 480px;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

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

.app-shell {
    max-width: var(--shell-width);
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    position: relative;
}

@media (min-width: 560px) {
    .app-shell {
        min-height: calc(100vh - 32px);
        margin-top: 16px;
        margin-bottom: 16px;
        border-radius: 28px;
        overflow: hidden;
        box-shadow: 0 20px 60px rgba(36, 31, 61, 0.18);
    }
}

.app-topbar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    padding: 16px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 15;
}

.app-topbar .topbar-title {
    flex: 1;
    font-size: 1.05rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-topbar .topbar-subtitle {
    display: block;
    font-size: 0.72rem;
    font-weight: 400;
    opacity: 0.8;
}

.app-topbar .topbar-icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.16);
    font-size: 1rem;
    flex-shrink: 0;
    border: none;
    color: #fff;
}

.app-content {
    flex: 1;
    padding: 16px 16px 100px 16px;
}

/* ---------- Bottom navigation ---------- */

.app-bottomnav {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    z-index: 20;
}

.app-bottomnav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 0.66rem;
    color: var(--text-muted);
    padding: 6px 10px;
    border-radius: 12px;
}

.app-bottomnav .nav-item i {
    font-size: 1.15rem;
}

.app-bottomnav .nav-item.active {
    color: var(--primary);
    font-weight: 600;
}

.app-bottomnav .nav-fab {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    margin-top: -30px;
    box-shadow: 0 8px 18px rgba(109, 76, 224, 0.45);
    border: 4px solid #fff;
}

/* ---------- Cards & surfaces ---------- */

.card {
    border: none;
    border-radius: 16px;
    box-shadow: 0 2px 10px rgba(36, 31, 61, 0.06);
}

.stat-card {
    border-radius: 16px;
    padding: 14px;
    color: #fff;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-card .stat-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-card .stat-label {
    font-size: 0.72rem;
    opacity: 0.9;
}

.stat-card .stat-value {
    font-size: 1.15rem;
    font-weight: 700;
}

.bg-grad-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.mini-stat {
    background: #fff;
    border-radius: 14px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 2px 10px rgba(36, 31, 61, 0.06);
}

.mini-stat .mini-stat-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    flex-shrink: 0;
}

.mini-stat .mini-stat-value {
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.1;
}

.mini-stat .mini-stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ---------- Badges (estado) ---------- */

.badge-estado {
    font-size: 0.68rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.badge-activo {
    background: var(--success-bg);
    color: var(--success);
}

.badge-vencido {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-pendiente {
    background: var(--warning-bg);
    color: var(--warning);
}

.badge-cancelado {
    background: #EEEEF3;
    color: var(--text-muted);
}

.badge-pagado {
    background: var(--success-bg);
    color: var(--success);
}

/* ---------- Search ---------- */

.search-box {
    position: relative;
}

.search-box i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    width: 100%;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 12px;
    padding: 10px 14px 10px 38px;
    font-size: 0.85rem;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ---------- Pill tabs ---------- */

.pill-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.pill-tabs a {
    flex-shrink: 0;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 7px 16px;
    border-radius: 999px;
    color: var(--text-muted);
    background: #fff;
    border: 1px solid var(--border);
}

.pill-tabs a.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.detail-tabs {
    display: flex;
    background: #fff;
    border-radius: 14px;
    padding: 4px;
    box-shadow: 0 2px 10px rgba(36, 31, 61, 0.06);
}

.detail-tabs a {
    flex: 1;
    text-align: center;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 8px 4px;
    border-radius: 10px;
}

.detail-tabs a i {
    display: block;
    font-size: 1rem;
    margin-bottom: 2px;
}

.detail-tabs a.active {
    background: var(--primary-light);
    color: var(--primary);
}

/* ---------- List items (clientes / prestamos) ---------- */

.list-item {
    background: #fff;
    border-radius: 14px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 2px 10px rgba(36, 31, 61, 0.06);
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.list-item .item-title {
    font-weight: 600;
    font-size: 0.88rem;
}

.list-item .item-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.list-item .item-trailing {
    text-align: right;
    flex-shrink: 0;
}

/* ---------- Progress bar ---------- */

.progress-thin {
    height: 8px;
    border-radius: 999px;
    background: var(--border);
    overflow: hidden;
}

.progress-thin .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success) 0%, #2FD98F 100%);
    border-radius: 999px;
}

/* ---------- Cronograma table ---------- */

.cronograma-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.cronograma-table th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.68rem;
    text-transform: uppercase;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}

.cronograma-table td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
}

.cronograma-table tr:last-child td {
    border-bottom: none;
}

.saldo-negativo {
    color: var(--danger);
}

/* ---------- Donut chart ---------- */

.donut {
    width: 108px;
    height: 108px;
    border-radius: 50%;
    flex-shrink: 0;
}

.donut-legend-dot {
    width: 9px;
    height: 9px;
    border-radius: 3px;
    display: inline-block;
    margin-right: 6px;
}

/* ---------- Stepper (nuevo prestamo) ---------- */

.stepper {
    display: flex;
    align-items: center;
    gap: 6px;
}

.stepper .step {
    flex: 1;
    text-align: center;
}

.stepper .step-circle {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    margin: 0 auto 4px;
}

.stepper .step.active .step-circle,
.stepper .step.done .step-circle {
    background: var(--primary);
    color: #fff;
}

.stepper .step-label {
    font-size: 0.62rem;
    color: var(--text-muted);
}

.stepper .step.active .step-label {
    color: var(--primary);
    font-weight: 600;
}

/* ---------- Forms ---------- */

.form-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text);
}

.form-control, .form-select {
    border-radius: 12px;
    border-color: var(--border);
    font-size: 0.88rem;
    padding: 10px 12px;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    border-radius: 12px;
    font-weight: 600;
    padding: 11px;
}

.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
    border-radius: 12px;
    font-weight: 600;
}

/* ---------- Utility ---------- */

.section-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.link-ver-todos {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
}

.summary-highlight {
    background: var(--danger-bg);
    border-radius: 12px;
    padding: 12px;
}

.summary-highlight .value {
    color: var(--danger);
    font-weight: 700;
    font-size: 1.1rem;
}

/* ---------- Notificaciones ---------- */

.notif-wrapper {
    position: relative;
}

.notif-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 15px;
    height: 15px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    border: 2px solid var(--primary);
    animation: notif-pulse 1.6s infinite;
}

@keyframes notif-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.notif-panel {
    display: none;
    position: absolute;
    top: 44px;
    right: 0;
    width: 280px;
    max-height: 340px;
    overflow-y: auto;
    background: #fff;
    color: var(--text);
    border-radius: 14px;
    box-shadow: 0 12px 30px rgba(36, 31, 61, 0.25);
    z-index: 30;
    padding: 6px;
}

.notif-panel.open {
    display: block;
}

.notif-panel-title {
    font-size: 0.8rem;
    font-weight: 700;
    padding: 8px 10px 4px;
}

.notif-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 10px;
}

.notif-item:hover {
    background: var(--bg);
}

.notif-item i {
    font-size: 1rem;
    margin-top: 2px;
}

.notif-item-title {
    font-size: 0.78rem;
    font-weight: 600;
}

.notif-item-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.notif-empty {
    padding: 16px 10px;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
}
