/* Custom Admin styles for AXIM Repuestos */

/* Widen the Razón Social input fields to look premium and spacious */
.field-razon_social input, 
#id_razon_social {
    min-width: 500px !important;
    max-width: 100% !important;
    width: 70% !important;
}

/* Widen commercial name and names as well for consistency */
.field-nombre_comercial input,
#id_nombre_comercial {
    min-width: 500px !important;
    max-width: 100% !important;
    width: 70% !important;
}

/* Image Preview Layout inside Django Admin */
.image-preview-wrapper {
    margin-top: 5px;
    display: inline-block;
    position: relative;
    border-radius: 8px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.image-preview-wrapper:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 0, 0, 0.12);
}

.image-preview-thumbnail {
    display: block;
    max-width: 280px;
    max-height: 200px;
    object-fit: contain;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.image-preview-thumbnail:hover {
    transform: scale(1.02);
}

/* Beautiful Overlay Modal for unresized view */
.admin-image-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    cursor: zoom-out;
}

.admin-image-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.admin-image-overlay img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.admin-image-overlay.active img {
    transform: scale(1);
}

.admin-image-overlay-close {
    position: absolute;
    top: 20px;
    right: 20px;
    color: #fff;
    font-size: 35px;
    font-weight: 200;
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s ease;
}

.admin-image-overlay-close:hover {
    transform: scale(1.1);
}

/* Premium Local Preview indicators */
.image-preview-wrapper.local-preview {
    border: 2px dashed #007bff !important; /* Dotted premium primary blue border */
    background: rgba(0, 123, 255, 0.04) !important;
    animation: pulseBorder 2s infinite ease-in-out;
}

.local-preview-badge {
    position: absolute;
    top: -12px;
    left: 12px;
    background: linear-gradient(135deg, #007bff, #00d2ff);
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    box-shadow: 0 4px 10px rgba(0, 123, 255, 0.25);
    pointer-events: none;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-family: 'Outfit', 'Inter', sans-serif;
}

@keyframes pulseBorder {
    0% {
        border-color: rgba(0, 123, 255, 0.5);
        box-shadow: 0 4px 12px rgba(0, 123, 255, 0.05);
    }
    50% {
        border-color: rgba(0, 123, 255, 0.9);
        box-shadow: 0 4px 20px rgba(0, 123, 255, 0.15);
    }
    100% {
        border-color: rgba(0, 123, 255, 0.5);
        box-shadow: 0 4px 12px rgba(0, 123, 255, 0.05);
    }
}

/* Widen and shorten the Descripción Detallada (descripcion_larga) field to 2 rows high */
.field-descripcion_larga textarea,
#id_descripcion_larga {
    min-width: 500px !important;
    max-width: 100% !important;
    width: 70% !important;
    height: 60px !important;
    min-height: 60px !important;
    resize: vertical;
}

/* Style for the relocated Image Preview in the right column (below save buttons) */
.model-articulo.change-form .field-imagen_preview {
    border: none !important;
    background: none !important;
    margin: 25px auto 0 auto !important;
    padding: 0 !important;
    float: none !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    width: 100% !important;
}

.model-articulo.change-form .field-imagen_preview > div {
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
}

.model-articulo.change-form .field-imagen_preview label {
    float: none !important;
    width: auto !important;
    margin: 0 0 10px 0 !important;
    padding: 0 !important;
    font-weight: bold !important;
    text-align: center !important;
    font-size: 13px !important;
    color: #444 !important;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.model-articulo.change-form .field-imagen_preview .readonly {
    margin: 0 !important;
    display: flex !important;
    justify-content: center !important;
    width: 100% !important;
}

.model-articulo.change-form .field-imagen_preview .image-preview-thumbnail {
    max-width: 100% !important;
    height: auto !important;
}

/* Hide the 'Logo de Marca' label in the main model_principal row */
.model-articulo.change-form label[for="id_marca_logo_preview"],
.model-articulo.change-form .field-marca_logo_preview label {
    display: none !important;
}

/* Style for Marca/Modelo Principal select combo */
.model-articulo.change-form .field-modelo_principal .related-widget-wrapper {
    display: inline-block !important;
    width: auto !important;
    vertical-align: middle !important;
}

.model-articulo.change-form .field-modelo_principal select,
.model-articulo.change-form #id_modelo_principal,
.model-articulo.change-form .field-modelo_principal .select2-container {
    min-width: 500px !important;
    width: 70% !important;
    max-width: 100% !important;
    display: inline-block !important;
    vertical-align: middle !important;
}

.model-articulo.change-form .field-modelo_principal select,
.model-articulo.change-form #id_modelo_principal {
    height: 38px !important;
    border-radius: 4px !important;
    border: 1px solid #ced4da !important;
    padding: 6px 12px !important;
    background-color: #fff !important;
    font-size: 14px !important;
}

/* Hide Django's built-in related action icons (add, change, delete, view) for specific select combos */
.model-articulo.change-form .field-categoria .related-widget-wrapper-link,
.model-articulo.change-form .field-categoria .add-related,
.model-articulo.change-form .field-categoria .change-related,
.model-articulo.change-form .field-categoria .delete-related,
.model-articulo.change-form .field-categoria .view-related,
.model-articulo.change-form .field-modelo_principal .related-widget-wrapper-link,
.model-articulo.change-form .field-modelo_principal .add-related,
.model-articulo.change-form .field-modelo_principal .change-related,
.model-articulo.change-form .field-modelo_principal .delete-related,
.model-articulo.change-form .field-modelo_principal .view-related {
    display: none !important;
}

/* --- Premium Custom Dashboard Styles --- */
.custom-dashboard-card {
    border-radius: 12px !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) !important;
    overflow: hidden;
    background-color: #ffffff !important;
}

.custom-dashboard-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.06) !important;
    border-color: rgba(0, 123, 255, 0.2) !important;
}

.card-icon-wrapper {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.03);
}

/* Light Background Colors for Icons */
.bg-primary-light { background-color: rgba(0, 123, 255, 0.08) !important; }
.bg-warning-light { background-color: rgba(255, 193, 7, 0.1) !important; }
.bg-success-light { background-color: rgba(40, 167, 69, 0.08) !important; }
.bg-info-light { background-color: rgba(23, 162, 184, 0.08) !important; }
.bg-purple-light { background-color: rgba(111, 66, 193, 0.08) !important; }
.bg-gray-light { background-color: rgba(108, 117, 125, 0.08) !important; }

/* Text & Button overrides */
.text-purple { color: #6f42c1 !important; }
.btn-outline-purple {
    color: #6f42c1 !important;
    border-color: rgba(111, 66, 193, 0.25) !important;
    background: transparent !important;
}
.btn-outline-purple:hover {
    color: #fff !important;
    background-color: #6f42c1 !important;
    border-color: #6f42c1 !important;
}

/* Custom spacing and margins */
.gap-2 {
    gap: 8px !important;
}

/* --- Premium Custom Timeline Styles --- */
.custom-recent-timeline {
    position: relative;
    margin: 0;
    padding: 0;
    list-style: none;
}

.custom-timeline-item {
    position: relative;
    padding-left: 24px !important;
    padding-bottom: 18px !important;
    border-left: 2px solid #e9ecef;
    margin-left: 10px;
}

.custom-timeline-item:last-child {
    border-left: none !important;
    padding-bottom: 0 !important;
}

.custom-timeline-badge {
    left: -10px;
    top: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 9px;
    z-index: 2;
    box-shadow: 0 0 0 3px #fff; /* Clean white ring to mask the vertical line */
}

.custom-timeline-content {
    padding-left: 6px;
}

/* ==========================================================================
   MÓDULO DE IMPRESIÓN DE ETIQUETAS AUTOADHESIVAS (TÉRMICAS)
   ========================================================================== */

.print-labels-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.print-labels-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.print-labels-card {
    background: #ffffff;
    border-radius: 14px;
    width: 820px;
    max-width: 92%;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.18);
    border: 1px solid rgba(0, 0, 0, 0.08);
    transform: scale(0.92);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.print-labels-overlay.active .print-labels-card {
    transform: scale(1);
}

.print-labels-header {
    padding: 16px 24px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.print-labels-header h5 {
    margin: 0;
    font-weight: 700;
    color: #1a1a1a;
    font-size: 16px;
    letter-spacing: 0.5px;
    font-family: 'Outfit', 'Inter', sans-serif;
}

.print-labels-close {
    font-size: 26px;
    font-weight: 300;
    color: #adb5bd;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.print-labels-close:hover {
    color: #dc3545;
}

.print-labels-body {
    padding: 24px;
    display: flex;
    gap: 24px;
    background: #fcfcfc;
}

.print-controls-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.print-preview-col {
    flex: 1.15;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f1f3f5;
    padding: 24px;
    border-radius: 12px;
    border: 1px solid #e9ecef;
}

.print-preview-title {
    font-size: 11px;
    font-weight: 700;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    margin-bottom: 16px;
    font-family: 'Outfit', sans-serif;
}

/* Fiel-to-life Thermal Label Mockup */
.thermal-label-preview {
    width: 380px;
    height: 228px; /* Proporción ideal 100mm x 60mm (1.66) */
    background: #ffffff;
    border: 1px solid #6c757d;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    border-radius: 6px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, sans-serif;
    color: #000000;
    position: relative;
    overflow: hidden;
    user-select: none;
    transition: all 0.3s;
}

.label-header-brand {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    border-bottom: 2px solid #000000;
    padding-bottom: 3px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.label-header-brand span {
    font-weight: 400;
    font-size: 9px;
    letter-spacing: 0.5px;
}

.label-content-grid {
    display: flex;
    flex: 1;
    margin-top: 10px;
    gap: 12px;
}

.label-details {
    flex: 1.6;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-width: 0;
}

.label-qr-wrapper {
    flex: 0.9;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #000000;
    padding: 4px;
    border-radius: 4px;
    background: #ffffff;
    height: fit-content;
    align-self: center;
}

.label-qr-wrapper img {
    width: 100%;
    height: auto;
    max-width: 105px;
    display: block;
}

.label-field {
    margin-bottom: 2px;
}

.label-field-title {
    font-size: 8px;
    font-weight: 800;
    text-transform: uppercase;
    color: #000000;
    margin: 0;
    line-height: 1;
}

.label-field-value {
    font-size: 11px;
    font-weight: 500;
    color: #000000;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.label-field-value.code-large {
    font-size: 22px;
    font-weight: 900;
    letter-spacing: -0.5px;
    line-height: 1;
    white-space: nowrap;
    margin-top: 1px;
}

.label-field-value.desc-wrap {
    font-size: 10px;
    font-weight: 700;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.25;
}

.label-footer-brand {
    font-size: 8px;
    font-weight: 800;
    text-align: center;
    border-top: 1px dashed #000000;
    padding-top: 4px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.print-labels-footer {
    padding: 16px 24px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* print-only elements hidden in browser */
#thermal-label-print-area {
    display: none !important;
}

/* ==========================================================================
   CSS DE IMPRESIÓN (OCULTA EL RESTO E IMPRIME A 100mm X 60mm)
   ========================================================================== */

@media print {
    /* Ocultar absolutamente todo en el navegador principal SOLO cuando imprimimos etiquetas */
    body.printing-labels html, body.printing-labels {
        background-color: #ffffff !important;
        margin: 0 !important;
        padding: 0 !important;
        height: auto !important;
    }
    
    /* Ocultar todos los hijos directos del body excepto el contenedor de etiquetas */
    body.printing-labels > :not(#thermal-label-print-area) {
        display: none !important;
    }
    
    /* Mostrar únicamente la sección especial de impresión */
    body.printing-labels #thermal-label-print-area {
        visibility: visible !important;
        display: block !important;
    }
    body.printing-labels #thermal-label-print-area * {
        visibility: visible !important;
    }

    body.printing-labels #thermal-label-print-area {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100mm !important;
        height: 60mm !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #ffffff !important;
        box-sizing: border-box !important;
    }

    /* Diseño específico a escala real de impresión (100mm x 60mm) */
    body.printing-labels .thermal-label-print-sticker {
        width: 100mm !important;
        height: 60mm !important;
        padding: 4mm !important;
        box-sizing: border-box !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        background: #ffffff !important;
        color: #000000 !important;
        page-break-after: always !important;
        font-family: 'Segoe UI', -apple-system, sans-serif !important;
    }

    body.printing-labels .thermal-label-print-sticker .label-header-brand {
        font-size: 11pt !important;
        font-weight: bold !important;
        border-bottom: 2pt solid #000000 !important;
        padding-bottom: 1mm !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        text-transform: uppercase !important;
        letter-spacing: 1.5px !important;
    }

    body.printing-labels .thermal-label-print-sticker .label-header-brand span {
        font-size: 8pt !important;
        font-weight: normal !important;
        display: inline !important;
    }

    body.printing-labels .thermal-label-print-sticker .label-content-grid {
        display: flex !important;
        flex-direction: row !important;
        flex: 1 !important;
        margin-top: 2mm !important;
        gap: 3mm !important;
    }

    body.printing-labels .thermal-label-print-sticker .label-details {
        flex: 1.6 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        min-width: 0 !important;
    }

    body.printing-labels .thermal-label-print-sticker .label-qr-wrapper {
        flex: 0.9 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border: 1pt solid #000000 !important;
        padding: 1mm !important;
        background: #ffffff !important;
        height: fit-content !important;
        align-self: center !important;
    }

    body.printing-labels .thermal-label-print-sticker .label-qr-wrapper img {
        width: 100% !important;
        max-width: 28mm !important;
        height: auto !important;
        display: block !important;
    }

    body.printing-labels .thermal-label-print-sticker .label-field-title {
        font-size: 7.5pt !important;
        font-weight: bold !important;
        text-transform: uppercase !important;
        margin: 0 !important;
    }

    body.printing-labels .thermal-label-print-sticker .label-field-value {
        font-size: 10.5pt !important;
        font-weight: 500 !important;
        margin: 0 !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }

    body.printing-labels .thermal-label-print-sticker .label-field-value.code-large {
        font-size: 21pt !important;
        font-weight: 900 !important;
        line-height: 1 !important;
    }

    body.printing-labels .thermal-label-print-sticker .label-field-value.desc-wrap {
        font-size: 9.5pt !important;
        font-weight: bold !important;
        white-space: normal !important;
        line-height: 1.2 !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
    }

    body.printing-labels .thermal-label-print-sticker .label-footer-brand {
        font-size: 7.5pt !important;
        font-weight: bold !important;
        text-align: center !important;
        border-top: 1pt dashed #000000 !important;
        padding-top: 1mm !important;
        text-transform: uppercase !important;
        letter-spacing: 2px !important;
    }
}

/* Styling Select2 Dropdowns globally to ensure beautiful borders, premium look, and standard padding */
.select2-container .select2-selection--single,
.select2-selection--single,
.select2-selection {
    height: 38px !important;
    border: 1px solid #ced4da !important;
    border-radius: 4px !important;
    background-color: #ffffff !important;
    display: flex !important;
    align-items: center !important;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out !important;
}

.select2-container .select2-selection--single .select2-selection__rendered,
.select2-selection__rendered {
    line-height: 36px !important;
    padding-left: 12px !important;
    padding-right: 30px !important;
    color: #495057 !important;
}

.select2-container .select2-selection--single .select2-selection__arrow,
.select2-selection__arrow {
    height: 36px !important;
    width: 30px !important;
    right: 6px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Focused state matching premium Bootstrap */
.select2-container.select2-container--focus .select2-selection--single,
.select2-container--focus .select2-selection--single,
.select2-container:focus-within .select2-selection {
    border-color: #80bdff !important;
    outline: 0 !important;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25) !important;
}

/* Ensure the wrapper fits perfectly inside the admin form rows */
.form-row .select2-container,
.form-group .select2-container,
.select2-container {
    width: 100% !important;
    max-width: 500px !important;
    display: inline-block !important;
    vertical-align: middle !important;
}

/* Custom styling for ArticuloFoto inlines */
.inline-group[data-inline-type="tabular"] .field-foto_preview,
.inline-group[data-inline-type="tabular"] .field-foto_preview_detail {
    min-width: 90px;
    text-align: center;
    vertical-align: middle;
}

.inline-group .field-foto input[type="file"] {
    font-size: 12px;
    padding: 4px;
    max-width: 220px;
}

.inline-group .field-descripcion input[type="text"] {
    min-width: 180px;
}

.inline-group .field-orden input[type="number"] {
    width: 70px !important;
    text-align: center;
}


