/* Microfinance layout layer built on top of the imported Zenith design system. */
:root {
    --mf-sidebar-width: 260px;
    --mf-topbar-height: 64px;
}

html {
    scroll-behavior: smooth;
}
body {
    min-width: 320px;
}
button,
a {
    -webkit-tap-highlight-color: transparent;
}

.mf-shell {
    min-height: 100vh;
    background: var(--background);
}
.mf-sidebar {
    width: var(--mf-sidebar-width);
}
.mf-content {
    min-width: 0;
    transition: margin 0.2s ease;
}
.mf-topbar {
    min-height: var(--mf-topbar-height);
}
.mf-page {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px;
}
.mf-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.025);
}
.mf-card-header {
    padding: 18px 20px 0;
}
.mf-card-body {
    padding: 20px;
}
.mf-card-title {
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--card-foreground);
}
.mf-card-subtitle {
    margin-top: 3px;
    font-size: 0.75rem;
    color: var(--muted-foreground);
}
.mf-kpi-value {
    margin-top: 16px;
    font-size: 1.75rem;
    line-height: 2rem;
    font-weight: 650;
    letter-spacing: -0.035em;
    color: var(--foreground);
}
.mf-kpi-meta {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.75rem;
    color: var(--muted-foreground);
}
.mf-icon-box {
    display: inline-flex;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border-radius: calc(var(--radius) - 2px);
    background: var(--muted);
    color: var(--foreground);
}
.mf-icon-box svg {
    width: 17px;
    height: 17px;
}
.mf-icon-box.primary {
    background: color-mix(in oklab, var(--primary) 8%, transparent);
    color: var(--primary);
}
.mf-icon-box.success {
    background: color-mix(in oklab, var(--success) 10%, transparent);
    color: var(--success);
}
.mf-icon-box.warning {
    background: color-mix(in oklab, var(--warning) 13%, transparent);
    color: color-mix(in oklab, var(--warning) 72%, var(--foreground));
}
.mf-icon-box.danger {
    background: color-mix(in oklab, var(--destructive) 9%, transparent);
    color: var(--destructive);
}

.mf-nav-label {
    padding: 6px 12px;
    font-size: 10px;
    font-weight: 650;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    color: color-mix(in oklab, var(--sidebar-foreground) 34%, transparent);
}
.mf-nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 38px;
    margin: 2px 0;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    color: color-mix(in oklab, var(--sidebar-foreground) 68%, transparent);
    transition:
        background 0.15s ease,
        color 0.15s ease;
}
.mf-nav-item svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    color: color-mix(in oklab, var(--sidebar-foreground) 48%, transparent);
}
.mf-nav-item:hover {
    background: color-mix(in oklab, var(--sidebar-accent) 58%, transparent);
    color: var(--sidebar-foreground);
}
.mf-nav-item:hover svg {
    color: var(--sidebar-foreground);
}
.mf-nav-item.is-active {
    background: var(--sidebar-accent);
    color: var(--sidebar-primary);
}
.mf-nav-item.is-active svg {
    color: var(--sidebar-primary);
}
.mf-nav-count {
    margin-inline-start: auto;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--muted);
    font-size: 10px;
    color: var(--muted-foreground);
}

.mf-btn {
    display: inline-flex;
    height: 36px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 13px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    background: var(--background);
    font-size: 0.8125rem;
    font-weight: 550;
    color: var(--foreground);
    transition:
        background 0.15s ease,
        border-color 0.15s ease,
        transform 0.15s ease;
}
.mf-btn:hover {
    background: var(--muted);
}
.mf-btn:active {
    transform: scale(0.98);
}
.mf-btn svg {
    width: 16px;
    height: 16px;
}
.mf-btn-primary {
    border-color: var(--primary);
    background: var(--primary);
    color: var(--primary-foreground);
}
.mf-btn-primary:hover {
    background: color-mix(in oklab, var(--primary) 90%, var(--background));
}
.mf-icon-btn {
    width: 36px;
    padding: 0;
}

.mf-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 550;
    white-space: nowrap;
}
.mf-badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: currentColor;
    opacity: 0.72;
}
.mf-badge-success {
    background: color-mix(in oklab, var(--success) 10%, transparent);
    color: var(--success);
}
.mf-badge-warning {
    background: color-mix(in oklab, var(--warning) 12%, transparent);
    color: color-mix(in oklab, var(--warning) 68%, var(--foreground));
}
.mf-badge-danger {
    background: color-mix(in oklab, var(--destructive) 9%, transparent);
    color: var(--destructive);
}
.mf-badge-muted {
    background: var(--muted);
    color: var(--muted-foreground);
}

.mf-stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}
.mf-dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.75fr);
    gap: 14px;
}
.mf-split-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

/* Dashboard filters: balanced desktop columns, aligned controls, and a proper period select. */
form.mf-dashboard-grid {
    grid-template-columns: minmax(0, 1.9fr) minmax(320px, 1fr);
    gap: 16px;
    align-items: start;
}
form.mf-dashboard-grid > div:first-child > .mf-split-grid {
    grid-template-columns: minmax(170px, 0.7fr) minmax(360px, 1.3fr);
    gap: 12px;
    align-items: end;
}
form.mf-dashboard-grid > div:first-child > .mf-split-grid > div:last-child {
    gap: 12px;
}
form.mf-dashboard-grid .mf-label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.75rem;
    line-height: 1rem;
    font-weight: 550;
    color: var(--foreground);
}
form.mf-dashboard-grid .mf-select {
    width: 100%;
    height: 40px;
    border: 1px solid var(--input);
    border-radius: calc(var(--radius) - 2px);
    background: var(--background);
    padding: 0 36px 0 12px;
    font-size: 0.875rem;
    color: var(--foreground);
    outline: none;
    line-height: 2.8;
}
form.mf-dashboard-grid .mf-select:focus {
    border-color: var(--ring);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 18%, transparent);
}
form.mf-dashboard-grid > div:last-child {
    min-width: 0;
}
form.mf-dashboard-grid > div:last-child > div:nth-child(2) {
    min-height: 40px;
}
form.mf-dashboard-grid > div:last-child > .mf-btn {
    height: 40px;
    margin-top: 8px;
}

.mf-table-wrap {
    overflow-x: auto;
}
.mf-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}
.mf-table th {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in oklab, var(--muted) 42%, transparent);
    color: var(--muted-foreground);
    font-size: 10px;
    font-weight: 650;
    text-align: left;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}
.mf-table td {
    padding: 12px 16px;
    border-bottom: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
    color: var(--foreground);
    vertical-align: middle;
    white-space: nowrap;
}
.mf-table tr:last-child td {
    border-bottom: 0;
}
.mf-table tbody tr:hover {
    background: color-mix(in oklab, var(--muted) 28%, transparent);
}

.mf-chart {
    height: 240px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding-top: 18px;
}
.mf-chart-col {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.mf-chart-bar-wrap {
    width: 100%;
    height: 190px;
    display: flex;
    align-items: flex-end;
}
.mf-chart-bar {
    width: 100%;
    min-height: 8px;
    border-radius: 4px 4px 2px 2px;
    background: color-mix(in oklab, var(--primary) 82%, var(--background));
    opacity: 0.9;
    transition: opacity 0.15s ease;
}
.mf-chart-bar:hover {
    opacity: 1;
}
.mf-chart-label {
    font-size: 10px;
    color: var(--muted-foreground);
}

.mf-progress {
    height: 7px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--muted);
}
.mf-progress > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
}
.mf-progress.success > span {
    background: var(--success);
}
.mf-progress.warning > span {
    background: var(--warning);
}

.mf-activity {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
}
.mf-activity:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}
.mf-activity:first-child {
    padding-top: 0;
}
.mf-activity-dot {
    margin-top: 5px;
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 999px;
    background: var(--muted-foreground);
    box-shadow: 0 0 0 4px color-mix(in oklab, var(--muted) 65%, transparent);
}

.mf-mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgb(0 0 0 / 0.42);
    backdrop-filter: blur(2px);
}
.mf-mobile-drawer {
    position: fixed;
    inset-block: 0;
    left: 0;
    z-index: 50;
    width: min(86vw, 290px);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
}
.mf-mobile-drawer.is-open {
    transform: translateX(0);
}
.mf-mobile-overlay.is-open {
    display: block;
}

/* Authentication */
.mf-auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(360px, 44%) 1fr;
    background: var(--background);
}
.mf-auth-brand-panel {
    position: relative;
    overflow: hidden;
    border-inline-end: 1px solid var(--border);
    background: color-mix(in oklab, var(--muted) 36%, var(--background));
}
.mf-auth-brand-panel::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        radial-gradient(
            circle at 20% 18%,
            color-mix(in oklab, var(--primary) 8%, transparent),
            transparent 32%
        ),
        linear-gradient(
            color-mix(in oklab, var(--border) 35%, transparent) 1px,
            transparent 1px
        ),
        linear-gradient(
            90deg,
            color-mix(in oklab, var(--border) 35%, transparent) 1px,
            transparent 1px
        );
    background-size:
        auto,
        44px 44px,
        44px 44px;
    mask-image: linear-gradient(to bottom, black, transparent 86%);
}
.mf-auth-brand-inner {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    padding: 32px;
    display: flex;
    flex-direction: column;
}
.mf-auth-brand-copy {
    margin: auto 0;
    max-width: 520px;
}
.mf-auth-brand-copy h1 {
    margin-top: 18px;
    max-width: 500px;
    font-size: clamp(2rem, 4vw, 3.75rem);
    line-height: 1.02;
    font-weight: 620;
    letter-spacing: -0.055em;
    color: var(--foreground);
}
.mf-auth-brand-copy p {
    margin-top: 20px;
    max-width: 480px;
    font-size: 0.925rem;
    line-height: 1.75;
    color: var(--muted-foreground);
}
.mf-auth-brand-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--muted-foreground);
}
.mf-auth-main {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}
.mf-auth-form-wrap {
    width: 100%;
    max-width: 410px;
}
.mf-auth-theme {
    position: absolute;
    top: 24px;
    right: 24px;
}
.mf-field-label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--foreground);
}
.mf-input {
    width: 100%;
    height: 36px;
    border: 1px solid var(--input);
    border-radius: calc(var(--radius) - 2px);
    background: var(--background);
    padding: 0 12px;
    font-size: 0.875rem;
    color: var(--foreground);
    outline: none;
    line-height: 2.7;
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
        
}
.mf-input::placeholder {
    color: var(--muted-foreground);
    opacity: 0.7;
}
.mf-input:focus {
    border-color: var(--ring);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 18%, transparent);
}
.mf-input.is-invalid {
    border-color: var(--destructive);
}
.mf-input.is-invalid:focus {
    box-shadow: 0 0 0 3px
        color-mix(in oklab, var(--destructive) 15%, transparent);
}
.mf-field-error {
    margin-top: 6px;
    font-size: 0.75rem;
    color: var(--destructive);
}
.mf-checkbox {
    width: 15px;
    height: 15px;
    accent-color: var(--primary);
}
.mf-user-menu > summary::-webkit-details-marker {
    display: none;
}
.mf-user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 60;
    width: 210px;
    display: none;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--popover);
    box-shadow: 0 12px 30px rgb(0 0 0 / 0.12);
    color: var(--popover-foreground);
}
.mf-user-menu[open] .mf-user-dropdown {
    display: block;
}
.mf-user-dropdown-item {
    width: 100%;
    min-height: 34px;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 9px;
    border-radius: calc(var(--radius) - 3px);
    font-size: 0.8125rem;
    color: var(--foreground);
    transition: background 0.15s ease;
}
.mf-user-dropdown-item:hover {
    background: var(--muted);
}
.mf-user-dropdown-item svg {
    width: 15px;
    height: 15px;
    color: var(--muted-foreground);
}

@media (min-width: 1024px) {
    .mf-content {
        margin-inline-start: var(--mf-sidebar-width);
    }
}
@media (max-width: 1100px) {
    .mf-stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .mf-dashboard-grid {
        grid-template-columns: 1fr;
    }
    form.mf-dashboard-grid {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 860px) {
    .mf-auth-shell {
        grid-template-columns: 1fr;
    }
    .mf-auth-brand-panel {
        display: none;
    }
    .mf-auth-main {
        padding: 72px 22px 32px;
        align-items: flex-start;
    }
    .mf-auth-form-wrap {
        margin-top: 7vh;
    }
}
@media (max-width: 720px) {
    .mf-page {
        padding: 16px;
    }
    .mf-stat-grid,
    .mf-split-grid {
        grid-template-columns: 1fr;
    }
    form.mf-dashboard-grid > div:first-child > .mf-split-grid,
    form.mf-dashboard-grid > div:first-child > .mf-split-grid > div:last-child {
        grid-template-columns: 1fr;
    }
    .mf-card-header {
        padding: 16px 16px 0;
    }
    .mf-card-body {
        padding: 16px;
    }
    .mf-chart {
        gap: 5px;
    }
}
