:root {
    color-scheme: light;
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #172033;
    --text-strong: #0b1220;
    --muted: #667085;
    --border: #d8dee8;
    --border-strong: #b9c3d1;
    --primary: #1859b8;
    --primary-hover: #104891;
    --primary-soft: #eaf2ff;
    --success: #18794e;
    --success-soft: #e9f7ef;
    --warning: #946200;
    --warning-soft: #fff5d6;
    --danger: #b42318;
    --danger-hover: #8e1c13;
    --danger-soft: #ffefed;
    --info: #175cd3;
    --info-soft: #edf4ff;
    --neutral: #596579;
    --neutral-soft: #eef1f5;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 12px 30px rgba(16, 24, 40, .14);
    --radius-sm: .45rem;
    --radius: .8rem;
    --radius-lg: 1.1rem;
    --page-width: 92rem;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 18rem;
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 1rem;
    line-height: 1.5;
}

button,
input,
select {
    font: inherit;
}

button,
input,
select,
summary {
    min-height: 2.75rem;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: .58;
}

a {
    color: var(--primary);
}

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

[hidden] {
    display: none !important;
}

:focus-visible {
    outline: .2rem solid #80b5ff;
    outline-offset: .15rem;
}

.skip-link {
    position: fixed;
    z-index: 1000;
    top: .75rem;
    left: .75rem;
    padding: .7rem 1rem;
    color: #fff;
    background: var(--text-strong);
    border-radius: var(--radius-sm);
    transform: translateY(-160%);
}

.skip-link:focus {
    transform: translateY(0);
}

.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.eyebrow {
    margin: 0 0 .2rem;
    color: var(--primary);
    font-size: .75rem;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-height: 2.75rem;
    padding: .65rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.button-primary {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.button-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.button-secondary {
    color: var(--text);
    background: var(--surface);
    border-color: var(--border-strong);
}

.button-secondary:hover:not(:disabled) {
    background: var(--surface-soft);
    border-color: var(--neutral);
}

.button-danger {
    color: #fff;
    background: var(--danger);
    border-color: var(--danger);
}

.button-danger:hover:not(:disabled) {
    background: var(--danger-hover);
    border-color: var(--danger-hover);
}

.button-quiet {
    color: var(--muted);
    background: transparent;
    border-color: transparent;
}

.button-quiet:hover:not(:disabled) {
    color: var(--text);
    background: rgba(255, 255, 255, .65);
}

.button-small {
    min-height: 2.35rem;
    padding: .5rem .75rem;
    font-size: .88rem;
}

.button-block {
    width: 100%;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    color: var(--muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 50%;
    font-size: 1.75rem;
    line-height: 1;
}

.icon-button:hover {
    color: var(--text);
    background: var(--neutral-soft);
}

.alert,
.notice {
    padding: .85rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
}

.alert-danger {
    color: #861910;
    background: var(--danger-soft);
    border-color: #f7b7b1;
}

.alert-success {
    color: #10633e;
    background: var(--success-soft);
    border-color: #a9ddbf;
}

.notice-warning {
    color: #704b00;
    background: var(--warning-soft);
    border-color: #efd078;
}

.login-page {
    display: grid;
    place-items: center;
    padding: 1rem;
    background:
        radial-gradient(circle at top left, rgba(24, 89, 184, .16), transparent 34rem),
        var(--bg);
}

.login-shell {
    width: 100%;
    max-width: 29rem;
}

.login-card {
    padding: clamp(1.4rem, 5vw, 2.4rem);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    margin-bottom: 1rem;
    color: #fff;
    background: var(--primary);
    border-radius: .8rem;
    font-size: 1.4rem;
    font-weight: 900;
}

.login-card h1 {
    margin: 0;
    color: var(--text-strong);
    font-size: clamp(1.65rem, 7vw, 2.15rem);
    line-height: 1.15;
}

.login-intro {
    margin: .8rem 0 1.4rem;
    color: var(--muted);
}

.login-card .alert {
    margin-bottom: 1rem;
}

.login-form {
    display: grid;
    gap: .65rem;
}

.login-form label {
    margin-top: .25rem;
    font-weight: 700;
}

.login-form input {
    width: 100%;
    min-height: 2.85rem;
    padding: .65rem .75rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
}

.login-form .button {
    margin-top: .65rem;
}

.security-note {
    margin: 1.15rem 0 0;
    color: var(--muted);
    font-size: .82rem;
    text-align: center;
}

.app-header {
    position: relative;
    z-index: 5;
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    width: min(100% - 2rem, var(--page-width));
    margin: 0 auto;
    padding: 1rem 0;
}

.header-title h1 {
    margin: 0;
    color: var(--text-strong);
    font-size: clamp(1.35rem, 3vw, 1.9rem);
    line-height: 1.2;
}

.last-refresh {
    margin: .2rem 0 0;
    color: var(--muted);
    font-size: .82rem;
}

.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .55rem;
    flex-wrap: wrap;
}

.logout-form {
    margin: 0;
}

.page-shell {
    width: min(100% - 2rem, var(--page-width));
    margin: 0 auto;
    padding: 1.5rem 0 3rem;
}

#global-alert {
    margin-bottom: 1rem;
}

.section {
    margin-bottom: 1.35rem;
    padding: clamp(1rem, 2.5vw, 1.4rem);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.section-heading h2 {
    margin: 0;
    color: var(--text-strong);
    font-size: clamp(1.2rem, 2.5vw, 1.55rem);
}

.result-count {
    margin: 0;
    color: var(--muted);
    font-size: .9rem;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    min-height: 2rem;
    padding: .25rem .7rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 800;
    white-space: nowrap;
}

.status-dot {
    width: .55rem;
    height: .55rem;
    background: currentColor;
    border-radius: 50%;
}

.status-success,
.status-subida,
.status-ya_existia,
.status-completada {
    color: var(--success);
    background: var(--success-soft);
    border-color: #b9e4cb;
}

.status-warning,
.status-pendiente,
.status-reintentar,
.status-parcial,
.status-completada_con_errores {
    color: var(--warning);
    background: var(--warning-soft);
    border-color: #efd78f;
}

.status-danger,
.status-error,
.status-error_permanente,
.status-fallida {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: #f5bbb6;
}

.status-info,
.status-en_cola,
.status-procesando,
.status-ejecutando {
    color: var(--info);
    background: var(--info-soft);
    border-color: #b9d2ff;
}

.status-neutral,
.status-cancelada {
    color: var(--neutral);
    background: var(--neutral-soft);
    border-color: #d4dae3;
}

.active-run {
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--info-soft);
    border: 1px solid #b9d2ff;
    border-radius: var(--radius);
}

.active-run-heading {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.active-run h3,
.active-run p {
    margin: 0;
}

.active-run p {
    color: var(--muted);
    font-size: .9rem;
}

.active-run progress {
    width: 100%;
    height: .75rem;
    margin-top: .85rem;
    accent-color: var(--primary);
}

.metric-list {
    display: flex;
    flex-wrap: wrap;
    gap: .55rem 1rem;
    margin: .65rem 0 0;
    font-size: .86rem;
}

.metric-list div {
    display: flex;
    gap: .3rem;
}

.metric-list dt {
    color: var(--muted);
}

.metric-list dd {
    margin: 0;
    font-weight: 800;
}

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

.seller-card {
    min-width: 0;
    padding: 1rem;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.seller-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .8rem;
}

.seller-card h3 {
    margin: 0;
    color: var(--text-strong);
    font-size: 1.15rem;
    text-transform: capitalize;
}

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

.seller-meta div {
    min-width: 0;
    padding: .7rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.seller-meta dt {
    color: var(--muted);
    font-size: .76rem;
    font-weight: 700;
}

.seller-meta dd {
    margin: .15rem 0 0;
    overflow-wrap: anywhere;
    font-size: .92rem;
    font-weight: 750;
}

.seller-error {
    margin: .8rem 0 0;
    padding: .65rem .75rem;
    color: #861910;
    background: var(--danger-soft);
    border-radius: var(--radius-sm);
    font-size: .83rem;
    overflow-wrap: anywhere;
}

.skeleton {
    height: .9rem;
    margin: .7rem 0;
    background: linear-gradient(90deg, #e5e9ef, #f2f4f7, #e5e9ef);
    background-size: 200% 100%;
    border-radius: 999px;
    animation: skeleton 1.4s linear infinite;
}

.skeleton-title {
    width: 45%;
    height: 1.25rem;
}

@keyframes skeleton {
    to { background-position: -200% 0; }
}

.filter-panel {
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.filters-grid,
.field-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(9rem, 1fr));
    gap: .75rem;
}

.field-search {
    grid-column: span 2;
}

.field {
    display: grid;
    align-content: start;
    gap: .3rem;
    min-width: 0;
    color: var(--text);
    font-size: .88rem;
    font-weight: 700;
}

.field small {
    color: var(--muted);
    font-size: .76rem;
    font-weight: 500;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    min-height: 2.75rem;
    padding: .58rem .65rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
}

.field input:invalid,
.field textarea:invalid {
    border-color: var(--danger);
}

.field textarea {
    min-height: 6.5rem;
    resize: vertical;
}

.retry-reason-field {
    margin-top: 1rem;
}

.filter-actions {
    display: flex;
    justify-content: flex-end;
    gap: .55rem;
    margin-top: .9rem;
}

.loading-line {
    padding: .75rem;
    color: var(--muted);
    background: var(--surface-soft);
    border-radius: var(--radius-sm);
    text-align: center;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.data-table {
    width: 100%;
    min-width: 78rem;
    border-collapse: collapse;
    font-size: .86rem;
}

.data-table th,
.data-table td {
    padding: .72rem .65rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.data-table th {
    color: #475467;
    background: var(--surface-soft);
    font-size: .75rem;
    font-weight: 800;
    letter-spacing: .025em;
    text-transform: uppercase;
    white-space: nowrap;
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.data-table tbody tr:hover {
    background: #fbfcfe;
}

.data-table td[data-label="Orden"],
.data-table td[data-label="Documento"] {
    font-weight: 750;
}

.data-table details {
    max-width: 22rem;
}

.data-table summary {
    display: inline-flex;
    align-items: center;
    min-height: 2.4rem;
    color: var(--primary);
    cursor: pointer;
    font-weight: 700;
}

.data-table pre {
    max-width: 22rem;
    margin: .4rem 0 0;
    padding: .55rem;
    overflow: auto;
    color: var(--text);
    background: var(--neutral-soft);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: .78rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.table-empty {
    padding: 2rem !important;
    color: var(--muted);
    text-align: center !important;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .8rem;
    margin-top: .85rem;
}

.pagination span {
    min-width: 8rem;
    color: var(--muted);
    font-size: .86rem;
    text-align: center;
}

.modal {
    width: min(44rem, calc(100% - 1.25rem));
    max-height: calc(100vh - 1.25rem);
    padding: 0;
    overflow: auto;
    color: var(--text);
    background: transparent;
    border: 0;
    border-radius: var(--radius-lg);
}

.modal::backdrop {
    background: rgba(8, 15, 28, .68);
    backdrop-filter: blur(2px);
}

.modal-small {
    width: min(34rem, calc(100% - 1.25rem));
}

.modal-shell {
    padding: clamp(1rem, 3vw, 1.5rem);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.1rem;
}

.modal-header h2 {
    margin: 0;
    color: var(--text-strong);
    font-size: clamp(1.35rem, 5vw, 1.75rem);
}

.seller-choice {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .65rem;
    margin: 0 0 1rem;
    padding: 0;
    border: 0;
}

.seller-choice legend {
    grid-column: 1 / -1;
    margin-bottom: .35rem;
    font-weight: 800;
}

.check-card {
    display: flex;
    align-items: flex-start;
    gap: .65rem;
    min-height: 5rem;
    padding: .8rem;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.check-card:has(input:checked) {
    background: var(--primary-soft);
    border-color: #8bb7f5;
}

.check-card input {
    flex: 0 0 auto;
    width: 1.1rem;
    height: 1.1rem;
    min-height: auto;
    margin-top: .2rem;
    accent-color: var(--primary);
}

.check-card span {
    display: grid;
    gap: .15rem;
}

.check-card small {
    color: var(--muted);
    font-size: .78rem;
}

.modal .notice,
.modal .alert {
    margin: 1rem 0 0;
    font-size: .88rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: .65rem;
    margin-top: 1.25rem;
}

.confirmation-summary {
    padding: 1rem;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.confirmation-summary h3 {
    margin: 0 0 .65rem;
    font-size: 1rem;
}

.confirmation-summary dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: .4rem .8rem;
    margin: 0;
}

.confirmation-summary dt {
    color: var(--muted);
}

.confirmation-summary dd {
    margin: 0;
    font-weight: 750;
}

.confirmation-check {
    display: flex;
    align-items: flex-start;
    gap: .65rem;
    margin-top: 1rem;
    padding: .8rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-weight: 700;
    cursor: pointer;
}

.confirmation-check input {
    flex: 0 0 auto;
    width: 1.15rem;
    height: 1.15rem;
    min-height: auto;
    margin-top: .15rem;
    accent-color: var(--danger);
}

.toast-region {
    position: fixed;
    z-index: 100;
    right: 1rem;
    bottom: 1rem;
    display: grid;
    gap: .55rem;
    width: min(24rem, calc(100% - 2rem));
}

.toast {
    padding: .85rem 1rem;
    color: #fff;
    background: var(--text-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    overflow-wrap: anywhere;
}

.toast-error {
    background: var(--danger);
}

@media (max-width: 68rem) {
    .filters-grid,
    .field-grid {
        grid-template-columns: repeat(2, minmax(10rem, 1fr));
    }
}

@media (max-width: 48rem) {
    .header-inner,
    .section-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .header-actions {
        justify-content: stretch;
    }

    .header-actions > .button,
    .header-actions .logout-form,
    .header-actions .logout-form .button {
        flex: 1 1 9rem;
    }

    .seller-grid,
    .filters-grid,
    .field-grid,
    .seller-choice,
    .seller-meta {
        grid-template-columns: 1fr;
    }

    .field-search {
        grid-column: auto;
    }

    .filter-actions,
    .modal-actions {
        align-items: stretch;
        flex-direction: column-reverse;
    }

    .filter-actions .button,
    .modal-actions .button {
        width: 100%;
    }

    .pagination {
        justify-content: space-between;
    }

    .data-table {
        min-width: 0;
    }

    .data-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
    }

    .data-table tbody {
        display: grid;
        gap: .75rem;
        padding: .75rem;
    }

    .data-table tbody tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        padding: .3rem;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
    }

    .data-table td {
        min-width: 0;
        padding: .55rem;
        border: 0;
        overflow-wrap: anywhere;
    }

    .data-table td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: .15rem;
        color: var(--muted);
        font-size: .7rem;
        font-weight: 800;
        letter-spacing: .025em;
        text-transform: uppercase;
    }

    .data-table td[data-wide="true"],
    .data-table .table-empty {
        grid-column: 1 / -1;
    }

    .data-table .table-empty::before {
        content: none;
    }

    .data-table details,
    .data-table pre {
        max-width: none;
    }

    .confirmation-summary dl {
        grid-template-columns: 1fr;
        gap: .1rem;
    }

    .confirmation-summary dd {
        margin-bottom: .5rem;
    }
}

@media (max-width: 26rem) {
    .page-shell,
    .header-inner {
        width: min(100% - 1rem, var(--page-width));
    }

    .section {
        padding: .8rem;
    }

    .data-table tbody tr {
        grid-template-columns: 1fr;
    }

    .data-table td[data-wide="true"] {
        grid-column: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}

@media (forced-colors: active) {
    .status-pill,
    .seller-card,
    .section,
    .check-card {
        border: 1px solid CanvasText;
    }

    .status-dot {
        forced-color-adjust: none;
    }
}
