/**
 * iPhoneHouse — diseño premium / tipo Apple Store (frontend.md)
 * Inter, mucho whitespace, sidebar glass, tablas estilo SaaS, foco accesible.
 */

:root {
    color-scheme: light;
    --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, monospace;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-xl: 14px;
    --radius-2xl: 18px;
    --radius-full: 9999px;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.1);

    /* Paleta frontend.md */
    --color-bg: #f8f9fb;
    --color-surface: #ffffff;
    --color-primary: #000000;
    --color-secondary: #6b7280;
    --color-border: #e5e7eb;
    --color-border-strong: #d1d5db;

    --color-accent: #0071e3;
    --color-accent-hover: #0077ed;
    --color-accent-ring: rgba(0, 113, 227, 0.25);

    --color-success: #16a34a;
    --color-success-bg: #f0fdf4;
    --color-whatsapp: #25d366;

    --color-danger: #dc2626;
    --color-danger-soft: #fef2f2;
    --color-warning-bg: #fffbeb;
    --color-warning-text: #b45309;

    --color-text: #000000;
    --color-text-muted: #6b7280;

    --sidebar-width: 260px;
    --sidebar-width-collapsed: 80px;
    --header-h: 56px;

    --focus-ring: 2px solid var(--color-accent);
    --focus-offset: 2px;
    --touch-min: 44px;
    --content-max: 1280px;
}

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

html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

body {
    font-family: var(--font-sans);
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.55;
    font-size: 1rem;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* ——— Layout app (sidebar + main) ——— */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
    transition: grid-template-columns 0.22s ease;
}

body.sidebar-collapsed .app-shell {
    grid-template-columns: var(--sidebar-width-collapsed) minmax(0, 1fr);
}

.sidebar {
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(20px) saturate(1.2);
    -webkit-backdrop-filter: blur(20px) saturate(1.2);
    border-right: 1px solid rgba(0, 0, 0, 0.06);
    z-index: 1100;
    transition: width 0.22s ease, transform 0.25s ease;
    overflow-x: hidden;
    width: 100%;
    min-width: 0;
}

.sidebar__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 1rem 0.75rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    min-height: 3.5rem;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    text-decoration: none;
    color: var(--color-primary);
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.03em;
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius-md);
    transition: background 0.15s ease;
}

.sidebar__brand:hover {
    background: rgba(0, 0, 0, 0.04);
}

.sidebar__brand-mark {
    flex-shrink: 0;
    display: flex;
    color: var(--color-primary);
}

.sidebar__brand-text {
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s ease, width 0.2s ease;
}

.sidebar__pin {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-secondary);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.sidebar__pin:hover {
    background: #f3f4f6;
    color: var(--color-primary);
}

body.sidebar-collapsed .sidebar__brand-text,
body.sidebar-collapsed .sidebar__label {
    opacity: 0;
    width: 0;
    overflow: hidden;
    pointer-events: none;
    position: absolute;
}

body.sidebar-collapsed .sidebar__top {
    flex-direction: column;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

body.sidebar-collapsed .sidebar__brand {
    justify-content: center;
    padding: 0.35rem;
}

body.sidebar-collapsed .sidebar__pin {
    width: 100%;
}

.sidebar__nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--color-text);
    font-size: 0.9375rem;
    font-weight: 500;
    min-height: var(--touch-min);
    transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
    border: 1px solid transparent;
}

.sidebar__link:hover {
    background: rgba(0, 0, 0, 0.04);
}

.sidebar__link--active {
    background: rgba(0, 0, 0, 0.06);
    color: var(--color-primary);
    font-weight: 600;
    border-color: rgba(0, 0, 0, 0.06);
}

.sidebar__icon {
    flex-shrink: 0;
    display: flex;
    color: var(--color-secondary);
    transition: color 0.15s ease;
}

.sidebar__link--active .sidebar__icon,
.sidebar__link:hover .sidebar__icon {
    color: var(--color-primary);
}

.sidebar__label {
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s ease;
}

.sidebar__footer {
    padding: 0.75rem 0.5rem 1rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.app-versions {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.35rem 0.65rem 0.15rem;
    font-size: 0.7rem;
    color: var(--color-text-muted);
    line-height: 1.35;
}

.app-versions__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
}

.app-versions__label {
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-size: 0.62rem;
}

.app-versions__value {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--color-secondary);
    background: rgba(0, 0, 0, 0.04);
    padding: 0.1rem 0.35rem;
    border-radius: var(--radius-sm);
}

.app-versions__value--pending {
    opacity: 0.5;
}

.app-versions__value--error {
    color: var(--color-danger);
    background: var(--color-danger-soft);
}

body.sidebar-collapsed .app-versions {
    display: none;
}

.sidebar__link--footer {
    font-size: 0.9rem;
}

.icon {
    display: block;
    flex-shrink: 0;
}

.app-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
    background: var(--color-bg);
}

.app-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: var(--header-h);
    padding: 0 1rem 0 0.75rem;
    border-bottom: 1px solid var(--color-border);
    background: rgba(248, 249, 251, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 800;
}

.app-header__menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--touch-min);
    height: var(--touch-min);
    border: none;
    background: transparent;
    color: var(--color-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s ease;
}

.app-header__menu-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.app-header__title {
    flex: 1;
    min-width: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-secondary);
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: 1050;
}

.sidebar-backdrop:not([hidden]) {
    display: block;
}

@media (min-width: 1024px) {
    .sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        overflow: hidden;
    }

    .sidebar__nav {
        flex: 1;
        min-height: 0;
    }

    .app-header__menu-btn {
        display: none;
    }

    .sidebar-backdrop {
        display: none !important;
    }
}

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

    body.sidebar-collapsed .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(300px, 88vw);
        max-width: 300px;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    .sidebar.sidebar--open {
        transform: translateX(0);
    }

    body.sidebar-collapsed .sidebar__brand-text,
    body.sidebar-collapsed .sidebar__label {
        opacity: 1;
        width: auto;
        position: static;
        pointer-events: auto;
    }
}

/* Login: sin sidebar */
body.layout-auth .app-shell {
    grid-template-columns: 1fr;
}

body.layout-auth .sidebar,
body.layout-auth .app-header,
body.layout-auth .sidebar-backdrop {
    display: none !important;
}

body.layout-auth .app-main {
    justify-content: center;
    background: linear-gradient(180deg, #fff 0%, var(--color-bg) 100%);
}

body.layout-auth .main-content {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    padding: clamp(2rem, 6vw, 3rem) 1.25rem;
}

body.layout-auth .container {
    box-shadow: var(--shadow-md);
}

body.layout-auth h2 {
    text-align: center;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 0.5rem;
}

/* Usuario dropdown en sidebar */
.user-menu {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.user-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    min-height: var(--touch-min);
    padding: 0.5rem 0.75rem;
    background: #f3f4f6;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-primary);
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.user-menu-toggle:hover {
    background: #e5e7eb;
}

.user-menu-toggle__text {
    flex: 1;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon--chevron {
    opacity: 0.6;
}

.user-dropdown {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + 6px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.35rem;
    z-index: 1200;
    box-shadow: var(--shadow-md);
    overscroll-behavior: contain;
}

.user-dropdown.open {
    display: block;
}

.user-dropdown-item {
    width: 100%;
    background: transparent;
    color: var(--color-text);
    border: none;
    padding: 0.65rem 0.75rem;
    border-radius: var(--radius-sm);
    min-height: 40px;
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background 0.12s ease;
}

.user-dropdown-item:hover {
    background: #f3f4f6;
}

/* Skip + foco */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 10000;
    padding: 0.75rem 1.25rem;
    background: var(--color-surface);
    color: var(--color-accent);
    font-weight: 600;
    text-decoration: none;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.skip-link:focus {
    left: 1rem;
    top: 1rem;
}

.skip-link:focus:not(:focus-visible) {
    outline: none;
}

.skip-link:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
}

:focus {
    outline: none;
}

:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
}

button:focus:not(:focus-visible),
.btn:focus:not(:focus-visible) {
    outline: none;
}

.main-content {
    flex: 1;
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: clamp(1.25rem, 3vw, 2rem) clamp(1rem, 3vw, 2rem);
    scroll-margin-top: 1rem;
}

.container {
    background: var(--color-surface);
    border-radius: var(--radius-2xl);
    padding: clamp(1.5rem, 3vw, 2.25rem);
    box-shadow: var(--shadow-xs), 0 0 0 1px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--color-border);
}

.welcome-section {
    text-align: center;
    margin-bottom: 2.5rem;
}

.welcome-section h2 {
    color: var(--color-primary);
    margin-bottom: 0.75rem;
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.welcome-section p {
    color: var(--color-secondary);
    max-width: 36rem;
    margin-left: auto;
    margin-right: auto;
    font-size: 1.05rem;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
    gap: 1.25rem;
    margin-top: 2rem;
}

.card {
    background: var(--color-surface);
    padding: 1.75rem;
    border-radius: var(--radius-2xl);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-3px);
    border-color: var(--color-border-strong);
}

@media (prefers-reduced-motion: reduce) {
    .card:hover {
        transform: none;
    }
}

.card h3 {
    color: var(--color-primary);
    margin-bottom: 0.5rem;
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.card p {
    color: var(--color-secondary);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
    line-height: 1.55;
}

.section {
    margin-bottom: 2rem;
}

.section h3 {
    color: var(--color-primary);
    margin-bottom: 1rem;
    padding-bottom: 0.65rem;
    border-bottom: 1px solid var(--color-border);
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.section h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 0.5rem;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-inline {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

/* Métodos de pago: fila de alta alineada (labels arriba, inputs alineados) */
.form-mp-alta {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-mp-alta__row {
    display: grid;
    grid-template-columns:
        minmax(160px, 1.4fr)
        minmax(90px, 0.5fr)
        minmax(150px, 1fr)
        minmax(150px, 1fr)
        minmax(140px, auto)
        auto;
    gap: 1rem 1.25rem;
    align-items: start;
}

.form-mp-alta__row .form-group {
    margin: 0;
    min-width: 0;
}

.form-mp-alta__hint {
    margin: 0 0 0.25rem 0;
    max-width: 52rem;
}

.form-mp-alta__checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: var(--touch-min);
    box-sizing: border-box;
}

.form-mp-alta__checkbox label {
    margin: 0;
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--color-secondary);
}

.form-mp-alta__label-spacer {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.25;
    min-height: 1.25rem;
    margin-bottom: 0.45rem;
    visibility: hidden;
}

.form-mp-alta__actions {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    align-items: stretch;
    min-width: 0;
}

.form-mp-alta__actions .form-mp-alta__label-spacer {
    flex-shrink: 0;
}

.form-mp-alta__actions .btn {
    align-self: flex-start;
    min-width: 8.5rem;
}

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

@media (max-width: 520px) {
    .form-mp-alta__row {
        grid-template-columns: 1fr;
    }
}

.data-table td.mp-actions {
    white-space: normal;
    vertical-align: middle;
}

.data-table td.mp-actions .btn {
    margin: 0.15rem 0.25rem 0.15rem 0;
    vertical-align: middle;
}

/* Historial ventas: acciones alineadas (REQ-0018) */
.historial-ventas-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.historial-ventas-actions .btn {
    margin: 0;
    flex: 0 0 auto;
}

.historial-ventas-table td:last-child {
    vertical-align: middle;
}

.modal-content--form h3 {
    margin-top: 0;
    margin-bottom: 1rem;
}

.modal-content--form .form-group:last-of-type {
    margin-bottom: 0.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.form-group label {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--color-secondary);
    letter-spacing: 0.01em;
}

.form-group input,
.form-group textarea,
.form-group select {
    padding: 0.7rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    font-size: max(16px, 1rem);
    font-family: inherit;
    color: var(--color-text);
    background: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    min-height: var(--touch-min);
}

.form-group input:hover,
.form-group textarea:hover,
.form-group select:hover {
    border-color: var(--color-border-strong);
}

.form-group input:focus-visible,
.form-group textarea:focus-visible,
.form-group select:focus-visible {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 4px var(--color-accent-ring);
    outline: none;
}

.form-group textarea {
    resize: vertical;
    min-height: max(100px, 6rem);
}

.form-group select {
    background-color: #fff;
    color: var(--color-text);
}

.btn {
    padding: 0.65rem 1.35rem;
    border-radius: var(--radius-xl);
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: var(--touch-min);
    line-height: 1.2;
    border: 1px solid transparent;
}

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

@media (prefers-reduced-motion: reduce) {
    .btn:active:not(:disabled) {
        transform: none;
    }
}

.btn-primary {
    background-color: var(--color-primary);
    color: #fff;
    box-shadow: var(--shadow-xs);
}

.btn-primary:hover:not(:disabled) {
    background-color: #1a1a1a;
}

.btn-secondary {
    background-color: transparent;
    color: var(--color-primary);
    border-color: var(--color-border-strong);
}

.btn-secondary:hover:not(:disabled) {
    background-color: rgba(0, 0, 0, 0.04);
    border-color: #9ca3af;
}

.btn-success {
    background-color: var(--color-success);
    color: #fff;
}

.btn-success:hover:not(:disabled) {
    background-color: #15803d;
}

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

.btn-danger:hover:not(:disabled) {
    background-color: #b91c1c;
}

.btn:disabled {
    background-color: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
    box-shadow: none;
    border-color: transparent;
}

.table-container {
    overflow-x: auto;
    margin-top: 1rem;
    border-radius: var(--radius-xl);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    font-variant-numeric: tabular-nums;
}

.data-table thead {
    background: #f8f9fb;
    color: var(--color-secondary);
}

.data-table th,
.data-table td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9375rem;
}

.data-table th {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    color: var(--color-secondary);
}

.data-table tbody tr {
    transition: background-color 0.12s ease;
}

.data-table tbody tr:hover {
    background-color: rgba(0, 113, 227, 0.04);
}

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

.empty-message {
    text-align: center;
    color: var(--color-text-muted);
    padding: 2.5rem 1rem;
}

.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
    padding: 1rem;
    overscroll-behavior: contain;
}

.modal-content {
    background-color: var(--color-surface);
    margin: 1rem auto;
    padding: clamp(1.25rem, 3vw, 2rem);
    border-radius: var(--radius-2xl);
    width: min(100%, 600px);
    max-width: 600px;
    position: relative;
    max-height: min(90vh, calc(100dvh - 2rem));
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
}

.modal-content--wide {
    max-width: 720px;
    width: min(100%, 720px);
}

.telefono-fila-click {
    cursor: pointer;
}

.telefono-fila-click:hover {
    background-color: rgba(0, 113, 227, 0.06) !important;
}

.detalle-dl {
    display: grid;
    grid-template-columns: minmax(8rem, 1fr) 2fr;
    gap: 0.4rem 1rem;
    margin: 0 0 1.25rem 0;
}

.detalle-dl dt {
    font-weight: 600;
    color: var(--color-secondary);
    margin: 0;
}

.detalle-dl dd {
    margin: 0;
}

.detalle-precios {
    border-top: 1px solid var(--color-border);
    padding-top: 1rem;
    margin-top: 0.5rem;
}

/* Auditoría */
.audit-json {
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
}

.audit-json code {
    display: block;
    white-space: pre-wrap;
    word-break: break-word;
    background: #f8f9fb;
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius-sm);
    margin-top: 0.15rem;
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

.audit-diff-empty {
    color: var(--color-text-muted);
    font-style: italic;
    margin: 0;
    font-size: 0.9rem;
}

.audit-diff-row {
    margin-bottom: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.audit-diff-campo {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--color-secondary);
    padding: 0.35rem 0.5rem;
    background: #f8f9fb;
    border-bottom: 1px solid var(--color-border);
}

.audit-diff-antes,
.audit-diff-despues {
    padding: 0.4rem 0.5rem;
    font-size: 0.85rem;
}

.audit-diff-antes {
    background: var(--color-danger-soft);
    border-left: 4px solid var(--color-danger);
}

.audit-diff-despues {
    background: var(--color-success-bg);
    border-left: 4px solid var(--color-success);
}

.audit-diff-tag {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    margin-right: 0.35rem;
    color: var(--color-secondary);
}

.audit-diff-antes .audit-diff-tag {
    color: #b91c1c;
}

.audit-diff-despues .audit-diff-tag {
    color: #15803d;
}

.audit-diff-antes code,
.audit-diff-despues code {
    display: block;
    white-space: pre-wrap;
    word-break: break-word;
    background: transparent;
    padding: 0.25rem 0 0 0;
    font-size: 0.88rem;
    font-family: var(--font-mono);
}

.audit-extra-context {
    margin-top: 0.5rem;
    padding: 0.35rem 0.5rem;
    font-size: 0.8rem;
    color: var(--color-secondary);
    background: #f8f9fb;
    border-radius: var(--radius-sm);
    border-left: 3px solid #9ca3af;
}

.audit-col-cambios {
    max-width: min(48rem, 92vw);
    min-width: 18rem;
    vertical-align: top;
    word-break: break-word;
}

.audit-bloque {
    font-size: 0.9rem;
}

.audit-entidad-header {
    margin-bottom: 0.5rem;
    padding: 0.45rem 0.55rem;
    background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 100%);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--color-accent);
}

.audit-entidad-titulo {
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.35;
    display: block;
}

.audit-entidad-body-wrap {
    position: relative;
}

.audit-entidad-body-wrap--collapsed .audit-entidad-body {
    max-height: 14rem;
    overflow: hidden;
    position: relative;
}

.audit-entidad-body-wrap--collapsed .audit-entidad-body::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2.5rem;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0), #fff);
    pointer-events: none;
}

.audit-btn-toggle {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    padding: 0.35rem 0.75rem;
}

.audit-entidad-dl {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.audit-entidad-fila {
    display: grid;
    grid-template-columns: minmax(6rem, 9rem) 1fr;
    gap: 0.35rem 0.75rem;
    align-items: start;
    padding: 0.35rem 0.45rem;
    border-radius: var(--radius-sm);
    background: #fafbfc;
    border: 1px solid var(--color-border);
}

.audit-entidad-fila--cambio {
    background: var(--color-warning-bg);
    border-color: #fde68a;
    box-shadow: inset 3px 0 0 0 #f59e0b;
}

.audit-entidad-k {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--color-secondary);
    margin: 0;
    word-break: break-word;
}

.audit-entidad-dd {
    margin: 0;
    min-width: 0;
}

.audit-entidad-val {
    display: block;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.86rem;
    background: #fff;
    padding: 0.25rem 0.4rem;
    border-radius: 3px;
    border: 1px solid var(--color-border);
}

.audit-cambio-par {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.audit-diff-antes--inline,
.audit-diff-despues--inline {
    padding: 0.3rem 0.45rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
}

.audit-diff-antes--inline code,
.audit-diff-despues--inline code {
    margin-top: 0.2rem;
    padding: 0;
    font-size: 0.85rem;
}

.audit-diff-empty--inline {
    margin: 0 0 0.5rem 0;
    font-size: 0.85rem;
}

.close {
    position: absolute;
    right: 0.75rem;
    top: 0.75rem;
    width: 2.75rem;
    height: 2.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1;
    color: var(--color-text-muted);
    cursor: pointer;
    border: none;
    background: transparent;
    border-radius: var(--radius-md);
    transition: background 0.12s ease, color 0.12s ease;
}

.close:hover {
    color: var(--color-primary);
    background: #f3f4f6;
}

.close:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
}

.alert {
    padding: 1rem 1.15rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.alert-success {
    background-color: var(--color-success-bg);
    color: #166534;
    border-color: #bbf7d0;
}

.alert-error {
    background-color: var(--color-danger-soft);
    color: #991b1b;
    border-color: #fecaca;
}

.resumen-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-top: 1rem;
}

.resumen-card {
    background: linear-gradient(145deg, #fafbfc 0%, #fff 100%);
    border: 1px solid var(--color-border);
    padding: 1.35rem;
    border-radius: var(--radius-xl);
    color: var(--color-primary);
    box-shadow: var(--shadow-xs);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.resumen-card:nth-child(1) {
    background: linear-gradient(135deg, #f0f4ff 0%, #fafbff 100%);
    border-color: #c7d2fe;
}

.resumen-card:nth-child(2) {
    background: linear-gradient(135deg, #fdf2f8 0%, #fff 100%);
    border-color: #fbcfe8;
}

.resumen-card:nth-child(3) {
    background: linear-gradient(135deg, #ecfeff 0%, #fff 100%);
    border-color: #a5f3fc;
}

.resumen-card:nth-child(4) {
    background: linear-gradient(135deg, #f0fdf4 0%, #fff 100%);
    border-color: #bbf7d0;
}

.resumen-card:nth-child(5) {
    background: linear-gradient(135deg, #fffbeb 0%, #fff 100%);
    border-color: #fde68a;
}

.resumen-card:nth-child(6) {
    background: linear-gradient(135deg, #f0fdfa 0%, #fff 100%);
    border-color: #99f6e4;
}

.resumen-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

@media (prefers-reduced-motion: reduce) {
    .resumen-card:hover {
        transform: none;
    }
}

.resumen-card h4 {
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
    color: var(--color-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.resumen-valor {
    font-size: clamp(1.45rem, 4vw, 1.85rem);
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.03em;
    color: var(--color-primary);
}

.filtros-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.filtros-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-nuevo {
    background-color: #dbeafe;
    color: #1e40af;
}

.badge-usado {
    background-color: #f3f4f6;
    color: #4b5563;
}

.badge-anulada {
    background-color: #fee2e2;
    color: #b91c1c;
}

.estado-badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
}

.estado-disponible {
    background-color: #d1fae5;
    color: #065f46;
}

.estado-pendiente-tasar {
    background-color: #fef3c7;
    color: #92400e;
}

.estado-vendido {
    background-color: #fee2e2;
    color: #991b1b;
}

.estado-reparacion {
    background-color: #fef3c7;
    color: #92400e;
}

.estado-devuelto {
    background-color: #e0e7ff;
    color: #3730a3;
}

.estado-garantia {
    background-color: #f3f4f6;
    color: #475569;
}

.estado-irreparable {
    background-color: #e5e7eb;
    color: #374151;
}

.estado-senado {
    background-color: #dbeafe;
    color: #1e40af;
}

#contadorResultados {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    font-weight: normal;
}

.help-text {
    color: var(--color-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    line-height: 1.55;
}

@media (max-width: 768px) {
    .form-inline {
        grid-template-columns: 1fr;
    }

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

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

    .filtros-actions {
        flex-direction: column;
    }

    .filtros-actions .btn {
        width: 100%;
    }

    .audit-entidad-fila {
        grid-template-columns: 1fr;
    }

    .data-table th,
    .data-table td {
        padding: 0.65rem 0.75rem;
        font-size: 0.875rem;
    }
}

/* —— Ventas: flujo por pasos + carrito sticky (REQ-0017) —— */
.ventas-page .ventas-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
    gap: 1.5rem;
    align-items: start;
    margin-bottom: 2rem;
}

.ventas-flow {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
}

.venta-step {
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-surface, #fff);
    overflow: hidden;
}

.venta-step__summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    padding: 0.85rem 1rem;
    font-weight: 600;
    font-size: 1rem;
    color: var(--color-primary);
    background: var(--color-surface-alt, #f8fafc);
    border-bottom: 1px solid transparent;
}

.venta-step__summary::-webkit-details-marker {
    display: none;
}

.venta-step[open] > .venta-step__summary {
    border-bottom-color: var(--color-border);
}

.venta-step__summary::after {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    margin-left: auto;
    border-right: 2px solid var(--color-text-muted);
    border-bottom: 2px solid var(--color-text-muted);
    transform: rotate(45deg);
    transition: transform 0.15s ease;
}

.venta-step[open] > .venta-step__summary::after {
    transform: rotate(-135deg);
    margin-top: 0.2rem;
}

.venta-step__num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.65rem;
    height: 1.65rem;
    border-radius: 50%;
    font-size: 0.8125rem;
    font-weight: 700;
    background: var(--color-primary);
    color: #fff;
}

.venta-step__title {
    flex: 1;
    min-width: 0;
}

.venta-step__badge {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-secondary);
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    background: var(--color-border);
}

.venta-step__body {
    padding: 1rem 1rem 1.1rem;
}

.venta-step__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.venta-form-productos {
    gap: 1.25rem;
}

.venta-producto-panel {
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 1rem 1rem 1.1rem;
    background: var(--color-surface, #fff);
}

.venta-producto-panel__title {
    margin: 0 0 0.35rem;
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-primary);
    letter-spacing: -0.02em;
}

.venta-producto-panel__hint {
    margin-top: 0;
    margin-bottom: 0.85rem;
}

.venta-producto-panel .btn {
    margin-top: 0.25rem;
}

.venta-step__confirm {
    margin-top: 1.25rem;
    width: 100%;
}

.ventas-cart {
    position: sticky;
    top: 0.75rem;
    align-self: start;
    border: 1px solid var(--color-border-strong, var(--color-border));
    border-radius: 12px;
    padding: 1rem 1rem 1.1rem;
    background: linear-gradient(165deg, var(--color-surface-alt, #f8fafc) 0%, var(--color-surface, #fff) 48%);
    box-shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
    max-height: calc(100vh - 1.5rem);
    overflow-y: auto;
    min-width: 0;
}

.ventas-cart__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.65rem;
}

.ventas-cart__title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--color-primary);
    letter-spacing: -0.02em;
}

.ventas-cart__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.75rem;
    height: 1.75rem;
    padding: 0 0.45rem;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 700;
    background: var(--color-primary);
    color: #fff;
}

.ventas-cart__cliente {
    margin: 0 0 0.5rem;
    font-size: 0.875rem;
    line-height: 1.45;
    color: var(--color-secondary);
}

.ventas-cart__cliente.ventas-cart__cliente--ok {
    color: var(--color-primary);
    font-weight: 500;
}

.ventas-cart__equipos {
    margin: 0 0 0.65rem;
    font-size: 0.8125rem;
    color: #92400e;
    font-weight: 500;
}

.ventas-cart__table-wrap {
    margin: 0 -0.25rem;
    max-width: 100%;
    overflow-x: auto;
}

.ventas-cart__table {
    font-size: 0.8125rem;
}

.ventas-cart__table th,
.ventas-cart__table td {
    white-space: nowrap;
}

.ventas-cart__table td:nth-child(3) {
    white-space: normal;
    max-width: 8rem;
}

.ventas-cart__alert {
    margin-top: 0.65rem;
    margin-bottom: 0;
    font-size: 0.875rem;
}

.ventas-cart__jump {
    width: 100%;
    margin-top: 0.85rem;
}

.ventas-historial {
    margin-top: 0.5rem;
}

@media (max-width: 960px) {
    .ventas-page .ventas-layout {
        grid-template-columns: 1fr;
    }

    .ventas-cart {
        position: relative;
        top: 0;
        max-height: none;
        order: -1;
    }
}
