/* ==========================================================================\n   Sistema de Ventas · UI Foundation v253\n   Capa visual reutilizable para módulos administrativos y comerciales.\n   No modifica lógica ni comportamiento funcional.\n   ========================================================================== */

:root {
    --ui-surface: var(--ui-panel, #ffffff);
    --ui-surface-soft: var(--ui-panel-soft, #f8fafc);
    --ui-surface-muted: var(--ui-bg, #f4f7fc);
    --ui-line: var(--ui-border, #e6ebf2);
    --ui-line-strong: var(--ui-border-strong, #d8e0ea);
    --ui-ink: var(--ui-text, #172033);
    --ui-ink-soft: color-mix(in srgb, var(--ui-text, #172033) 86%, var(--ui-muted, #667085));
    --ui-copy: var(--ui-muted, #667085);
    --ui-copy-soft: var(--ui-muted-2, #98a2b3);
    --ui-success-soft: #ecfdf3;
    --ui-warning-soft: #fffaeb;
    --ui-danger-soft: #fef3f2;
    --ui-info-soft: #eff8ff;
    --ui-focus-ring: 0 0 0 4px color-mix(in srgb, var(--ui-primary, #2d176f) 12%, transparent);
    --ui-card-radius: 16px;
    --ui-control-radius: 10px;
    --ui-pill-radius: 999px;
    --ui-card-shadow: 0 1px 2px rgba(16,24,40,.02), 0 8px 24px rgba(16,24,40,.035);
    --ui-card-shadow-hover: 0 2px 4px rgba(16,24,40,.03), 0 16px 32px rgba(16,24,40,.06);
}

/* ---------- Cabeceras de página ---------- */
.app-content .page-head {
    margin: 0 0 20px;
    padding: 0;
    align-items: center;
}

.app-content .page-head > div:first-child {
    min-width: 0;
}

.app-content .page-head h1 {
    margin: 0;
    color: var(--ui-ink);
    font-size: clamp(1.55rem, 2vw, 2rem);
    font-weight: 700;
    line-height: 1.18;
    letter-spacing: -.025em;
}

.app-content .page-head .muted,
.app-content .page-head p {
    margin: 6px 0 0;
    color: var(--ui-copy);
    font-size: .9rem;
}

/* ---------- Tarjetas ---------- */
.app-content .card {
    border: 1px solid var(--ui-line);
    border-radius: var(--ui-card-radius);
    background: var(--ui-surface);
    box-shadow: var(--ui-card-shadow);
    padding: 22px;
}

.app-content .card + .card {
    margin-top: 18px;
}

.app-content .card > h2:first-child,
.app-content .section-head h2 {
    margin: 0;
    color: var(--ui-ink);
    font-size: 1rem;
    line-height: 1.35;
    font-weight: 700;
    letter-spacing: -.01em;
}

.app-content .section-head {
    margin-bottom: 16px;
    align-items: center;
}

.app-content .section-head p {
    margin: 4px 0 0;
    color: var(--ui-copy);
    font-size: .82rem;
}

/* ---------- Botones ---------- */
.app-content .button,
.app-content button.button {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 15px;
    border: 1px solid transparent;
    border-radius: var(--ui-control-radius);
    font-size: .82rem;
    line-height: 1.2;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 1px 2px rgba(16,24,40,.04);
    transition: transform .16s ease, box-shadow .16s ease, background .16s ease, border-color .16s ease;
}

.app-content .button:hover,
.app-content button.button:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(16,24,40,.08);
}

.app-content .button:focus-visible,
.app-content button.button:focus-visible {
    outline: none;
    box-shadow: var(--ui-focus-ring);
}

.app-content .button.secondary {
    background: var(--ui-surface);
    color: var(--ui-ink-soft);
    border-color: var(--ui-line-strong);
}

.app-content .button.secondary:hover {
    color: var(--ui-primary, #2d176f);
    border-color: color-mix(in srgb, var(--ui-primary, #2d176f) 34%, var(--ui-line));
    background: color-mix(in srgb, var(--ui-primary-soft, #f0edfa) 45%, #fff);
}

.app-content .button.danger {
    background: #d92d20;
    color: #fff;
}

.app-content .actions {
    gap: 8px;
}

.app-content .actions form {
    margin: 0;
}

/* ---------- Inputs ---------- */
.app-content input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.app-content select,
.app-content textarea {
    min-height: 42px;
    border: 1px solid var(--ui-line-strong);
    border-radius: var(--ui-control-radius);
    background: var(--ui-surface);
    color: var(--ui-ink);
    box-shadow: 0 1px 2px rgba(16,24,40,.02);
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.app-content input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):hover,
.app-content select:hover,
.app-content textarea:hover {
    border-color: #c8d2df;
}

.app-content input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):focus,
.app-content select:focus,
.app-content textarea:focus {
    outline: none;
    border-color: color-mix(in srgb, var(--ui-primary, #2d176f) 55%, #d8e0ea);
    box-shadow: var(--ui-focus-ring);
}

.app-content label {
    color: var(--ui-ink-soft);
}

/* ---------- Badges ---------- */
.app-content .badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 25px;
    padding: 4px 9px;
    border: 1px solid transparent;
    border-radius: var(--ui-pill-radius);
    font-size: .68rem;
    line-height: 1;
    font-weight: 800;
    letter-spacing: .01em;
    white-space: nowrap;
}

/* ---------- Tablas ---------- */
.app-content .table-wrap {
    overflow: hidden;
}

.app-content .table-wrap table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.app-content .table-wrap thead th {
    padding: 12px 14px;
    color: #475467;
    background: var(--ui-surface-soft);
    border-bottom: 1px solid var(--ui-line);
    font-size: .72rem;
    line-height: 1.25;
    font-weight: 800;
    letter-spacing: .025em;
    text-transform: none;
}

.app-content .table-wrap tbody td {
    padding: 13px 14px;
    color: var(--ui-ink-soft);
    border-bottom: 1px solid #edf0f4;
    font-size: .8rem;
    vertical-align: middle;
}

.app-content .table-wrap tbody tr {
    transition: background .14s ease;
}

.app-content .table-wrap tbody tr:hover {
    background: color-mix(in srgb, var(--ui-primary-soft, #f0edfa) 22%, var(--ui-surface));
}

.app-content .table-wrap tbody tr:last-child td {
    border-bottom: 0;
}

.app-content .table-wrap td strong {
    color: var(--ui-ink);
}

.app-content .table-wrap td small {
    margin-top: 3px;
    color: var(--ui-copy);
    line-height: 1.35;
}

.app-content .table-wrap tfoot th,
.app-content .table-wrap tfoot td {
    padding: 12px 14px;
    background: var(--ui-surface-soft);
    border-top: 1px solid var(--ui-line);
    color: var(--ui-ink);
}

/* ---------- Listas campo/valor ---------- */
.app-content .data-list > div,
.app-content .totals-card dl > div {
    min-height: 44px;
    padding: 10px 0;
    border-bottom: 1px solid #edf0f4;
    align-items: center;
}

.app-content .data-list > div:last-child,
.app-content .totals-card dl > div:last-child {
    border-bottom: 0;
}

.app-content .data-list dt,
.app-content .totals-card dt {
    color: var(--ui-copy);
    font-size: .79rem;
    font-weight: 550;
}

.app-content .data-list dd,
.app-content .totals-card dd {
    color: var(--ui-ink);
    font-size: .82rem;
    font-weight: 650;
}

/* ---------- Alertas ---------- */
.app-content .alert {
    padding: 12px 14px;
    border-radius: 11px;
    font-size: .8rem;
    line-height: 1.45;
    box-shadow: none;
}

.app-content .alert-success {
    background: var(--ui-success-soft);
    border-color: #abefc6;
    color: #067647;
}

.app-content .alert-warning {
    background: var(--ui-warning-soft);
    border-color: #fedf89;
    color: #93370d;
}

.app-content .alert-error {
    background: var(--ui-danger-soft);
    border-color: #fecdca;
    color: #b42318;
}

.app-content .alert-info {
    background: var(--ui-info-soft);
    border: 1px solid #b2ddff;
    color: #175cd3;
}

/* ---------- Empty states ---------- */
.app-content .empty-state {
    padding: 28px 18px;
    color: var(--ui-copy);
    font-size: .82rem;
    text-align: center;
}

/* ---------- Vista de detalle premium reutilizable ---------- */
.app-content .document-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 18px;
    align-items: center;
    margin-bottom: 18px;
    padding: 20px 22px;
    border: 1px solid var(--ui-line);
    border-radius: var(--ui-card-radius);
    background: linear-gradient(135deg, var(--ui-surface) 0%, color-mix(in srgb, var(--ui-primary-soft, #f0edfa) 20%, var(--ui-surface)) 100%);
    box-shadow: var(--ui-card-shadow);
}

.app-content .document-hero__eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 5px;
    color: var(--ui-copy);
    font-size: .7rem;
    font-weight: 800;
    letter-spacing: .075em;
    text-transform: uppercase;
}

.app-content .document-hero h1 {
    margin: 0;
    color: var(--ui-ink);
    font-size: clamp(1.55rem, 2.4vw, 2.15rem);
    line-height: 1.14;
    letter-spacing: -.035em;
}

.app-content .document-hero__subtitle {
    margin: 7px 0 0;
    color: var(--ui-copy);
    font-size: .86rem;
}

.app-content .document-hero__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-top: 12px;
    color: var(--ui-copy);
    font-size: .76rem;
}

.app-content .document-hero__meta strong {
    color: var(--ui-ink-soft);
}

.app-content .document-hero__total {
    min-width: 170px;
    padding-left: 20px;
    border-left: 1px solid var(--ui-line);
    text-align: right;
}

.app-content .document-hero__total span {
    display: block;
    margin-bottom: 3px;
    color: var(--ui-copy);
    font-size: .7rem;
    font-weight: 700;
}

.app-content .document-hero__total strong {
    display: block;
    color: var(--ui-ink);
    font-size: 1.55rem;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.app-content .document-actionbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    padding: 10px;
    border: 1px solid var(--ui-line);
    border-radius: 13px;
    background: color-mix(in srgb, var(--ui-surface) 94%, transparent);
    box-shadow: 0 1px 3px rgba(16,24,40,.025);
}

.app-content .document-actionbar__main,
.app-content .document-actionbar__secondary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.app-content .detail-grid {
    grid-template-columns: minmax(0, 1.55fr) minmax(300px, .75fr);
    gap: 18px;
}

.app-content .summary-card {
    position: relative;
}

.app-content .summary-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    border-radius: var(--ui-card-radius) 0 0 var(--ui-card-radius);
    background: color-mix(in srgb, var(--ui-primary, #2d176f) 70%, #fff);
    opacity: .75;
}

.app-content .summary-total-row {
    margin-top: 2px;
    padding: 13px 12px !important;
    border: 1px solid #dce5ef !important;
    border-radius: 10px;
    background: var(--ui-surface-soft);
}

.app-content .summary-total-row dt,
.app-content .summary-total-row dd {
    color: var(--ui-ink) !important;
    font-weight: 800 !important;
}

.app-content .summary-balance-row dd {
    font-size: .94rem;
}

.app-content .grant-card {
    margin-bottom: 18px !important;
}

.app-content .grant-card__body {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
}

.app-content .grant-card__state {
    min-width: 180px;
}

.app-content .grant-card__state-label {
    display: block;
    margin-bottom: 5px;
    color: var(--ui-copy);
    font-size: .72rem;
}

.app-content .grant-card__state strong {
    color: var(--ui-ink);
    font-size: .95rem;
}

/* ---------- Ajustes del tema oscuro ---------- */
html[data-theme="dark"] .app-content .table-wrap tbody td {
    border-bottom-color: color-mix(in srgb, var(--ui-border) 72%, transparent);
}

html[data-theme="dark"] .app-content .data-list > div,
html[data-theme="dark"] .app-content .totals-card dl > div {
    border-bottom-color: color-mix(in srgb, var(--ui-border) 72%, transparent);
}

html[data-theme="dark"] .app-content .summary-total-row {
    background: var(--ui-panel-soft);
    border-color: var(--ui-border-strong) !important;
}

html[data-theme="dark"] .app-content .document-actionbar {
    background: var(--ui-panel);
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .app-content .document-hero {
        grid-template-columns: 1fr;
    }

    .app-content .document-hero__total {
        min-width: 0;
        padding: 14px 0 0;
        border-left: 0;
        border-top: 1px solid var(--ui-line);
        text-align: left;
    }

    .app-content .document-actionbar {
        align-items: stretch;
        flex-direction: column;
    }

    .app-content .detail-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 700px) {
    .app-content .card {
        padding: 17px;
        border-radius: 13px;
    }

    .app-content .document-hero {
        padding: 17px;
        border-radius: 13px;
    }

    .app-content .document-actionbar__main,
    .app-content .document-actionbar__secondary {
        display: grid;
        grid-template-columns: 1fr;
    }

    .app-content .document-actionbar .button {
        width: 100%;
    }

    .app-content .table-wrap {
        overflow-x: auto;
    }

    .app-content .table-wrap table {
        min-width: 680px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-content .button,
    .app-content button.button,
    .app-content .table-wrap tbody tr,
    .app-content input,
    .app-content select,
    .app-content textarea {
        transition: none !important;
    }
}

/* ==========================================================================\n   Fase 2 · Listados comerciales profesionales v254\n   ========================================================================== */
.app-content .commercial-list-page {
    display: grid;
    gap: 18px;
}

.app-content .commercial-list-page > .page-head,
.app-content .commercial-list-page > .card,
.app-content .commercial-list-page > .pagination,
.app-content .commercial-list-page > .page-counter,
.app-content .commercial-list-page > section.card {
    margin: 0;
}

.app-content .commercial-list-head {
    min-height: 74px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.app-content .commercial-list-head__copy {
    min-width: 0;
}

.app-content .commercial-list-head__eyebrow {
    display: block;
    margin-bottom: 4px;
    color: color-mix(in srgb, var(--ui-primary, #2d176f) 76%, var(--ui-copy));
    font-size: .66rem;
    line-height: 1.2;
    font-weight: 800;
    letter-spacing: .09em;
    text-transform: uppercase;
}

.app-content .commercial-list-head__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
    flex-wrap: wrap;
}

.app-content .commercial-list-meta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border: 1px solid var(--ui-line);
    border-radius: var(--ui-pill-radius);
    background: var(--ui-surface);
    color: var(--ui-copy);
    font-size: .71rem;
    font-weight: 700;
    white-space: nowrap;
}

.app-content .commercial-list-meta strong {
    color: var(--ui-ink);
    font-weight: 800;
}

.app-content .commercial-filter-card {
    padding: 0;
    overflow: hidden;
}

.app-content .commercial-filter-card .data-grid-toolbar {
    min-height: 62px;
    padding: 14px 16px;
    border-bottom: 1px solid transparent;
    background: linear-gradient(180deg, var(--ui-surface) 0%, color-mix(in srgb, var(--ui-surface-soft) 62%, var(--ui-surface)) 100%);
}

.app-content .commercial-filter-card:has(.data-grid-filters:not(.is-collapsed)) .data-grid-toolbar {
    border-bottom-color: var(--ui-line);
}

.app-content .commercial-filter-card .data-grid-toolbar strong {
    color: var(--ui-ink);
    font-size: .88rem;
    font-weight: 750;
}

.app-content .commercial-filter-card .data-grid-toolbar small {
    margin-top: 2px;
    color: var(--ui-copy);
    font-size: .72rem;
}

.app-content .commercial-filter-card .advanced-filter-grid {
    margin: 0;
    border: 0;
    background: color-mix(in srgb, var(--ui-surface-soft) 58%, var(--ui-surface));
}

.app-content .commercial-filter-card .advanced-filter-grid label {
    display: grid;
    gap: 6px;
    color: var(--ui-copy);
    font-size: .69rem;
    font-weight: 750;
    letter-spacing: .01em;
}

.app-content .commercial-filter-card .advanced-filter-grid input,
.app-content .commercial-filter-card .advanced-filter-grid select {
    min-height: 40px;
    border-color: var(--ui-line-strong);
    background: var(--ui-surface);
    color: var(--ui-ink);
    font-size: .78rem;
}

.app-content .commercial-table-card {
    padding: 0;
    overflow: hidden;
}

.app-content .commercial-table-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-height: 68px;
    padding: 15px 17px;
    border-bottom: 1px solid var(--ui-line);
    background: linear-gradient(180deg, var(--ui-surface) 0%, color-mix(in srgb, var(--ui-surface-soft) 45%, var(--ui-surface)) 100%);
}

.app-content .commercial-table-card__title {
    min-width: 0;
}

.app-content .commercial-table-card__title .section-kicker {
    display: block;
    margin-bottom: 2px;
}

.app-content .commercial-table-card__title h2 {
    margin: 0;
    color: var(--ui-ink);
    font-size: .98rem;
    line-height: 1.3;
    font-weight: 750;
    letter-spacing: -.012em;
}

.app-content .commercial-table-card__title p {
    margin: 3px 0 0;
    color: var(--ui-copy);
    font-size: .72rem;
    line-height: 1.45;
}

.app-content .commercial-table-card__summary {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.app-content .commercial-table-scroll {
    width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
}

.app-content .commercial-list-table {
    min-width: 860px;
}

.app-content .commercial-list-table thead th {
    padding-top: 11px;
    padding-bottom: 11px;
    background: var(--ui-surface-soft);
    color: #667085;
    font-size: .68rem;
    font-weight: 800;
    letter-spacing: .025em;
}

.app-content .commercial-list-table tbody td {
    min-height: 58px;
    padding-top: 12px;
    padding-bottom: 12px;
}

.app-content .commercial-list-table tbody td > strong:first-child,
.app-content .commercial-list-table tbody td > a:first-child {
    color: var(--ui-ink);
    font-weight: 700;
}

.app-content .commercial-list-table tbody td > small {
    display: block;
    margin-top: 3px;
    color: var(--ui-copy);
    font-size: .69rem;
}

.app-content .commercial-list-table .amount-cell {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.app-content .commercial-list-table .amount-cell strong {
    font-weight: 800;
}

.app-content .commercial-list-table .document-cell strong,
.app-content .commercial-list-table .customer-cell strong {
    display: block;
    max-width: 270px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-content .commercial-list-table .table-actions-column {
    width: 48px;
    padding-left: 8px;
    padding-right: 10px;
    text-align: right;
}

.app-content .commercial-list-table .empty-state {
    padding: 46px 20px;
    color: var(--ui-copy);
    text-align: center;
}

.app-content .commercial-list-table .empty-state::before {
    content: "";
    display: block;
    width: 34px;
    height: 34px;
    margin: 0 auto 10px;
    border: 1px dashed var(--ui-line-strong);
    border-radius: 50%;
    background: var(--ui-surface-soft);
}

.app-content .commercial-list-page .pagination {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 2px;
}

.app-content .commercial-list-page .pagination a {
    min-width: 34px;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    border: 1px solid var(--ui-line);
    border-radius: 9px;
    background: var(--ui-surface);
    color: var(--ui-copy);
    font-size: .74rem;
    font-weight: 750;
    text-decoration: none;
}

.app-content .commercial-list-page .pagination a:hover {
    border-color: color-mix(in srgb, var(--ui-primary, #2d176f) 28%, var(--ui-line));
    color: var(--ui-primary, #2d176f);
}

.app-content .commercial-list-page .pagination a.active {
    border-color: var(--ui-primary, #2d176f);
    background: var(--ui-primary, #2d176f);
    color: #fff;
}

/* Listado de pedidos: sustituye el formulario compacto heredado. */
.app-content .commercial-list-page .commercial-quick-filter {
    display: grid;
    grid-template-columns: minmax(240px, 1.5fr) minmax(180px, .7fr) auto;
    gap: 12px;
    align-items: end;
    padding: 16px;
}

.app-content .commercial-list-page .commercial-quick-filter label {
    display: grid;
    gap: 6px;
    margin: 0;
    color: var(--ui-copy);
    font-size: .7rem;
    font-weight: 750;
}

.app-content .commercial-list-page .commercial-quick-filter .actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin: 0;
}

/* Devoluciones: conserva sus dos bloques pero adopta el mismo lenguaje visual. */
.app-content .commercial-list-page .return-section-card {
    padding: 0;
    margin: 0;
}

.app-content .commercial-list-page .return-section-head {
    min-height: 68px;
    padding: 15px 17px;
    border-bottom-color: var(--ui-line);
    background: linear-gradient(180deg, var(--ui-surface) 0%, color-mix(in srgb, var(--ui-surface-soft) 45%, var(--ui-surface)) 100%);
}

html[data-theme="dark"] .app-content .commercial-filter-card .data-grid-toolbar,
html[data-theme="dark"] .app-content .commercial-table-card__head,
html[data-theme="dark"] .app-content .commercial-list-page .return-section-head {
    background: var(--ui-panel);
}

@media (max-width: 900px) {
    .app-content .commercial-list-head {
        align-items: flex-start;
        flex-direction: column;
        min-height: 0;
    }

    .app-content .commercial-list-head__actions {
        width: 100%;
        justify-content: flex-start;
    }

    .app-content .commercial-list-page .commercial-quick-filter {
        grid-template-columns: 1fr 1fr;
    }

    .app-content .commercial-list-page .commercial-quick-filter .actions {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }
}

@media (max-width: 620px) {
    .app-content .commercial-list-page {
        gap: 14px;
    }

    .app-content .commercial-list-head__actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .app-content .commercial-list-head__actions .button,
    .app-content .commercial-list-head__actions .commercial-list-meta {
        width: 100%;
    }

    .app-content .commercial-table-card__head {
        align-items: flex-start;
        flex-direction: column;
    }

    .app-content .commercial-table-card__summary {
        width: 100%;
    }

    .app-content .commercial-list-page .commercial-quick-filter {
        grid-template-columns: 1fr;
    }

    .app-content .commercial-list-page .commercial-quick-filter .actions {
        grid-column: auto;
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}

/* ==========================================================================\n   UI Fase 3 · Formularios comerciales v255\n   ========================================================================== */
.app-content .commercial-form-page {
    display: grid;
    gap: 18px;
    padding-bottom: 92px;
}

.app-content .commercial-form-head {
    min-height: 62px;
    margin-bottom: 0;
}

.app-content .commercial-form-eyebrow,
.app-content .commercial-summary-kicker {
    display: block;
    margin-bottom: 5px;
    color: var(--ui-primary, #2d176f);
    font-size: .66rem;
    font-weight: 850;
    letter-spacing: .075em;
    text-transform: uppercase;
}

.app-content .commercial-form-layout {
    display: grid;
    gap: 18px;
}

.app-content .commercial-form-section {
    position: relative;
    border-color: var(--ui-line);
    border-radius: 16px;
    background: var(--ui-surface);
    box-shadow: var(--ui-card-shadow);
}

.app-content .commercial-form-section::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    border-radius: 16px 0 0 16px;
    background: color-mix(in srgb, var(--ui-primary, #2d176f) 58%, #ffffff);
    opacity: .7;
}

.app-content .commercial-form-section--items::before {
    background: #2e90fa;
}

.app-content .commercial-form-section--payment::before,
.app-content .commercial-form-section--terms::before {
    background: #12b76a;
}

.app-content .commercial-form-section--notes::before {
    background: #98a2b3;
}

.app-content .commercial-form-section-head {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: flex-start;
    margin-bottom: 18px;
}

.app-content .commercial-form-section-head > div:first-child {
    min-width: 0;
}

.app-content .commercial-form-step {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid color-mix(in srgb, var(--ui-primary, #2d176f) 20%, var(--ui-line));
    border-radius: 10px;
    background: color-mix(in srgb, var(--ui-primary-soft, #f0edfa) 62%, #fff);
    color: var(--ui-primary, #2d176f);
    font-size: .72rem;
    font-weight: 850;
}

.app-content .commercial-form-grid {
    gap: 14px 16px;
}

.app-content .commercial-form-grid label,
.app-content .commercial-form-full {
    display: grid;
    gap: 7px;
    margin: 0;
    color: var(--ui-ink-soft);
    font-size: .74rem;
    font-weight: 750;
}

.app-content .commercial-form-grid--single {
    grid-template-columns: 1fr;
}

.app-content .commercial-form-full textarea {
    width: 100%;
    min-height: 104px;
    resize: vertical;
}

.app-content .commercial-form-two-column {
    display: grid;
    grid-template-columns: minmax(0, 1.7fr) minmax(280px, .8fr);
    gap: 18px;
    align-items: start;
}

.app-content .commercial-form-summary-card {
    position: sticky;
    top: 84px;
    align-self: start;
    border: 1px solid color-mix(in srgb, var(--ui-primary, #2d176f) 14%, var(--ui-line));
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--ui-primary-soft, #f0edfa) 42%, #fff) 0%, var(--ui-surface) 38%);
}

.app-content .commercial-form-summary-card h2 {
    margin: 0 0 14px;
    color: var(--ui-ink);
    font-size: 1.08rem;
}

.app-content .commercial-summary-list {
    display: grid;
    gap: 0;
    margin: 0;
}

.app-content .commercial-summary-list > div {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 11px 0;
    border-bottom: 1px solid var(--ui-line);
}

.app-content .commercial-summary-list dt {
    color: var(--ui-copy);
    font-size: .72rem;
    font-weight: 700;
}

.app-content .commercial-summary-list dd {
    margin: 0;
    color: var(--ui-ink);
    font-size: .76rem;
    font-weight: 780;
    text-align: right;
}

.app-content .commercial-summary-list .grand-total {
    margin-top: 5px;
    padding: 14px 12px;
    border: 0;
    border-radius: 11px;
    background: color-mix(in srgb, var(--ui-primary-soft, #f0edfa) 65%, #fff);
}

.app-content .commercial-summary-list .grand-total dt,
.app-content .commercial-summary-list .grand-total dd {
    color: var(--ui-primary, #2d176f);
    font-size: .84rem;
    font-weight: 850;
}

.app-content .commercial-summary-note {
    margin-top: 14px;
    padding: 12px 13px;
    border: 1px solid var(--ui-line);
    border-radius: 10px;
    background: var(--ui-surface-soft);
    color: var(--ui-copy);
    font-size: .7rem;
    line-height: 1.5;
}

.app-content .commercial-form-actionbar {
    border: 1px solid var(--ui-line);
    border-radius: 14px;
    background: color-mix(in srgb, var(--ui-surface) 94%, transparent);
    box-shadow: 0 -5px 24px rgba(16,24,40,.045);
    backdrop-filter: blur(12px);
}

.app-content .commercial-form-actionbar--page {
    position: sticky;
    z-index: 16;
    bottom: 12px;
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 14px 12px 16px;
}

.app-content .commercial-form-actionbar .actions,
.app-content .commercial-form-actionbar--page > .button,
.app-content .commercial-form-actionbar--page > button {
    flex: 0 0 auto;
}

.app-content .commercial-form-action-copy {
    min-width: 0;
    display: grid;
    gap: 3px;
}

.app-content .commercial-form-action-copy strong {
    color: var(--ui-ink);
    font-size: .78rem;
}

.app-content .commercial-form-action-copy span {
    color: var(--ui-copy);
    font-size: .68rem;
}

.app-content .commercial-form-notice {
    margin: 0;
}

/* Pedidos de venta */
.app-content .commercial-order-lines {
    display: grid;
    gap: 10px;
}

.app-content .commercial-order-line {
    display: grid;
    grid-template-columns: 32px minmax(250px, 2fr) minmax(105px, .55fr) minmax(115px, .6fr) minmax(115px, .6fr) auto;
    gap: 10px;
    align-items: end;
    padding: 12px;
    border: 1px solid var(--ui-line);
    border-radius: 12px;
    background: var(--ui-surface-soft);
}

.app-content .commercial-order-line label {
    display: grid;
    gap: 6px;
    color: var(--ui-copy);
    font-size: .68rem;
    font-weight: 750;
}

.app-content .commercial-order-line__number {
    width: 28px;
    height: 28px;
    align-self: center;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--ui-surface);
    color: var(--ui-copy);
    border: 1px solid var(--ui-line);
    font-size: .68rem;
    font-weight: 800;
}

.app-content .commercial-order-line .button.compact {
    min-height: 42px;
    padding-inline: 12px;
}

/* POS / venta / cotización: misma base sin alterar su lógica especializada. */
.app-content .commercial-sale-form-page .pos-sheet,
.app-content .commercial-quotation-form-page .pos-sheet {
    border-color: var(--ui-line);
    border-radius: 16px;
    box-shadow: var(--ui-card-shadow);
}

.app-content .commercial-sale-form-page .pos-products-section,
.app-content .commercial-quotation-form-page .quotation-products-section {
    overflow: hidden;
}

.app-content .commercial-sale-form-page .pos-product-toolbar,
.app-content .commercial-quotation-form-page .pos-product-toolbar {
    padding-bottom: 12px;
    border-bottom: 1px solid var(--ui-line);
}

.app-content .commercial-sale-form-page .pos-lines-wrap,
.app-content .commercial-quotation-form-page .pos-lines-wrap {
    margin-top: 12px;
    border: 1px solid var(--ui-line);
    border-radius: 12px;
}

.app-content .commercial-sale-form-page .commercial-form-summary-card,
.app-content .commercial-quotation-form-page .commercial-form-summary-card {
    top: 78px;
}

.app-content .commercial-sale-form-page .commercial-form-actionbar,
.app-content .commercial-quotation-form-page .commercial-form-actionbar {
    border-color: var(--ui-line);
}

/* Anticipos */
.app-content .commercial-advance-form-page .advance-create-main,
.app-content .commercial-advance-form-page .advance-create-preview {
    border-radius: 16px;
    box-shadow: var(--ui-card-shadow);
}

.app-content .commercial-advance-form-page .advance-selected-summary {
    border-radius: 12px;
    border-color: var(--ui-line);
}

/* Devoluciones */
.app-content .commercial-return-form-page .commercial-form-context-grid .card {
    min-height: 100%;
}

.app-content .commercial-return-form-page .return-product-card {
    overflow: hidden;
}

.app-content .commercial-return-form-page .return-serial-table {
    min-width: 820px;
}

.app-content .commercial-return-form-page .form-actions.commercial-form-actionbar {
    flex-wrap: wrap;
}

html[data-theme="dark"] .app-content .commercial-form-section,
html[data-theme="dark"] .app-content .commercial-form-summary-card,
html[data-theme="dark"] .app-content .commercial-order-line,
html[data-theme="dark"] .app-content .commercial-form-actionbar {
    background: var(--ui-panel);
}

html[data-theme="dark"] .app-content .commercial-summary-list .grand-total,
html[data-theme="dark"] .app-content .commercial-form-step {
    background: color-mix(in srgb, var(--ui-primary, #7c6ee6) 14%, var(--ui-panel));
}

@media (max-width: 1100px) {
    .app-content .commercial-order-line {
        grid-template-columns: 32px minmax(220px, 1.8fr) repeat(3, minmax(95px, .6fr));
    }

    .app-content .commercial-order-line .remove-line {
        grid-column: 2 / -1;
        justify-self: end;
    }
}

@media (max-width: 900px) {
    .app-content .commercial-form-two-column {
        grid-template-columns: 1fr;
    }

    .app-content .commercial-form-summary-card {
        position: static;
    }

    .app-content .commercial-form-actionbar--page {
        align-items: flex-start;
        flex-direction: column;
    }

    .app-content .commercial-form-actionbar--page .actions {
        width: 100%;
    }

    .app-content .commercial-order-line {
        grid-template-columns: 32px 1fr 1fr;
    }

    .app-content .commercial-order-line__product {
        grid-column: 2 / -1;
    }

    .app-content .commercial-order-line .remove-line {
        grid-column: 2 / -1;
    }
}

@media (max-width: 620px) {
    .app-content .commercial-form-page {
        gap: 14px;
        padding-bottom: 74px;
    }

    .app-content .commercial-form-section {
        padding: 17px;
    }

    .app-content .commercial-form-section-head {
        margin-bottom: 14px;
    }

    .app-content .commercial-form-step {
        display: none;
    }

    .app-content .commercial-form-actionbar--page {
        bottom: 8px;
        padding: 10px;
    }

    .app-content .commercial-form-actionbar--page .actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .app-content .commercial-form-actionbar--page .button,
    .app-content .commercial-form-actionbar--page button {
        width: 100%;
    }

    .app-content .commercial-order-line {
        grid-template-columns: 28px 1fr;
        padding: 10px;
    }

    .app-content .commercial-order-line__product,
    .app-content .commercial-order-line label,
    .app-content .commercial-order-line .remove-line {
        grid-column: 2;
    }
}


/* ==========================================================================\n   Fase 4 · Vistas de detalle comerciales profesionales v256\n   ========================================================================== */
.app-content .commercial-detail-page {
    display: grid;
    gap: 18px;
}
.app-content .commercial-detail-page > .document-hero,
.app-content .commercial-detail-page > .document-actionbar,
.app-content .commercial-detail-page > .card,
.app-content .commercial-detail-page > .detail-grid,
.app-content .commercial-detail-page > .alert {
    margin-top: 0;
    margin-bottom: 0;
}
.app-content .document-hero__statusline {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 12px;
}
.app-content .document-hero__total small {
    display: block;
    margin-top: 5px;
    color: var(--ui-copy);
    font-size: .69rem;
    line-height: 1.35;
}
.app-content .detail-section-card {
    padding: 0;
    overflow: hidden;
}
.app-content .detail-section-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 64px;
    padding: 14px 17px;
    border-bottom: 1px solid var(--ui-line);
    background: linear-gradient(180deg, var(--ui-surface) 0%, color-mix(in srgb, var(--ui-surface-soft) 52%, var(--ui-surface)) 100%);
}
.app-content .detail-section-card__head h2,
.app-content .detail-section-card__head h3 {
    margin: 0;
    color: var(--ui-ink);
    font-size: .96rem;
    line-height: 1.3;
    font-weight: 750;
}
.app-content .detail-section-card__head p {
    margin: 3px 0 0;
    color: var(--ui-copy);
    font-size: .72rem;
}
.app-content .detail-section-card__body {
    padding: 18px;
}
.app-content .detail-key-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 20px;
}
.app-content .detail-key-grid > div {
    min-height: 52px;
    padding: 11px 0;
    border-bottom: 1px solid #edf0f4;
}
.app-content .detail-key-grid dt {
    margin-bottom: 4px;
    color: var(--ui-copy);
    font-size: .7rem;
    font-weight: 700;
}
.app-content .detail-key-grid dd {
    margin: 0;
    color: var(--ui-ink);
    font-size: .82rem;
    font-weight: 650;
    line-height: 1.4;
}
.app-content .financial-highlight {
    padding: 13px 14px;
    border: 1px solid color-mix(in srgb, var(--ui-primary, #2d176f) 18%, var(--ui-line));
    border-radius: 12px;
    background: color-mix(in srgb, var(--ui-primary-soft, #f0edfa) 42%, var(--ui-surface));
}
.app-content .financial-highlight span {
    display: block;
    color: var(--ui-copy);
    font-size: .69rem;
    font-weight: 700;
}
.app-content .financial-highlight strong {
    display: block;
    margin-top: 4px;
    color: var(--ui-ink);
    font-size: 1.08rem;
    font-variant-numeric: tabular-nums;
}
.app-content .detail-timeline {
    display: grid;
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}
.app-content .detail-timeline__item {
    position: relative;
    display: grid;
    grid-template-columns: 18px minmax(0,1fr);
    gap: 11px;
    padding: 0 0 18px;
}
.app-content .detail-timeline__item:last-child { padding-bottom: 0; }
.app-content .detail-timeline__marker {
    position: relative;
    width: 10px;
    height: 10px;
    margin: 5px auto 0;
    border-radius: 50%;
    background: var(--ui-primary, #2d176f);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--ui-primary, #2d176f) 12%, transparent);
}
.app-content .detail-timeline__item:not(:last-child) .detail-timeline__marker::after {
    content: "";
    position: absolute;
    top: 13px;
    left: 4px;
    width: 2px;
    height: calc(100% + 18px);
    background: var(--ui-line);
}
.app-content .detail-timeline__content strong {
    display: block;
    color: var(--ui-ink);
    font-size: .8rem;
}
.app-content .detail-timeline__content p {
    margin: 3px 0 0;
    color: var(--ui-copy);
    font-size: .75rem;
    line-height: 1.45;
}
.app-content .detail-timeline__content small {
    display: block;
    margin-top: 4px;
    color: var(--ui-copy-soft);
    font-size: .68rem;
}
.app-content .detail-danger-zone {
    border-color: #fecdca !important;
    background: color-mix(in srgb, var(--ui-danger-soft) 42%, var(--ui-surface));
}
.app-content .detail-danger-zone h3 { color: #b42318; }
.app-content .detail-inline-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
.app-content .detail-inline-actions form { margin: 0; }
.app-content .document-actionbar .button.small { min-height: 36px; }

@media (max-width: 760px) {
    .app-content .detail-key-grid { grid-template-columns: 1fr; }
    .app-content .detail-section-card__head { align-items: flex-start; flex-direction: column; }
}


/* v295.0.3 · POS: feedback flotante sin desplazar el terminal */
.app-content .app-flash-stack.pos-flash-toast-stack {
    position: fixed;
    top: 88px;
    right: 18px;
    z-index: 6000;
    width: min(460px, calc(100vw - 36px));
    margin: 0;
    pointer-events: none;
}
.app-content .pos-flash-toast-stack .app-feedback {
    pointer-events: auto;
    border-radius: 14px;
    box-shadow: 0 18px 42px rgba(16, 24, 40, .18);
    backdrop-filter: blur(8px);
}
.app-content .pos-flash-toast-stack .app-feedback.is-leaving {
    transform: translateY(-10px) scale(.985);
}
@media (max-width: 760px) {
    .app-content .app-flash-stack.pos-flash-toast-stack {
        top: 74px;
        left: 12px;
        right: 12px;
        width: auto;
    }
}

/* ==========================================================================\n   UI Fase 5 v257 · Feedback, confirmaciones, estados vacíos y acciones\n   ========================================================================== */
.app-content .app-flash-stack {
    position: relative;
    display: grid;
    gap: 10px;
    margin: 0 0 18px;
}

.app-content .app-feedback {
    position: relative;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 30px;
    gap: 11px;
    align-items: center;
    min-height: 58px;
    margin: 0;
    padding: 11px 12px;
    border-width: 1px;
    border-style: solid;
    box-shadow: 0 10px 26px rgba(16, 24, 40, .06);
    animation: ui-feedback-enter .2s ease both;
}

.app-content .app-feedback.is-leaving {
    opacity: 0;
    transform: translateY(-5px);
    transition: opacity .18s ease, transform .18s ease;
}

.app-feedback__icon {
    width: 32px;
    height: 32px;
    display: inline-grid;
    place-items: center;
    border-radius: 9px;
    font-size: .9rem;
    font-weight: 900;
    background: color-mix(in srgb, currentColor 11%, transparent);
}

.app-feedback__copy {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.app-feedback__copy strong {
    color: currentColor;
    font-size: .79rem;
    line-height: 1.25;
}

.app-feedback__copy span {
    color: color-mix(in srgb, currentColor 86%, var(--ui-ink));
    font-size: .77rem;
    line-height: 1.42;
}

.app-feedback__close {
    width: 30px;
    height: 30px;
    display: inline-grid;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: currentColor;
    font-size: 1rem;
    cursor: pointer;
    opacity: .65;
}

.app-feedback__close:hover,
.app-feedback__close:focus-visible {
    opacity: 1;
    background: color-mix(in srgb, currentColor 8%, transparent);
    outline: none;
}

@keyframes ui-feedback-enter {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

.ux-confirm-dialog {
    width: min(470px, calc(100vw - 28px));
    padding: 0;
    border: 0;
    border-radius: 18px;
    background: transparent;
    box-shadow: 0 28px 80px rgba(15, 23, 42, .25);
}

.ux-confirm-dialog::backdrop {
    background: rgba(15, 23, 42, .48);
    backdrop-filter: blur(2px);
}

.ux-confirm-panel {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 14px;
    margin: 0;
    padding: 22px;
    border: 1px solid var(--ui-line);
    border-radius: 18px;
    background: var(--ui-surface);
    color: var(--ui-ink);
}

.ux-confirm-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: var(--ui-warning-soft);
    color: #b54708;
    font-size: 1.05rem;
    font-weight: 900;
}

.ux-confirm-dialog[data-tone="danger"] .ux-confirm-icon { background: var(--ui-danger-soft); color: #b42318; }
.ux-confirm-dialog[data-tone="info"] .ux-confirm-icon { background: var(--ui-info-soft); color: #175cd3; }

.ux-confirm-copy h2 {
    margin: 2px 0 7px;
    color: var(--ui-ink);
    font-size: 1.08rem;
    line-height: 1.3;
}

.ux-confirm-copy p {
    margin: 0;
    color: var(--ui-copy);
    font-size: .81rem;
    line-height: 1.55;
}

.ux-confirm-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 5px;
    padding-top: 16px;
    border-top: 1px solid var(--ui-line);
}

.ux-confirm-dialog[data-tone="danger"] [data-ux-confirm-accept] {
    background: #d92d20;
    border-color: #d92d20;
    color: #fff;
}

.app-content form[aria-busy="true"] button[type="submit"].is-busy {
    position: relative;
    cursor: wait;
    opacity: .82;
}

.app-content form[aria-busy="true"] button[type="submit"].is-busy::before {
    content: "";
    width: 13px;
    height: 13px;
    flex: 0 0 13px;
    border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: ui-action-spin .65s linear infinite;
}

@keyframes ui-action-spin { to { transform: rotate(360deg); } }

.app-content .empty-state .empty-state__content {
    display: grid;
    justify-items: center;
    gap: 5px;
    max-width: 460px;
    margin: 0 auto;
}

.app-content .empty-state .empty-state__content strong {
    color: var(--ui-ink-soft);
    font-size: .8rem;
    font-weight: 800;
}

.app-content .empty-state .empty-state__content span {
    max-width: 420px;
    color: var(--ui-copy);
    font-size: .72rem;
    line-height: 1.45;
}

.app-content .document-hero__statusline .badge,
.app-content .commercial-list-table .badge,
.app-content .detail-section-card .badge {
    box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 8%, transparent);
}

@media (max-width: 600px) {
    .ux-confirm-panel { grid-template-columns: 38px minmax(0, 1fr); padding: 18px; }
    .ux-confirm-icon { width: 36px; height: 36px; }
    .ux-confirm-actions { justify-content: stretch; }
    .ux-confirm-actions .button { flex: 1; }
    .app-content .app-feedback { grid-template-columns: 30px minmax(0, 1fr) 28px; }
    .app-feedback__icon { width: 28px; height: 28px; }
}

@media (prefers-reduced-motion: reduce) {
    .app-content .app-feedback { animation: none; }
    .app-content form[aria-busy="true"] button[type="submit"].is-busy::before { animation-duration: 1.2s; }
}

/* ==========================================================================
   UI Fase 6 v258 · Responsive y adaptación por dispositivo
   PC / laptop / tablet / móvil. Sin cambios en lógica funcional.
   ========================================================================== */

/* Evitar que contenido flexible fuerce desbordes horizontales. */
.app-content,
.app-content > *,
.app-content .card,
.app-content .commercial-form-layout,
.app-content .commercial-list-page,
.app-content .commercial-detail-page,
.app-content .detail-section-card,
.app-content .document-hero,
.app-content .commercial-table-card {
    min-width: 0;
}

.app-content img,
.app-content video,
.app-content canvas,
.app-content svg {
    max-width: 100%;
}

/* Tablas comerciales: scroll predecible, barra visible y acciones accesibles. */
.app-content .commercial-table-scroll,
.app-content .table-wrap,
.app-content .professional-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--ui-copy) 34%, transparent) transparent;
}

.app-content .commercial-table-scroll::-webkit-scrollbar,
.app-content .table-wrap::-webkit-scrollbar,
.app-content .professional-table-wrap::-webkit-scrollbar {
    height: 8px;
}

.app-content .commercial-table-scroll::-webkit-scrollbar-thumb,
.app-content .table-wrap::-webkit-scrollbar-thumb,
.app-content .professional-table-wrap::-webkit-scrollbar-thumb {
    border: 2px solid transparent;
    border-radius: 999px;
    background: color-mix(in srgb, var(--ui-copy) 32%, transparent);
    background-clip: padding-box;
}

.app-content .commercial-list-table,
.app-content .professional-table,
.app-content .return-professional-table {
    min-width: 760px;
}

/* Inputs y selects jamás deben desbordar su columna. */
.app-content input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.app-content select,
.app-content textarea,
.app-content .field-with-action,
.app-content .field-action-row {
    max-width: 100%;
    min-width: 0;
}

/* Desktop ancho: aprovechar mejor el espacio sin estirar excesivamente el contenido. */
@media (min-width: 1440px) {
    .app-content .commercial-list-page,
    .app-content .commercial-form-page,
    .app-content .commercial-detail-page {
        width: 100%;
    }

    .app-content .commercial-form-two-column {
        grid-template-columns: minmax(0, 1.9fr) minmax(300px, .72fr);
    }

    .app-content .document-hero {
        grid-template-columns: minmax(0, 1fr) minmax(260px, auto);
    }
}

/* Laptop / tablet horizontal. */
@media (max-width: 1180px) {
    .app-content .card {
        padding: 18px;
    }

    .app-content .commercial-form-section,
    .app-content .detail-section-card {
        padding: 18px;
    }

    .app-content .commercial-form-two-column {
        grid-template-columns: minmax(0, 1.45fr) minmax(260px, .75fr);
        gap: 14px;
    }

    .app-content .commercial-form-summary-card {
        top: 72px;
    }

    .app-content .commercial-list-head,
    .app-content .page-head {
        gap: 12px;
    }

    .app-content .document-actionbar {
        gap: 10px;
    }

    .app-content .document-actionbar__main,
    .app-content .document-actionbar__secondary {
        flex-wrap: wrap;
    }
}

/* Tablet: una columna, acciones cómodas y tablas con última columna fija. */
@media (max-width: 980px) {
    .app-content .commercial-form-two-column,
    .app-content .detail-grid,
    .app-content .purchase-bottom-grid,
    .app-content .commercial-form-context-grid {
        grid-template-columns: 1fr !important;
    }

    .app-content .commercial-form-summary-card {
        position: static;
        order: 20;
    }

    .app-content .commercial-list-head,
    .app-content .document-hero,
    .app-content .page-head {
        align-items: flex-start;
    }

    .app-content .document-hero__total {
        min-width: 190px;
    }

    .app-content .commercial-list-head__actions,
    .app-content .document-actionbar {
        width: 100%;
    }

    .app-content .commercial-list-head__actions {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .app-content .commercial-list-table th:last-child,
    .app-content .commercial-list-table td:last-child {
        position: sticky;
        right: 0;
        z-index: 2;
        background: var(--ui-surface);
        box-shadow: -10px 0 18px -18px rgba(15, 23, 42, .55);
    }

    .app-content .commercial-list-table thead th:last-child {
        z-index: 3;
        background: var(--ui-surface-soft);
    }

    .app-content .commercial-list-table tbody tr:hover td:last-child {
        background: color-mix(in srgb, var(--ui-primary-soft, #f0edfa) 22%, var(--ui-surface));
    }

    .app-content .commercial-form-actionbar--page {
        position: static;
        margin-top: 4px;
        box-shadow: var(--ui-card-shadow);
        backdrop-filter: none;
    }

    .app-content .commercial-form-page {
        padding-bottom: 20px;
    }
}

/* Tablet vertical / móvil grande. */
@media (max-width: 760px) {
    .app-content {
        overflow-x: clip;
    }

    .app-content .page-head,
    .app-content .commercial-list-head,
    .app-content .document-hero,
    .app-content .section-head,
    .app-content .detail-section-card__head {
        flex-direction: column;
        align-items: stretch;
    }

    .app-content .page-head > .actions,
    .app-content .commercial-list-head__actions,
    .app-content .document-actionbar,
    .app-content .document-actionbar__main,
    .app-content .document-actionbar__secondary {
        width: 100%;
    }

    .app-content .document-actionbar,
    .app-content .document-actionbar__main,
    .app-content .document-actionbar__secondary {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .app-content .document-actionbar .button,
    .app-content .document-actionbar button,
    .app-content .document-actionbar form,
    .app-content .document-actionbar form .button,
    .app-content .document-actionbar form button {
        width: 100%;
        min-width: 0;
    }

    .app-content .commercial-list-head__actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .app-content .commercial-list-head__actions > .button,
    .app-content .commercial-list-head__actions > button,
    .app-content .commercial-list-head__actions > form,
    .app-content .commercial-list-head__actions > form .button,
    .app-content .commercial-list-head__actions .commercial-list-meta {
        width: 100%;
    }

    .app-content .commercial-list-meta {
        justify-content: center;
    }

    .app-content .document-hero__total {
        width: 100%;
        min-width: 0;
        text-align: left;
    }

    .app-content .document-hero__meta,
    .app-content .document-hero__statusline,
    .app-content .detail-inline-actions,
    .app-content .actions {
        flex-wrap: wrap;
    }

    .app-content .commercial-form-grid,
    .app-content .form-grid,
    .app-content .compact-form-grid,
    .app-content .advanced-filter-grid,
    .app-content .data-grid-filters,
    .app-content .info-grid,
    .app-content .metric-grid,
    .app-content .footer-grid,
    .app-content .pos-bottom-grid,
    .app-content .quotation-bottom-grid-v58 {
        grid-template-columns: 1fr !important;
    }

    .app-content .commercial-order-line {
        grid-template-columns: 28px minmax(0, 1fr) !important;
    }

    .app-content .commercial-order-line > *:not(.commercial-order-line__number) {
        grid-column: 2 !important;
    }

    .app-content .commercial-table-card,
    .app-content .commercial-form-section,
    .app-content .detail-section-card,
    .app-content .card {
        border-radius: 13px;
    }

    .app-content .commercial-list-table,
    .app-content .professional-table,
    .app-content .return-professional-table {
        min-width: 680px;
    }

    .app-content .commercial-list-table thead th,
    .app-content .commercial-list-table tbody td {
        padding-left: 11px;
        padding-right: 11px;
    }

    .app-content .pagination {
        max-width: 100%;
        overflow-x: auto;
        justify-content: flex-start;
        padding-bottom: 3px;
        scrollbar-width: none;
    }

    .app-content .pagination::-webkit-scrollbar {
        display: none;
    }

    /* Modales: alto útil completo, header/footer fijos dentro del panel. */
    .app-modal,
    .entity-modal-wide,
    .product-modal,
    .address-book-modal,
    .entity-modal-compact,
    .quotation-discount-review-dialog,
    .ux-confirm-dialog {
        max-width: calc(100vw - 16px) !important;
    }

    .app-modal-panel,
    .entity-modal-panel,
    .product-modal-panel,
    .address-book-panel {
        max-height: calc(100dvh - 16px) !important;
        overflow: hidden;
    }

    .app-modal-body,
    .entity-modal-body,
    .product-modal-body,
    .address-book-body,
    .modal-body {
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
}

/* Móvil compacto. */
@media (max-width: 560px) {
    .app-content .card,
    .app-content .commercial-form-section,
    .app-content .detail-section-card {
        padding: 14px;
    }

    .app-content .page-head h1,
    .app-content .document-hero h1 {
        font-size: 1.32rem;
    }

    .app-content .page-head .muted,
    .app-content .page-head p,
    .app-content .document-hero__subtitle {
        font-size: .8rem;
    }

    .app-content .commercial-list-head__actions,
    .app-content .document-actionbar,
    .app-content .document-actionbar__main,
    .app-content .document-actionbar__secondary {
        grid-template-columns: 1fr;
    }

    .app-content .button,
    .app-content button.button {
        min-height: 42px;
        padding: 10px 12px;
    }

    .app-content .commercial-form-actionbar--page,
    .app-content .form-actions {
        width: 100%;
    }

    .app-content .form-actions {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .app-content .form-actions .button,
    .app-content .form-actions button,
    .app-content .form-actions form,
    .app-content .form-actions form .button,
    .app-content .form-actions form button {
        width: 100%;
    }

    .app-content .commercial-list-table,
    .app-content .professional-table,
    .app-content .return-professional-table {
        min-width: 620px;
    }

    .app-content .commercial-summary-list > div,
    .app-content .data-list > div,
    .app-content .totals-card dl > div {
        align-items: flex-start;
        gap: 8px;
    }

    .app-content .commercial-summary-list dd,
    .app-content .data-list dd,
    .app-content .totals-card dd {
        overflow-wrap: anywhere;
    }

    .ux-confirm-panel {
        max-height: calc(100dvh - 20px);
        overflow-y: auto;
    }
}

/* Terminal POS: preservar usabilidad táctil y evitar cortes en tablet. */
@media (min-width: 601px) and (max-width: 900px) {
    .terminal-pos-products {
        min-height: 520px;
        height: 56vh;
    }

    .terminal-pos-cart {
        min-height: 560px;
    }

    .terminal-pos-product-grid {
        grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    }
}

@media (max-width: 600px) {
    .terminal-pos {
        min-width: 0;
    }

    .terminal-pos-products,
    .terminal-pos-cart {
        min-width: 0;
    }

    .terminal-pos-document-tabs,
    .terminal-pos-categories {
        scrollbar-width: none;
    }

    .terminal-pos-document-tabs::-webkit-scrollbar,
    .terminal-pos-categories::-webkit-scrollbar {
        display: none;
    }
}


/* ==========================================================================
   UI Fase 7 v259 · Accesibilidad y legibilidad
   ========================================================================== */

/* Enlace de salto visible solo al navegar con teclado. */
.skip-link {
    position: fixed;
    top: 10px;
    left: 12px;
    z-index: 10000;
    max-width: calc(100vw - 24px);
    padding: 10px 14px;
    border: 2px solid currentColor;
    border-radius: 10px;
    background: var(--ui-surface, #fff);
    color: var(--ui-primary, #2d176f);
    font-weight: 800;
    text-decoration: none;
    box-shadow: 0 8px 28px rgba(15, 23, 42, .18);
    transform: translateY(-160%);
    transition: transform .14s ease;
}

.skip-link:focus,
.skip-link:focus-visible {
    transform: translateY(0);
    outline: 3px solid color-mix(in srgb, var(--ui-primary, #2d176f) 38%, transparent);
    outline-offset: 2px;
}

#main-content:focus {
    outline: none;
}

/* Foco consistente para cualquier control interactivo del shell y contenido. */
:where(
    .app-shell,
    .app-content,
    .guest-content
) :where(
    a[href],
    button,
    summary,
    input:not([type="hidden"]),
    select,
    textarea,
    [role="button"],
    [role="menuitem"],
    [role="option"],
    [tabindex]:not([tabindex="-1"])
):focus-visible {
    outline: 3px solid color-mix(in srgb, var(--ui-primary, #2d176f) 40%, transparent);
    outline-offset: 2px;
}

/* No ocultar el foco por sombras de componentes existentes. */
.app-content .button:focus-visible,
.app-content button.button:focus-visible,
.table-action-trigger:focus-visible,
.sidebar-toggle:focus-visible,
.topbar-quick-edit:focus-visible,
.modal-close:focus-visible,
.quick-actions-close:focus-visible,
.app-feedback__close:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--ui-primary, #2d176f) 44%, transparent);
    outline-offset: 2px;
    box-shadow: none;
}

/* Área de interacción mínima recomendada sin inflar visualmente los iconos. */
:where(.app-shell, .app-content) :where(
    button,
    .button,
    .table-action-trigger,
    .modal-close,
    .quick-actions-close,
    .app-feedback__close,
    .sidebar-submenu-action
) {
    min-height: 44px;
}

:where(.app-shell, .app-content) :where(
    .table-action-trigger,
    .modal-close,
    .quick-actions-close,
    .app-feedback__close
) {
    min-width: 44px;
}

/* Texto secundario más legible; se evita usar grises demasiado tenues. */
.app-content :where(.muted, small, .commercial-list-subtitle, .document-hero__subtitle, .section-head p) {
    color: color-mix(in srgb, var(--ui-copy, #667085) 92%, var(--ui-ink, #172033));
}

.app-content :where(label, .field-label) {
    font-weight: 650;
    line-height: 1.35;
}

.app-content :where(input, select, textarea)::placeholder {
    color: color-mix(in srgb, var(--ui-copy, #667085) 82%, transparent);
    opacity: 1;
}

/* Campos inválidos: borde + iconografía/estado, no solo color. */
.app-content :where(input, select, textarea)[aria-invalid="true"],
.app-content :where(input, select, textarea):user-invalid {
    border-color: #b42318;
    box-shadow: 0 0 0 3px rgba(180, 35, 24, .12);
}

.app-content :where(input, select, textarea)[aria-invalid="true"]:focus-visible,
.app-content :where(input, select, textarea):user-invalid:focus-visible {
    outline-color: #b42318;
}

/* Controles deshabilitados siguen siendo legibles. */
.app-content :where(input, select, textarea, button):disabled,
.app-content :where(.button)[aria-disabled="true"] {
    opacity: .64;
    cursor: not-allowed;
}

/* Tablas: cabeceras más contrastadas y foco visible en acciones internas. */
.app-content .table-wrap thead th,
.app-content .commercial-list-table thead th {
    color: color-mix(in srgb, var(--ui-ink, #172033) 82%, var(--ui-copy, #667085));
}

.app-content .table-wrap tbody td,
.app-content .commercial-list-table tbody td {
    line-height: 1.45;
}

/* Status/badges siempre conservan texto; borde reforzado para no depender solo del color. */
.app-content .badge,
.app-content [class*="status-"] {
    border-width: 1px;
    border-style: solid;
}

/* Mejor lectura de bloques financieros y pares campo/valor. */
.app-content :where(.data-list, .commercial-summary-list, .totals-card) dt {
    line-height: 1.35;
}

.app-content :where(.data-list, .commercial-summary-list, .totals-card) dd {
    line-height: 1.45;
}

/* Avisos y feedback dinámico: separación suficiente para lectura y zoom. */
.app-flash-stack {
    scroll-margin-top: 76px;
}

.app-feedback__copy span,
.alert {
    line-height: 1.5;
}

/* Diálogos: foco/lectura y zoom hasta 200% sin perder acciones. */
:where(.quick-actions-dialog, .detail-view-dialog, .ux-confirm-dialog, .app-modal, .product-modal, .entity-modal-wide) {
    max-inline-size: min(96vw, var(--dialog-max-width, 1100px));
}

:where(.quick-actions-dialog, .detail-view-dialog, .ux-confirm-dialog) :where(button, a[href], input, select, textarea):focus-visible {
    outline-offset: 3px;
}

/* Alta legibilidad en preferencia de mayor contraste. */
@media (prefers-contrast: more) {
    :root {
        --ui-line: color-mix(in srgb, var(--ui-ink, #172033) 35%, transparent);
        --ui-line-strong: color-mix(in srgb, var(--ui-ink, #172033) 52%, transparent);
    }

    .app-content .card,
    .app-content .commercial-form-section,
    .app-content .detail-section-card,
    .app-content .commercial-table-card {
        border-width: 2px;
    }

    .app-content .badge,
    .app-content [class*="status-"] {
        border-color: currentColor;
    }

    .app-content :where(.muted, small) {
        color: var(--ui-ink);
    }
}

/* Windows High Contrast / forced-colors. */
@media (forced-colors: active) {
    .skip-link,
    .app-content .card,
    .app-content .button,
    .app-content .badge,
    .app-feedback,
    .ux-confirm-panel,
    .detail-view-panel,
    .quick-actions-panel {
        forced-color-adjust: auto;
        border: 1px solid CanvasText;
    }

    :where(.app-shell, .app-content) :where(a[href], button, summary, input, select, textarea):focus-visible {
        outline: 3px solid Highlight;
    }

    .app-content :where(input, select, textarea)[aria-invalid="true"] {
        outline: 2px solid Mark;
    }
}

/* Zoom/tamaño de texto: evitar recortes por alturas rígidas. */
@media (max-width: 760px), (min-resolution: 1.5dppx) {
    .app-content .button,
    .app-content button.button,
    .app-content input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    .app-content select,
    .app-content textarea {
        line-height: 1.35;
    }
}

/* ==========================================================================
   UI Fase 8 v260 · Pulido premium final
   Ajustes de acabado, consistencia, microinteracciones y jerarquía visual.
   ========================================================================== */
:root {
    --ui-premium-shadow: 0 1px 2px rgba(16,24,40,.025), 0 10px 30px rgba(16,24,40,.045);
    --ui-premium-shadow-hover: 0 2px 6px rgba(16,24,40,.035), 0 18px 42px rgba(16,24,40,.075);
    --ui-premium-line: color-mix(in srgb, var(--ui-primary, #2d176f) 12%, var(--ui-line, #e6ebf2));
    --ui-premium-glow: color-mix(in srgb, var(--ui-primary, #2d176f) 8%, transparent);
    --ui-section-gap: 18px;
}

/* Ritmo general: mismo espaciado vertical para listados, formularios y detalles. */
.app-content :where(.commercial-list-page, .commercial-form-page, .commercial-detail-page) {
    gap: var(--ui-section-gap);
}

/* Superficies principales con profundidad más limpia y consistente. */
.app-content :where(
    .card,
    .commercial-table-card,
    .commercial-form-section,
    .commercial-form-summary-card,
    .detail-section-card,
    .document-hero,
    .document-actionbar
) {
    border-color: var(--ui-premium-line);
    box-shadow: var(--ui-premium-shadow);
}

.app-content :where(.commercial-table-card, .commercial-form-section, .detail-section-card) {
    transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.app-content :where(.commercial-table-card, .commercial-form-section, .detail-section-card):hover {
    border-color: color-mix(in srgb, var(--ui-primary, #2d176f) 18%, var(--ui-line));
    box-shadow: var(--ui-premium-shadow-hover);
}

/* Cabeceras: pequeño acento visual sin recargar la interfaz. */
.app-content .document-hero {
    position: relative;
    isolation: isolate;
    overflow: hidden;
}

.app-content .document-hero::before {
    content: "";
    position: absolute;
    z-index: -1;
    width: 210px;
    height: 210px;
    right: -86px;
    top: -106px;
    border-radius: 50%;
    background: radial-gradient(circle, color-mix(in srgb, var(--ui-primary, #2d176f) 13%, transparent) 0%, transparent 70%);
    pointer-events: none;
}

.app-content .document-hero::after {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: linear-gradient(180deg,
        color-mix(in srgb, var(--ui-primary, #2d176f) 92%, #fff),
        color-mix(in srgb, var(--ui-primary, #2d176f) 42%, transparent));
    pointer-events: none;
}

.app-content .commercial-list-head__eyebrow,
.app-content .document-hero__eyebrow {
    text-wrap: balance;
}

.app-content :where(.page-head h1, .document-hero h1, .commercial-list-head h1) {
    text-wrap: balance;
}

/* Resúmenes financieros con cifras alineadas y lectura ejecutiva. */
.app-content :where(
    .document-hero__total strong,
    .financial-highlight strong,
    .commercial-summary-list dd,
    .totals-card dd,
    .summary-total-row dd,
    .table-money,
    [data-money]
) {
    font-variant-numeric: tabular-nums lining-nums;
}

.app-content .financial-highlight {
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.32);
}

.app-content .financial-highlight::after {
    content: "";
    position: absolute;
    width: 72px;
    height: 72px;
    right: -26px;
    bottom: -34px;
    border-radius: 50%;
    background: var(--ui-premium-glow);
    pointer-events: none;
}

/* Barra de acciones: aspecto de toolbar y separación visual de grupos. */
.app-content .document-actionbar {
    background: color-mix(in srgb, var(--ui-surface) 94%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.app-content .document-actionbar__secondary {
    padding-left: 10px;
    border-left: 1px solid var(--ui-line);
}

/* Botones: interacción más precisa sin efecto llamativo. */
.app-content :where(.button, button.button) {
    position: relative;
    overflow: hidden;
    transform: translateZ(0);
}

.app-content :where(.button, button.button):active:not(:disabled):not([aria-disabled="true"]) {
    transform: translateY(0) scale(.985);
    box-shadow: 0 1px 2px rgba(16,24,40,.05);
}

.app-content :where(.button, button.button) :where(svg, .icon) {
    flex: 0 0 auto;
}

.app-content :where(.button, button.button) svg {
    width: 16px;
    height: 16px;
}

.app-content :where(.button, button.button)[data-busy="true"],
.app-content :where(.button, button.button).is-busy {
    cursor: wait;
}

/* Inputs: acabado uniforme y fondo sutil al interactuar. */
.app-content :where(
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select,
    textarea
):focus {
    background: color-mix(in srgb, var(--ui-surface) 97%, var(--ui-primary-soft, #f0edfa));
}

.app-content textarea {
    resize: vertical;
}

/* Cards de sección: cabecera y cuerpo visualmente conectados. */
.app-content .detail-section-card__head,
.app-content .commercial-table-card__head,
.app-content .commercial-form-section-head {
    position: relative;
}

.app-content .detail-section-card__head::after,
.app-content .commercial-table-card__head::after {
    content: "";
    position: absolute;
    left: 17px;
    bottom: -1px;
    width: 46px;
    height: 2px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--ui-primary, #2d176f) 48%, transparent);
}

/* Tablas: mayor definición, hover más controlado y acciones mejor separadas. */
.app-content :where(.table-wrap, .commercial-table-scroll) {
    scrollbar-color: color-mix(in srgb, var(--ui-copy, #667085) 32%, transparent) transparent;
    scrollbar-width: thin;
}

.app-content :where(.table-wrap, .commercial-table-scroll)::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.app-content :where(.table-wrap, .commercial-table-scroll)::-webkit-scrollbar-thumb {
    border: 2px solid transparent;
    border-radius: 999px;
    background-clip: padding-box;
    background-color: color-mix(in srgb, var(--ui-copy, #667085) 32%, transparent);
}

.app-content :where(.table-wrap, .commercial-table-scroll)::-webkit-scrollbar-track {
    background: transparent;
}

.app-content .commercial-list-table tbody tr:hover td,
.app-content .table-wrap tbody tr:hover td {
    background: color-mix(in srgb, var(--ui-primary-soft, #f0edfa) 25%, var(--ui-surface));
}

.app-content :where(.commercial-list-table, .table-wrap table) tbody td:last-child {
    border-right-color: transparent;
}

/* Badges con marcador semántico discreto: el estado no depende solo del color. */
.app-content :where(
    .badge.status-tone--success,
    .badge.status-tone--danger,
    .badge.status-tone--warning,
    .badge.status-tone--info,
    .badge.status-tone--special,
    .badge.status-tone--neutral,
    .document-hero__statusline .status-tone--success,
    .document-hero__statusline .status-tone--danger,
    .document-hero__statusline .status-tone--warning,
    .document-hero__statusline .status-tone--info,
    .document-hero__statusline .status-tone--special,
    .document-hero__statusline .status-tone--neutral
)::before {
    content: "";
    width: 6px;
    height: 6px;
    flex: 0 0 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: .8;
}

/* Modales: profundidad premium sin perder el comportamiento responsive. */
:where(.app-modal-panel, .entity-modal-panel, .product-modal-panel, .address-book-panel, .ux-confirm-panel, .detail-view-panel, .quick-actions-panel) {
    border-color: color-mix(in srgb, var(--ui-primary, #2d176f) 12%, var(--ui-line));
    box-shadow: 0 24px 70px rgba(15,23,42,.20), 0 4px 18px rgba(15,23,42,.08);
}

/* Empty states más deliberados y menos “pantalla vacía”. */
.app-content .empty-state {
    max-width: 620px;
    margin-inline: auto;
    padding-block: 34px;
    line-height: 1.55;
}

.app-content .empty-state::before {
    content: "—";
    display: block;
    width: 38px;
    height: 38px;
    margin: 0 auto 10px;
    border: 1px solid var(--ui-line);
    border-radius: 12px;
    background: var(--ui-surface-soft);
    color: var(--ui-copy);
    font-size: 1.15rem;
    line-height: 36px;
    font-weight: 700;
}

/* Microentrada muy breve: solo para contenido administrativo, nunca para impresión. */
@media (prefers-reduced-motion: no-preference) {
    @keyframes ui-premium-enter {
        from { opacity: .01; transform: translateY(4px); }
        to { opacity: 1; transform: translateY(0); }
    }

    .app-content :where(.commercial-list-page, .commercial-form-page, .commercial-detail-page) > :where(.commercial-list-head, .document-hero, .document-actionbar, .card, .commercial-table-card, .commercial-form-section, .detail-grid) {
        animation: ui-premium-enter .22s ease-out both;
    }
}

/* Dark mode: sombras y decoraciones más contenidas. */
html[data-theme="dark"] .app-content :where(
    .card,
    .commercial-table-card,
    .commercial-form-section,
    .commercial-form-summary-card,
    .detail-section-card,
    .document-hero,
    .document-actionbar
) {
    box-shadow: 0 1px 2px rgba(0,0,0,.18), 0 12px 30px rgba(0,0,0,.20);
}

html[data-theme="dark"] .app-content .document-actionbar {
    background: color-mix(in srgb, var(--ui-panel) 94%, transparent);
}

/* En tablet/móvil el toolbar secundario vuelve a ser una fila independiente. */
@media (max-width: 980px) {
    .app-content .document-actionbar__secondary {
        padding-left: 0;
        padding-top: 10px;
        border-left: 0;
        border-top: 1px solid var(--ui-line);
    }
}

@media (max-width: 560px) {
    :root { --ui-section-gap: 14px; }

    .app-content .document-hero::after {
        width: 3px;
    }

    .app-content .detail-section-card__head::after,
    .app-content .commercial-table-card__head::after {
        left: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-content :where(.commercial-table-card, .commercial-form-section, .detail-section-card) {
        transition: none !important;
    }
}

@media print {
    .app-content :where(.commercial-list-page, .commercial-form-page, .commercial-detail-page) > * {
        animation: none !important;
    }
}


/* v318 · Sidebar flotante global en escritorio + nivelación de encabezados */
@media (min-width: 1121px) {
    body.app-layout .sidebar {
        width: var(--sidebar-width, 276px) !important;
        transform: translateX(-100%) !important;
        transition: transform .18s ease, box-shadow .18s ease !important;
        overflow: hidden !important;
        box-shadow: 14px 0 40px rgba(15, 23, 42, .16) !important;
    }

    body.app-layout.pos-sidebar-expanded .sidebar {
        transform: translateX(0) !important;
        overflow: visible !important;
    }

    body.app-layout .app-main,
    body.app-layout.pos-sidebar-expanded .app-main,
    body.app-layout.pos-mode .app-main,
    body.app-layout.pos-mode.pos-sidebar-expanded .app-main,
    body.app-layout.terminal-pos-mode .app-main,
    body.app-layout.terminal-pos-mode.pos-sidebar-expanded .app-main {
        margin-left: 0 !important;
        width: 100% !important;
    }

    body.app-layout .sidebar-toggle {
        display: none !important;
    }

    body.app-layout .app-sidebar-hover-zone,
    body.app-layout .pos-sidebar-hover-zone {
        position: fixed !important;
        inset: 0 auto 0 0 !important;
        z-index: 69 !important;
        display: block !important;
        width: 16px !important;
        background: transparent !important;
    }

    body.app-layout.pos-sidebar-expanded .app-sidebar-hover-zone,
    body.app-layout.pos-sidebar-expanded .pos-sidebar-hover-zone {
        pointer-events: none !important;
    }

    /* POS también abre el menú a tamaño completo, pero siempre flotante. */
    body.app-layout.pos-mode .sidebar,
    body.app-layout.terminal-pos-mode .sidebar {
        width: var(--sidebar-width, 276px) !important;
    }

    body.app-layout.pos-mode.pos-sidebar-expanded .sidebar-brand,
    body.app-layout.terminal-pos-mode.pos-sidebar-expanded .sidebar-brand {
        justify-content: flex-start !important;
    }

    /* El área de trabajo aprovecha todo el ancho disponible. */
    body.app-layout .app-content {
        width: 100%;
        max-width: none;
        margin-left: 0;
        margin-right: 0;
    }

    /* Encabezados con muchas acciones: título estable y acciones niveladas. */
    .app-content .page-head,
    .app-content .compact-page-head,
    .app-content .commercial-list-head {
        min-width: 0;
        align-items: center;
        column-gap: 18px;
        row-gap: 10px;
    }

    .app-content .page-head > :first-child,
    .app-content .compact-page-head > :first-child,
    .app-content .commercial-list-head > :first-child {
        min-width: 250px;
        flex: 0 1 360px;
    }

    .app-content .page-head > .actions,
    .app-content .compact-page-head > .actions,
    .app-content .commercial-list-head__actions,
    .app-content .catalog-primary-actions {
        min-width: 0;
        flex: 1 1 auto;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 8px;
        flex-wrap: wrap;
    }

    .app-content .page-head > .actions form,
    .app-content .compact-page-head > .actions form,
    .app-content .catalog-primary-actions form {
        margin: 0;
        display: inline-flex;
    }

    .app-content .page-head > .actions .button,
    .app-content .compact-page-head > .actions .button,
    .app-content .catalog-primary-actions .button {
        white-space: nowrap;
    }
}

@media (min-width: 1121px) and (max-width: 1380px) {
    .app-content .page-head,
    .app-content .compact-page-head,
    .app-content .commercial-list-head {
        align-items: flex-start;
    }
    .app-content .page-head > :first-child,
    .app-content .compact-page-head > :first-child,
    .app-content .commercial-list-head > :first-child {
        flex-basis: 280px;
    }
}

/* v338 · Restauración de menú lateral fijado por empresa */
@media (min-width: 1121px) {
    body.app-layout.sidebar-pinned .sidebar {
        width: var(--sidebar-width, 276px) !important;
        transform: translateX(0) !important;
        overflow: visible !important;
        box-shadow: 8px 0 24px rgba(15, 23, 42, .08) !important;
    }

    body.app-layout.sidebar-pinned .app-main,
    body.app-layout.sidebar-pinned.pos-mode .app-main,
    body.app-layout.sidebar-pinned.terminal-pos-mode .app-main {
        margin-left: var(--sidebar-width, 276px) !important;
        width: calc(100% - var(--sidebar-width, 276px)) !important;
    }

    body.app-layout.sidebar-pinned .app-sidebar-hover-zone,
    body.app-layout.sidebar-pinned .pos-sidebar-hover-zone {
        display: none !important;
        pointer-events: none !important;
    }

    body.app-layout.sidebar-pinned .sidebar-toggle {
        display: none !important;
    }

    body.app-layout.sidebar-pinned .app-content {
        width: 100%;
        max-width: none;
    }
}

