/* ==========================================
   CONFIGURACIÓN Y PALETA DE COLORES - ARCADIA
   ========================================== */
@import url('https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css');

:root {
    /* Paleta Neón de Arcadia Coleccionables */
    --primary-purple: #7a1fa2;         /* Morado Principal */
    --primary-purple-hover: #5c0f7f;
    --primary-purple-dark: #1e0a2d;

    --accent-pink: #ff007f;            /* Rosa Neón Secundario */
    --accent-pink-hover: #d6006b;
    --accent-pink-light: #fff0f6;

    --tertiary-blue: #00d2ff;          /* Azul Neón Terciario */
    --tertiary-blue-hover: #0099bc;
    --tertiary-blue-dark: #005f73;

    /* Aliases y Compatibilidad */
    --arcadia-purple: var(--primary-purple);
    --arcadia-pink: var(--accent-pink);
    --arcadia-blue: var(--tertiary-blue);

    /* Fondos y Estructura */
    --bg-color: #f6f4f9;
    --card-bg: #ffffff;
    --sidebar-bg: #180825;
    --sidebar-active: #2f1247;
    --border-color: #e6dbf1;
    --subtext-color: #6c757d;
    --text-color: #231929;
    --sidebar-width: 250px;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
}

/* ==========================================
   UTILIDADES Y CLASES ARCADIA
   ========================================== */
.d-none { display: none !important; }

.clickable-row { cursor: pointer; transition: background-color 0.15s ease-in-out; }
.clickable-row:hover { background-color: #f8f0fc !important; }
.clickable-row td { user-select: none; }
.clickable-row .btn, .clickable-row a { position: relative; z-index: 2; }

/* Componentes Temáticos Arcadia */
.text-arcadia { color: var(--primary-purple) !important; }

.btn-arcadia {
    background-color: var(--primary-purple) !important;
    color: #ffffff !important;
    border: none;
    transition: all 0.2s ease-in-out;
}

.btn-arcadia:hover {
    background-color: var(--primary-purple-hover) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(122, 31, 162, 0.35);
}

/* Badges y Acentos */
.badge-arcadia-pink {
    background-color: var(--accent-pink) !important;
    color: #ffffff !important;
    font-weight: 700;
}

.badge-arcadia-blue {
    background-color: var(--tertiary-blue) !important;
    color: #0b253a !important;
    font-weight: 700;
}

.card-header-arcadia {
    border-top: 4px solid var(--primary-purple) !important;
}

/* ==========================================
   AUTENTICACIÓN / LOGIN
   ========================================== */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: var(--sidebar-bg);
    padding: 20px;
}

.login-card {
    background: var(--card-bg);
    padding: 35px;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(255, 0, 127, 0.25);
    border: 2px solid var(--accent-pink);
    width: 100%;
    max-width: 380px;
}

.login-card h2 {
    margin: 0 0 20px 0;
    text-align: center;
    color: var(--primary-purple);
}

.btn-submit {
    width: 100%;
    padding: 11px;
    background: linear-gradient(135deg, var(--primary-purple), var(--accent-pink));
    border: none;
    color: #fff;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(255, 0, 127, 0.4);
}

.alert {
    padding: 12px 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 14px;
}

.alert-danger {
    background-color: #fff0f3;
    color: #c01c47;
    border: 1px solid #ffccd5;
}

/* ==========================================
   LAYOUT Y CONTENEDORES (BLOQUEO DE VIEWPORT)
   ========================================== */
.main-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden !important;
    align-items: stretch;
}

.mobile-header {
    display: none;
    background-color: var(--sidebar-bg);
    color: #fff;
    padding: 12px 16px;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 2px solid var(--accent-pink);
}

.mobile-brand { font-weight: 700; font-size: 1.1rem; color: #fff; }
.hamburger-btn, .close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
}

.content-wrapper, .main-content {
    flex: 1 1 auto;
    min-width: 0; 
    padding: 25px 30px;
    background-color: var(--bg-color);
    height: 100vh;
    overflow-y: auto !important;
    display: flex;
    flex-direction: column;
}

/* ==========================================
   TARJETAS Y CABECERAS
   ========================================== */
.page-header, .header-bar, .card, .form-container {
    background: #fff;
    padding: 18px 24px;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(122, 31, 162, 0.04);
    border: 1px solid var(--border-color);
}

.page-header, .header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    flex-shrink: 0;
}

.page-header h1, .header-bar h1 {
    margin: 0;
    font-size: 22px;
    color: var(--primary-purple);
    font-weight: 700;
}

.card, .form-container {
    padding: 25px;
    display: flex;
    flex-direction: column;
}

/* ==========================================
   ENLACES Y ELEMENTOS PASO A PASO
   ========================================== */
.back-link {
    display: inline-flex;
    align-items: center;
    color: var(--primary-purple);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    margin-top: 10px;
    margin-bottom: 15px;
    transition: color 0.2s ease;
}

.back-link:hover {
    color: var(--accent-pink);
    text-decoration: underline;
}

.step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--primary-purple);
    color: #ffffff;
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 20px;
}

.section-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-color);
    margin-top: 10px;
    margin-bottom: 15px;
}

/* ==========================================
   FORMULARIOS Y ENTRADAS
   ========================================== */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px 22px;
}

.form-group { display: flex; flex-direction: column; }
.form-group.span-2 { grid-column: span 2; }

label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 6px;
    color: var(--primary-purple);
}

input[type="text"], input[type="number"], input[type="date"], input[type="datetime-local"],
input[type="password"], input[type="file"], input[type="url"], select, textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: 13.5px;
    border: 1px solid #d1c4e9;
    border-radius: 6px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-pink);
    box-shadow: 0 0 0 3px rgba(255, 0, 127, 0.18);
}

input[type="date"], input[type="datetime-local"] {
    padding: 11px 14px !important;
    font-size: 15px !important;
    font-weight: 600;
    color: var(--primary-purple);
    border-color: #d1c4e9;
    background-color: #fcfaff;
    cursor: pointer;
    min-height: 44px;
}

input[type="date"]:disabled, input[type="datetime-local"]:disabled {
    background-color: #e9ecef !important;
    color: #888 !important;
    cursor: not-allowed;
    opacity: 0.7;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    filter: invert(18%) sepia(85%) saturate(3000%) hue-rotate(285deg);
    transform: scale(1.35);
    margin-right: 6px;
}

/* Tags y Chips */
.tag-selector-container { display: flex; flex-direction: column; gap: 10px; }
.tags-wrapper {
    display: flex; flex-wrap: wrap; gap: 8px;
    min-height: 38px; padding: 6px;
    background-color: #fcf8ff;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
}

.tag-pill, .branch-pill {
    display: inline-flex; align-items: center;
    background-color: #f3e5f5; color: var(--primary-purple);
    border: 1px solid #e1bee7; padding: 4px 12px;
    border-radius: 20px; font-size: 13px; font-weight: 600;
}

.tag-pill.primary-tag { background-color: var(--primary-purple); color: #fff; }
.tag-pill .tag-remove { margin-left: 8px; cursor: pointer; opacity: 0.7; }
.tag-pill .tag-remove:hover { opacity: 1; color: var(--accent-pink); }

.branch-pill { gap: 8px; padding: 6px 12px; font-size: 13.5px; }
.branch-pill input[type="number"] {
    width: 75px !important; padding: 3px 6px !important;
    font-size: 13px !important; height: 28px; text-align: center;
    border: 1px solid var(--primary-purple); border-radius: 4px; font-weight: bold;
}
.branch-pill .branch-remove { cursor: pointer; color: var(--accent-pink); margin-left: 4px; }
.branch-pill .branch-remove:hover { transform: scale(1.25); color: #dc3545; }

.primary-badge-text {
    font-size: 10px; background: var(--accent-pink); color: #fff;
    padding: 2px 6px; border-radius: 10px; margin-right: 6px; text-transform: uppercase;
}

/* ==========================================
   BOTONES
   ========================================== */
.form-actions { display: flex; align-items: center; gap: 12px; margin: 24px 0 8px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 16px; font-size: 13px; font-weight: 600;
    border-radius: 6px; text-decoration: none; border: none;
    cursor: pointer; transition: all 0.2s ease;
}

.btn-primary { background: var(--primary-purple); color: #fff; }
.btn-primary:hover { background: var(--primary-purple-hover); box-shadow: 0 4px 12px rgba(122, 31, 162, 0.3); }

.btn-secondary { background: var(--tertiary-blue); color: #072a38; }
.btn-secondary:hover { background: var(--tertiary-blue-hover); color: #fff; }

.btn-edit, .btn-delete { color: #fff; padding: 5px 14px; font-size: 12px; border-radius: 6px; font-weight: 600; }
.btn-edit { background: var(--accent-pink); }
.btn-edit:hover { background: var(--accent-pink-hover); }
.btn-delete { background: #dc3545; }
.btn-delete:hover { background: #bb2d3b; }

/* ==========================================
   TABLAS Y MÓDULOS (BARRA HORIZONTAL FIJA A PANTALLA)
   ========================================== */
.table-responsive {
    width: 100%;
    max-width: 100%;
    max-height: calc(100vh - 220px) !important; 
    overflow-x: auto !important;                
    overflow-y: auto !important;                
    -webkit-overflow-scrolling: touch;
    border: 1px solid #f0e2f7;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 4px 20px rgba(122, 31, 162, 0.03);
    margin-bottom: 1.5rem;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    white-space: nowrap;
}

th, td {
    padding: 14px 20px;
    text-align: left;
    border-bottom: 1px solid #f6ecfa;
    font-size: 13.5px;
    vertical-align: middle;
}

th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #fbf5fd !important;
    color: var(--primary-purple) !important;
    font-weight: 700;
    font-size: 13px;
    border-bottom: 1px solid #f2e2f9;
}

tr:first-child th:first-child { border-top-left-radius: 14px; }
tr:first-child th:last-child { border-top-right-radius: 14px; }

tr:last-child td { border-bottom: none; }

tbody tr {
    transition: background-color 0.15s ease-in-out;
}

tbody tr:hover {
    background-color: #fcf7fe;
}

/* Badges estilizados */
.badge { padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; display: inline-block; }
.badge-active { background-color: #e6f8f3; color: #0d8a6a; border: 1px solid #b2ece0; }
.badge-inactive { background-color: #fff0f3; color: #c01c47; border: 1px solid #ffccd5; }

/* ==========================================
   BIBLIOTECA DE MEDIOS Y GALERÍAS
   ========================================== */
.drop-zone {
    border: 2px dashed #d1c4e9; border-radius: 8px; padding: 25px;
    text-align: center; background: #fcf8ff; cursor: pointer; transition: all 0.2s ease;
}
.drop-zone:hover, .drop-zone.dragover { background: #f3e8fa; border-color: var(--accent-pink); }
.drop-zone-icon { font-size: 2rem; margin-bottom: 8px; color: var(--primary-purple); }
.drop-zone-text { font-size: 0.9rem; color: var(--subtext-color); }
.drop-zone-text span { color: var(--accent-pink); font-weight: 600; text-decoration: underline; }

.file-list-preview { margin-top: 15px; display: flex; flex-wrap: wrap; gap: 12px; }

.preview-thumb-card {
    position: relative; width: 90px; background: #fff;
    border: 1px solid var(--border-color); border-radius: 6px; padding: 6px;
    display: flex; flex-direction: column; align-items: center;
}

.preview-thumb-img { width: 100%; height: 70px; object-fit: cover; border-radius: 4px; }
.preview-thumb-name { font-size: 0.7rem; color: var(--text-color); margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; text-align: center; }

.preview-thumb-remove, .thumb-status-badge {
    position: absolute; top: -6px; right: -6px;
    border-radius: 50%; width: 20px; height: 20px;
    font-size: 12px; display: flex; align-items: center; justify-content: center;
}

.preview-thumb-remove { background: #dc3545; color: #fff; border: none; cursor: pointer; z-index: 12; }
.preview-thumb-remove:hover { background: #a71d2a; }

.thumb-status-badge { display: none; width: 22px; height: 22px; font-weight: bold; z-index: 10; }
.thumb-status-badge.success { background-color: #28a745; }
.thumb-status-badge.error { background-color: #dc3545; }

.thumb-progress-bar-container { width: 100%; height: 4px; background-color: #e9ecef; border-radius: 2px; margin-top: 4px; overflow: hidden; }
.thumb-progress-bar { width: 0%; height: 100%; background-color: var(--accent-pink); transition: width 0.2s ease; }

.accordion-section { border: 1px solid var(--border-color); border-radius: 8px; margin-bottom: 20px; background: #fff; overflow: hidden; }
.accordion-header {
    background-color: #fcf8ff; padding: 15px 20px; cursor: pointer;
    display: flex; justify-content: space-between; align-items: center;
    user-select: none; font-weight: bold; font-size: 1.05rem; color: var(--primary-purple);
    border-bottom: 1px solid var(--border-color); transition: background-color 0.2s;
}
.accordion-header:hover { background-color: #f3e8fa; }
.accordion-body { padding: 20px; }
.accordion-body.collapsed { display: none; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 15px; margin-top: 20px; }
.media-card { border: 1px solid var(--border-color); border-radius: 8px; padding: 10px; text-align: center; background: var(--card-bg); transition: transform 0.2s; }
.media-card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(255, 0, 127, 0.15); border-color: var(--accent-pink); }
.media-card img { width: 100%; height: 120px; object-fit: cover; border-radius: 6px; cursor: pointer; }
.media-card .file-name { font-size: 0.8rem; color: var(--subtext-color); margin: 8px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn-copy { width: 100%; font-size: 0.75rem; padding: 6px 10px; background: var(--tertiary-blue); color: #072a38; border: none; border-radius: 4px; cursor: pointer; font-weight: 700; }
.btn-copy:hover { background: var(--tertiary-blue-hover); color: #fff; }

/* Pestañas y Modales */
.media-tabs { display: flex; gap: 10px; border-bottom: 2px solid var(--border-color); padding-bottom: 8px; }
.tab-btn { padding: 10px 20px; background: #f1f1f1; border: none; border-radius: 6px 6px 0 0; font-weight: 600; cursor: pointer; color: var(--text-color); }
.tab-btn.active { background: var(--primary-purple); color: #fff; }

.tab-content { display: none; }
.tab-content.active { display: block; }
.media-card-actions { display: flex; gap: 5px; margin-top: 6px; }

/* Modales */
.media-modal, .image-lightbox, .loading-overlay {
    display: none; position: fixed; inset: 0;
    align-items: center; justify-content: center;
}

.media-modal { background: rgba(24, 8, 37, 0.8); z-index: 2000; }
.media-modal-content { background: #fff; width: 90%; max-width: 900px; border-radius: 10px; padding: 25px; position: relative; max-height: 90vh; overflow-y: auto; border: 2px solid var(--primary-purple); }

.modal-close, .lightbox-close { font-size: 28px; font-weight: bold; cursor: pointer; color: #555; position: absolute; }
.modal-close { top: 15px; right: 20px; z-index: 10; }

.modal-body { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 15px; }

.modal-image-container {
    position: relative; display: flex; align-items: center; justify-content: center;
    overflow: hidden; border-radius: 8px; background: #f8f9fa; border: 1px solid var(--border-color);
}
.modal-image-container img { width: 100%; max-height: 400px; object-fit: contain; border-radius: 8px; }

.zoom-badge {
    position: absolute; top: 10px; right: 10px; background: rgba(24, 8, 37, 0.75); color: #fff;
    border: 1px solid var(--tertiary-blue); border-radius: 50%; width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 5;
}
.zoom-badge:hover { background: var(--accent-pink); transform: scale(1.1); }

/* Lightbox */
.image-lightbox { background: rgba(10, 3, 16, 0.9); z-index: 3000; padding: 20px; }
.lightbox-content { position: relative; max-width: 90vw; max-height: 90vh; }
.lightbox-content img { max-width: 90vw; max-height: 85vh; object-fit: contain; border-radius: 8px; border: 2px solid var(--tertiary-blue); }
.lightbox-close { top: -35px; right: -10px; color: #fff; font-size: 32px; }

/* Overlay de Carga */
.loading-overlay { background: rgba(24, 8, 37, 0.9); backdrop-filter: blur(4px); z-index: 9999; }
.loading-box { background: #fff; padding: 35px 45px; border-radius: 12px; text-align: center; max-width: 400px; width: 90%; border: 2px solid var(--accent-pink); }
.loading-box h3 { margin: 15px 0 8px; color: var(--primary-purple); font-size: 1.25rem; }
.loading-box p { margin: 0; color: var(--subtext-color); font-size: 0.9rem; }

.spinner {
    width: 50px; height: 50px; border: 5px solid #f3e8ff; border-top-color: var(--accent-pink);
    border-radius: 50%; margin: 0 auto; animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* ==========================================
   ESTILOS PARA AUTOCOMPLETADO Y MÓDULO ÓRDENES
   ========================================== */
.table-responsive-overflow-visible {
    overflow-x: visible !important;
    overflow-y: visible !important;
}

.dropdown-resultados-ajax,
.ui-autocomplete {
    position: fixed !important;
    z-index: 9999 !important;
    max-height: 280px !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain !important;
    pointer-events: auto !important;
    background-color: #ffffff !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    box-shadow: 0 8px 24px rgba(122, 31, 162, 0.22) !important;
}

.dropdown-resultados-ajax::-webkit-scrollbar,
.ui-autocomplete::-webkit-scrollbar {
    width: 7px;
}

.dropdown-resultados-ajax::-webkit-scrollbar-thumb,
.ui-autocomplete::-webkit-scrollbar-thumb {
    background-color: var(--primary-purple);
    border-radius: 4px;
}

.dropdown-resultados-ajax::-webkit-scrollbar-track,
.ui-autocomplete::-webkit-scrollbar-track {
    background-color: #f3e8fa;
}

/* ==========================================
   MEDIA QUERIES (MÓVIL / PANTALLAS PEQUEÑAS)
   ========================================== */
@media (max-width: 768px) {
    html, body {
        height: 100vh;
        overflow: hidden !important;
    }

    .mobile-header { 
        display: flex; 
        position: sticky; 
        top: 0; 
        z-index: 1000; 
    }

    .main-layout { 
        display: flex; 
        flex-direction: column;
        height: 100vh; 
        overflow: hidden !important; 
    }

    .content-wrapper, .main-content { 
        padding: 12px !important; 
        width: 100vw; 
        height: calc(100vh - 55px);
        overflow-y: auto !important;
    }

    /* Contenedores y tarjetas generales adaptados a móvil */
    .card, .form-container, .page-header, .header-bar {
        padding: 15px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Forzar que las cuadrículas de los formularios sean de una sola columna */
    .form-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 15px !important;
        width: 100% !important;
    }

    .form-grid .span-2 {
        grid-column: span 1 !important;
        width: 100% !important;
    }

    /* Inputs, selects y textareas adaptados al 100% sin desbordarse */
    input[type="text"], input[type="number"], input[type="date"], input[type="datetime-local"],
    input[type="password"], input[type="file"], input[type="url"], select, textarea {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Secciones especiales y preventa */
    #seccion_preventa {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        box-sizing: border-box !important;
        padding: 12px !important;
    }

    .drop-zone {
        width: 100% !important;
        box-sizing: border-box !important;
        padding: 15px !important;
    }

    /* Botones de acción al fondo con espacio suficiente para que no queden ocultos */
    .form-actions {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        margin-bottom: 40px !important;
        width: 100% !important;
    }

    .form-actions button, .btn {
        width: 100% !important;
        padding: 12px !important;
        font-size: 1rem !important;
        margin-bottom: 5px !important;
    }

    /* Mantiene la tabla fija al viewport en dispositivos móviles */
    .table-responsive { 
        max-height: calc(100vh - 210px) !important; 
        overflow-x: auto !important; 
        overflow-y: auto !important; 
    }

    .page-header, .header-bar { flex-direction: column; align-items: stretch; gap: 12px; }
    .media-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
    .modal-body { grid-template-columns: 1fr; }

    .dropdown-resultados-ajax {
        max-width: 90vw !important;
    }
}