/**
 * Estilos del Módulo de Categorías
 * Diseño limpio, minimalista y moderno
 */

/* Layout principal */
.categorias-layout {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 20px;
}

/* Header con breadcrumb y acciones */
.categorias-header {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Breadcrumb de navegación */
.categorias-breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 12px 16px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.breadcrumb-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: #6b7280;
    font-weight: 500;
}

.breadcrumb-item svg {
    flex-shrink: 0;
}

.breadcrumb-clickable {
    cursor: pointer;
    transition: color 0.2s ease;
}

.breadcrumb-clickable:hover {
    color: #111827;
}

.breadcrumb-separator {
    color: #d1d5db;
    flex-shrink: 0;
}

/* Acciones (buscador + botón) */
.categorias-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.categorias-search-container {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.categorias-search-input {
    width: 100%;
    padding: 10px 12px 10px 38px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s ease;
    background-color: #f9fafb;
}

.categorias-search-input:focus {
    outline: none;
    border-color: #9ca3af;
    background-color: #ffffff;
}

.categorias-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    pointer-events: none;
}

/* Grid de categorías */
.categorias-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

/* Tarjeta de categoría */
.categoria-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.2s ease;
    position: relative;
}

.categoria-card-actions-top {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 6px;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.categoria-card:hover .categoria-card-actions-top {
    opacity: 1;
}

.categoria-card-drag-handle {
    width: 32px;
    height: 32px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: move;
    display: none;
}

.categoria-card-drag-handle:hover {
    background: #f9fafb;
}

.categoria-card-drag-handle svg {
    color: #9ca3af;
}

.categoria-card-edit-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #9ca3af;
}

.categoria-card-edit-btn:hover {
    background: #6366f1;
    border-color: #6366f1;
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.2);
}

.categoria-card-edit-btn:active {
    transform: translateY(0);
}

.categoria-card-edit-btn svg {
    width: 16px;
    height: 16px;
}

.categoria-card-content-wrapper {
    cursor: pointer;
}

.categoria-card-content-wrapper:hover {
    opacity: 0.95;
}

/* Estados de drag & drop */
.categoria-card-ghost {
    opacity: 0.4;
}

.categoria-card-chosen {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
    transform: rotate(2deg);
}

.categoria-card-drag {
    opacity: 0.8;
    cursor: grabbing !important;
}

.categoria-card-header {
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}

.categoria-card-image {
    width: 100%;
    height: 100%;
}

.categoria-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.categoria-card-color {
    width: 80px;
    height: 80px;
    border-radius: 12px;
}

.categoria-card-content {
    padding: 16px;
}

.categoria-card-title {
    margin: 0 0 12px 0;
    font-size: 18px;
    font-weight: 600;
    color: #111827;
}

.categoria-card-stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.categoria-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #6b7280;
}

.categoria-stat svg {
    flex-shrink: 0;
}

.categoria-stat-children {
    font-weight: 500;
    color: #111827;
}

.categoria-navigate-icon {
    margin-left: 4px;
    color: #9ca3af;
}

.categoria-parent {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #9ca3af;
    padding-top: 12px;
    border-top: 1px solid #f3f4f6;
}

.categoria-parent svg {
    flex-shrink: 0;
}

/* Estado vacío */
.categorias-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: #9ca3af;
}

.categorias-empty-state svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.categorias-empty-state p {
    margin: 0;
    font-size: 16px;
}

/* ==============================================
   MODAL DE CATEGORÍA
   ============================================== */

.categorias-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
}

.categorias-modal.active {
    display: flex;
}

.categorias-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
}

.categorias-modal-content {
    position: relative;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    background: #ffffff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    z-index: 1;
    box-sizing: border-box;
}

.categorias-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border: none;
    background: #ffffff;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
    border: 1px solid #e5e7eb;
}

.categorias-modal-close:hover {
    background: #f9fafb;
}

.categorias-modal-close svg {
    color: #6b7280;
}

.categorias-modal-body {
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 90vh;
    width: 100%;
    box-sizing: border-box;
}

/* Container del modal */
.cm-container {
    display: flex;
    flex-direction: column;
}

/* Header */
.cm-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 24px 24px 20px 24px;
    border-bottom: 1px solid #e5e7eb;
    background: #ffffff;
    position: sticky;
    top: 0;
    z-index: 5;
}

.cm-header-left {
    flex: 1;
}

.cm-parent {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.cm-title {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    color: #111827;
}

.cm-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Body */
.cm-body {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 32px;
    padding: 32px 24px;
}

/* Imagen */
.cm-image-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cm-image-section img {
    width: 100%;
    height: auto;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.cm-color-placeholder {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 64px;
    font-weight: 700;
    color: #ffffff;
    border: 1px solid #e5e7eb;
}

.cm-image-upload-area {
    width: 100%;
}

.cm-image-upload-area img {
    width: 100%;
    height: auto;
}

.cm-image-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Detalles */
.cm-details-section {
    flex: 1;
}

.cm-section {
    margin-bottom: 32px;
}

.cm-section:last-child {
    margin-bottom: 0;
}

.cm-section-title {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 600;
    color: #111827;
}

/* Info grid */
.cm-info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.cm-info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cm-label {
    font-size: 13px;
    color: #6b7280;
    font-weight: 500;
}

.cm-value {
    font-size: 14px;
    color: #111827;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cm-color-box {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    display: inline-block;
    border: 1px solid #e5e7eb;
}

/* Stats grid */
.cm-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.cm-stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.cm-stat-icon {
    width: 40px;
    height: 40px;
    background: #ffffff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
}

.cm-stat-content {
    flex: 1;
}

.cm-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: #111827;
    line-height: 1;
    margin-bottom: 4px;
}

.cm-stat-label {
    font-size: 13px;
    color: #6b7280;
}

/* Subcategorías */
.cm-subcategorias-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cm-subcat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.cm-subcat-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

.cm-subcat-name {
    flex: 1;
    font-size: 14px;
    color: #111827;
    font-weight: 500;
}

.cm-subcat-count {
    font-size: 13px;
    color: #6b7280;
}

/* ==============================================
   MODO EDICIÓN
   ============================================== */

.cm-edit-mode .cm-body {
    grid-template-columns: 200px 1fr;
}

/* Formularios */
.cm-form-group {
    margin-bottom: 20px;
}

.cm-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s ease;
    background-color: #ffffff;
    color: #111827;
}

.cm-input:focus {
    outline: none;
    border-color: #9ca3af;
}

.cm-help-text {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: #9ca3af;
}

/* Color picker */
.cm-color-picker {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.color-option {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.color-option:hover {
    transform: scale(1.1);
}

.color-option.selected {
    border-color: #111827;
    box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #111827;
}

/* Checkboxes */
.cm-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cm-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.cm-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.cm-checkbox span {
    font-size: 14px;
    color: #111827;
}

/* Botón peligro */
.btn-danger {
    background: #dc2626;
    color: #ffffff;
}

.btn-danger:hover {
    background: #b91c1c;
}

/* Scrollbar */
.categorias-modal-body::-webkit-scrollbar {
    width: 8px;
}

.categorias-modal-body::-webkit-scrollbar-track {
    background: #f3f4f6;
    border-radius: 4px;
}

.categorias-modal-body::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

.categorias-modal-body::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Responsive */
@media (max-width: 1024px) {
    .cm-body {
        grid-template-columns: 1fr;
    }

    .cm-image-section {
        max-width: 300px;
        margin: 0 auto;
    }

    .cm-stats-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .categorias-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .categorias-search-container {
        max-width: none;
    }

    .breadcrumb-item {
        font-size: 13px;
    }

    .categorias-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 16px;
    }

    /* Modal de categorías mejorado para móvil */
    .categorias-modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .categorias-modal-body {
        max-height: calc(100vh - 60px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .cm-header {
        flex-direction: column;
        gap: 16px;
        padding: 16px;
        position: relative;
    }

    .cm-header-right {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 8px;
    }

    .cm-header-right .btn {
        flex: 1;
        min-width: 0;
    }

    /* Body del modal - cambiar de grid a flex column en móvil */
    .cm-body {
        display: flex;
        flex-direction: column;
        gap: 24px;
        padding: 16px;
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    /* Imagen arriba en móvil */
    .cm-image-section {
        width: 100%;
        max-width: 100%;
        order: 1;
        margin: 0 auto;
    }

    .cm-image-section img,
    .cm-color-placeholder {
        width: 100%;
        max-width: 100%;
        height: auto;
        object-fit: contain;
    }

    .cm-image-actions {
        flex-direction: column;
        width: 100%;
    }

    .cm-image-actions .btn {
        width: 100%;
    }

    /* Detalles/formularios abajo en móvil */
    .cm-details-section {
        width: 100%;
        max-width: 100%;
        order: 2;
        box-sizing: border-box;
    }

    .cm-info-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .cm-stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .cm-section {
        margin-bottom: 24px;
    }

    /* Asegurar que todos los inputs dentro del modal no se desborden */
    .cm-details-section input,
    .cm-details-section textarea,
    .cm-details-section select,
    .cm-details-section .cm-input,
    .cm-input {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        font-size: 16px !important;
        min-height: 48px;
        padding: 14px 16px;
    }

    /* Modo edición también en columna */
    .cm-edit-mode .cm-body {
        display: flex;
        flex-direction: column;
    }
}

/* Warning box para confirmaciones */
.cm-warning-box {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: #fef3cd;
    border: 1px solid #fbbf24;
    border-radius: 8px;
    margin: 16px 0;
}

.cm-warning-box svg {
    color: #f59e0b;
    flex-shrink: 0;
    margin-top: 2px;
}

.cm-warning-box div {
    color: #92400e;
    font-size: 14px;
    line-height: 1.5;
}

.cm-warning-box strong {
    font-weight: 600;
}

