/* ====================================
   SIDEBAR & HISTORY PANEL STYLES
   Sections:
     1. SIDEBAR PANEL — FAB, panel base, rating panel  (sidebar-panel.js)
     2. HISTORY PANEL — history-specific components    (generation-history.js)
   ==================================== */

/* ============================================================
   § 1  SIDEBAR PANEL — FAB + panel scaffolding + rating panel
   Owned by: frontend/js/sidebar-panel.js
   ============================================================ */

/* =====================================================
   Floating Action Button — history trigger
   ===================================================== */

/* Wrapper: fixed bottom-right, above footer */
.fab-panel-wrap {
    position: fixed;
    bottom: 72px; /* sit above the fixed site footer */
    right: 24px;
    z-index: 999;
}

/* MD FAB container — bottom-to-top expand on hover */
.fab-panel-wrap .fab-md-container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    user-select: none;
}

.fab-panel-wrap .fab-md-container:hover .sub-md-button:nth-child(2) {
    transform: translateY(-70px);
    opacity: 1;
    pointer-events: auto;
}
.fab-panel-wrap .fab-md-container:hover .sub-md-button:nth-child(3) {
    transform: translateY(-130px);
    opacity: 1;
    pointer-events: auto;
}

/* Extend hover area upward so menu stays open when moving toward sub-buttons */
.fab-panel-wrap .fab-md-container:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    height: 150px;
    width: 60px;
    background: transparent;
    z-index: 0;
}

/* Main circle button */
.fab-panel-wrap .fab-md {
    position: relative;
    z-index: 2;
    height: 56px;
    width: 56px;
    color: #ffffff;
    background-color: #0F74FD;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(15, 116, 253, 0.45);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    padding: 0;
}

.fab-panel-wrap .fab-md:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(15, 116, 253, 0.6);
}

.fab-panel-wrap .fab-md-content {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: 50%;
}

/* Badge on the main button */
.fab-panel-wrap .history-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    display: none;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background: rgba(244, 67, 54, 0.95);
    border-radius: 10px;
    border: 2px solid #1a1a1a;
    color: white;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
}

/* Sub-buttons — small blue circles, stacked behind main btn initially */
.fab-panel-wrap .sub-md-button {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    width: 44px;
    background: #0F74FD;
    border-radius: 50%;
    transition: transform 0.3s ease, opacity 0.2s ease, background 0.2s ease;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.35);
    top: 6px;
    opacity: 0;
    pointer-events: none;
}

.fab-panel-wrap .sub-md-button:hover {
    background: #0560d8;
}

/* Link inside sub-button */
.fab-panel-wrap .hover-style-8 {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    color: rgba(255, 255, 255, 1);
    text-decoration: none;
}

.fab-panel-wrap .hover-style-8:hover {
    color: rgba(255, 255, 255, 0.75);
}

/* Hide text labels — icon-only sub-buttons */
.fab-panel-wrap .sub-btn-label {
    display: none;
}

/* Badge on the History sub-button */
.fab-panel-wrap .history-sub-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    display: none;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: rgba(244, 67, 54, 0.95);
    border-radius: 9px;
    border: 2px solid #1e1e2a;
    color: white;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
}

/* Mobile: move above bottom nav if any */
@media (max-width: 768px) {
    .fab-panel-wrap {
        bottom: 80px;
        right: 16px;
    }
}



/* History Panel (slide-out from right) */
.history-panel {
    position: fixed;
    right: -360px;
    top: 0;
    bottom: 0;
    width: 360px;
    z-index: 1000;
    
    display: flex;
    flex-direction: column;
    
    background: linear-gradient(180deg, rgba(26, 26, 26, 0.98), rgba(18, 18, 18, 0.98));
    backdrop-filter: blur(10px);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: -4px 0 30px rgba(0, 0, 0, 0.5);
    
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.history-panel.open {
    right: 0;
}

/* Rating panel — reuses history-panel base, extra adjustments */
.rating-panel #rating-section {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    /* override the old inline animation that collapses it */
    opacity: 1 !important;
    transform: none !important;
    max-height: none !important;
    pointer-events: auto !important;
    margin-bottom: 0 !important;
    padding: 24px !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
}

.rating-panel .rating-content {
    max-width: 100%;
    text-align: center;
}

.rating-panel .rating-content h3 {
    font-size: 14px;
    color: rgba(255,255,255,0.6);
    margin-bottom: 20px;
}

/* Empty state inside rating panel */
.rating-panel-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 40px 24px;
    gap: 12px;
    color: rgba(255, 255, 255, 0.3);
    text-align: center;
}

.rating-panel-empty p {
    margin: 0;
    font-size: 15px;
    color: rgba(255, 255, 255, 0.5);
}

.rating-panel-empty small {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.3);
}

/* ============================================================
   § 2  HISTORY PANEL — history-specific components
   Owned by: frontend/js/generation-history.js  (HistoryPanel)
   ============================================================ */

/* Header */
.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.history-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #ffffff);
    flex: 1;
    text-align: left;
}

.history-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    
    width: 36px;
    height: 36px;
    padding: 0;
    
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text-secondary, #b0b0b0);
    cursor: pointer;
    
    transition: all 0.2s ease;
}

.history-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary, #ffffff);
    transform: scale(1.05);
}

/* Info Section */
.history-info {
    padding: 12px 24px;
    background: rgba(76, 175, 80, 0.08);
    border-bottom: 1px solid rgba(76, 175, 80, 0.15);
}

.history-info p {
    margin: 0;
    font-size: 13px;
    color: rgba(76, 175, 80, 0.9);
    text-align: center;
}

/* Container (scrollable area) */
.history-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
}

.history-container::-webkit-scrollbar {
    width: 6px;
}

.history-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
}

.history-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.history-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Empty State */
.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 60px 20px;
    text-align: center;
}

.history-empty svg {
    opacity: 0.3;
    stroke: var(--text-secondary, #b0b0b0);
}

.history-empty p {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-secondary, #b0b0b0);
}

.history-empty small {
    font-size: 13px;
    color: var(--text-tertiary, #808080);
}

/* Generation Item */
.history-generation {
    margin-bottom: 20px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    transition: all 0.2s ease;
}

.history-generation:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.12);
    transform: translateX(-2px);
}

.history-generation.active {
    background: rgba(76, 175, 80, 0.1);
    border-color: rgba(76, 175, 80, 0.3);
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.15);
}

/* Generation Header */
.history-generation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.history-generation-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #ffffff);
}

.history-generation-time {
    font-size: 12px;
    color: var(--text-tertiary, #808080);
}

/* Metadata Badges */
.history-generation-meta {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}

.history-meta-badge {
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary, #b0b0b0);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Thumbnails Grid */
.history-thumbnails {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.history-thumbnail {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
}

.history-thumbnail:hover {
    transform: scale(1.05);
    border-color: rgba(76, 175, 80, 0.5);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
    z-index: 2;
}

.history-thumbnail:active {
    transform: scale(0.98);
}

.history-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.history-thumbnail::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    transition: background 0.2s ease;
}

.history-thumbnail:hover::after {
    background: rgba(76, 175, 80, 0.15);
}

/* Footer */
.history-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.clear-history-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    
    background: rgba(244, 67, 54, 0.1);
    border: 1px solid rgba(244, 67, 54, 0.3);
    border-radius: 8px;
    color: rgba(244, 67, 54, 0.9);
    cursor: pointer;
    
    font-size: 14px;
    font-weight: 500;
    
    transition: all 0.2s ease;
}

.clear-history-btn:hover:not(:disabled) {
    background: rgba(244, 67, 54, 0.2);
    border-color: rgba(244, 67, 54, 0.5);
    color: rgba(244, 67, 54, 1);
}

.clear-history-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.clear-history-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Mobile Responsive */
@media (max-width: 767px) {
    .history-panel {
        width: 100%;
        right: -100%;
    }
    
    .history-thumbnails {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .history-panel {
        width: 320px;
        right: -320px;
    }
}

/* Animations */
@keyframes slideInRight {
    from {
        right: -360px;
    }
    to {
        right: 0;
    }
}

@keyframes slideOutRight {
    from {
        right: 0;
    }
    to {
        right: -360px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .history-panel,
    .history-thumbnail,
    .fab-panel-wrap .sub-md-button,
    .fab-panel-wrap .fab-md {
        transition: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .history-panel {
        border-left-width: 2px;
    }
    
    .history-generation {
        border-width: 2px;
    }
    
    .history-thumbnail {
        border-width: 3px;
    }
}

/* Thumbnail Overlay Buttons */
.history-thumbnail-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 3;
}

.history-thumbnail:hover .history-thumbnail-overlay {
    opacity: 1;
}

.history-thumbnail-enlarge,
.history-thumbnail-use {
    background: rgba(255, 255, 255, 0.95);
    border: none;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #333;
    padding: 0;
}

.history-thumbnail-enlarge:hover,
.history-thumbnail-use:hover {
    background: white;
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.history-thumbnail-enlarge svg,
.history-thumbnail-use svg {
    display: block;
}

/* Refinement Prompt Display */
.history-refinement-prompt {
    margin: 8px 0 12px;
    padding: 10px 12px;
    background: rgba(76, 175, 80, 0.08);
    border-left: 3px solid rgba(76, 175, 80, 0.6);
    border-radius: 4px;
}

.history-refinement-label {
    font-size: 10px;
    font-weight: 700;
    color: rgba(76, 175, 80, 0.9);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.history-refinement-text {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.5;
    word-wrap: break-word;
    font-style: italic;
}

/* Image Lightbox Modal */
.history-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
}

.history-lightbox.open {
    display: flex;
}

.history-lightbox-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.92);
    cursor: pointer;
    backdrop-filter: blur(8px);
}

.history-lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    z-index: 10001;
    animation: lightboxZoomIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes lightboxZoomIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.history-lightbox-image {
    max-width: 100%;
    max-height: 90vh;
    display: block;
    border-radius: 12px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
}

.history-lightbox-close {
    position: absolute;
    top: -20px;
    right: -20px;
    background: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
    color: #333;
    padding: 0;
}

.history-lightbox-close:hover {
    transform: scale(1.15) rotate(90deg);
    background: #f5f5f5;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.history-lightbox-close svg {
    display: block;
}

/* Lightbox Mobile */
@media (max-width: 767px) {
    .history-lightbox-content {
        max-width: 95vw;
        max-height: 85vh;
    }
    
    .history-lightbox-close {
        top: -15px;
        right: -15px;
        width: 36px;
        height: 36px;
    }
    
    .history-lightbox-close svg {
        width: 20px;
        height: 20px;
    }
}
