/* ======================================================================
   MARKARTE DESIGN SYSTEM - "LASER PRECISION SAAS"
   Colores: #0284c7 (Laser Cyan Blue), #0f172a (Deep Carbon Slate),
   #10b981 (Emerald Production Green), #f59e0b (Amber), #e11d48 (Rose Alert)
   ====================================================================== */

:root {
    --primary: #0284c7;
    --primary-hover: #0369a1;
    --primary-light: #e0f2fe;
    --secondary: #0f172a;
    --secondary-hover: #1e293b;
    --tertiary: #10b981;
    --tertiary-light: #ecfdf5;
    --amber: #f59e0b;
    --amber-light: #fef3c7;
    --danger: #e11d48;
    --danger-light: #ffe4e6;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --border: #e2e8f0;
    --border-focus: #0284c7;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --sidebar-width: 260px;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.05), 0 1px 2px -1px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.06);
}

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

html, body {
    max-width: 100%;
    overflow-x: clip;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
}

/* Sidebar táctico de navegación */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--secondary);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1000;
    border-right: 1px solid #1e293b;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
    padding: 16px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-sidebar-close {
    display: none;
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    line-height: 1;
    margin-left: auto;
    transition: all 0.15s ease;
}

.btn-sidebar-close:hover {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.12);
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 990;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.brand-monogram {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--primary), #38bdf8);
    color: #ffffff;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.5px;
    box-shadow: 0 0 12px rgba(2, 132, 199, 0.4);
}

.brand-info h1 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.5px;
    line-height: 1.2;
}

.brand-info span {
    font-size: 11px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.nav-menu {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}

.nav-section-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #64748b;
    padding: 12px 10px 4px 10px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: #cbd5e1;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s ease;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

.nav-item.active {
    background-color: var(--primary);
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(2, 132, 199, 0.3);
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background-color: #0b1120;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
}

.user-meta {
    line-height: 1.2;
}

.user-name {
    font-size: 12px;
    font-weight: 600;
    color: #f8fafc;
}

.user-role-badge {
    display: inline-block;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 600;
    text-transform: uppercase;
}

.role-admin {
    background-color: rgba(2, 132, 199, 0.2);
    color: #38bdf8;
    border: 1px solid rgba(2, 132, 199, 0.4);
}

.role-ventas {
    background-color: rgba(16, 185, 129, 0.2);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.4);
}

.role-produccion {
    background-color: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.4);
}

.btn-logout {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-logout:hover {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.1);
}

/* Área de contenido principal */
.main-wrapper {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
    transition: margin-left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Colapso en escritorio (pantalla completa para Kanban / tablas) */
body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
}
body.sidebar-collapsed .main-wrapper {
    margin-left: 0 !important;
}

.top-bar {
    min-height: 60px;
    height: auto;
    background-color: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 24px;
    position: sticky;
    top: 0;
    z-index: 500;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.05);
    transition: all 0.2s ease;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.btn-sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--secondary);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.btn-sidebar-toggle:hover {
    background-color: #f1f5f9;
    color: var(--primary);
    border-color: #cbd5e1;
}

body.sidebar-collapsed .btn-sidebar-toggle {
    background-color: var(--primary-light);
    color: var(--primary);
    border-color: #bae6fd;
}

.page-title {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.page-guide-breadcrumb {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    line-height: 1.2;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.page-guide-breadcrumb .guide-sep {
    color: #94a3b8;
    font-size: 11px;
}

.page-guide-breadcrumb .guide-role {
    font-size: 9.5px;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 700;
}

.page-guide-breadcrumb .guide-current {
    color: var(--primary);
    font-weight: 700;
}

.page-title h2 {
    font-size: 17px;
    font-weight: 700;
    color: var(--secondary);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.content-container {
    padding: 24px;
    flex: 1;
    min-width: 0;
}

/* Componentes de Cards y Paneles */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f1f5f9;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--secondary);
}

/* Grilla de Métricas KPIs */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.kpi-card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background-color: var(--primary);
}

.kpi-card.success::before { background-color: var(--tertiary); }
.kpi-card.warning::before { background-color: var(--amber); }
.kpi-card.danger::before { background-color: var(--danger); }

.kpi-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--secondary);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.kpi-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* Botones */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s ease;
    text-decoration: none;
    font-family: inherit;
}

.btn-primary {
    background-color: var(--primary);
    color: #ffffff;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: #ffffff;
    border-color: var(--border);
    color: var(--secondary);
}

.btn-secondary:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
}

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

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

/* Tablas de Datos de Alta Densidad */
.data-table-container {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 220px);
    position: relative;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: #ffffff;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 13px;
}

.data-table thead th,
.data-table th,
.master-table thead th,
.master-table th {
    background-color: #f8fafc;
    color: var(--text-muted);
    font-weight: 600;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 15;
    box-shadow: inset 0 -1px 0 var(--border), 0 2px 4px rgba(15, 23, 42, 0.05);
}

.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-main);
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background-color: #f8fafc;
}

.data-table td.numeric,
.data-table th.numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Badges / Chips de Estatus */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.badge-info {
    background-color: var(--primary-light);
    color: var(--primary);
    border: 1px solid #bae6fd;
}

.badge-success {
    background-color: var(--tertiary-light);
    color: #047857;
    border: 1px solid #a7f3d0;
}

.badge-warning {
    background-color: var(--amber-light);
    color: #b45309;
    border: 1px solid #fde68a;
}

.badge-danger {
    background-color: var(--danger-light);
    color: #be123c;
    border: 1px solid #fecdd3;
}

.badge-backorder {
    background-color: #ffe4e6;
    color: #be123c;
    font-weight: 700;
    border: 1px solid #fda4af;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Formularios e Inputs */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--secondary);
    margin-bottom: 6px;
}

.form-label.required::after {
    content: ' *';
    color: var(--danger);
}

.form-control {
    width: 100%;
    height: 38px;
    padding: 8px 12px;
    background-color: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    color: var(--text-main);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.15);
}

/* Modales y Notificaciones Toast */
.modal-overlay,
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay.active,
.modal.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content,
.modal-card,
.modal-dialog {
    background: #ffffff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 540px;
    overflow: hidden;
    transform: translateY(20px);
    transition: transform 0.2s ease;
}

.modal-overlay.active .modal-content,
.modal-overlay.active .modal-card,
.modal.active .modal-content,
.modal.active .modal-card,
.modal.active .modal-dialog {
    transform: translateY(0);
}

.modal-header {
    padding: 16px 20px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-body {
    padding: 20px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 16px 20px;
    background: #f8fafc;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Toast flotante */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    background: var(--secondary);
    color: #ffffff;
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.2s ease;
}

.toast.success { border-left: 4px solid var(--tertiary); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--amber); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ======================================================================
   LOGO DINÁMICO ADAPTATIVO (MODO DIURNO / NOCTURNO)
   - Modo diurno: marco blanco, elementos negros
   - Modo nocturno: marco negro, elementos blancos (inversión de espectro)
   ====================================================================== */
.brand-logo-frame {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: #ffffff;
    border-radius: var(--radius-md);
    padding: 10px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    overflow: hidden;
}

.brand-logo-dynamic {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: filter 0.3s ease;
    filter: none; /* Modo diurno: fondo blanco con elementos negros */
}

/* Adaptación automática al modo nocturno (Dark Mode del dispositivo/SO) */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .brand-logo-frame {
        background-color: #000000;
        border-color: #1e293b;
        box-shadow: 0 0 16px rgba(2, 132, 199, 0.2);
    }
    :root:not([data-theme="light"]) .brand-logo-dynamic {
        filter: invert(1); /* Modo nocturno: fondo negro con elementos blancos */
    }
}

/* Soporte explícito con atributo data-theme o clase .dark */
[data-theme="dark"] .brand-logo-frame,
.dark .brand-logo-frame {
    background-color: #000000 !important;
    border-color: #1e293b !important;
    box-shadow: 0 0 16px rgba(2, 132, 199, 0.2) !important;
}
[data-theme="dark"] .brand-logo-dynamic,
.dark .brand-logo-dynamic {
    filter: invert(1) !important;
}

[data-theme="light"] .brand-logo-frame {
    background-color: #ffffff !important;
    border-color: var(--border) !important;
    box-shadow: var(--shadow-sm) !important;
}
[data-theme="light"] .brand-logo-dynamic {
    filter: none !important;
}

/* En la barra lateral oscura del ERP */
.sidebar .brand-logo-frame {
    background-color: #000000;
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
    padding: 4px;
}
.sidebar .brand-logo-dynamic {
    filter: invert(1);
}

/* ======================================================================
   RESPONSIVIDAD MÓVIL Y TABLET (MARKARTE RESPONSIVE ENGINE)
   ====================================================================== */

@media (max-width: 1023px) {
    body {
        overflow-x: hidden;
    }

    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        max-width: 85vw;
        box-shadow: none;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 4px 0 25px rgba(0, 0, 0, 0.45);
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .btn-sidebar-close {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar-backdrop {
        display: block;
    }

    body.sidebar-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .main-wrapper {
        margin-left: 0 !important;
        width: 100%;
        min-width: 0;
        max-width: 100vw;
    }

    .top-bar {
        padding: 8px 14px;
        min-height: 56px;
        gap: 8px;
    }

    .top-bar-left {
        gap: 10px;
    }

    .page-title h2 {
        font-size: 15px;
    }

    .top-actions {
        gap: 6px;
    }

    .top-actions .btn {
        padding: 6px 10px;
        font-size: 12px;
    }

    .content-container {
        padding: 14px;
    }

    .kpi-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 10px;
    }

    .kpi-card {
        padding: 14px;
    }

    .kpi-value {
        font-size: 20px;
    }

    .pos-grid {
        grid-template-columns: 1fr !important;
    }

    .data-table-container {
        max-height: calc(100vh - 180px);
    }

    /* Tablero Kanban responsive con deslizamiento horizontal suave */
    .kanban-board {
        display: flex !important;
        overflow-x: auto !important;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        gap: 12px !important;
        padding-bottom: 16px;
        padding-right: 20px;
    }

    .kanban-col {
        flex: 0 0 85vw !important;
        max-width: 320px !important;
        scroll-snap-align: center;
        max-height: calc(100vh - 140px);
    }

    .col-header {
        position: sticky;
        top: 0;
        z-index: 5;
    }
}

@media (max-width: 640px) {
    .top-bar {
        flex-wrap: wrap;
        padding: 8px 12px;
    }

    .top-bar-left {
        width: 100%;
        justify-content: flex-start;
    }

    .top-actions {
        width: 100%;
        justify-content: flex-end;
        padding-top: 6px;
        border-top: 1px dashed rgba(226, 232, 240, 0.7);
        margin-top: 4px;
        flex-wrap: wrap;
    }

    .kpi-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .kpi-card {
        padding: 10px;
    }

    .kpi-label {
        font-size: 10px;
        margin-bottom: 4px;
    }

    .kpi-value {
        font-size: 17px;
    }

    .kpi-meta {
        display: none;
    }

    .card {
        padding: 14px;
        margin-bottom: 14px;
    }
}


