:root {
    --brand-primary: #ee7800;
    --brand-secondary: #d8363a;
    --brand-accent: #1f3320;
    --brand-surface: #fff8ef;
    --brand-text: #223326;
}

body {
    background-color: #ffffff;
    color: var(--brand-text);
}

.card {
    background: #ffffff;
    border: 1px solid #ece8df;
    border-radius: 18px;
}

.card-header {
    background: #ffffff;
    border-bottom: 1px solid #f1ede5;
    padding: 1rem 1.25rem;
}

.card-body {
    padding: 1.25rem;
}

.gradient-custom-2 {
    background: linear-gradient(to right, var(--brand-primary), var(--brand-secondary), var(--brand-secondary), var(--brand-primary));
}

@media (min-width: 769px) {
    .gradient-custom-2 {
        border-top-right-radius: 0.3rem;
        border-bottom-right-radius: 0.3rem;
    }
}

.sidebar-card .list-group-item.active,
.sidebar-card .list-group-item:hover {
    background: linear-gradient(to right, var(--brand-primary), var(--brand-secondary), var(--brand-secondary), var(--brand-primary));
    color: #fff;
    border-color: transparent;
}

.sidebar-dropdown {
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.sidebar-dropdown summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    list-style: none;
}

.sidebar-dropdown summary::-webkit-details-marker {
    display: none;
}

.sidebar-submenu {
    background: var(--brand-surface);
}

.sidebar-subitem {
    padding-left: 2.6rem;
    font-size: 0.94rem;
}

.metric-card {
    min-height: 120px;
}

.page-shell {
    padding-top: 2rem;
    padding-bottom: 2rem;
}

.portal-summary {
    border-left: 4px solid var(--brand-secondary);
}

.portal-dashboard-v2 {
    padding-bottom: 1rem;
}

.portal-sidebar-card {
    overflow: hidden;
}

.portal-sidebar-summary {
    background: linear-gradient(135deg, var(--brand-surface) 0%, #f7efdf 55%, #efe1bf 100%);
    color: var(--brand-text);
    border-bottom: 1px solid #ece3cf;
}

.portal-sidebar-kicker {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--brand-primary);
}

.portal-sidebar-summary h5 {
    margin: 0 0 0.3rem;
}

.portal-sidebar-summary p {
    font-size: 0.92rem;
    color: var(--brand-text);
    word-break: break-word;
}

.portal-sidebar-badge {
    float: right;
    min-width: 22px;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: var(--brand-secondary);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.4;
}

.portal-sidebar-avatar,
.portal-profile-avatar {
    width: 84px;
    height: 84px;
    border-radius: 999px;
    object-fit: cover;
    display: block;
    margin: 0 auto 0.85rem;
    border: 3px solid #efe1bf;
}

.portal-sidebar-avatar-placeholder,
.portal-profile-avatar-placeholder {
    background: linear-gradient(135deg, #f0deba 0%, #e3c77b 100%);
    color: #6b5a31;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 700;
}

.portal-profile-avatar {
    margin-bottom: 0;
    width: 110px;
    height: 110px;
    border-color: #efe1bf;
}

.portal-profile-avatar-placeholder {
    background: linear-gradient(135deg, #1f3320 0%, #4c6f31 100%);
}

.portal-toolbar {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.portal-page-logo {
    width: 86px;
    height: auto;
    flex-shrink: 0;
}

.portal-stats-compact {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.portal-snapshot-list {
    display: grid;
    gap: 0.8rem;
}

.portal-snapshot-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1rem;
    border: 1px solid #ece8df;
    border-radius: 14px;
    background: linear-gradient(180deg, #fffdf8 0%, #f8f5ee 100%);
}

.portal-snapshot-row span {
    color: #6b7280;
    font-size: 0.9rem;
}

.portal-snapshot-row strong {
    color: var(--brand-text);
    text-align: right;
}

.portal-notification-list {
    display: grid;
    gap: 0.75rem;
}

.portal-notification-item {
    border-radius: 14px;
    padding: 0.9rem 1rem;
    border: 1px solid #ece8df;
    background: #fffdf8;
    color: var(--brand-text);
}

.portal-notification-item.tone-primary {
    background: #eef4ff;
    border-color: #c9dbff;
}

.portal-notification-item.tone-success {
    background: #eef9f0;
    border-color: #cdebd3;
}

.portal-notification-item.tone-warning {
    background: #fff7e8;
    border-color: #f2dbab;
}

.portal-notification-item.tone-danger {
    background: #fff1f0;
    border-color: #f1c1be;
}

.chat-thread {
    display: grid;
    gap: 0.9rem;
    max-height: 560px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.chat-row {
    display: flex;
}

.chat-row.is-self {
    justify-content: flex-end;
}

.chat-row.is-other {
    justify-content: flex-start;
}

.chat-bubble {
    max-width: 78%;
    border-radius: 16px;
    padding: 0.9rem 1rem;
    border: 1px solid #ece8df;
    box-shadow: 0 8px 22px rgba(34, 51, 38, 0.06);
}

.chat-bubble.is-self {
    background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-secondary) 100%);
    color: #fff;
    border-color: transparent;
}

.chat-bubble.is-other {
    background: #fffdf8;
    color: var(--brand-text);
}

.chat-meta {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.45rem;
    font-size: 0.78rem;
    opacity: 0.82;
}

.chat-empty {
    border: 1px dashed #d9d2c4;
    border-radius: 14px;
    padding: 1rem;
    background: #fffdf8;
    color: #6b7280;
    text-align: center;
}

.chat-attachment-link {
    display: inline-flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-top: 0.7rem;
    color: inherit;
    text-decoration: none;
}

.chat-attachment-link:hover {
    color: inherit;
    text-decoration: none;
}

.chat-attachment-image {
    width: 220px;
    max-width: 100%;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.08);
    object-fit: cover;
}

.message-fab {
    position: fixed;
    right: 1.35rem;
    bottom: 1.35rem;
    z-index: 1050;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.85rem 1rem;
    border-radius: 999px;
    box-shadow: 0 16px 30px rgba(31, 51, 32, 0.2);
}

.message-fab-badge,
.message-inline-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 0.45rem;
    border-radius: 999px;
    background: #ffffff;
    color: var(--brand-secondary);
    font-size: 0.75rem;
    font-weight: 700;
}

.message-inline-badge {
    min-width: 20px;
    height: 20px;
    background: rgba(216, 54, 58, 0.1);
}

.message-fab-thread-picks {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.message-fab-pick {
    border-radius: 999px;
}

.portal-notification-item.tone-secondary {
    background: #f8fafc;
    border-color: #dbe3ec;
}

.v2-dashboard {
    padding-bottom: 1rem;
}

.v2-dashboard-hero {
    background: linear-gradient(135deg, var(--brand-accent) 0%, #4c6f31 52%, var(--brand-primary) 100%);
    border-radius: 22px;
    color: #fff;
    padding: 2rem;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    align-items: flex-end;
    box-shadow: 0 18px 36px rgba(31, 51, 32, 0.18);
}

.v2-dashboard-kicker {
    margin-bottom: 0.55rem;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    opacity: 0.82;
}

.v2-dashboard-title {
    margin: 0;
    font-size: 2rem;
    font-weight: 700;
}

.v2-dashboard-copy {
    margin: 0.7rem 0 0;
    max-width: 620px;
    color: rgba(255, 255, 255, 0.88);
}

.v2-dashboard-hero-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.v2-dashboard-btn {
    border-radius: 999px;
    padding: 0.65rem 1rem;
    font-weight: 600;
}

.v2-metric-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.v2-metric-card {
    border-radius: 18px;
    padding: 1.2rem 1.25rem;
    color: #fff;
    box-shadow: 0 14px 26px rgba(17, 24, 39, 0.08);
}

.tone-forest {
    background: linear-gradient(135deg, #1b3526, #3f6b4a);
}

.tone-ember {
    background: linear-gradient(135deg, #8e2d1a, #dd6437);
}

.tone-gold {
    background: linear-gradient(135deg, #b7830b, #e5be58);
}

.tone-slate {
    background: linear-gradient(135deg, #32404d, #627485);
}

.tone-olive {
    background: linear-gradient(135deg, #56692c, #8aa04d);
}

.tone-clay {
    background: linear-gradient(135deg, #7d4639, #b96d56);
}

.v2-metric-label {
    font-size: 0.88rem;
    opacity: 0.9;
    margin-bottom: 0.45rem;
}

.v2-metric-value {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1.1;
}

.v2-metric-note {
    margin-top: 0.55rem;
    font-size: 0.84rem;
    color: rgba(255, 255, 255, 0.82);
}

.v2-panel-card {
    border: 1px solid #ece8df;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 12px 28px rgba(17, 24, 39, 0.06);
}

.v2-panel-header {
    background: #fff;
    border-bottom: 1px solid #f1ede5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
}

.v2-panel-header h3 {
    margin: 0;
    font-size: 1.12rem;
    font-weight: 700;
    color: #223326;
}

.v2-panel-header p {
    margin: 0.3rem 0 0;
    color: #6b7280;
    font-size: 0.92rem;
}

.v2-panel-card .card-body {
    padding: 1.25rem;
}

.v2-inline-link {
    color: #4c6f31;
    font-weight: 600;
    white-space: nowrap;
}

.v2-inline-link:hover {
    color: #355020;
    text-decoration: none;
}

.v2-table thead th {
    border-top: 0;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #667085;
}

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    margin-bottom: 0.8rem;
    color: #5f6b63;
    font-size: 0.92rem;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    margin-top: 0.8rem;
    color: #6b7280 !important;
    font-size: 0.92rem;
}

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border: 1px solid #d8dce3;
    border-radius: 8px;
    padding: 0.35rem 0.55rem;
    background: #fff;
}

.dataTables_wrapper .dataTables_filter input:focus,
.dataTables_wrapper .dataTables_length select:focus {
    outline: none;
    border-color: #d88939;
    box-shadow: 0 0 0 0.18rem rgba(216, 137, 57, 0.16);
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: 10px !important;
    border: 1px solid #ece3cf !important;
    background: #fffdf8 !important;
    color: #6b5a31 !important;
    margin-left: 0.3rem;
    min-width: 2.2rem;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    border-color: #dabb72 !important;
    background: linear-gradient(135deg, #fff8ef 0%, #f7efdf 55%, #efe1bf 100%) !important;
    color: #4f3d16 !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    border-color: #1f3320 !important;
    background: linear-gradient(135deg, #1f3320 0%, #4c6f31 100%) !important;
    color: #fff !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
    opacity: 0.55;
    cursor: not-allowed !important;
    background: #f8fafc !important;
    color: #98a2b3 !important;
}

.dataTables_wrapper .dataTables_filter label,
.dataTables_wrapper .dataTables_length label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.dataTables_wrapper .dataTables_processing {
    border: 1px solid #ece3cf;
    border-radius: 14px;
    background: #fffdf8;
    color: #223326;
    box-shadow: 0 12px 24px rgba(17, 24, 39, 0.08);
}

.dataTables_wrapper .dataTables_filter {
    text-align: right;
}

.dataTables_wrapper .dataTables_length {
    text-align: left;
}

.v2-quick-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
}

.v2-quick-grid-wide {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.v2-quick-card {
    border: 1px solid #ece8df;
    border-radius: 16px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    color: #223326;
    background: linear-gradient(180deg, #fffdf8 0%, #f8f5ee 100%);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.v2-quick-card:hover {
    text-decoration: none;
    color: #223326;
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(76, 111, 49, 0.12);
}

.v2-quick-card i {
    font-size: 1.2rem;
    color: #4c6f31;
}

.v2-quick-card span {
    font-weight: 600;
    font-size: 1rem;
}

.v2-member-list {
    display: grid;
    gap: 0.85rem;
}

.v2-member-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.95rem 1rem;
    border: 1px solid #ece8df;
    border-radius: 14px;
    background: linear-gradient(180deg, #fffdf8 0%, #f8f5ee 100%);
}

.v2-member-main {
    min-width: 0;
    flex: 1 1 auto;
}

.v2-member-rank {
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    background: #efe1bf;
    color: #6b5a31;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.v2-member-main strong {
    display: block;
    font-size: 0.95rem;
    line-height: 1.2;
    margin-bottom: 0.18rem;
}

.v2-member-email {
    color: #6b7280;
    font-size: 0.78rem;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.v2-member-row span {
    display: inline-block;
    font-weight: 700;
    color: #223326;
    font-size: 0.9rem;
    white-space: nowrap;
    text-align: right;
    flex-shrink: 0;
}

.v2-page {
    padding-bottom: 1rem;
}

.v2-page-hero {
    background: linear-gradient(135deg, #fff8ef 0%, #f7efdf 55%, #efe1bf 100%);
    border: 1px solid #ece3cf;
    border-radius: 22px;
    padding: 1.6rem 1.75rem;
    margin-bottom: 1.2rem;
}

.v2-page-kicker {
    margin-bottom: 0.45rem;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: #8b6a18;
}

.v2-page-title {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
    color: #223326;
}

.v2-page-copy {
    margin: 0.6rem 0 0;
    color: #5f6b63;
    max-width: 620px;
}

.v2-page-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.2rem;
}

.v2-mini-stat {
    background: #ffffff;
    border: 1px solid #ece8df;
    border-radius: 16px;
    padding: 1rem 1.1rem;
    box-shadow: 0 10px 20px rgba(17, 24, 39, 0.05);
}

.v2-mini-stat span {
    display: block;
    color: #6b7280;
    font-size: 0.88rem;
    margin-bottom: 0.35rem;
}

.v2-mini-stat strong {
    color: #223326;
    font-size: 1.35rem;
}

.v2-inline-form {
    display: grid;
    grid-template-columns: minmax(180px, 220px) auto auto;
    gap: 0.75rem;
    align-items: center;
}

.v2-inline-form-compact {
    grid-template-columns: minmax(160px, 220px) auto;
}

.v2-checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0;
    color: #4b5563;
    font-size: 0.92rem;
}

.v2-staff-role-form select {
    min-width: 170px;
}

.v2-staff-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.v2-modal-card {
    border: 1px solid #ece8df;
    border-radius: 18px;
    overflow: hidden;
}

.v2-modal-card .modal-header,
.v2-modal-card .modal-footer {
    border-color: #f1ede5;
}

.v2-loan-product-modal {
    max-width: 1360px;
}

.loan-products-table {
    table-layout: fixed;
    width: 100%;
}

.loan-products-table colgroup col:nth-child(1) { width: 23%; }
.loan-products-table colgroup col:nth-child(2) { width: 13%; }
.loan-products-table colgroup col:nth-child(3) { width: 14%; }
.loan-products-table colgroup col:nth-child(4) { width: 8%; }
.loan-products-table colgroup col:nth-child(5) { width: 8%; }
.loan-products-table colgroup col:nth-child(6) { width: 13%; }
.loan-products-table colgroup col:nth-child(7) { width: 13%; }
.loan-products-table colgroup col:nth-child(8) { width: 8%; }

.loan-products-table th,
.loan-products-table td {
    vertical-align: middle;
    font-size: 0.94rem;
}

.loan-products-table th {
    white-space: nowrap;
}

.loan-products-name {
    font-weight: 600;
    white-space: normal;
    overflow-wrap: anywhere;
}

.loan-products-number {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.loan-products-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.28rem 0.7rem;
    border-radius: 999px;
    background: rgba(187, 76, 41, 0.12);
    color: #8d3117;
    font-size: 0.82rem;
    font-weight: 700;
    white-space: normal;
    line-height: 1.2;
    text-align: center;
}

.loan-products-method-col,
.loan-products-method-cell {
    min-width: 130px;
}

@media (max-width: 1200px) {
    .loan-products-table th,
    .loan-products-table td {
        font-size: 0.88rem;
    }
}

.v2-modal-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem 1rem;
}

.v2-section-nav {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.2rem;
}

.v2-section-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.7rem 1rem;
    border: 1px solid #ece3cf;
    border-radius: 999px;
    background: #fffdf8;
    color: #6b5a31;
    font-weight: 600;
}

.v2-section-pill:hover {
    color: #4f3d16;
    text-decoration: none;
    border-color: #dabb72;
}

.v2-section-pill.is-active {
    background: linear-gradient(135deg, #1f3320 0%, #4c6f31 100%);
    border-color: #1f3320;
    color: #fff;
}

.portal-mpesa-planner {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.9rem;
}

.portal-mpesa-summary-card {
    border: 1px solid #ece3cf;
    border-radius: 16px;
    padding: 0.95rem 1rem;
    background: linear-gradient(180deg, #fffdf9 0%, #f8f4ea 100%);
}

.portal-mpesa-summary-card span {
    display: block;
    font-size: 0.82rem;
    color: #81693a;
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.portal-mpesa-summary-card strong {
    display: block;
    font-size: 1.15rem;
    color: #223326;
    margin-bottom: 0.25rem;
}

.portal-mpesa-summary-card small {
    display: block;
    line-height: 1.35;
}

.portal-mpesa-loan-section {
    padding-top: 0.3rem;
    border-top: 1px dashed #eadfc8;
    margin-top: 0.85rem;
}

.portal-mpesa-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.9rem;
}

.portal-mpesa-callout {
    margin-top: 1rem;
    padding: 0.9rem 1rem;
    border-radius: 16px;
    background: #f6f4eb;
    color: #5c5230;
}

.dashboard-chart-shell {
    position: relative;
    min-height: 320px;
}

.dashboard-chart-shell-donut {
    min-height: 360px;
}

@media (max-width: 991px) {
    .v2-dashboard-hero,
    .v2-panel-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .v2-metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .portal-stats-compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }

    .v2-page-stats {
        grid-template-columns: 1fr;
    }

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

    .v2-inline-form {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .v2-modal-checkbox-grid {
        grid-template-columns: 1fr;
    }

    .portal-mpesa-planner {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

}

@media (max-width: 767px) {
    .v2-dashboard-hero {
        padding: 1.4rem;
    }

    .v2-dashboard-title {
        font-size: 1.55rem;
    }

    .v2-metric-grid,
    .portal-stats-compact,
    .v2-quick-grid,
    .v2-quick-grid-wide {
        grid-template-columns: 1fr;
    }

    .message-fab {
        right: 1rem;
        bottom: 1rem;
    }

    .portal-mpesa-planner {
        grid-template-columns: 1fr;
    }
}
