:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #dfe2e8;
    --text: #1b1f27;
    --muted: #667085;
    --accent: #3451d1;
    --accent-hover: #2a43b3;
    --accent-text: #ffffff;
    --danger-bg: #fdecec;
    --danger-text: #b42318;
    --focus: rgba(52, 81, 209, .35);
    --radius: 10px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1115;
        --surface: #171a21;
        --border: #2a2f3a;
        --text: #e7e9ee;
        --muted: #98a0b0;
        --accent: #6b83f2;
        --accent-hover: #8496f5;
        --accent-text: #0f1115;
        --danger-bg: #3a1a1a;
        --danger-text: #ff9b91;
        --focus: rgba(107, 131, 242, .4);
        color-scheme: dark;
    }
}

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

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

body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 .5rem; }
a { color: var(--accent); }
code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; }
.muted { color: var(--muted); margin: 0; }

/* Шапка */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: .6rem;
    color: var(--text);
    font-weight: 650;
    font-size: 1.05rem;
    text-decoration: none;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 700;
    font-size: .95rem;
}

.brand-mark-lg { width: 44px; height: 44px; border-radius: 12px; font-size: 1.3rem; }

.account { display: flex; align-items: center; gap: .75rem; }
.account form { margin: 0; }
.account-name { font-weight: 550; }

.badge {
    padding: .1rem .5rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: .75rem;
}

.content { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }

/* Вход */
.auth {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 1.5rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 380px;
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(16, 24, 40, .06);
}

.auth-head { display: grid; justify-items: center; gap: .35rem; margin-bottom: 1.5rem; text-align: center; }
.auth-head h1 { margin: .5rem 0 0; }

.alert {
    margin-bottom: 1rem;
    padding: .65rem .85rem;
    border-radius: var(--radius);
    background: var(--danger-bg);
    color: var(--danger-text);
    font-size: .925rem;
}

.field { display: grid; gap: .35rem; margin-bottom: 1rem; }
.field > span:first-child { font-weight: 550; font-size: .9rem; }

.field input {
    width: 100%;
    padding: .6rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.field input.input-validation-error { border-color: var(--danger-text); }
.field-error { color: var(--danger-text); font-size: .85rem; }
.field-error:empty { display: none; }

.check { display: flex; align-items: center; gap: .5rem; margin-bottom: 1.25rem; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* Кнопки */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .55rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); padding: .35rem .8rem; font-weight: 550; }
.btn-ghost:hover { background: var(--bg); }

/* Навигация в шапке */
.topbar-left { display: flex; align-items: center; gap: 1.75rem; }
.nav { display: flex; gap: 1.25rem; }
.nav a { color: var(--muted); text-decoration: none; font-weight: 550; }
.nav a:hover, .nav a.active { color: var(--text); }

/* Главная */
.page-head { margin-bottom: 1.5rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.tile {
    display: block;
    padding: 1.1rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    text-decoration: none;
}
.tile:hover { border-color: var(--accent); }
.tile h2 { margin: 0 0 .25rem; font-size: 1.05rem; }

/* Сверка */
.file-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }

.panel {
    min-width: 0;
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.panel h2 { margin: 0 0 1rem; font-size: 1.05rem; }

.dropzone {
    position: relative;
    display: grid;
    gap: .2rem;
    justify-items: center;
    padding: 1.4rem 1rem;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    text-align: center;
    cursor: pointer;
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--accent); }
.dropzone input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.dropzone-title { font-weight: 600; overflow-wrap: anywhere; }
.dropzone .muted { font-size: .85rem; }

.mapping { margin-top: 1rem; }
.mapping-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; }
.mapping-fields .field { margin-bottom: .75rem; }

.field select {
    width: 100%;
    padding: .5rem .6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font: inherit;
}
.field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }

.preview { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.preview table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.preview th, .preview td { padding: .4rem .6rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.preview th { background: var(--bg); font-weight: 600; color: var(--muted); }
.preview tr:last-child td { border-bottom: 0; }
.preview .mapped { background: var(--focus); color: var(--text); }

.steps ol { margin: 0; padding-left: 1.25rem; display: grid; gap: .35rem; }
.steps { margin-bottom: 1rem; }

.actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 820px) {
    .file-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
    .mapping-fields { grid-template-columns: 1fr; gap: 0; }
    .nav { display: none; }
}

@media (max-width: 480px) {
    .topbar { padding: .65rem 1rem; }
    .account .badge { display: none; }
    .auth-card { padding: 1.5rem; }
}
