/**
 * Spectrum Categories Display Styles
 * สไตล์สำหรับ Widget แสดงหมวดหมู่
 */

/* Container หลัก */
.categories-container {
    margin: 20px 0;
    position: relative;
}

/* หัวข้อ */
.categories-display-title {
    margin-bottom: 20px;
    font-size: 24px;
    font-weight: 600;
    color: #333;
    text-align: center;
}

/* Categories List Layout */
.categories-list {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 25px;
    align-items: flex-start;
    align-content: flex-start;
    justify-content: center;
}


/* จำกัดแค่ 3 แถว */
.categories-list:not(.show-all) {
    /* max-height: calc(3 * (60px + 15px) - 15px); */
    /* 3 แถว * (ความสูงโดยประมาณ + gap) - gap สุดท้าย */
    /* overflow: hidden; */
}

/* รายการหมวดหมู่ */
.category-item {
    padding: 1px 3px;
    border: 2px solid #000000;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    position: relative;
    /* overflow: hidden; */
    opacity: 0;
    transform: translateY(20px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    min-height: 27px;
    flex-shrink: 0;
}

/* 
.category-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #007cba, #0073aa);
    transform: scaleX(0);
    transition: transform 0.3s ease;
} */

/* .category-item:hover::before {
    transform: scaleX(1);
} */

.category-item.fade-in {
    opacity: 1;
    transform: translateY(0);
}

.category-item:hover {
    border-color: #000000;
    background: #000000 !important;
    /* box-shadow: 0 8px 25px rgba(0, 124, 186, 0.15);
    transform: translateY(-5px); */
}

/* สถานะเมื่อคลิก/เลือกหมวดหมู่ */
.category-item.selected,
.category-item.clicked {
    background: #000000 !important;
    border-color: #000000 !important;
    color: #ffffff !important;
    /* box-shadow: 0 8px 25px rgba(44, 62, 80, 0.3); */
    transform: translateY(-3px);
}

.category-item.selected:hover,
.category-item.clicked:hover {
    background: #000000 !important;
    border-color: #000000 !important;
}

.category-item.selected::before,
.category-item.clicked::before {
    background: linear-gradient(90deg, #ffffff, #f8f9fa);
    transform: scaleX(1);
}

.category-item.selected .elementor-heading-title,
.category-item.clicked .elementor-heading-title,
.category-item:hover .elementor-3582 .elementor-element.elementor-element-5789c33 .elementor-heading-title {
    color: #ffffff !important;
}

.category-item.selected .category-description,
.category-item.clicked .category-description {
    color: #e9ecef !important;
}

.category-item.selected .category-count,
.category-item.clicked .category-count {
    background: #495057 !important;
    color: #ffffff !important;
}

/* ชื่อหมวดหมู่ */
.category-name {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
    color: #2c3e50;
    line-height: 1.2;
    transition: color 0.3s ease;
    text-align: center;
}

.category-item:hover .category-name {
    color: #007cba;
}

/* ซ่อน description และ count สำหรับการแสดงแบบ inline */
.category-description,
.category-count {
    display: none;
}

/* ปุ่มควบคุม */
.categories-controls {
    text-align: center;
    margin-top: -13px;
}

.show-all-categories-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    background: #fff;
    color: white;
    text-decoration: none;
    border-radius: 25px;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    font-weight: 500;
    /* box-shadow: 0 4px 15px rgba(0, 124, 186, 0.3); */
    position: relative;
    /* overflow: hidden; */
    gap: 8px;
}

/* สไตล์สำหรับไอคอนในปุ่ม */
.show-all-categories-btn .btn-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.show-all-categories-btn .btn-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.show-all-categories-btn .btn-text {
    flex: 1;
    white-space: nowrap;
}

/* เมื่อแสดงเฉพาะไอคอน */
.show-all-categories-btn.icon-only {
    padding: 12px;
    min-width: 48px;
    border-radius: 50%;
}

.show-all-categories-btn.icon-only .btn-text {
    display: none;
}

.show-all-categories-btn.icon-only .btn-icon {
    width: 24px;
    height: 24px;
}

/* Animation สำหรับไอคอน */
/* .show-all-categories-btn:hover .btn-icon {
    transform: scale(1.1);
}

.show-all-categories-btn.showing-all .btn-icon {
    transform: rotate(180deg);
} */

/* .show-all-categories-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.6s ease;
} */
/* 
.show-all-categories-btn:hover::before {
    left: 100%;
}

.show-all-categories-btn:hover {
    background: linear-gradient(135deg, #005a87, #004666);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 124, 186, 0.4);
    color: white;
    text-decoration: none;
}

.show-all-categories-btn.showing-all {
    background: linear-gradient(135deg, #dc3545, #c82333);
    box-shadow: 0 4px 15px rgba(220, 53, 69, 0.3);
}

.show-all-categories-btn.showing-all:hover {
    background: linear-gradient(135deg, #c82333, #a71d2a);
    box-shadow: 0 6px 20px rgba(220, 53, 69, 0.4);
} */

/* สถานะการโหลด */
.categories-loading {
    text-align: center;
    padding: 40px 20px;
    color: #6c757d;
    font-size: 16px;
    grid-column: 1 / -1;
    background: #f8f9fa;
    border-radius: 12px;
    border: 2px dashed #dee2e6;
}

.categories-loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-left: 10px;
    border: 2px solid #dee2e6;
    border-top-color: #007cba;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* สถานะข้อผิดพลาด */
.categories-error {
    text-align: center;
    padding: 40px 20px;
    color: #dc3545;
    font-size: 16px;
    grid-column: 1 / -1;
    background: #f8d7da;
    border: 2px solid #f5c6cb;
    border-radius: 12px;
}

/* Animation */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Visual feedback สำหรับการแทนที่คำค้นหา */
.term-replaced {
    background-color: #fff3cd !important;
    border-color: #ffeaa7 !important;
    animation: highlightPulse 1s ease-in-out;
}

@keyframes highlightPulse {

    0%,
    100% {
        background-color: #fff3cd;
    }

    50% {
        background-color: #ffecb3;
    }
}

/* Responsive Design */
@media (max-width: 1200px) {
    .categories-list {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 15px;
    }
}

@media (max-width: 768px) {
    .categories-container {
        margin: 15px 0;
    }

    .categories-display-title {
        font-size: 20px;
        margin-bottom: 15px;
    }

    .categories-list {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 20px;
    }

    .category-item {
        padding: 1px;
    }

    .category-name {
        font-size: 16px;
    }

    .category-description {
        font-size: 13px;
        -webkit-line-clamp: 2;
    }

    .show-all-categories-btn {
        padding: 10px 20px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .categories-list {
        gap: 10px;
    }

    .category-item {
        padding: 1px;
    }

    .category-name {
        font-size: 15px;
        margin-bottom: 8px;
    }

    .category-description {
        margin-bottom: 8px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .category-item {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .category-item:hover {
        border-color: #63b3ed;
        box-shadow: 0 8px 25px rgba(99, 179, 237, 0.15);
    }

    .category-item.selected,
    .category-item.clicked {
        background: #1a202c !important;
        border-color: #1a202c !important;
        color: #ffffff !important;
        box-shadow: 0 8px 25px rgba(26, 32, 44, 0.5);
    }

    .category-item.selected::before,
    .category-item.clicked::before {
        background: linear-gradient(90deg, #63b3ed, #4299e1);
    }

    .category-name {
        color: #f7fafc;
    }

    .category-item:hover .category-name {
        color: #63b3ed;
    }

    .category-item.selected .category-name,
    .category-item.clicked .category-name {
        color: #ffffff !important;
    }

    .category-description {
        color: #a0aec0;
    }

    .category-item.selected .category-description,
    .category-item.clicked .category-description {
        color: #cbd5e0 !important;
    }

    .category-count {
        background: #4a5568;
        color: #e2e8f0;
    }

    .category-item.selected .category-count,
    .category-item.clicked .category-count {
        background: #2d3748 !important;
        color: #ffffff !important;
    }

    .categories-loading {
        background: #2d3748;
        border-color: #4a5568;
        color: #a0aec0;
    }

    .categories-error {
        background: #742a2a;
        border-color: #e53e3e;
        color: #fed7d7;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .categories-list {
        gap: 10px;
    }

    .category-item {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 36px;
    }

    .categories-list:not(.show-all) {
        /* max-height: calc(4 * (40px + 10px) - 10px); */
    }
}

@media (max-width: 480px) {
    .categories-list {
        gap: 8px;
    }

    .category-item {
        padding: 8px 12px;
        font-size: 13px;
        min-height: 32px;
    }

    .categories-list:not(.show-all) {
        /* max-height: calc(3 * (36px + 8px) - 8px); */
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .category-item {
        border-width: 3px;
    }

    .category-item:hover {
        border-width: 3px;
        border-color: #000;
    }

    .show-all-categories-btn {
        border: 2px solid #000;
    }
}