.hm-sorter {
    --hm-accent: #c2185b;
    --hm-accent-dark: #941246;
    --hm-text: #1f2328;
    --hm-muted: #5f6670;
    --hm-border: #cfd4da;
    --hm-soft: #f4f5f7;
    --hm-soft-strong: #e9ebef;
    --hm-good: #176b3a;
    --hm-good-bg: #e9f6ee;
    --hm-warn: #8a5a00;
    --hm-warn-bg: #fff6df;
    --hm-bad: #9d2a2a;
    --hm-bad-bg: #fff0f0;
    color: var(--hm-text);
    width: min(980px, 100%);
    margin: 22px auto 36px;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

.hm-sorter *,
.hm-sorter *::before,
.hm-sorter *::after { box-sizing: border-box; }

/* Hidden must always win over component display rules and theme CSS. */
.hm-sorter [hidden] {
    display: none !important;
}

.hm-sorter button,
.hm-sorter input { font: inherit; }

.hm-sorter[aria-busy="true"] { cursor: progress; }

.hm-sorter-heading { margin-bottom: 24px; }
.hm-sorter-kicker {
    display: block;
    margin-bottom: 7px;
    color: var(--hm-accent-dark);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.hm-sorter h2,
.hm-sorter h3 { color: var(--hm-text) !important; }
.hm-sorter h2 { margin: 0 0 9px; font-size: clamp(28px, 5vw, 42px); line-height: 1.1; }
.hm-sorter h3 { margin: 0 0 7px; font-size: 22px; line-height: 1.2; }
.hm-sorter p { margin: 0; }

.hm-sorter-choices {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}
.hm-sorter-choice {
    min-height: 190px;
    padding: 26px;
    border: 2px solid #b8bec6 !important;
    border-radius: 16px;
    background: #e6e8ec !important;
    color: #17191c !important;
    text-align: left;
    cursor: pointer;
    box-shadow: none;
}
.hm-sorter-choice:hover,
.hm-sorter-choice:focus-visible {
    border-color: var(--hm-accent) !important;
    background: #dde0e5 !important;
    outline: 3px solid rgba(194, 24, 91, .15);
    outline-offset: 2px;
}
.hm-sorter-choice strong {
    display: block;
    margin-bottom: 11px;
    color: #15171a !important;
    font-size: 23px;
    line-height: 1.2;
}
.hm-sorter-choice span {
    display: block;
    color: #333941 !important;
    font-size: 16px;
}

.hm-sorter-topbar {
    display: flex;
    gap: 16px;
    align-items: center;
    padding: 16px 0 22px;
    border-bottom: 1px solid var(--hm-border);
    margin-bottom: 24px;
}
.hm-sorter-back,
.hm-sorter-clear {
    border: 1px solid var(--hm-border) !important;
    background: #fff !important;
    color: var(--hm-text) !important;
    border-radius: 10px;
    padding: 10px 14px;
    cursor: pointer;
}
.hm-sorter-mode-title { display: block; font-size: 19px; }
.hm-sorter-mode-subtitle { display: block; color: var(--hm-muted); font-size: 14px; }

.hm-sorter-path { display: grid; gap: 16px; }
.hm-sorter-step {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 14px;
    padding: 20px;
    border: 1px solid var(--hm-border);
    border-radius: 14px;
    background: #fff;
}
.hm-sorter-step-number {
    display: flex;
    width: 38px;
    height: 38px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--hm-accent);
    color: #fff;
    font-weight: 800;
}
.hm-sorter-step-body > p { color: var(--hm-muted); margin-bottom: 16px; }

.hm-sorter-upload-button,
.hm-sorter-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 112px;
    padding: 18px;
    border: 2px dashed #aeb4bc;
    border-radius: 12px;
    background: var(--hm-soft);
    color: var(--hm-text) !important;
    text-align: center;
    cursor: pointer;
}
.hm-sorter-upload-button { min-height: 58px; flex-direction: row; font-weight: 750; }
.hm-sorter-dropzone strong { color: var(--hm-text) !important; font-size: 17px; }
.hm-sorter-dropzone span { color: var(--hm-muted); font-size: 14px; margin-top: 4px; }
.hm-sorter-upload-button:hover,
.hm-sorter-dropzone:hover,
.hm-sorter-dropzone.hm-dragover {
    border-color: var(--hm-accent);
    background: #f7eef2;
}
.hm-sorter-upload-button input,
.hm-sorter-dropzone input {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
}
.hm-sorter-file-label { margin-top: 10px; color: var(--hm-muted); font-size: 14px; }
.hm-sorter-small-status { margin-top: 8px; font-size: 14px; color: var(--hm-muted); }

.hm-sorter-run,
.hm-sorter-download {
    width: 100%;
    min-height: 58px;
    padding: 13px 18px;
    border: 2px solid var(--hm-accent) !important;
    border-radius: 12px;
    background: var(--hm-accent) !important;
    color: #fff !important;
    font-weight: 800;
    cursor: pointer;
}
.hm-sorter-run:hover,
.hm-sorter-download:hover { background: var(--hm-accent-dark) !important; border-color: var(--hm-accent-dark) !important; }
.hm-sorter-run:disabled,
.hm-sorter-download:disabled { opacity: .45; cursor: not-allowed; }

.hm-sorter-status {
    min-height: 24px;
    margin: 18px 0 0;
    color: var(--hm-muted);
    font-weight: 650;
}
.hm-sorter-status.hm-error { color: var(--hm-bad); }

.hm-sorter-results {
    margin-top: 26px;
    padding-top: 24px;
    border-top: 2px solid var(--hm-border);
}
.hm-sorter-results-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}
.hm-sorter-summary { color: var(--hm-muted); }
.hm-sorter-start-number-wrap { min-width: 180px; }
.hm-sorter-start-number-wrap span { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 700; color: var(--hm-muted); }
.hm-sorter-start-number {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--hm-border);
    border-radius: 9px;
    background: #fff;
    color: var(--hm-text);
}

.hm-result-section { margin: 22px 0 10px; }
.hm-result-section-title {
    margin: 0 0 9px;
    color: var(--hm-text);
    font-size: 15px;
    font-weight: 850;
    letter-spacing: .02em;
}
.hm-result-card {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr) auto;
    gap: 14px;
    align-items: start;
    padding: 14px;
    margin-bottom: 9px;
    border: 1px solid var(--hm-border);
    border-radius: 12px;
    background: #fff;
}
.hm-result-number {
    display: flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border-radius: 9px;
    background: var(--hm-soft-strong);
    font-weight: 850;
    font-size: 18px;
}
.hm-result-main { min-width: 0; }
.hm-result-title {
    margin-bottom: 3px;
    color: var(--hm-text);
    font-weight: 780;
    overflow-wrap: anywhere;
}
.hm-result-meta { color: var(--hm-muted); font-size: 14px; }
.hm-result-diagnostic {
    margin-top: 7px;
    color: var(--hm-text);
    font-size: 14px;
    font-weight: 720;
}
.hm-result-candidate {
    margin-top: 3px;
    color: var(--hm-muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}
.hm-result-files { display: grid; gap: 5px; margin-top: 8px; }
.hm-result-file {
    width: fit-content;
    max-width: 100%;
    padding: 0;
    border: 0 !important;
    background: transparent !important;
    color: var(--hm-accent-dark) !important;
    text-align: left;
    text-decoration: underline;
    overflow-wrap: anywhere;
    cursor: pointer;
}
.hm-result-side {
    display: grid;
    gap: 8px;
    justify-items: end;
}
.hm-result-remove {
    min-height: 32px;
    padding: 5px 10px !important;
    border: 1px solid #d7a9a9 !important;
    border-radius: 8px !important;
    background: #fff !important;
    color: #a51f1f !important;
    font-size: 12px !important;
    font-weight: 800 !important;
    line-height: 1.2 !important;
    cursor: pointer;
}
.hm-result-remove:hover,
.hm-result-remove:focus-visible {
    border-color: #a51f1f !important;
    background: #fff3f3 !important;
}
.hm-result-badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}
.hm-result-badge-certain { color: var(--hm-good); background: var(--hm-good-bg); }
.hm-result-badge-strong,
.hm-result-badge-possible { color: var(--hm-warn); background: var(--hm-warn-bg); }
.hm-result-badge-unmatched { color: var(--hm-bad); background: var(--hm-bad-bg); }

.hm-sorter-unmatched-transactions {
    margin-top: 18px;
    padding: 14px 16px;
    border: 1px solid #e2c97c;
    border-radius: 12px;
    background: #fff9e9;
}
.hm-sorter-unmatched-transactions strong { display: block; margin-bottom: 6px; }
.hm-sorter-unmatched-transactions ul { margin: 0; padding-left: 20px; }

.hm-sorter-result-actions { display: grid; gap: 10px; margin-top: 22px; }
.hm-sorter-privacy-note { margin-top: 24px !important; color: var(--hm-muted); font-size: 13px; }

@media (max-width: 700px) {
    .hm-sorter-choices { grid-template-columns: 1fr; }
    .hm-sorter-choice { min-height: 150px; }
    .hm-sorter-step { grid-template-columns: 36px minmax(0, 1fr); padding: 16px; }
    .hm-sorter-step-number { width: 32px; height: 32px; }
    .hm-sorter-results-head { align-items: stretch; flex-direction: column; }
    .hm-sorter-start-number-wrap { width: 100%; }
    .hm-result-card { grid-template-columns: 52px minmax(0, 1fr); }
    .hm-result-side { grid-column: 2; justify-items: start; }
}
