:root {
    /* Material Design 3 Color Tokens - ECOS Brand Theme */
    --md-sys-color-primary: HSL(203, 86%, 22%);
    --md-sys-color-on-primary: HSL(0, 0%, 100%);
    --md-sys-color-primary-container: HSL(203, 86%, 92%);
    --md-sys-color-on-primary-container: HSL(203, 95%, 15%);
    --md-sys-color-secondary: HSL(120, 60%, 25%);
    --md-sys-color-on-secondary: HSL(0, 0%, 100%);
    --md-sys-color-secondary-container: HSL(120, 40%, 90%);
    --md-sys-color-on-secondary-container: HSL(120, 60%, 25%);
    --md-sys-color-error: HSL(0, 75%, 40%);
    --md-sys-color-on-error: HSL(0, 0%, 100%);
    --md-sys-color-error-container: HSL(0, 85%, 95%);
    --md-sys-color-on-error-container: HSL(0, 90%, 15%);
    --md-sys-color-background: HSL(203, 15%, 98%);
    --md-sys-color-on-background: HSL(203, 30%, 12%);
    --md-sys-color-surface: HSL(0, 0%, 100%);
    --md-sys-color-on-surface: HSL(203, 30%, 12%);
    --md-sys-color-surface-variant: HSL(203, 10%, 94%);
    --md-sys-color-on-surface-variant: HSL(203, 15%, 35%);
    --md-sys-color-outline: HSL(203, 10%, 75%);
    --md-sys-color-outline-variant: HSL(203, 12%, 88%);
    
    /* Typography */
    --md-sys-typescale-font: 'Roboto', sans-serif;
    
    /* Elevations */
    --md-elevation-1: 0px 1px 3px 1px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.30);
    --md-elevation-2: 0px 2px 6px 2px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.30);
}

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

html, body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

body {
    font-family: var(--md-sys-typescale-font);
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    min-height: 100vh;
    padding: 20px 20px 70px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
}

.container {
    background-color: var(--md-sys-color-surface);
    border-radius: 28px;
    padding: 32px;
    max-width: 1000px;
    width: 100%;
    margin-top: 20px;
    margin-bottom: 40px;
    border: 1px solid var(--md-sys-color-outline-variant);
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.header h1 {
    font-size: 28px;
    font-weight: 400;
    color: var(--md-sys-color-on-background);
    margin-bottom: 8px;
}

.header .subtitle {
    font-size: 14px;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 16px;
}

.header-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
}

/* Buttons */
.btn-volver,
.btn-admin-panel,
.tab-btn,
.btn-guardar-cambios,
.btn-cancelar-modal {
    font-family: var(--md-sys-typescale-font);
    font-size: 14px;
    font-weight: 500;
    border-radius: 100px;
    padding: 10px 24px;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.btn-volver {
    background-color: HSL(120, 40%, 90%);
    color: HSL(120, 60%, 25%);
}

.btn-volver:hover {
    background-color: HSL(120, 40%, 82%);
}

.btn-admin-panel {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.btn-admin-panel:hover {
    background-color: HSL(203, 86%, 15%);
}

/* M3 Segmented Buttons for tabs */
.nav-buttons {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
    width: 100%;
}

.tab-buttons {
    display: inline-flex;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 100px;
    overflow: hidden;
    background-color: var(--md-sys-color-surface);
}

.tab-btn {
    border-radius: 0;
    background-color: transparent;
    color: var(--md-sys-color-on-surface-variant);
    border-right: 1px solid var(--md-sys-color-outline);
    padding: 10px 20px;
}

.tab-btn:last-child {
    border-right: none;
}

.tab-btn:hover:not(.active) {
    background-color: rgba(0, 0, 0, 0.04);
}

.tab-btn.active {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    font-weight: 600;
}

/* Tab content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.2s cubic-bezier(0.2, 0, 0, 1);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Resumen Cards (M3 Cards) */
.resumen-section {
    margin-bottom: 24px;
}

.resumen-section h2 {
    font-size: 18px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.stat-card {
    background-color: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 16px;
    padding: 20px;
    text-align: center;
    transition: all 0.2s;
}

.stat-card:hover {
    border-color: var(--md-sys-color-outline);
    box-shadow: var(--md-elevation-1);
}

.stat-card.highlight {
    background-color: var(--md-sys-color-primary-container);
    border-color: var(--md-sys-color-primary);
}

.stat-card.highlight .stat-value {
    color: var(--md-sys-color-on-primary-container);
}

.stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card.highlight .stat-label {
    color: var(--md-sys-color-primary);
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--md-sys-color-on-surface);
}

/* Filters Section */
.filters-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
    padding: 16px;
    background-color: var(--md-sys-color-surface-variant);
    border-radius: 16px;
    border: 1px solid var(--md-sys-color-outline-variant);
}

.filter-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-item label {
    font-size: 12px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
}

.filter-item select {
    font-family: var(--md-sys-typescale-font);
    padding: 10px 12px;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 8px;
    font-size: 14px;
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    outline: none;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-item select:focus {
    border-color: var(--md-sys-color-primary);
}

/* Tables styling */
.tabla-container {
    overflow-x: auto;
    border-radius: 16px;
    border: 1px solid var(--md-sys-color-outline-variant);
    background-color: var(--md-sys-color-surface);
}

.tabla-grande {
    max-height: 500px;
}

.tabla-ventas {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.tabla-ventas thead {
    background-color: var(--md-sys-color-surface-variant);
    position: sticky;
    top: 0;
    z-index: 10;
}

.tabla-ventas th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    border-bottom: 1px solid var(--md-sys-color-outline);
}

.tabla-ventas td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    color: var(--md-sys-color-on-surface);
}

.tabla-ventas tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.tabla-ventas .estado-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 500;
}

.tabla-ventas .estado-badge.sin-pagar {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
}

.tabla-ventas .estado-badge.pagada {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.tabla-ventas .estado-badge.entregada {
    background-color: HSL(120, 40%, 90%);
    color: HSL(120, 60%, 25%);
}

.tabla-ventas .estado-badge.cancelada {
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface-variant);
}

.btn-editar {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    padding: 6px 16px;
    border-radius: 100px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    font-size: 12px;
}

.btn-editar:hover {
    background-color: HSL(203, 86%, 85%);
}

/* Pagination */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 24px;
}

/* Vendedores Section Grid */
.vendedores-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.vendedor-card {
    background-color: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

.vendedor-card h3 {
    font-size: 18px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.vendedor-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.vendedor-stat {
    display: flex;
    flex-direction: column;
    padding: 8px;
    background-color: var(--md-sys-color-surface-variant);
    border-radius: 8px;
}

.vendedor-stat-label {
    font-size: 11px;
    color: var(--md-sys-color-on-surface-variant);
    font-weight: 500;
}

.vendedor-stat-value {
    font-size: 15px;
    font-weight: 700;
    color: var(--md-sys-color-primary);
    margin-top: 4px;
}

/* Seller Deudas & Pagos lists */
.vendedor-desglose {
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 12px;
    margin-bottom: 12px;
    overflow: hidden;
}

.desglose-header {
    display: flex;
    justify-content: space-between;
    padding: 10px 14px;
    background-color: var(--md-sys-color-surface-variant);
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.desglose-title {
    font-size: 12px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    display: flex;
    align-items: center;
}

.desglose-total {
    font-size: 14px;
    font-weight: 700;
}

.desglose-items {
    padding: 8px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.desglose-item {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}

.desglose-item span {
    color: var(--md-sys-color-on-surface-variant);
    display: inline-flex;
    align-items: center;
}

.desglose-item strong {
    font-weight: 600;
}

.vendedor-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
}

.vendedor-deudores {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
    padding: 12px;
    border-radius: 12px;
}

.deudores-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.deuda-item-mobile {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.4);
    padding: 8px 12px;
    border-radius: 6px;
}

.deuda-info {
    display: flex;
    flex-direction: column;
}

.deuda-info strong {
    font-size: 13px;
}

.deuda-metodo {
    font-size: 11px;
    color: var(--md-sys-color-on-error-container);
    opacity: 0.8;
}

.deuda-monto {
    font-weight: 700;
    font-size: 13px;
}

.vendedor-pagado-completo {
    background-color: HSL(120, 40%, 90%);
    color: HSL(120, 60%, 25%);
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1500;
    backdrop-filter: blur(2px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: var(--md-sys-color-surface);
    border-radius: 28px;
    box-shadow: var(--md-elevation-2);
    width: calc(100% - 32px);
    max-width: 500px;
    padding: 24px;
    border: 1px solid var(--md-sys-color-outline-variant);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 400;
}

.btn-close-modal {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
}

.modal-body .form-group {
    margin-bottom: 0;
}

.entrega-preview {
    display: flex;
    align-items: center;
    gap: 12px;
}

.entrega-actual {
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-primary);
}

#productosEditables {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.producto-editable-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--md-sys-color-surface-variant);
    padding: 8px 12px;
    border-radius: 8px;
}

.producto-editable-row .nombre {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
}

.producto-editable-row .cantidad {
    margin: 0 12px;
}

.producto-editable-row .cantidad input[type="number"] {
    width: 60px;
    text-align: center;
    padding: 6px;
    font-size: 14px;
    border-radius: 6px;
}

.btn-eliminar-item-modal {
    background: none;
    border: none;
    color: var(--md-sys-color-error);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}

.agregar-producto-section {
    background-color: var(--md-sys-color-surface-variant);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--md-sys-color-outline-variant);
}

.agregar-producto-section h4 {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 12px;
}

.agregar-producto-grid {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 8px;
    align-items: center;
}

.cantidad-controls-modal {
    display: flex;
    align-items: center;
    gap: 4px;
    background-color: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 8px;
    padding: 2px;
}

.btn-cantidad-mas-modal,
.btn-cantidad-menos-modal {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 16px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cantidad-controls-modal input {
    width: 40px;
    text-align: center;
    border: none;
    background: none;
    font-weight: bold;
    outline: none;
}

.cantidad-controls-modal input::-webkit-outer-spin-button,
.cantidad-controls-modal input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.cantidad-controls-modal input[type=number] {
    -moz-appearance: textfield;
}

#btnAgregarProducto {
    padding: 8px 16px;
    border-radius: 100px;
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    font-weight: 500;
    cursor: pointer;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.btn-guardar-cambios {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.btn-cancelar-modal {
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface-variant);
    border: 1px solid var(--md-sys-color-outline);
}

/* Spinner Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(2px);
}

.loading-overlay.hidden {
    display: none;
}

.loading-content {
    background-color: var(--md-sys-color-surface);
    padding: 24px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    box-shadow: var(--md-elevation-2);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--md-sys-color-outline-variant);
    border-top-color: var(--md-sys-color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-size: 14px;
    color: var(--md-sys-color-on-surface-variant);
}

/* Feedback messages */
.mensaje {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    margin-top: 16px;
}

.mensaje.hidden {
    display: none;
}

.mensaje.success {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border: 1px solid var(--md-sys-color-primary);
}

.mensaje.error {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
    border: 1px solid var(--md-sys-color-error);
}

/* Footer Main M3 Style */
.footer-main {
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface-variant);
    padding: 40px 24px 24px 24px;
    margin-top: auto;
    width: 100%;
    border-top: 1px solid var(--md-sys-color-outline-variant);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 32px;
}

.footer-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.footer-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--md-sys-color-primary);
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.footer-section-item {
    font-size: 13px;
    line-height: 1.6;
}

.footer-section-item a {
    color: var(--md-sys-color-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.footer-section-item a:hover {
    color: HSL(120, 60%, 25%);
    text-decoration: underline;
}

.user-badge {
    display: inline-block;
    background-color: var(--md-sys-color-outline-variant);
    color: var(--md-sys-color-on-surface-variant);
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 500;
}

.user-badge.registered {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.footer-divider {
    height: 1px;
    background-color: var(--md-sys-color-outline-variant);
    margin: 24px 0;
}

.footer-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    font-size: 12px;
}

.footer-credit a {
    color: var(--md-sys-color-primary);
    text-decoration: none;
}

/* RESPONSIVE LAYOUTS */
@media (max-width: 480px) {
    body {
        padding: 0 0 70px 0;
        background-color: var(--md-sys-color-surface);
        overflow-x: hidden;
    }

    .container {
        border-radius: 0;
        border: none;
        padding: 16px;
        margin-top: 0;
        margin-bottom: 0;
        box-shadow: none;
    }

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

    .header h1 {
        font-size: 22px;
    }

    .tab-buttons {
        width: 100%;
        border-radius: 8px;
    }

    .tab-btn {
        flex: 1;
        font-size: 11px;
        padding: 10px 4px;
    }

    /* Remove cards styling (flat edge-to-edge layout) */
    .stat-card,
    .vendedor-card {
        border-radius: 0;
        border: none;
        border-bottom: 1px solid var(--md-sys-color-outline-variant);
        padding: 16px 8px;
        margin-left: -16px;
        margin-right: -16px;
        background-color: transparent;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 8px;
        margin-left: -16px;
        margin-right: -16px;
    }

    .vendedores-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .vendedor-stats-grid {
        grid-template-columns: 1fr;
    }



    .filters-container {
        border-radius: 8px;
        padding: 12px;
        grid-template-columns: 1fr;
    }

    .footer-main {
        padding: 32px 16px 16px 16px;
    }

    .footer-content {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .footer-bottom {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    .agregar-producto-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .cantidad-controls-modal {
        justify-content: center;
        width: 100%;
    }
    
    #btnAgregarProducto {
        width: 100%;
    }
}