:root {
    color-scheme: light;
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #dbe3ef;
    --text: #132033;
    --text-muted: #607089;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #15803d;
    --warning: #b45309;
    --danger: #b91c1c;
    --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: linear-gradient(180deg, #eef3fb 0%, var(--bg) 160px);
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
input,
select,
textarea {
    font: inherit;
}

pre,
code,
.mono {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

pre {
    margin: 0;
    padding: 1rem;
    overflow: auto;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 14px;
    font-size: 0.85rem;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px 1fr;
}

.app-shell-auth {
    grid-template-columns: 1fr;
}

.sidebar {
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.7);
    border-right: 1px solid var(--border);
    backdrop-filter: blur(18px);
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.brand {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.brand h1,
.page-header h2,
.section-heading h3,
.auth-card h2 {
    margin: 0;
}

.brand p,
.page-header p,
.section-heading p,
.auth-card p,
.stat-meta,
small,
.muted {
    color: var(--text-muted);
}

.brand-badge {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    color: white;
    font-weight: 700;
}

.nav {
    display: grid;
    gap: 0.5rem;
}

.nav a {
    padding: 0.8rem 1rem;
    border-radius: 12px;
    color: var(--text);
    font-weight: 600;
}

.nav a.active,
.nav a:hover {
    background: var(--surface);
    box-shadow: var(--shadow);
    text-decoration: none;
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 0.8rem;
}

.user-chip {
    padding: 0.8rem 1rem;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
}

.content {
    padding: 2rem;
    display: grid;
    gap: 1.5rem;
    align-content: start;
    align-items: start;
}

.page-header,
.section-heading.inline {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-end;
}

.section-heading {
    margin-bottom: 1.25rem;
}

.eyebrow {
    margin: 0 0 0.35rem 0;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.75rem;
    font-weight: 700;
}

.card,
.stat-card,
.auth-card {
    background: var(--surface);
    border: 1px solid rgba(219, 227, 239, 0.9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card,
.auth-card {
    padding: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

.stats-grid.compact {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat-card {
    padding: 1.25rem;
    display: grid;
    gap: 0.5rem;
}

.stat-card strong {
    font-size: 1.8rem;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.two-column {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.stack {
    display: grid;
    gap: 1rem;
}

.gap-lg {
    gap: 1.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.field {
    display: grid;
    gap: 0.45rem;
}

.field-wide {
    grid-column: 1 / -1;
}

.field input,
.field select {
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    padding: 0.9rem 1rem;
    color: var(--text);
}

.field input:focus,
.field select:focus {
    outline: 2px solid rgba(37, 99, 235, 0.16);
    border-color: var(--primary);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 1.25rem;
}

.toolbar-search {
    display: flex;
    flex: 1 1 auto;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}

.search-field {
    width: min(420px, 100%);
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.25rem;
}

.pagination-summary {
    margin: 0;
}

.empty-row {
    text-align: center;
    color: var(--text-muted);
}

.upload-form {
    display: flex;
    gap: 1rem;
    align-items: stretch;
}

.upload-picker {
    position: relative;
    display: grid;
    gap: 0.45rem;
    flex: 1 1 auto;
    min-width: 0;
    padding: 1rem 1.1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    color: var(--text);
    cursor: pointer;
}

.upload-picker:hover {
    border-color: var(--primary);
    background: #f3f7ff;
}

.upload-picker-label {
    font-size: 0.9rem;
    font-weight: 600;
}

.upload-picker strong {
    font-size: 1rem;
    font-weight: 700;
}

.upload-picker-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.upload-actions {
    display: grid;
    gap: 0.75rem;
    align-content: end;
    width: 170px;
    flex: 0 0 170px;
}

.upload-mode-field,
.upload-actions .primary-button {
    width: 150px;
}

.upload-actions .primary-button {
    width: 100%;
    min-height: 52px;
}

.primary-button,
.secondary-button,
.ghost-button {
    border: 0;
    border-radius: 12px;
    padding: 0.9rem 1.15rem;
    cursor: pointer;
    font-weight: 700;
}

.primary-button {
    background: var(--primary);
    color: white;
}

.primary-button:hover {
    background: var(--primary-dark);
}

.secondary-button,
.ghost-button {
    background: var(--surface-muted);
    color: var(--text);
    border: 1px solid var(--border);
}

.flash {
    padding: 1rem 1.1rem;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.flash-success {
    border-color: rgba(21, 128, 61, 0.18);
    background: rgba(22, 163, 74, 0.08);
}

.flash-warning {
    border-color: rgba(180, 83, 9, 0.18);
    background: rgba(245, 158, 11, 0.12);
}

.flash-error {
    border-color: rgba(185, 28, 28, 0.18);
    background: rgba(239, 68, 68, 0.1);
}

.table-wrap {
    overflow: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.95rem 0.85rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 700;
    background: rgba(248, 250, 252, 0.9);
}

td strong,
.truncate {
    display: block;
}

.truncate {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem 0.7rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: capitalize;
    background: #e2e8f0;
    color: var(--text);
}

.status-completed,
.status-success,
.status-duplicate {
    background: rgba(22, 163, 74, 0.12);
    color: var(--success);
}

.status-completed_with_errors,
.status-warning {
    background: rgba(245, 158, 11, 0.16);
    color: var(--warning);
}

.status-failed,
.status-error,
.status-invalid {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
}

.status-valid,
.status-processing,
.status-uploaded {
    background: rgba(37, 99, 235, 0.12);
    color: var(--primary);
}

.status-skipped {
    background: rgba(100, 116, 139, 0.12);
    color: var(--text-muted);
}

.compact-list {
    margin: 0;
    padding-left: 1rem;
}

.header-pills {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.checkbox-cell {
    text-align: center;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem;
}

.auth-card {
    width: min(460px, 100%);
}

@media (max-width: 1080px) {
    .stats-grid,
    .stats-grid.compact,
    .two-column,
    .form-grid {
        grid-template-columns: 1fr 1fr;
    }
}

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

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .stats-grid,
    .stats-grid.compact,
    .two-column,
    .form-grid,
    .upload-form {
        grid-template-columns: 1fr;
        display: grid;
    }

    .toolbar-search {
        width: 100%;
    }

    .upload-actions,
    .upload-mode-field,
    .upload-actions .primary-button {
        width: 100%;
    }

    .page-header,
    .section-heading.inline {
        align-items: flex-start;
        flex-direction: column;
    }
}
