/* =========================================
   ESTILOS DEL MÓDULO DE PLANTILLAS
   Alineado con identidad AutoDeal 360
   ========================================= */

:root {
    --color-primary: #3498db;
    --color-primary-dark: #2980b9;
    --color-secondary: #2c3e50;
    --color-success: #27ae60;
    --color-danger: #e74c3c;
    --color-border: #dee2e6;
    --bg-light: #f4f6f9;
}

body {
    background-color: var(--bg-light);
    font-family: 'Roboto', sans-serif;
    margin: 0;
    padding: 0;
    /* Aseguramos que el body pueda hacer scroll */
    overflow-y: auto;
}

.module-wrapper {
    max-width: 1100px;
    margin: 20px auto;
    padding: 0 15px;
}

/* Cabeceras estilo ERP */
.module-header {
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    margin-bottom: 20px;
    border-left: 5px solid var(--color-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.module-title {
    font-size: 20px;
    color: var(--color-secondary);
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Tarjetas base ERP */
.card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    padding: 20px;
    border: 1px solid #e9ecef;
}

/* Tablas */
.modern-data-table {
    width: 100%;
    border-collapse: collapse;
}
.modern-data-table th {
    background-color: #f8f9fa;
    color: #495057;
    font-weight: 600;
    padding: 12px;
    border-bottom: 2px solid #dee2e6;
    text-transform: uppercase;
    font-size: 12px;
}
.modern-data-table td {
    padding: 12px;
    border-bottom: 1px solid #eee;
    color: #333;
    font-size: 14px;
}
.modern-data-table tr:hover { background-color: #f1f5ff; }

/* Botones Acciones Tabla */
.btn-action {
    background: #f8f9fa;
    border: 1px solid #ced4da;
    color: #495057;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}
.btn-action:hover { background: var(--color-primary); color: white; border-color: var(--color-primary); }

/* =========================================
   ZONA DEL CONSTRUCTOR (WIZARD)
   ========================================= */
.builder-container {
    max-width: 900px;
    margin: 0 auto;
    padding-bottom: 50px; /* Espacio extra al final para scrollear cómodo */
}

.builder-card {
    background: white;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
    position: relative;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.builder-card:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.15);
}

.card-top-border {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 8px;
    background-color: var(--color-primary);
    border-radius: 8px 8px 0 0;
}

.form-title-input {
    width: 100%;
    font-size: 24px;
    font-weight: 700;
    color: var(--color-secondary);
    border: none;
    border-bottom: 2px solid #eee;
    padding: 10px 0;
    margin-bottom: 5px;
    box-sizing: border-box;
}
.form-title-input:focus { outline: none; border-bottom-color: var(--color-primary); }

.help-text { color: #888; font-size: 12px; margin: 0; }

/* Categorías */
.category-block {
    margin-bottom: 40px;
    background: #fdfdfd;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 15px;
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f1f3f5;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 15px;
    border-left: 4px solid var(--color-secondary);
}

.cat-title-input {
    font-size: 18px;
    font-weight: 700;
    border: none;
    background: transparent;
    width: 100%;
    color: #2c3e50;
    border-bottom: 1px solid transparent;
}
.cat-title-input:focus { outline: none; border-bottom-color: var(--color-primary); }

/* Preguntas */
.question-card {
    margin-left: 20px;
    margin-bottom: 15px;
}

.q-row-1 {
    display: flex;
    flex-wrap: wrap; /* En móviles se apila */
    gap: 15px;
    margin-bottom: 20px;
}

.q-input {
    flex: 1;
    min-width: 250px;
    font-size: 15px;
    padding: 12px;
    background: #f8f9fa;
    border: 1px solid #ced4da;
    border-radius: 4px;
    box-sizing: border-box;
}
.q-input:focus { outline: none; border-color: var(--color-primary); background: #fff; }

.q-type-select {
    width: 250px;
    padding: 12px;
    border-radius: 4px;
    border: 1px solid #ced4da;
    font-size: 14px;
    color: #495057;
}

/* Opciones Internas (Corrección de Desbordamiento) */
.options-list { margin-top: 15px; }

.option-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    width: 100%;
}

.option-icon { color: #adb5bd; font-size: 16px; width: 20px; text-align: center; }

.option-input {
    flex: 1; /* Ocupa el espacio disponible en lugar de ancho fijo */
    border: 1px solid transparent;
    border-bottom: 1px solid #dee2e6;
    padding: 8px;
    font-size: 14px;
    transition: 0.2s;
    box-sizing: border-box;
}
.option-input:focus { outline: none; border-bottom-color: var(--color-primary); background: #f8f9fa; }

.btn-remove-opt { color: #adb5bd; cursor: pointer; border: none; background: none; font-size: 16px; padding: 5px 10px; }
.btn-remove-opt:hover { color: var(--color-danger); }

/* Cuadrículas (Grids) - CORRECCIÓN DE DESBORDAMIENTO */
.grid-setup-container {
    display: flex;
    flex-wrap: wrap; /* CLAVE: Si no cabe, baja a la siguiente línea */
    gap: 20px;
    margin-top: 15px;
}

.grid-col {
    flex: 1;
    min-width: 250px; /* Ancho mínimo para que no se aplaste */
    border: 1px solid #e9ecef;
    padding: 15px;
    border-radius: 8px;
    background: #fcfcfc;
    box-sizing: border-box;
}

.grid-col h5 { margin-top: 0; color: #6c757d; margin-bottom: 15px; font-size: 14px; }

/* Escala Lineal */
.scale-container { display: flex; align-items: center; gap: 15px; flex-wrap: wrap; }
.scale-selects { display: flex; align-items: center; gap: 10px; }
.scale-labels { display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 200px; }
.scale-label-row { display: flex; align-items: center; gap: 10px; }

/* Footer de Pregunta */
.q-footer {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.8);
    display: flex; justify-content: center; align-items: center;
    z-index: 9999;
}
.spinner-box { text-align:center; background:white; padding:30px; border-radius:10px; box-shadow:0 4px 15px rgba(0,0,0,0.1); }

/* =========================================
   DRAG AND DROP (ARRASTRAR Y SOLTAR)
   ========================================= */

.drag-handle {
    cursor: grab;
    text-align: center;
    color: #dadce0;
    padding: 2px 0 8px 0;
    margin-top: -10px;
    font-size: 16px;
    transition: color 0.2s;
    width: 100%;
}

.drag-handle:hover {
    color: #5f6368;
}

.drag-handle:active {
    cursor: grabbing;
}

/* Efecto cuando el elemento está siendo arrastrado (fantasma) */
.dragging {
    opacity: 0.4;
    transform: scale(0.98);
}

/* Efecto sobre el área donde se va a soltar */
.drag-over {
    border-top: 3px solid var(--color-primary) !important;
    padding-top: 15px !important;
    transition: padding 0.2s, border 0.2s;
}

/* Zona para soltar preguntas en categorías vacías */
.empty-q-drop {
    border: 2px dashed #ccc;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    color: #999;
    margin: 10px 0 10px 20px;
    transition: all 0.2s;
}

.empty-q-drop.drag-over {
    background-color: #f0f7ff;
    border-color: var(--color-primary);
    color: var(--color-primary);
    border-top: 2px dashed var(--color-primary) !important; /* Overriding top border */
}

/* Agarrador pequeño para opciones/filas */
.drag-handle-small {
    cursor: grab; color: #ccc; padding: 0 5px; font-size: 14px;
}
.drag-handle-small:active { cursor: grabbing; color: #999; }

/* Switch para "Obligatorio" */
.switch { position: relative; display: inline-block; width: 34px; height: 18px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 2px; bottom: 2px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--color-success); }
input:checked + .slider:before { transform: translateX(16px); }