:root {
    color-scheme: light;
    --bg: #f5f6f7;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #68717b;
    --line: #dce1e5;
    --line-dark: #c8ced4;
    --primary: #146c5a;
    --primary-dark: #0d5143;
    --primary-soft: #e6f3ef;
    --success: #157347;
    --success-soft: #e8f5ee;
    --danger: #b42318;
    --danger-soft: #fcebea;
    --warning: #9a6700;
    --warning-soft: #fff4d6;
    --focus: #1677c8;
    --shadow: 0 12px 32px rgba(22, 32, 42, .1);
    font-family: Inter, "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
    font-size: 15px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.hidden { display: none !important; }

:focus-visible {
    outline: 3px solid rgba(22, 119, 200, .28);
    outline-offset: 2px;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #eef1f2;
}

.login-panel {
    width: min(100%, 390px);
    padding: 34px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.brand-mark {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    background: var(--primary);
    color: white;
    border-radius: 6px;
    font-weight: 800;
    margin-bottom: 20px;
}

.login-panel h1 { font-size: 1.42rem; margin: 0 0 5px; }
.login-panel > p { margin: 0 0 24px; color: var(--muted); }
label { display: block; font-weight: 600; }

input, select, textarea {
    width: 100%;
    border: 1px solid var(--line-dark);
    border-radius: 5px;
    background: #fff;
    color: var(--text);
}

input, select { height: 42px; padding: 0 11px; }
textarea { padding: 12px; resize: vertical; min-height: 230px; }
label input, label select { margin-top: 6px; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: 2px solid rgba(22, 119, 200, .13); }

.password-row { display: flex; margin: 6px 0 16px; }
.password-row input { margin: 0; border-radius: 5px 0 0 5px; }
.password-row .icon-button { border-left: 0; border-radius: 0 5px 5px 0; }

.primary, .secondary, .text-button, .tab {
    min-height: 40px;
    border-radius: 5px;
    border: 1px solid transparent;
    padding: 0 16px;
    font-weight: 700;
}

.primary { background: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-dark); }
.secondary { background: #fff; color: var(--text); border-color: var(--line-dark); }
.secondary:hover { background: #f2f4f5; }
.full { width: 100%; }

.icon-button {
    width: 40px;
    height: 40px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line-dark);
    border-radius: 5px;
    font-size: 1.2rem;
}

.form-error { color: var(--danger) !important; margin: 10px 0 0 !important; min-height: 22px; }

.topbar {
    min-height: 58px;
    padding: 0 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.product-name { font-weight: 800; }
.environment { margin-left: 10px; color: var(--success); background: var(--success-soft); border-radius: 4px; padding: 3px 7px; font-size: .78rem; font-weight: 700; }
.topbar nav { display: flex; gap: 3px; }
.text-button { background: transparent; color: var(--muted); padding: 0 10px; }
.text-button:hover { color: var(--text); background: #f2f4f5; }

main { width: min(1280px, calc(100% - 40px)); margin: 0 auto; padding: 30px 0 60px; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 22px; }
.page-heading h1 { margin: 0 0 5px; font-size: 1.7rem; }
.page-heading p { margin: 0; color: var(--muted); }
.read-only-note { color: var(--muted); white-space: nowrap; font-size: .9rem; }
.read-only-note span { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--success); margin-right: 7px; }

.workspace-panel, .progress-panel, .results-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 7px;
}

.workspace-panel { padding: 22px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -5px -5px 20px; }
.tab { border-radius: 4px 4px 0 0; background: transparent; color: var(--muted); border-bottom: 3px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content > label { margin-bottom: 6px; }

.drop-zone {
    min-height: 180px;
    border: 1px dashed #9aa4ad;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    color: var(--muted);
    cursor: pointer;
    background: #fafbfb;
}

.drop-zone:hover, .drop-zone.dragging { border-color: var(--primary); background: var(--primary-soft); }
.drop-zone strong { color: var(--text); }
.upload-icon { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line-dark); border-radius: 50%; color: var(--primary); font-size: 1.4rem; margin-bottom: 5px; }

.excel-config { margin-top: 20px; }
.config-grid { display: grid; grid-template-columns: 1fr 150px 1fr 1fr; gap: 14px; }
.preview-head { display: flex; justify-content: space-between; gap: 20px; color: var(--muted); margin: 22px 0 8px; font-size: .88rem; }
.preview-head strong { color: var(--text); margin-right: 10px; }
.preview-scroll { max-height: 360px; }

.table-scroll { overflow: auto; border: 1px solid var(--line); border-radius: 5px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 10px 12px; white-space: nowrap; vertical-align: top; }
th { background: #f5f7f8; color: #4c5661; font-size: .82rem; position: sticky; top: 0; z-index: 1; }
tr:last-child td { border-bottom: 0; }
.preview-selected { background: var(--primary-soft); }
.preview-group { background: var(--warning-soft); }
.row-number { color: var(--muted); background: #fafafa; text-align: right; }
.skipped-row td { color: #8a939c; background: #f7f7f7; }

.match-options { margin-top: 22px; display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.match-options fieldset { border: 0; padding: 0; margin: 0; display: flex; gap: 22px; }
.match-options legend { font-weight: 700; margin-bottom: 8px; }
.radio-option { display: flex; align-items: flex-start; gap: 8px; font-weight: 400; }
.radio-option input { width: 17px; height: 17px; margin: 3px 0 0; }
.radio-option span { display: flex; flex-direction: column; }
.radio-option small { color: var(--muted); }
#start-button { min-width: 130px; }
.input-hint { color: var(--muted); margin-top: 6px; font-size: .88rem; }

.progress-panel { margin-top: 16px; padding: 18px 22px; }
.progress-panel > div:first-child { display: flex; justify-content: space-between; }
.progress-panel p { color: var(--muted); margin: 8px 0 0; }
.progress-track { height: 8px; background: #e8ecee; border-radius: 4px; overflow: hidden; margin-top: 11px; }
.progress-track span { display: block; height: 100%; width: 0; background: var(--primary); transition: width .2s ease; }
#retry-button { margin-top: 12px; }

.results-panel { margin-top: 16px; overflow: hidden; }
.results-heading { padding: 18px 20px; display: flex; justify-content: space-between; align-items: center; gap: 18px; border-bottom: 1px solid var(--line); }
.results-heading h2 { margin: 0; font-size: 1.12rem; }
.results-heading p { margin: 3px 0 0; color: var(--muted); font-size: .86rem; }
.stat-filters { display: grid; grid-template-columns: repeat(6, 1fr); border-bottom: 1px solid var(--line); }
.stat { min-height: 76px; background: #fff; border: 0; border-right: 1px solid var(--line); border-bottom: 3px solid transparent; padding: 9px; }
.stat:last-child { border-right: 0; }
.stat span { display: block; font-size: 1.3rem; font-weight: 800; }
.stat small { color: var(--muted); }
.stat:hover { background: #f7f8f8; }
.stat.active { border-bottom-color: var(--primary); background: var(--primary-soft); }
.stat.success span { color: var(--success); }
.stat.danger span { color: var(--danger); }
.stat.warning span { color: var(--warning); }
.results-panel > .table-scroll { border: 0; border-radius: 0; max-height: 620px; }
.results-table th:nth-child(1) { width: 72px; }
.results-table th:nth-child(3) { width: 150px; }
.status { display: inline-block; padding: 3px 7px; border-radius: 4px; font-size: .82rem; font-weight: 700; }
.status.matched { color: var(--success); background: var(--success-soft); }
.status.group_matched { color: #0b5d75; background: #e5f3f7; }
.status.multiple { color: var(--warning); background: var(--warning-soft); }
.status.not_found, .status.invalid { color: var(--danger); background: var(--danger-soft); }
.status.pending { color: var(--muted); background: #eef0f1; }
.duplicate-note { color: var(--warning); font-size: .82rem; }
.match-lines { white-space: normal; min-width: 140px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px; border-top: 1px solid var(--line); }

.dialog { width: min(460px, calc(100% - 32px)); border: 0; border-radius: 7px; padding: 24px; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(20, 28, 35, .48); }
.dialog-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.dialog-head h2 { margin: 0; font-size: 1.22rem; }
.dialog-head p { margin: 3px 0 0; color: var(--muted); }
.dialog label { margin-top: 12px; }
.wide-dialog { width: min(720px, calc(100% - 32px)); }
.history-list { max-height: 470px; overflow: auto; }
.history-item { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 8px 18px; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 13px 4px; }
.history-item:hover { background: #f7f8f8; }
.history-item strong { overflow: hidden; text-overflow: ellipsis; }
.history-item span, .history-item small { color: var(--muted); }

@media (max-width: 780px) {
    .topbar { padding: 0 14px; align-items: flex-start; flex-direction: column; gap: 5px; padding-top: 12px; padding-bottom: 8px; }
    .environment { display: none; }
    .topbar nav { width: 100%; justify-content: space-between; }
    main { width: min(100% - 20px, 1280px); padding-top: 20px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .read-only-note { white-space: normal; }
    .workspace-panel { padding: 15px; }
    .config-grid { grid-template-columns: 1fr; }
    .match-options { align-items: stretch; flex-direction: column; }
    .match-options fieldset { flex-direction: column; gap: 10px; }
    #start-button { width: 100%; }
    .stat-filters { grid-template-columns: repeat(3, 1fr); }
    .stat { border-bottom: 1px solid var(--line); }
    .stat.active { border-bottom: 3px solid var(--primary); }
    .results-heading { align-items: stretch; flex-direction: column; }
    #export-button { width: 100%; }
    .login-panel { padding: 26px 22px; }
}

@media (min-width: 781px) and (max-width: 1050px) {
    .config-grid { grid-template-columns: 1fr 1fr; }
}
