:root {
    --font: "Work Sans", "Segoe UI", system-ui, sans-serif;
    --canvas: #f3f2f1;
    --surface: #ffffff;
    --surface-alt: #fafafa;
    --surface-low: #f7f3f0;
    --surface-high: #ece7e4;
    --text: #201f1e;
    --text-2: #404752;
    --text-3: #605e5c;
    --stroke: #edebe9;
    --stroke-strong: #d2d0ce;
    --stroke-input: #605e5c;
    --brand: #c41e2a;
    --brand-hover: #a81822;
    --brand-pressed: #8f141c;
    --brand-soft: #f6e8e9;
    --transit: #d83b01;
    --shadow: 0 1.6px 3.6px rgba(0, 0, 0, 0.04), 0 0.3px 0.9px rgba(0, 0, 0, 0.02);
    --shadow-bar: 0 1px 8px rgba(0, 0, 0, 0.04);
    --radius: 4px;
    --focus: 0 0 0 2px #fff, 0 0 0 4px var(--brand);
}

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

html {
    margin: 0;
    min-height: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100%;
    min-height: 100dvh;
    font-family: var(--font);
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--text);
    background: var(--canvas);
    font-feature-settings: "tnum" 1;
    overflow-x: hidden;
}

h1,
h2,
p {
    margin: 0;
}

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

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

.skip-link {
    position: absolute;
    left: 12px;
    top: -40px;
    z-index: 20;
    padding: 8px 12px;
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius);
}

.skip-link:focus {
    top: 8px;
}

.hub {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--surface);
    box-shadow: var(--shadow-bar);
}

.hub-top {
    display: flex;
    align-items: center;
    gap: 24px;
    min-height: 64px;
    padding: 8px 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.brand-logo {
    height: 32px;
    width: auto;
}

.brand-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand-line {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-name {
    font-size: 1rem;
    line-height: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

.brand-badge {
    padding: 1px 6px;
    border-radius: var(--radius);
    background: var(--surface-high);
    color: var(--transit);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.brand-org {
    font-size: 0.75rem;
    color: var(--text-3);
}

.hub-search {
    flex: 1;
    max-width: 36rem;
    display: flex;
    align-items: center;
    height: 36px;
    padding: 0 12px;
    background: var(--surface-low);
    border-radius: var(--radius);
}

.hub-search input {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
}

.hub-search input:focus {
    outline: none;
}

.hub-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 48px;
    padding: 0 24px;
    background: var(--surface-alt);
    border-top: 1px solid var(--stroke);
    overflow-x: auto;
}

.hub-link {
    padding: 6px 12px;
    border-radius: var(--radius);
    color: var(--text-2);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
}

.hub-link:hover {
    background: var(--surface-high);
    color: var(--text);
}

.hub-link.is-active {
    background: var(--brand);
    color: #fff;
    font-weight: 700;
}

.hub-link.is-active:hover {
    background: var(--brand-hover);
    color: #fff;
}

button.hub-link {
    border: 0;
    background: transparent;
    cursor: pointer;
}

.hub-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.hub-user {
    color: var(--text-2);
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
}

.auth-card {
    max-width: 440px;
}

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

.login-stage {
    display: flex;
    justify-content: center;
    padding: 40px 0 56px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    min-width: 0;
    flex: 0 1 420px;
    margin: 0;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--stroke);
    border-top: 3px solid var(--brand);
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(32, 31, 30, 0.08), var(--shadow);
}

.login-body {
    padding: 28px 28px 24px;
}

.login-icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin-bottom: 16px;
    border-radius: 8px;
    background: var(--brand-soft);
    color: var(--brand);
}

.login-card h1 {
    font-size: 1.5rem;
    line-height: 2rem;
}

.login-copy {
    margin: 8px 0 20px;
    color: var(--text-2);
    font-size: 0.9375rem;
    line-height: 1.4rem;
}

.login-card .notice {
    margin-bottom: 16px;
}

.login-fields {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-card .field input,
.login-card .field select {
    height: 40px;
    padding: 0 12px;
    background: var(--surface-alt);
    border-color: var(--stroke-strong);
}

.login-card .field select {
    padding-right: 32px;
}

.login-card .field input:focus,
.login-card .field input:focus-visible,
.login-card .field select:focus,
.login-card .field select:focus-visible {
    background: var(--surface);
    border-color: var(--brand);
    box-shadow: inset 0 -2px 0 var(--brand);
}


.login-card .login-submit {
    width: 100%;
    height: 40px;
    margin-top: 20px;
}

.button-ms {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: #fff;
    color: #1b1b1b;
    border: 1px solid var(--stroke-strong);
    text-decoration: none;
    font-weight: 600;
}

.button-ms:hover {
    background: var(--surface-alt);
    color: #1b1b1b;
}

.ms-logo {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}


.panel-actions {
    margin-bottom: 16px;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.main {
    padding: 24px;
}

.page-header {
    margin-bottom: 16px;
}

.eyebrow {
    margin-bottom: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
}

h1 {
    font-size: 1.75rem;
    line-height: 2.25rem;
    font-weight: 600;
    letter-spacing: -0.015em;
}

.lede {
    max-width: 72ch;
    margin-top: 4px;
    color: var(--text-2);
    font-size: 0.9375rem;
    line-height: 1.375rem;
}

.surface {
    background: var(--surface);
    border: 1px solid var(--stroke);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

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

.kpi {
    display: flex;
    flex-direction: column;
    min-height: 168px;
    padding: 16px;
}

.kpi h2 {
    margin-top: 8px;
    font-size: 1.25rem;
    line-height: 1.75rem;
    font-weight: 600;
}

.kpi p {
    margin-top: 6px;
    color: var(--text-2);
}

.kpi .button {
    margin-top: auto;
    align-self: flex-start;
}

.kpi-lead {
    border-top: 3px solid var(--brand);
}

.command-bar,
.data-panel {
    background: var(--surface);
    border: 1px solid var(--stroke);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.command-bar {
    margin-bottom: 16px;
    padding: 12px;
}

.filter-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
}

.filter-grid.has-dates {
    grid-template-columns: minmax(160px, 0.8fr) minmax(180px, 1.2fr) 150px 150px auto;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.field label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-3);
}

.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 0 10px;
    border: 1px solid var(--stroke-input);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.field input,
.field select {
    height: 32px;
}

.field textarea {
    min-height: 72px;
    padding: 8px 10px;
    resize: vertical;
}

.field select {
    padding-right: 32px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23666666' d='M1.1 1.1 6 6l4.9-4.9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px 8px;
    cursor: pointer;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: inset 0 -2px 0 var(--brand);
}


.filter-actions {
    display: flex;
    gap: 8px;
}

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

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

.form-actions {
    margin-top: 16px;
}

.import-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
}

.import-actions {
    margin-top: 0;
}

.field-hint {
    margin: 4px 0 0;
    color: var(--text-3);
    font-size: 0.8rem;
    line-height: 1.35;
}

.field input[type="file"] {
    height: auto;
    padding: 6px 10px;
}

.notice {
    margin-bottom: 16px;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: #dff6dd;
    color: #0b6a0b;
    font-weight: 600;
}

.notice-error {
    background: #fde7e9;
    color: #a80000;
}

.field-error {
    color: #a80000;
    font-size: 0.75rem;
    font-weight: 600;
}

.button {
    height: 32px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.button:focus-visible,
.hub-link:focus-visible,
.brand:focus-visible,
.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible,
.hub-search:focus-within {
    outline: none;
    box-shadow: var(--focus);
}


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

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

.button-primary:active {
    background: var(--brand-pressed);
}

.button-subtle {
    background: var(--surface-alt);
    border-color: var(--stroke-strong);
}

.button-subtle:hover {
    background: var(--canvas);
    color: var(--text);
}

.button:disabled {
    background: var(--surface-low);
    border-color: var(--stroke);
    color: #a19f9d;
    cursor: default;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--stroke);
}

.panel-head h2 {
    font-size: 1rem;
    line-height: 1.5rem;
    font-weight: 600;
}

.count-pill {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin: 0;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--surface-low);
    color: var(--text-3);
}

.count-value {
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text);
}

.count-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.data-panel {
    overflow: hidden;
}

.data-scroll {
    overflow: auto;
    max-height: calc(100vh - 360px);
}

.data-grid {
    width: 100%;
    min-width: 920px;
    border-collapse: collapse;
    font-size: 0.75rem;
    line-height: 1rem;
}

.data-grid th,
.data-grid td {
    padding: 10px 12px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--stroke);
}

.data-grid th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-low);
    color: var(--text-3);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.data-grid tbody tr:hover td {
    background: var(--surface-low);
}

.data-grid .num {
    text-align: right;
    white-space: nowrap;
    font-weight: 500;
}

.data-grid .key {
    font-weight: 600;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.data-grid tbody tr:hover .key {
    color: var(--brand);
}

.data-grid .nowrap {
    white-space: nowrap;
}

.data-grid .wrap {
    min-width: 160px;
    max-width: 280px;
}

.row-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin: -2px 6px -2px 0;
    padding: 0;
    border: 1px solid var(--stroke-strong);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-2);
    vertical-align: middle;
    cursor: pointer;
}

.row-toggle svg {
    width: 14px;
    height: 14px;
}

.row-toggle:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.row-toggle:focus-visible {
    outline: none;
    box-shadow: var(--focus);
}

.row-toggle[aria-expanded="true"] svg {
    transform: rotate(90deg);
}

.data-grid tbody tr.is-open td {
    background: var(--surface-low);
}

.data-grid tbody tr.detail-row td,
.data-grid tbody tr.detail-row:hover td {
    background: var(--surface-alt);
    padding-top: 0;
    padding-bottom: 12px;
}

.detail-grid {
    width: min(720px, 100%);
    min-width: 0;
    margin-left: 28px;
    border: 1px solid var(--stroke-strong);
    border-radius: 4px;
    background: var(--surface);
    font-size: 0.75rem;
}

.detail-grid caption {
    padding: 8px 12px 0;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
}

.data-grid .detail-grid th,
.data-grid .detail-grid td {
    position: static;
    background: var(--surface);
    border-bottom: 1px solid var(--stroke);
}

.data-grid .detail-grid tr:last-child td {
    border-bottom: 0;
}

.data-grid tbody tr.detail-row:hover .detail-grid td {
    background: var(--surface);
}

.empty-title {
    font-weight: 600;
    font-size: 0.875rem;
}

.empty-text {
    margin-top: 2px;
    color: var(--text-3);
}

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-top: 1px solid var(--stroke);
    background: var(--surface-alt);
}

.pager-summary {
    margin: 0;
    color: var(--text-3);
    font-size: 0.75rem;
    font-weight: 500;
}

.pager-actions {
    display: flex;
    gap: 8px;
}

@media (max-width: 1100px) {
    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 800px) {
    .hub-top,
    .hub-nav,
    .main {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    .hub {
        padding-top: env(safe-area-inset-top);
    }

    .hub-top {
        flex-wrap: wrap;
        gap: 12px;
        min-height: 56px;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .brand-logo {
        height: 28px;
    }

    .brand-name {
        font-size: 0.875rem;
        line-height: 1.25rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 42vw;
    }

    .brand-badge {
        display: none;
    }

    .hub-search {
        flex: 1 1 100%;
        max-width: none;
        min-height: 44px;
        height: 44px;
    }

    .hub-nav {
        height: auto;
        min-height: 48px;
        padding-top: 6px;
        padding-bottom: 6px;
        gap: 6px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        overscroll-behavior-x: contain;
    }

    .hub-link,
    button.hub-link {
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        padding: 8px 12px;
    }

    .hub-logout {
        margin-left: 0;
        flex: 0 0 auto;
    }

    .hub-user {
        max-width: 42vw;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .main {
        padding-top: 16px;
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }

    .page-header {
        margin-bottom: 12px;
    }

    .lede {
        font-size: 0.875rem;
        line-height: 1.35rem;
    }

    .command-bar {
        padding: 12px;
    }

    .filter-grid,
    .filter-grid.has-dates,
    .form-grid,
    .import-grid,
    .kpi-grid {
        grid-template-columns: 1fr;
    }

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

    .field input,
    .field select,
    .field textarea {
        font-size: 16px; /* evita zoom automático en iOS */
        min-height: 44px;
        height: auto;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .field textarea {
        min-height: 88px;
    }

    .filter-actions,
    .form-actions,
    .import-actions,
    .row-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .filter-actions .button,
    .form-actions .button,
    .import-actions .button,
    .row-actions .button {
        flex: 1 1 auto;
        min-height: 44px;
        justify-content: center;
    }

    .button {
        height: auto;
        min-height: 44px;
        padding: 10px 14px;
        white-space: normal;
        text-align: center;
    }


    .pager,
    .panel-head {
        flex-direction: column;
        align-items: flex-start;
    }

    h1 {
        font-size: 1.375rem;
        line-height: 1.75rem;
    }

    .data-scroll {
        max-height: none;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .data-grid {
        min-width: 720px;
    }

    .login-stage {
        padding: 20px 0 32px;
    }

    .login-card {
        max-width: none;
        flex: 1 1 auto;
        border-radius: 8px;
    }

    .login-body {
        padding: 22px 16px 20px;
    }

    .login-card h1 {
        font-size: 1.35rem;
        line-height: 1.75rem;
    }

    .login-card .field input,
    .login-card .field select,
    .login-card .login-submit,
    .button-ms {
        min-height: 48px;
        height: auto;
        font-size: 16px;
    }

    .detail-grid {
        margin-left: 0;
        width: 100%;
    }
}

@media (max-width: 480px) {
    .brand-org {
        display: none;
    }

    .brand-name {
        max-width: 58vw;
    }

    .hub-top,
    .hub-nav,
    .main {
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
    }

    .data-grid {
        min-width: 640px;
        font-size: 0.6875rem;
    }

    .data-grid th,
    .data-grid td {
        padding: 8px 10px;
    }

    .filter-actions .button,
    .form-actions .button {
        flex: 1 1 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        scroll-behavior: auto !important;
        transition: none !important;
    }
}

.data-grid tbody tr.flete-aceptado td,
.data-grid tbody tr.flete-aceptado:hover td {
    background: #dcfce7;
}

.data-grid tbody tr.flete-rechazado td,
.data-grid tbody tr.flete-rechazado:hover td {
    background: #fee2e2;
}
