/* Collapse Component - Cacao UI Framework */

.collapse {
    border: 1px solid #e8e8e8;
    border-radius: 4px;
    margin-bottom: 8px;
    background-color: #fff;
    overflow: hidden;
    transition: all 0.3s ease;
}

.collapse:hover {
    border-color: #8B4513;
}

.collapse:last-child {
    margin-bottom: 0;
}

/* Collapse Header */
.collapse-header {
    padding: 12px 16px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #e8e8e8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    transition: background-color 0.2s ease;
    position: relative;
}

.collapse-header:hover {
    background-color: #e9ecef;
}

.collapse-header:focus {
    outline: 2px solid #8B4513;
    outline-offset: -2px;
    background-color: #e9ecef;
}

.collapse-header:active {
    background-color: #dee2e6;
}

.collapse-title {
    font-weight: 500;
    font-size: 14px;
    color: #333;
    flex: 1;
    margin-right: 8px;
}

.collapse-indicator {
    font-size: 12px;
    color: #666;
    transition: transform 0.2s ease;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.collapse-indicator::before {
    content: "▼";
}

.collapse[aria-expanded="false"] .collapse-indicator {
    transform: rotate(-90deg);
}

.collapse[aria-expanded="true"] .collapse-indicator {
    transform: rotate(0deg);
}

/* Collapse Content */
.collapse-content {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    border-top: 1px solid #e8e8e8;
    max-height: 0;
    opacity: 0;
}

.collapse[aria-expanded="true"] .collapse-content {
    opacity: 1;
    border-top: 1px solid #e8e8e8;
}

.collapse[aria-expanded="false"] .collapse-content {
    max-height: 0;
    opacity: 0;
    border-top: none;
}

.collapse-content-wrapper {
    padding: 16px;
    color: #333;
    line-height: 1.6;
}

.collapse-content-wrapper:empty::before {
    content: "Collapse content goes here...";
    color: #666;
    font-style: italic;
}

/* Collapse Variants */
.collapse.borderless {
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.collapse.borderless .collapse-header {
    border-bottom: 1px solid #e8e8e8;
}

.collapse.ghost {
    border: none;
    background-color: transparent;
}

.collapse.ghost .collapse-header {
    background-color: transparent;
    border-bottom: 1px solid #e8e8e8;
}

.collapse.ghost .collapse-header:hover {
    background-color: #f8f9fa;
}

/* Collapse Sizes */
.collapse.small .collapse-header {
    padding: 8px 12px;
}

.collapse.small .collapse-title {
    font-size: 12px;
}

.collapse.small .collapse-content-wrapper {
    padding: 12px;
}

.collapse.large .collapse-header {
    padding: 16px 20px;
}

.collapse.large .collapse-title {
    font-size: 16px;
}

.collapse.large .collapse-content-wrapper {
    padding: 20px;
}

/* Collapse Group */
.collapse-group {
    border: 1px solid #e8e8e8;
    border-radius: 4px;
    overflow: hidden;
}

.collapse-group .collapse {
    border: none;
    border-radius: 0;
    margin-bottom: 0;
}

.collapse-group .collapse:not(:last-child) {
    border-bottom: 1px solid #e8e8e8;
}

.collapse-group .collapse-header {
    border-bottom: none;
}

.collapse-group .collapse[aria-expanded="true"] .collapse-content {
    border-bottom: 1px solid #e8e8e8;
}

.collapse-group .collapse:last-child[aria-expanded="true"] .collapse-content {
    border-bottom: none;
}

/* Accordion Behavior */
.collapse-accordion .collapse {
    border-radius: 0;
}

.collapse-accordion .collapse:first-child {
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
}

.collapse-accordion .collapse:last-child {
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
}

/* Disabled State */
.collapse.disabled {
    opacity: 0.6;
    pointer-events: none;
}

.collapse.disabled .collapse-header {
    cursor: not-allowed;
    background-color: #f8f9fa;
}

/* Loading State */
.collapse.loading .collapse-header::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid #e8e8e8;
    border-top: 2px solid #8B4513;
    border-radius: 50%;
    animation: collapseLoading 1s linear infinite;
    margin-left: 8px;
}

@keyframes collapseLoading {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Custom Icons */
.collapse-header.custom-icon .collapse-indicator::before {
    content: none;
}

.collapse-header.plus-icon .collapse-indicator::before {
    content: "+";
    font-size: 16px;
    font-weight: bold;
}

.collapse[aria-expanded="true"] .collapse-header.plus-icon .collapse-indicator::before {
    content: "−";
}

.collapse-header.chevron-icon .collapse-indicator::before {
    content: "›";
    font-size: 16px;
    font-weight: bold;
}

.collapse[aria-expanded="true"] .collapse-header.chevron-icon .collapse-indicator {
    transform: rotate(90deg);
}

.collapse[aria-expanded="false"] .collapse-header.chevron-icon .collapse-indicator {
    transform: rotate(0deg);
}

/* Responsive Design */
@media (max-width: 768px) {
    .collapse-header {
        padding: 10px 12px;
    }
    
    .collapse-title {
        font-size: 13px;
    }
    
    .collapse-content-wrapper {
        padding: 12px;
    }
    
    .collapse.large .collapse-header {
        padding: 12px 16px;
    }
    
    .collapse.large .collapse-content-wrapper {
        padding: 16px;
    }
}

/* Accessibility */
.collapse-header[role="button"] {
    outline: none;
}

.collapse-header[role="button"]:focus {
    outline: 2px solid #8B4513;
    outline-offset: -2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .collapse {
        border: 2px solid #000;
    }
    
    .collapse-header {
        border-bottom: 2px solid #000;
    }
    
    .collapse-content {
        border-top: 2px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .collapse-header {
        transition: none;
    }
    
    .collapse-content {
        transition: none;
    }
    
    .collapse-indicator {
        transition: none;
    }
    
    .collapse.loading .collapse-header::after {
        animation: none;
    }
}

/* Print Styles */
@media print {
    .collapse {
        border: 1px solid #000;
        break-inside: avoid;
    }
    
    .collapse-content {
        max-height: none !important;
        opacity: 1 !important;
        overflow: visible !important;
    }
    
    .collapse-header {
        background-color: #f0f0f0;
    }
}