/* FrontCat Modern Category Selector - Updated for Better Hierarchy */
.frontcat-category-selector {
    border: 1px solid var(--fc-border-color, #e2e8f0);
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
    margin-bottom: 15px;
}

.frontcat-cat-header {
    padding: 12px 16px;
    background: #f8fafc;
    border-bottom: 1px solid var(--fc-border-color, #e2e8f0);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.frontcat-cat-search {
    width: 100%;
    position: relative;
}

.frontcat-cat-search input {
    width: 100%;
    padding: 8px 12px 8px 36px !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 6px !important;
    font-size: 14px !important;
    background: #fff !important;
}

.frontcat-cat-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    width: 16px;
    height: 16px;
}

.frontcat-cat-list {
    max-height: 250px;
    overflow-y: auto;
    padding: 10px;
}

/* Scrollbar Styling */
.frontcat-cat-list::-webkit-scrollbar {
    width: 6px;
}
.frontcat-cat-list::-webkit-scrollbar-track {
    background: #f1f5f9;
}
.frontcat-cat-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
.frontcat-cat-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Clear All Button */
.frontcat-clear-all {
    font-size: 12px;
    color: #ef4444;
    text-decoration: none;
    font-weight: 500;
    margin-left: auto;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}
.frontcat-clear-all:hover {
    background: #fef2f2;
    text-decoration: underline;
}

/* Tree Item Structure */
.frontcat-cat-item {
    display: block; /* Ensure block for nesting */
    position: relative;
}

/* Item Header (Toggle + Label + Actions) */
.frontcat-item-header {
    display: flex;
    align-items: center;
    padding: 4px 0;
    border-radius: 6px;
    transition: background 0.2s;
}

.frontcat-item-header:hover {
    background: #f1f5f9;
}

/* Toggle Button & Placeholder */
.frontcat-cat-toggle,
.frontcat-toggle-placeholder {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    cursor: pointer;
    flex-shrink: 0;
    margin-right: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.frontcat-cat-toggle:hover {
    background: #e2e8f0;
    color: #475569;
}

.frontcat-cat-toggle.open svg {
    transform: rotate(180deg);
}

/* Label & Input */
.frontcat-item-label {
    flex: 1;
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
    color: #334155;
    margin: 0 !important;
    user-select: none;
}

.frontcat-item-input {
    display: none; /* Hide default input */
}

/* Custom Checkbox/Radio */
.frontcat-item-custom-check {
    width: 18px;
    height: 18px;
    border: 2px solid #cbd5e1;
    border-radius: 4px;
    margin-right: 10px;
    position: relative;
    transition: all 0.2s;
    flex-shrink: 0;
}

.frontcat-item-input[type="radio"] + .frontcat-item-custom-check {
    border-radius: 50%;
}

.frontcat-item-input:checked + .frontcat-item-custom-check {
    background-color: var(--fc-primary-color, #673DE6);
    border-color: var(--fc-primary-color, #673DE6);
}

.frontcat-item-input:checked + .frontcat-item-custom-check::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Active Text */
.frontcat-item-input:checked ~ .frontcat-item-text {
    color: var(--fc-primary-color, #673DE6);
    font-weight: 500;
}

/* Actions (Delete) */
.frontcat-item-actions {
    opacity: 0;
    margin-left: 8px;
    transition: opacity 0.2s;
}

.frontcat-item-header:hover .frontcat-item-actions {
    opacity: 1;
}

@media (hover: none) {
    .frontcat-item-actions {
        opacity: 1;
    }
}

.frontcat-delete-cat-btn {
    color: #cbd5e1;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
}

.frontcat-delete-cat-btn:hover {
    color: #ef4444;
    background: #fef2f2;
    border-radius: 4px;
}

/* Sub-category List (Hierarchy) - Clean Tree Style */
.frontcat-sub-cat-list {
    display: none;
    padding-left: 0;
    margin-left: 0; 
    border-left: none; /* Remove vertical line */
}

/* Indent items inside sub-list - Simple Indentation */
.frontcat-sub-cat-list .frontcat-cat-item {
    padding-left: 24px; /* Increase indentation for clear hierarchy */
}
.frontcat-sub-cat-list .frontcat-sub-cat-list .frontcat-cat-item {
    padding-left: 48px; /* 2nd Level */
}
/* We can use a general rule or just rely on nesting if DOM is nested. 
   Current PHP nesting: frontcat_render_cat_tree is recursive inside the item div? 
   Yes: echo '</div>'; is AFTER the recursive call.
   So .frontcat-sub-cat-list is inside .frontcat-cat-item.
   
   Structure:
   .item
     .header
     .sub-list
       .item
         .header
         .sub-list
   
   So padding-left on .sub-list or margin-left on .sub-list works recursively.
*/
.frontcat-sub-cat-list {
    margin-left: 20px; /* Indent the whole list */
}

.frontcat-sub-cat-list .frontcat-cat-item {
    padding-left: 0; /* Reset padding since we use margin on list */
}

/* Toggle Button Rotation */
.frontcat-cat-toggle svg {
    transition: transform 0.2s;
    color: #cbd5e1; /* Lighter toggle color */
}

.frontcat-cat-toggle.open svg {
    transform: rotate(90deg); /* Rotate 90deg for down direction */
}

/* Checkbox Styling - Cleaner Rounder Look */
.frontcat-item-custom-check {
    width: 18px;
    height: 18px;
    border: 1px solid #cbd5e1; /* Thinner border */
    border-radius: 4px; /* Rounded square */
    background: #fff;
}

.frontcat-item-input[type="radio"] + .frontcat-item-custom-check {
    border-radius: 50%;
}

.frontcat-item-input:checked + .frontcat-item-custom-check {
    background-color: var(--fc-primary-color, #673DE6);
    border-color: var(--fc-primary-color, #673DE6);
}

/* Checkmark refinement */
.frontcat-item-input:checked + .frontcat-item-custom-check::after {
    left: 6px;
    top: 2px;
    width: 4px;
    height: 9px;
    border-width: 0 2px 2px 0;
}

.frontcat-selected-cats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px;
    background: #fff;
    border-top: 1px solid var(--fc-border-color, #e2e8f0);
}

.frontcat-cat-pill {
    background: #f1f5f9;
    color: #475569;
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #e2e8f0;
}

.frontcat-cat-pill .remove-cat {
    cursor: pointer;
    color: #94a3b8;
    display: flex;
    align-items: center;
}

.frontcat-cat-pill .remove-cat:hover {
    color: #ef4444;
}

/* Actions Footer */
.frontcat-cat-actions {
    padding: 10px 16px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
}

.frontcat-add-cat-btn {
    font-size: 13px;
    color: var(--fc-primary-color, #673DE6);
    text-decoration: none;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.frontcat-add-cat-btn:hover {
    text-decoration: underline;
}
