:root {
    --primary-color: #00A9E0;
    /* Blue from logo */
    --primary-hover: #008fbb;
    --secondary-color: #8DC63F;
    --secondary-hover: #79ab34;
    --accent-color: #F36523;
    --bg-color: #f4f7f6;
    --card-bg: rgba(255, 255, 255, 0.9);
    --text-main: #1a1a1a;
    --text-muted: #595959;
    --sidebar-bg: #1A2E35;
    --sidebar-text: #ffffff;
    --glass-border: rgba(0, 0, 0, 0.05);
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 80px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    padding: 0 0.5rem;
}

.sidebar.collapsed #brand-name {
    display: none;
}

.btn-toggle {
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: background 0.2s;
}

.btn-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar nav ul {
    list-style: none;
    flex-grow: 1;
}

.sidebar nav li {
    display: flex;
    align-items: center;
    padding: 0.75rem 0.8rem;
    margin-bottom: 0.5rem;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    gap: 1rem;
    white-space: nowrap;
}

.sidebar.collapsed nav li span {
    display: none;
}

.sidebar nav li:hover,
.sidebar nav li.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
}

.user-info {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    overflow: hidden;
}

.sidebar.collapsed .user-details {
    display: none;
}

.user-details p {
    font-weight: 600;
    font-size: 0.9rem;
}

.user-details small {
    color: rgba(255, 255, 255, 0.5);
    text-transform: capitalize;
}

/* Main Content */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.top-bar {
    padding: 1.5rem 2rem;
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

.viewport {
    padding: 2rem;
    flex-grow: 1;
}

/* Glassmorphism Cards */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.3s;
}

.hidden {
    display: none;
    opacity: 0;
}

.modal-content {
    background: white;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    border-radius: 1rem;
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 1.25rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    flex-shrink: 0;
    background: white;
    border-radius: 1rem 1rem 0 0;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex-grow: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
    background: white;
    border-radius: 0 0 1rem 1rem;
}

/* Buttons */
.btn-primary {
    background-color: var(--primary-color);
    color: white;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 600;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.2rem;
}

.btn-delete:hover {
    filter: drop-shadow(0 0 5px rgba(243, 101, 35, 0.5));
}

/* Tables */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 1rem;
    background: #f1f5f9;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.875rem;
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

/* Badges */
.badge {
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge.administrador {
    background: #e5e7eb;
    color: #111827;
}

.badge.vendedor {
    background: #dcfce7;
    color: #166534;
}

.badge.cartera {
    background: #fef3c7;
    color: #92400e;
}

.badge.logistica {
    background: #ddd6fe;
    color: #5b21b6;
}

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

.badge.status-autorizado {
    background: #dcfce7;
    color: #166534;
}

.badge.status-enviado {
    background: #fef9c3;
    color: #854d0e;
}

.badge.status-anulado {
    background: #fdebe1;
    color: #c9521c;
}

.badge.cliente {
    background: #e0f2fe;
    color: #0369a1;
}

.status-activo {
    color: var(--secondary-color);
    font-weight: 600;
}

.status-inactivo {
    color: var(--accent-color);
    font-weight: 600;
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

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

.form-group label {
    margin-bottom: 0.4rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.form-group input,
.form-group select {
    padding: 0.6rem;
    border: 1px solid #d1d5db;
    border-radius: 0.4rem;
}

.form-group input[type="file"] {
    max-width: 100%;
}

.btn-secondary {
    background-color: #f1f5f9;
    color: #475569;
    padding: 0.6rem 1.2rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background-color: #e2e8f0;
    color: #1e293b;
}

.form-actions {
    grid-column: span 2;
    padding-top: 1rem;
    display: flex;
    justify-content: flex-end;
}

/* Modal refinements */
.visible {
    display: flex;
    opacity: 1;
}

/* Notifications */
.notification-banner {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    animation: slideDown 0.3s ease-out;
}

.notification-banner.warning {
    background-color: #fff7ed;
    border-color: #fdba74;
    color: #9a3412;
}

.notification-banner button {
    margin-left: auto;
    background: #c2410c;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.3rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tabs UI Refinement */
.tabs-container {
    background: var(--card-bg);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.tabs-header {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 2rem;
    padding: 0.5rem;
    background: #f1f5f9;
    border-radius: 0.75rem;
    width: fit-content;
}

.tab-btn {
    background-color: transparent;
    color: var(--text-muted);
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tab-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-main);
}

.tab-btn.active {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 12px rgba(74, 105, 189, 0.3);
}

/* Order Editor Meta Info */
.order-editor-meta {
    background: #ffffff;
    padding: 1.5rem 2rem;
    border: 1px solid #e2e8f0;
    border-radius: 1rem;
    margin-bottom: 2rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

.order-editor-meta .meta-item {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.order-editor-meta .meta-item strong,
.order-editor-meta .meta-item label strong {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    font-weight: 600;
}

.order-editor-meta .meta-item span {
    font-size: 1.1rem;
    font-weight: 600;
    color: #0f172a;
}

.order-editor-meta .total-item {
    margin-left: auto;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    border: 1px solid #bae6fd;
    box-shadow: 0 2px 4px rgba(14, 165, 233, 0.1);
    align-items: flex-end;
}

.order-editor-meta .total-item strong {
    color: #0369a1;
}

.order-editor-meta .total-item span {
    font-size: 1.75rem;
    color: #0284c7;
    line-height: 1;
}

.order-editor-meta .meta-item select {
    padding: 0.6rem 2.5rem 0.6rem 1rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    background-color: #f8fafc;
    font-size: 1rem;
    color: #334155;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b' stroke-width='2'%3e%3cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7' /%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 1rem;
    min-width: 200px;
}

.order-editor-meta .meta-item select:focus {
    border-color: var(--primary-color);
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(74, 105, 189, 0.15);
}

/* Dashboard Stat Cards Enhanced */
.stat-card {
    position: relative;
    overflow: hidden;
    padding: 1.25rem !important;
}

.stat-card .stat-icon {
    position: absolute;
    right: -10px;
    bottom: -10px;
    width: 100px;
    height: 100px;
    opacity: 0.15;
    background: transparent !important;
    transform: rotate(-15deg);
}

.stat-card .stat-icon svg {
    width: 100%;
    height: 100%;
}

.stat-content {
    width: 100%;
    position: relative;
    z-index: 1;
}

.stat-content h3 {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.stat-main {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-main);
    display: block;
}

.stat-grid-goals {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    padding-top: 0.75rem;
}

.stat-sub-item {
    display: flex;
    flex-direction: column;
}

.stat-sub-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: #64748b;
    font-weight: 600;
}

.stat-sub-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: #334155;
}

.stat-percentage {
    font-weight: 800;
    color: var(--primary-color);
}

/* =========================================
   RESPONSIVE DESIGN (Mobile & Tablet)
   ========================================= */
@media (max-width: 768px) {
    body {
        overflow-y: auto;
        /* Permitir scroll en el cuerpo */
        height: auto;
    }

    .app-container {
        flex-direction: column;
        /* Cambiar layout a vertical */
        height: auto;
        overflow: visible;
    }

    /* Sidebar transformado en Men�� Superior de Botones */
    .sidebar {
        width: 100%;
        height: auto;
        padding: 1rem;
        overflow: visible;
    }

    .sidebar.collapsed {
        width: 100%;
        /* Desactivar colapso en m��vil */
    }

    .sidebar-header {
        justify-content: center;
        margin-bottom: 1rem;
    }

    #toggle-sidebar {
        display: none;
        /* Ocultar bot��n de colapsar */
    }

    .sidebar nav ul {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        /* 3 Columnas */
        gap: 0.5rem;
    }

    .sidebar nav li {
        flex-direction: column;
        /* Icono arriba, texto abajo */
        justify-content: center;
        text-align: center;
        padding: 0.8rem 0.5rem;
        gap: 0.3rem;
        border: 1px solid rgba(255, 255, 255, 0.1);
        white-space: normal;
    }

    .sidebar nav li span {
        display: block !important;
        font-size: 0.75rem;
        line-height: 1.1;
    }

    .user-info {
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    /* Ajustes de Contenido Principal */
    .main-content {
        overflow: visible;
        height: auto;
    }

    .viewport {
        padding: 1rem;
    }

    /* Grillas a 1 sola columna */
    .dashboard-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-group {
        grid-column: span 1 !important;
    }

    /* Asegurar que los form-actions tambi��n se adapten a 1 columna */
    .form-actions {
        grid-column: span 1 !important;
    }

    /* Forzar campos de formulario que usen inline span 2 a 1 columna */
    .form-grid [style*="grid-column: span 2"],
    .form-grid [style*="grid-column:span 2"] {
        grid-column: span 1 !important;
    }

    /* Botones compactos (solo iconos) */
    .btn-primary span {
        display: none;
    }

    .btn-primary {
        padding: 0.6rem;
        justify-content: center;
    }

    /* Modales ajustados */
    .modal-content {
        width: 95%;
        margin: 1rem;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* Responsive Orders Table & Toolbar */
    .desktop-only {
        display: none !important;
    }

    .orders-header {
        flex-direction: column;
        align-items: stretch !important;
        gap: 1rem !important;
    }

    .orders-filters {
        flex-wrap: wrap;
        width: 100%;
    }

    .orders-filters select,
    .orders-filters input {
        flex: 1 1 40%;
        min-width: 0 !important;
        width: auto !important;
    }

    .orders-filters button {
        flex: 1 1 100%;
        justify-content: center;
        margin-top: 0.5rem;
    }

    /* Order Editor Meta Responsive */
    .order-editor-meta {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.5rem;
        padding: 1rem;
    }

    .order-editor-meta .meta-item {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem 0;
        border-bottom: 1px solid #f1f5f9;
        gap: 0.5rem;
    }

    .order-editor-meta .meta-item:last-child {
        border-bottom: none;
    }

    .order-editor-meta .total-item {
        margin-left: 0;
        margin-top: 0.5rem;
        background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
        border: 1px solid #bae6fd;
        border-radius: 0.75rem;
        padding: 1rem;
    }

    .order-editor-meta .meta-item select {
        width: 100%;
        min-width: 0;
        margin-top: 0.25rem;
    }
}

.mobile-only-block {
    display: none;
}

@media (max-width: 768px) {
    .mobile-only-block {
        display: block;
    }
}

/* Loading Spinner */
.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border-left-color: var(--primary-color);
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem auto;
}

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

    100% {
        transform: rotate(360deg);
    }
}