/* Component Usage Popup and Toast Styles */
/* Designed to fit with the dark theme of the application */

/* ===== TOAST MESSAGE (No Components Found) ===== */
.usage-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #060607;
    color: #f0f6fc;
    padding: 16px 24px;
    border-radius: 8px;
    border: 1px solid #5e0a0a;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    font-size: 14px;
    font-weight: 500;
    max-width: 400px;
    text-align: center;
    z-index: 10000; /* Above everything */
    animation: toastSlideIn 0.3s ease-out;
    cursor: pointer;
    user-select: none;
    transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

.usage-toast:hover {
    background: #1c1d1f;
    border-color: #444c56;
}

.usage-toast.fade-out {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ===== MODAL OVERLAY ===== */
.component-usage-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999; /* Above everything except toast */
    display: flex;
    align-items: center;
    justify-content: center;
    animation: overlayFadeIn 0.3s ease-out;
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ===== MODAL CONTAINER ===== */
.component-usage-modal {
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 12px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.8);
    max-width: 500px;
    width: 90%;
    max-height: 80vh; /* Restored to normal height */
    min-height: 300px; /* Ensure minimum height for usability */
    animation: modalSlideIn 0.3s ease-out;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Restore to prevent content overflow beyond modal */
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ===== MODAL CONTENT ===== */
.component-usage-modal-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0; /* Allow flex shrinking */
}

/* ===== MODAL HEADER ===== */
.component-usage-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #21262d;
    background: #060607;
    border-radius: 12px 12px 0 0;
}

.component-usage-title-container {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.color-indicator {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 1px solid #444c56;
}

.component-usage-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #f0f6fc;
    flex: 1;
}

.component-usage-close-x {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #8b949e;
    font-size: 18px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    margin-left: 12px;
}

.component-usage-close-x:hover {
    background: #21262d;
    color: #f0f6fc;
}

.component-usage-close-x:active {
    background: #30363d;
}

/* ===== MODAL BODY ===== */
.component-usage-body {
    flex: 1;
    padding: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    background: #000000;
    min-height: 0; /* Allow flex item to shrink smaller than content */
    scroll-behavior: smooth;
}

.component-usage-list {
    /* Remove list-style since we're not using <ul> anymore */
    margin: 0;
    padding: 0;
    /* Ensure the list can grow to trigger scrolling */
    min-height: fit-content;
}

/* Remove the generic hover - we'll handle it specifically for each item type */
/* Note: .component-usage-item class is now only used for simple standalone list items */

/* Component Set Styles */
.component-set-item {
    /* Ensure the container itself has no background or hover effects */
    background: transparent;
    margin-bottom: 4px;
}

.component-set-header {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    position: relative;
}

.component-set-header:hover {
    background: var(--bg-interactive);
}

.expand-icon {
    width: 16px;
    height: 16px;
    margin-right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--text-muted);
    transition: color 0.2s ease;
    user-select: none;
}

.component-set-item.expanded .expand-icon {
    color: var(--accent-primary);
}

.component-set-children {
    margin-left: 16px;
    border-left: 1px solid var(--border-default);
    padding-left: 8px;
    transition: all 0.2s ease;
}

.component-set-item.expanded .component-set-children {
    border-left-color: var(--border-interactive);
}

.component-variant-item {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    padding-left: 8px; /* Base padding since these are nested under component sets */
    margin: 2px 0;
    border-radius: 6px;
    transition: background-color 0.2s ease;
    cursor: pointer;
}

.component-variant-item:hover {
    background: var(--bg-interactive);
}

.component-variant-item .component-name {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 400;
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Component Set Name Styling */
.component-set-header .component-name {
    font-weight: 500;
    font-size: 12px;
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Standalone Component Styling */
.component-standalone-item {
    display: flex;
    align-items: center;
    padding: 8px;
    padding-left: 32px; /* 24px for expand icon space + 8px base padding */
    border-radius: 8px;
    transition: background-color 0.2s ease;
    cursor: pointer;
    margin-bottom: 4px;
}

.component-standalone-item:hover {
    background: var(--bg-interactive);
}

.component-standalone-item .component-name {
    font-size: 12px;
    color: var(--text-primary);
    font-weight: 500;
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Component usage items - simplified structure */

.component-item-content {
    display: flex;
    align-items: center;
    flex: 1;
}

.component-name {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Figma Links */
.figma-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-left: 8px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.2s ease;
    font-size: 12px;
    opacity: 0.7;
}

.figma-link:hover {
    color: var(--accent-primary);
    background: var(--accent-primary-10);
    opacity: 1;
}

/* Focus styles for accessibility */
.figma-link:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    color: var(--accent-primary);
}

/* ===== RESPONSIVE DESIGN ===== */
.component-usage-footer {
    padding: 16px 20px;
    border-top: 1px solid #21262d;
    background: #060607;
    border-radius: 0 0 12px 12px;
    display: flex;
    justify-content: center;
}

.component-usage-close-button {
    background: #060607;
    color: #f0f6fc;
    border: 1px solid #30363d;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 80px;
}

.component-usage-close-button:hover {
    background: #191a1b;
    border-color: #444c56;
}

.component-usage-close-button:active {
    background: #282e33;
    transform: translateY(1px);
}

/* ===== SIMPLE COMPONENT USAGE ITEMS (UPDATED APPROACH) ===== */
.component-usage-item {
    display: flex;
    align-items: center;
    padding: 12px 8px;
    padding-left: 32px; /* 24px for expand icon space + 8px base padding */
    color: #f0f6fc;
    font-size: 14px;
    border-radius: 4px;
    transition: all 0.2s ease;
    cursor: pointer;
    margin-bottom: 4px;
}

.component-usage-item:hover {
    background: var(--bg-interactive);
}

.component-usage-item:last-child {
    border-bottom: none;
}

.component-usage-item .component-item-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
}

.component-usage-item .component-name {
    flex: 1;
    color: #f0f6fc;
    font-size: 14px;
    font-weight: 500;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    min-width: 0;
}

/* ===== COMPONENT LOADING TOAST ===== */
.component-loading-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: #0d1117;
    color: #f0f6fc;
    padding: 12px 20px;
    border-radius: 8px;
    border: 1px solid #30363d;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    font-size: 14px;
    font-weight: 500;
    max-width: 600px; /* Fixed: Added px unit */
    z-index: 10001; /* Above the regular toast */
    animation: componentToastSlideIn 0.3s ease-out;
    cursor: pointer;
    user-select: none;
    transition: opacity 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 16px;
    /* Ensure consistent positioning */
    right: auto;
    top: auto;
}

.component-loading-toast.loading {
    border-color: #1f6feb;
    background: linear-gradient(135deg, #0d1117 0%, #0e1419 100%);
}

.component-loading-toast.success {
    border-color: #238636;
    background: linear-gradient(135deg, #0d1117 0%, #0e1419 100%);
}

.component-loading-toast.error {
    border-color: var(--accent-error-alt);
    background: linear-gradient(135deg, #0d1117 0%, #0e1419 100%);
}

.component-loading-toast .toast-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.component-loading-toast .toast-message {
    flex: 1;
}

.component-loading-toast:hover {
    background: #1c1d1f;
    border-color: #444c56;
}

.component-loading-toast.fade-out {
    opacity: 0;
    /* Don't use transform on fade out to maintain position */
}

.component-loading-toast.flash {
    animation: componentToastFlash 0.6s ease-in-out;
}

/* ===== SMALL LOADING ANIMATION FOR TOAST ===== */
.component-loading-icon {
    position: relative;
    width: 10px;
    height: 10px;
    transform: scale(1.6); /* 16px total size */
    flex-shrink: 0;
}

.component-loading-icon .loading-top-bar-container {
    position: absolute;
    overflow: hidden;
    width: 10px;
    height: 2.67px;
    left: 0px;
    top: 0px;
}

.component-loading-icon .loading-top-bar {
    position: absolute;
    background: var(--text-primary);
    width: 10px;
    height: 2.67px;
    left: 0px;
    top: 0px;
    animation: topBarAnimation 3s ease-in-out infinite;
}

.component-loading-icon .loading-left-rect-container {
    position: absolute;
    overflow: hidden;
    width: 3.44px;
    height: 6.5px;
    left: 2.06px;
    top: 3.5px;
}

.component-loading-icon .loading-left-rect {
    position: absolute;
    background: var(--text-primary);
    width: 3.44px;
    height: 6.5px;
    left: 0px;
    top: 0px;
    animation: leftRectAnimation 3s ease-in-out infinite 0.4s;
}

.component-loading-icon .loading-right-rect-container {
    position: absolute;
    overflow: hidden;
    width: 3px;
    height: 2.67px;
    left: 6.41px;
    top: 4.34px;
}

.component-loading-icon .loading-right-rect {
    position: absolute;
    background: var(--text-primary);
    width: 3px;
    height: 2.67px;
    left: 0px;
    top: 0px;
    animation: rightRectAnimation 3s ease-in-out infinite 0.8s;
}

/* Success checkmark animation */
.component-loading-icon.success {
    transform: scale(1.6);
}

.component-loading-icon.success::before {
    content: "✓";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: var(--accent-success);
    font-size: 12px;
    font-weight: bold;
    animation: checkmarkPop 0.3s ease-out;
}

.component-loading-icon.success .loading-top-bar,
.component-loading-icon.success .loading-left-rect,
.component-loading-icon.success .loading-right-rect {
    display: none;
}

/* Error X animation */
.component-loading-icon.error {
    transform: scale(1.6);
}

.component-loading-icon.error::before {
    content: "✕";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: var(--accent-error);
    font-size: 12px;
    font-weight: bold;
    animation: errorPop 0.3s ease-out;
}

.component-loading-icon.error .loading-top-bar,
.component-loading-icon.error .loading-left-rect,
.component-loading-icon.error .loading-right-rect {
    display: none;
}

@keyframes checkmarkPop {
    0% { transform: translate(-50%, -50%) scale(0); }
    50% { transform: translate(-50%, -50%) scale(1.2); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

@keyframes errorPop {
    0% { transform: translate(-50%, -50%) scale(0); }
    50% { transform: translate(-50%, -50%) scale(1.2); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

@keyframes componentToastSlideIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes componentToastFlash {
    0%, 100% {
        transform: translateX(-50%) scale(1);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    }
    25% {
        transform: translateX(-50%) scale(1.05);
        box-shadow: 0 12px 40px rgba(31, 111, 235, 0.3);
    }
    50% {
        transform: translateX(-50%) scale(1.02);
        box-shadow: 0 10px 36px rgba(31, 111, 235, 0.2);
    }
    75% {
        transform: translateX(-50%) scale(1.05);
        box-shadow: 0 12px 40px rgba(31, 111, 235, 0.3);
    }
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 600px) {
    .component-usage-modal {
        width: 95%;
        max-height: 90vh;
        min-height: 250px; /* Smaller minimum on mobile */
    }
    
    .component-usage-header {
        padding: 12px 16px;
    }
    
    .component-usage-title {
        font-size: 14px;
    }
    
    .component-usage-body {
        padding: 12px;
        min-height: 150px; /* Smaller minimum on mobile */
    }
    
    .component-usage-footer {
        padding: 12px 16px;
    }
}

/* Additional responsive handling for very small screens */
@media (max-height: 500px) {
    .component-usage-modal {
        max-height: 95vh;
        min-height: 200px;
    }
    
    .component-usage-body {
        min-height: 120px;
    }
}

/* ===== MOBILE-SPECIFIC NOTIFICATION STYLES ===== */
@media (max-width: 768px) {
    .component-loading-toast {
        max-width: 90vw; /* Use most of the viewport width on mobile */
        min-width: 280px; /* Ensure minimum readability */
        left: 50%;
        right: auto; /* Override any conflicting positioning */
        padding: 14px 20px; /* Slightly more padding for touch targets */
        font-size: 15px; /* Slightly larger text for mobile readability */
        gap: 12px; /* Adjust gap for mobile spacing */
    }
    
    .usage-toast {
        max-width: 90vw; /* Also make the regular toast wider on mobile */
        padding: 16px 20px; /* Better padding for mobile */
        font-size: 15px; /* Better mobile font size */
    }
}

/* Extra small mobile devices */
@media (max-width: 375px) {
    .component-loading-toast {
        max-width: 95vw; /* Even more width on very small screens */
        min-width: 260px; /* Smaller minimum for very small screens */
        padding: 12px 16px; /* Adjusted padding for small screens */
        font-size: 14px; /* Back to standard font size for small screens */
    }
    
    .usage-toast {
        max-width: 95vw;
        padding: 14px 18px;
    }
}

/* ===== FOCUS STYLES FOR ACCESSIBILITY ===== */
.component-usage-close-x:focus,
.component-usage-close-button:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ===== ANIMATION FOR SMOOTH INTERACTIONS ===== */
.component-usage-modal * {
    transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

/* ===== SCROLLING ENHANCEMENTS ===== */
/* Fade effect at top/bottom when content is scrollable */
.component-usage-body::before,
.component-usage-body::after {
    content: '';
    position: sticky;
    display: block;
    height: 16px;
    margin: 0 -8px;
    pointer-events: none;
    z-index: 1;
}

.component-usage-body::before {
    top: 0;
    background: linear-gradient(180deg, #000000 0%, transparent 100%);
    margin-bottom: -16px;
}

.component-usage-body::after {
    bottom: 0;
    background: linear-gradient(0deg, #000000 0%, transparent 100%);
    margin-top: -16px;
}

/* Hide fade effects when not needed */
.component-usage-body:not([data-scrollable])::before,
.component-usage-body:not([data-scrollable])::after {
    display: none;
}

/* Smooth focus scrolling for keyboard navigation */
.component-usage-body:focus-within {
    scroll-behavior: smooth;
}

/* Ensure component items are keyboard accessible */
.component-variant-item:focus,
.component-standalone-item:focus,
.component-set-header:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    scroll-margin: 20px;
}

/* ===== FALLBACK SCROLLBAR STYLING ===== */
/* Ensure scrollbar appears even if global-scrollbar class isn't applied */
.component-usage-body::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.component-usage-body::-webkit-scrollbar-track {
    background: #00000000;
    border-radius: 4px;
}

.component-usage-body::-webkit-scrollbar-thumb {
    background: #30363d;
    border-radius: 4px;
    border: 1px solid #00000000;
}

.component-usage-body::-webkit-scrollbar-thumb:hover {
    background: #484f58;
}

.component-usage-body::-webkit-scrollbar-corner {
    background: #00000000;
}

/* Firefox scrollbar styling */
.component-usage-body {
    scrollbar-width: thin;
    scrollbar-color: #30363d #00000000;
}

/* ===== MULTI-FILE MODAL STYLES ===== */
.multi-file-modal {
    max-width: 800px !important; /* Wider for multi-file data */
    width: 95% !important;
    max-height: 90vh !important; /* Taller for tabbed content */
}

/* ===== USAGE TABS STYLES ===== */
.usage-tabs-container {
    border-bottom: 1px solid #30363d;
    background: #0d1117;
}

.usage-tabs-header {
    display: flex;
    overflow-x: auto;
    padding: 0 20px;
    gap: 4px;
    background: #0d1117;
}

.usage-tab {
    background: transparent;
    border: none;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    color: #7c8590;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    min-width: fit-content;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.usage-tab:hover {
    color: #c9d1d9;
    background: #161b22;
}

.usage-tab.active {
    color: #58a6ff;
    border-bottom-color: #58a6ff;
    background: #0c1116;
}

.tab-content-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tab-file-status {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tab-file-status.current {
    background: #238636;
    color: #ffffff;
}

.tab-file-status.recent {
    background: #1f6feb;
    color: #ffffff;
}

.tab-file-status.outdated {
    background: #fb8500;
    color: #ffffff;
}

.tab-file-status.stale {
    background: #da3633;
    color: #ffffff;
}

.tab-file-status.unknown {
    background: #6e7681;
    color: #ffffff;
}

/* ===== USAGE TAB CONTENT ===== */
.usage-tabs-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.usage-tab-pane {
    display: none;
    flex: 1;
    overflow: auto;
}

.usage-tab-pane.active {
    display: flex;
    flex-direction: column;
}

.usage-file-content {
    padding: 20px;
    flex: 1;
}

.multi-file-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid #21262d;
}

.multi-file-header h4 {
    margin: 0;
    color: #f0f6fc;
    font-size: 16px;
    font-weight: 600;
}

.file-status {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.file-status.current {
    background: #238636;
    color: #ffffff;
}

.file-status.recent {
    background: #1f6feb;
    color: #ffffff;
}

.file-status.outdated {
    background: #fb8500;
    color: #ffffff;
}

.file-status.stale {
    background: #da3633;
    color: #ffffff;
}

.file-status.unknown {
    background: #6e7681;
    color: #ffffff;
}

/* ===== MULTI-FILE COMPONENT LISTS ===== */
.multi-file-list .component-usage-item {
    border-left: 2px solid transparent;
    padding-left: 12px;
    margin-left: -2px;
    transition: border-color 0.2s ease;
}

.multi-file-list .component-usage-item:hover {
    border-left-color: #58a6ff;
}

/* ===== EMPTY STATE FOR MULTI-FILE ===== */
.empty-usage-state {
    text-align: center;
    padding: 40px 20px;
    color: #7c8590;
}

.empty-usage-state h3 {
    margin: 0 0 8px 0;
    color: #f0f6fc;
    font-size: 18px;
    font-weight: 600;
}

.empty-usage-state p {
    margin: 0;
    font-size: 14px;
    line-height: 1.4;
}

/* ===== RESPONSIVE ADJUSTMENTS ===== */
@media (max-width: 768px) {
    .multi-file-modal {
        max-width: 95% !important;
        width: 95% !important;
        max-height: 95vh !important;
    }
    
    .usage-tabs-header {
        padding: 0 12px;
        gap: 2px;
    }
    
    .usage-tab {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .tab-file-status {
        font-size: 10px;
        padding: 1px 4px;
    }
    
    .multi-file-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .usage-file-content {
        padding: 16px;
    }
}
