.mf-extract {
    max-width: 1200px;
}

.mf-extract__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--mf-space-4);
    margin-bottom: var(--mf-space-6);
    flex-wrap: wrap;
}

.mf-extract__title {
    font-size: 24px;
    font-weight: 600;
    color: var(--mf-text);
    margin: 0;
}

.mf-extract__subtitle {
    color: var(--mf-text-muted);
    font-size: 14px;
    margin: var(--mf-space-1) 0 0 0;
    max-width: 640px;
}

/* ---------- Controls card ---------- */
.mf-extract__controls-card {
    margin-bottom: var(--mf-space-5);
}

.mf-extract__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--mf-space-4);
}

.mf-extract__custom-range {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--mf-space-3);
    margin-top: var(--mf-space-4);
    padding-top: var(--mf-space-4);
    border-top: 1px dashed var(--mf-border);
}

.mf-extract__status {
    flex: 1;
    font-size: 13px;
    color: var(--mf-text-muted);
    text-align: left;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mf-extract__controls-card .mf-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--mf-space-3);
    flex-wrap: wrap;
}

/* On mobile, the buttons drop to a new row below the status text */
@media (max-width: 575.98px) {
    .mf-extract__controls-card .mf-card__footer .mf-btn {
        flex: 1;
    }
}

/* ---------- Live progress bar ---------- */
.mf-progress {
    margin-bottom: var(--mf-space-5);
}

.mf-progress__bar {
    height: 8px;
    background: var(--mf-surface-2);
    border-radius: var(--mf-radius-full);
    overflow: hidden;
}

.mf-progress__bar > span {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--mf-primary), var(--mf-primary-hover));
    border-radius: var(--mf-radius-full);
    transition: width 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

.mf-progress__bar > span.mf-progress--indeterminate {
    width: 30% !important;
    animation: mf-indeterminate 1.6s ease-in-out infinite;
}

.mf-progress__fill--cancelled {
    background: linear-gradient(90deg, var(--mf-warning), #D97706);
}

@keyframes mf-indeterminate {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

.mf-progress__label {
    margin-top: var(--mf-space-2);
    font-size: 13px;
    color: var(--mf-text-muted);
    display: flex;
    justify-content: space-between;
    gap: var(--mf-space-3);
}

/* ---------- Summary stats ---------- */
.mf-extract__summary {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--mf-space-3);
    margin-bottom: var(--mf-space-5);
}

.mf-extract__stat {
    background: var(--mf-surface);
    border: 1px solid var(--mf-border);
    border-radius: var(--mf-radius-lg);
    padding: var(--mf-space-4);
}

.mf-extract__stat-label {
    font-size: 12px;
    color: var(--mf-text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 var(--mf-space-2) 0;
}

.mf-extract__stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--mf-text);
    margin: 0;
    line-height: 1.1;
}

/* ---------- Toolbar (tabs + filter + view + export) ---------- */
.mf-extract__toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--mf-space-3);
    margin-bottom: var(--mf-space-4);
    flex-wrap: wrap;
}

.mf-extract__tabs {
    display: flex;
    background: var(--mf-surface);
    border: 1px solid var(--mf-border);
    border-radius: var(--mf-radius);
    padding: 4px;
    gap: 4px;
}

.mf-extract__tab {
    display: inline-flex;
    align-items: center;
    gap: var(--mf-space-2);
    padding: 6px var(--mf-space-3);
    background: transparent;
    border: 0;
    color: var(--mf-text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--mf-radius-sm);
    font-family: inherit;
    transition: background-color var(--mf-transition), color var(--mf-transition);
}

.mf-extract__tab:hover { color: var(--mf-text); }

.mf-extract__tab--active {
    background: var(--mf-bg);
    color: var(--mf-text);
    box-shadow: var(--mf-shadow-sm);
}

.mf-extract__tab-count {
    background: var(--mf-surface-2);
    color: var(--mf-text-muted);
    padding: 1px 6px;
    border-radius: var(--mf-radius-full);
    font-size: 11px;
    font-weight: 600;
}

.mf-extract__tab--active .mf-extract__tab-count {
    background: var(--mf-primary-subtle);
    color: var(--mf-primary);
}

.mf-extract__toolbar-actions {
    display: flex;
    align-items: center;
    gap: var(--mf-space-2);
    flex-wrap: wrap;
}

.mf-extract__filter {
    width: 240px;
}

.mf-extract__system-toggle {
    font-size: 13px;
}

.mf-extract__view-select {
    width: auto;
    min-width: 140px;
    height: 36px;
}

/* ---------- Results tables ---------- */
.mf-extract__group {
    background: var(--mf-surface);
    border: 1px solid var(--mf-border);
    border-radius: var(--mf-radius-lg);
    margin-bottom: var(--mf-space-5);
    overflow: hidden;
}

.mf-extract__group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--mf-space-3);
    padding: var(--mf-space-4) var(--mf-space-5);
    border-bottom: 1px solid var(--mf-border);
    background: var(--mf-bg);
}

.mf-extract__group-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--mf-text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--mf-space-2);
}

.mf-extract__count {
    color: var(--mf-text-muted);
    font-weight: 500;
    font-size: 13px;
}

.mf-extract__table-wrap {
    overflow-x: auto;
}

.mf-extract__table {
    width: 100%;
    border-collapse: collapse;
}

.mf-extract__table thead th {
    padding: var(--mf-space-3) var(--mf-space-5);
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    color: var(--mf-text-muted);
    background: var(--mf-surface);
    border-bottom: 1px solid var(--mf-border);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.mf-extract__table thead th:hover { color: var(--mf-text); }

.mf-extract__table thead th[aria-sort="ascending"]::after  { content: ' ▲'; color: var(--mf-primary); }
.mf-extract__table thead th[aria-sort="descending"]::after { content: ' ▼'; color: var(--mf-primary); }

.mf-extract__col-check { width: 44px; padding-right: 0; cursor: default; }
.mf-extract__col-count { width: 100px; text-align: right; }
.mf-extract__col-sources { width: 260px; }

.mf-extract__table tbody td {
    padding: var(--mf-space-3) var(--mf-space-5);
    font-size: 14px;
    color: var(--mf-text);
    border-bottom: 1px solid var(--mf-border);
    vertical-align: middle;
}

.mf-extract__table tbody tr:last-child td { border-bottom: 0; }
.mf-extract__table tbody tr:hover { background: var(--mf-surface-2); }
.mf-extract__table tbody tr.mf-row--checked { background: var(--mf-primary-subtle); }

.mf-extract__col-value {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: var(--mf-space-2);
    flex-wrap: wrap;
}

.mf-extract__col-count-cell {
    text-align: right;
    color: var(--mf-text-muted);
    font-variant-numeric: tabular-nums;
}

.mf-extract__col-check-cell {
    width: 44px;
    padding-right: 0;
}

.mf-extract__col-check-cell input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--mf-primary);
    cursor: pointer;
}

.mf-extract__copy {
    background: transparent;
    border: 0;
    color: var(--mf-text-subtle);
    cursor: pointer;
    padding: 2px;
    border-radius: var(--mf-radius-sm);
    margin-left: auto;
    opacity: 0;
    transition: opacity var(--mf-transition);
}

.mf-extract__table tr:hover .mf-extract__copy {
    opacity: 1;
}

.mf-extract__copy:hover {
    color: var(--mf-primary);
    background: var(--mf-primary-subtle);
}

/* Source pills */
.mf-extract__source-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.mf-source-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 500;
    background: var(--mf-surface-2);
    border-radius: var(--mf-radius-full);
    color: var(--mf-text-muted);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mf-source-pill::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: var(--mf-radius-full);
    background: currentColor;
    opacity: 0.7;
    flex: 0 0 6px;
}

.mf-source-pill--c0 { background: #EEF2FF; color: #4F46E5; }
.mf-source-pill--c1 { background: #ECFDF5; color: #047857; }
.mf-source-pill--c2 { background: #FEF3C7; color: #B45309; }
.mf-source-pill--c3 { background: #FEE2E2; color: #B91C1C; }
.mf-source-pill--c4 { background: #DBEAFE; color: #1D4ED8; }
.mf-source-pill--c5 { background: #F3E8FF; color: #7E22CE; }

[data-bs-theme="dark"] .mf-source-pill--c0 { background: #1E1B4B; color: #A5B4FC; }
[data-bs-theme="dark"] .mf-source-pill--c1 { background: #064E3B; color: #6EE7B7; }
[data-bs-theme="dark"] .mf-source-pill--c2 { background: #78350F; color: #FCD34D; }
[data-bs-theme="dark"] .mf-source-pill--c3 { background: #7F1D1D; color: #FCA5A5; }
[data-bs-theme="dark"] .mf-source-pill--c4 { background: #1E3A8A; color: #93C5FD; }
[data-bs-theme="dark"] .mf-source-pill--c5 { background: #581C87; color: #D8B4FE; }

/* ---------- Per-account view ---------- */
.mf-extract__account-card {
    background: var(--mf-surface);
    border: 1px solid var(--mf-border);
    border-radius: var(--mf-radius-lg);
    margin-bottom: var(--mf-space-4);
    overflow: hidden;
}

.mf-extract__account-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--mf-space-3);
    padding: var(--mf-space-3) var(--mf-space-5);
    border-bottom: 1px solid var(--mf-border);
}

.mf-extract__account-meta {
    color: var(--mf-text-muted);
    font-size: 12px;
    margin-top: 2px;
}

/* Empty + loading states */
.mf-extract__empty {
    padding: var(--mf-space-7);
    text-align: center;
    color: var(--mf-text-muted);
    font-size: 13px;
    margin: 0;
}

.mf-extract__progress-empty {
    text-align: center;
    padding: var(--mf-space-9);
    color: var(--mf-text-muted);
}

.mf-extract__progress-empty .mf-spinner {
    margin-bottom: var(--mf-space-4);
}

/* ---------- History dropdown ---------- */
.mf-extract__history {
    position: absolute;
    background: var(--mf-bg);
    border: 1px solid var(--mf-border);
    border-radius: var(--mf-radius-lg);
    box-shadow: var(--mf-shadow-lg);
    width: 360px;
    max-height: 400px;
    overflow-y: auto;
    padding: var(--mf-space-2);
    z-index: 1200;
    display: none;
}

.mf-extract__history--open { display: block; }

.mf-extract__history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--mf-space-2);
    padding: var(--mf-space-3);
    border-radius: var(--mf-radius);
    cursor: pointer;
    border: 0;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.mf-extract__history-item:hover { background: var(--mf-surface-2); }

.mf-extract__history-time {
    font-size: 12px;
    color: var(--mf-text-muted);
    margin-top: 2px;
}

.mf-extract__history-meta {
    font-size: 12px;
    color: var(--mf-text-subtle);
}

.mf-extract__history-empty {
    padding: var(--mf-space-5);
    text-align: center;
    color: var(--mf-text-muted);
    font-size: 13px;
}

.mf-extract__history-clear {
    width: 100%;
    margin-top: var(--mf-space-2);
}

/* ---------- Responsive ---------- */
@media (max-width: 767.98px) {
    .mf-extract__toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .mf-extract__tabs { width: 100%; }
    .mf-extract__tab { flex: 1; justify-content: center; }

    .mf-extract__toolbar-actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .mf-extract__filter,
    .mf-extract__view-select {
        width: 100%;
    }

    .mf-extract__col-sources { display: none; }
    .mf-extract__table thead th.mf-extract__col-sources,
    .mf-extract__table tbody td:nth-child(4) { display: none; }

    .mf-extract__custom-range {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 575.98px) {
    .mf-extract__grid {
        grid-template-columns: 1fr;
    }
}
