:root {
    --primary-color: #4f46e5;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #0ea5e9;
    
    --bg-body: #f8fafc;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --sidebar-width: 260px;
    --header-height: 70px;
    --radius-md: 12px;
    --radius-lg: 20px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: all 0.3s ease;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    vertical-align: middle;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.brand span {
    font-size: 1.3em;
    vertical-align: middle;
    margin-left: 8px;
    font-weight: 600;
    color: var(--primary-color);
}

.sidebar-nav {
    flex: 1;
    padding: 1.5rem 1rem;
    overflow-y: auto;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li {
    margin-bottom: 0.5rem;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    font-weight: 500;
}

.sidebar-nav a:hover {
    background-color: rgba(13, 110, 253, 0.05);
    color: var(--primary-color);
}

.sidebar-nav li.active a {
    background-color: var(--primary-color);
    color: #ffffff;
    box-shadow: var(--shadow-sm);
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    background-color: rgba(0,0,0,0.02);
}

.user-avatar {
    width: 40px;
    height: 40px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

.top-bar {
    height: var(--header-height);
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 90;
}

.page-title h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.top-actions {
    display: flex;
    gap: 1rem;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

.content-wrapper {
    padding: 2rem;
    flex: 1;
    overflow-y: auto;
}

/* Dashboard Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid rgba(0,0,0,0.03);
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-icon.blue { background: rgba(13, 110, 253, 0.1); color: var(--primary-color); }
.stat-icon.green { background: rgba(25, 135, 84, 0.1); color: var(--success-color); }
.stat-icon.orange { background: rgba(255, 193, 7, 0.1); color: var(--warning-color); }
.stat-icon.red { background: rgba(220, 53, 69, 0.1); color: var(--danger-color); }

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
}

.trend-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 20px;
    background: #f8f9fa;
    color: var(--text-secondary);
    font-weight: 600;
}
.trend-badge.up { color: var(--success-color); background: rgba(25, 135, 84, 0.1); }
.trend-badge.down { color: var(--danger-color); background: rgba(220, 53, 69, 0.1); }


/* Filters Section from Image */
.filters-section {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: var(--radius-lg);
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 500;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}
.btn-primary:hover { opacity: 0.9; }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.btn-outline:hover { background: #f8f9fa; }

.form-control {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    outline: none;
    font-family: inherit;
}

/* Base Tables */
.table-container {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    /* overflow-x: auto;  Removed to let inner container handle scrolling */
}

.modern-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.modern-table th {
    text-align: left;
    padding: 0.6rem;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    background-color: var(--bg-card);
}

.modern-table td {
    padding: 0.6rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.75rem;
}

.modern-table tr:last-child td {
    border-bottom: none;
}

.status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.5rem;
}
.status-indicator.green { background-color: var(--success-color); }
.status-indicator.red { background-color: var(--danger-color); }

/* Scrollable Table Container */
.table-scroll-container {
    height: calc(100vh - 220px); /* Adjust automatically to screen resolution */
    overflow-y: auto; 
    overflow-x: auto;
    position: relative;
    border: none;
    border-radius: var(--radius-md);
    /* Custom Scrollbar Styles */
    scrollbar-width: thin;
    scrollbar-color: #a1a1a1 #f1f1f1;
}

.table-scroll-container::-webkit-scrollbar {
    width: 6px; 
    height: 6px;
}

.table-scroll-container::-webkit-scrollbar-track {
    background: transparent; 
    border-radius: 3px;
}

.table-scroll-container::-webkit-scrollbar-thumb {
    background: #c1c1c1; 
    border-radius: 3px;
}

.table-scroll-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.table-scroll-container .modern-table {
    width: 100%;
}

.table-scroll-container .modern-table thead {
    position: sticky;
    top: 0;
    z-index: 100;
}

.table-scroll-container .modern-table thead tr {
    display: table;
    width: 100%;
    table-layout: fixed;
}

.table-scroll-container .modern-table tbody {
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
}

.table-scroll-container .modern-table tbody tr {
    display: table;
    width: 100%;
    table-layout: fixed;
}

.table-scroll-container .modern-table th {
    position: sticky;
    top: 0;
    background-color: #ffffff !important;
    z-index: 101; 
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    white-space: nowrap;
}

.table-scroll-container .modern-table td {
    white-space: normal; 
}

/* Specific column widths for clientes table */
.modern-table th.col-nombre,
.modern-table td.col-nombre {
    width: 20%;
    max-width: 20%;
}

.modern-table th.col-ciudad,
.modern-table td.col-ciudad {
    width: 20%;
    max-width: 20%;
}

/* Table Column Resizer Styles */
.resizer:hover, .resizer.resizing {
    background-color: var(--primary-color);
    opacity: 0.5;
}
.th-content {
    width: 100%;
}

/* Table Column Resizer Styles */
.resizer:hover, .resizer.resizing {
    background-color: var(--primary-color);
    opacity: 0.5;
}
.th-content {
    width: 100%;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(3px);
}

.modal-content-pedido {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    max-width: 900px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.modal-header h4 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 2rem;
    color: white;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.modal-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.loading-spinner {
    text-align: center;
    padding: 2rem;
    color: var(--primary-color);
    font-size: 1.1rem;
}

.detalle-grid {
    width: 100%;
}

.clickable-cell:hover {
    background-color: #e3f2fd !important;
    transition: background-color 0.2s;
}

/* Small Button Styles */
.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
    border-radius: 0.25rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-info {
    background-color: var(--info-color);
    color: #000;
}

.btn-info:hover {
    background-color: #0bb5db;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-info i {
    font-size: 0.9rem;
}

/* ===== RESPONSIVE ===== */

/* Overlay fondo oscuro - solo activo en móvil */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 99;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}
.sidebar-overlay.active { display: block; }

/* ── TABLET (768 – 1024px): rail de iconos, siempre visible ── */
@media (min-width: 768px) and (max-width: 1024px) {
    :root { --sidebar-width: 72px; }

    .sidebar { overflow: visible; }
    .sidebar-header { justify-content: center; padding: 0 0.5rem; }
    .brand span { display: none; }
    .brand img  { width: 38px; height: 38px; }

    .sidebar-nav { padding: 1rem 0.5rem; }
    .sidebar-nav a {
        justify-content: center;
        padding: 0.85rem;
        border-radius: 14px;
        position: relative;
    }
    .sidebar-nav a span { display: none; }
    .sidebar-nav a i    { font-size: 1.2rem; margin: 0; }

    .sidebar-nav a::after {
        content: attr(data-tip);
        position: absolute;
        left: calc(100% + 12px);
        top: 50%;
        transform: translateY(-50%);
        background: #1e293b;
        color: #fff;
        padding: 5px 12px;
        border-radius: 8px;
        font-size: 0.78rem;
        font-weight: 500;
        white-space: nowrap;
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.15s ease;
        box-shadow: var(--shadow-md);
        z-index: 300;
    }
    .sidebar-nav a:hover::after { opacity: 1; }

    .sidebar-footer  { padding: 0.75rem 0.5rem; }
    .user-details    { display: none; }
    .user-info       { justify-content: center; }
    .user-avatar     { width: 36px; height: 36px; font-size: 1rem; }
}

/* ── MÓVIL (< 768px): drawer que entra desde la izquierda ── */
@media (max-width: 767px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 600;
        box-shadow: none;
        transition: transform 0.27s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 6px 0 24px rgba(0,0,0,0.15);
    }
    .main-content    { margin-left: 0; padding-bottom: 60px; }
    .content-wrapper { padding: 1rem; }
    .top-bar         { padding: 0 1rem; }
    .page-title h1   { font-size: 1.05rem; }

    /* Ocultar botón ☰ — reemplazado por bottom nav */
    .mobile-menu-btn { display: none !important; }

    /* Mostrar bottom nav */
    .mobile-bottom-nav { display: flex !important; }

    /* Subir el chat widget para que no tape la bottom nav */
    #n8n-chat-widget { bottom: 80px !important; }
}

/* Botón ☰ — oculto por defecto */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 98;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: #fff;
    color: var(--text-primary);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    box-shadow: var(--shadow-md);
    transition: all 0.18s;
}
.mobile-menu-btn:hover {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

/* ─────────────────────────────────────────────
   MOBILE BOTTOM NAVIGATION BAR
   Visible solo en móvil (< 768px)
───────────────────────────────────────────── */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    z-index: 500;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
}

.mobile-bottom-nav::-webkit-scrollbar { height: 2px; }
.mobile-bottom-nav::-webkit-scrollbar-track { background: transparent; }
.mobile-bottom-nav::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 1px; }

.mobile-bottom-nav a,
.mobile-bottom-nav .mob-more-btn {
    flex-shrink: 0;
    min-width: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
    transition: color 150ms ease;
    min-height: 60px;
    padding: 4px 8px;
    border: none;
    background: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    font-family: var(--font-family);
}

.mobile-bottom-nav a i,
.mobile-bottom-nav .mob-more-btn i {
    font-size: 1.25rem;
    line-height: 1;
}

.mobile-bottom-nav a .label,
.mobile-bottom-nav .mob-more-btn .label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mobile-bottom-nav a.active,
.mobile-bottom-nav a.active i {
    color: var(--primary-color);
}

@media (hover: hover) {
    .mobile-bottom-nav a:hover,
    .mobile-bottom-nav .mob-more-btn:hover {
        color: var(--primary-color);
    }
}
