/**
 * Personalization Sidebar Component
 * Displays Unomi context and personalization information
 */

/* Sidebar Styles */
.personalization-sidebar {
    position: fixed;
    top: 0;
    left: -400px; /* Hidden by default */
    width: 400px;
    height: 100vh;
    background: #1a1a2e;
    color: #eee;
    border-right: 2px solid #16213e;
    transition: left 0.3s ease-in-out;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

.personalization-sidebar.open {
    left: 0;
}

/* Sidebar Header */
.personalization-header {
    background: #16213e;
    padding: 15px 20px;
    border-bottom: 1px solid #0f3460;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.personalization-header h2 {
    margin: 0;
    font-size: 16px;
    color: #00d4ff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
}

.personalization-refresh {
    background: none;
    border: none;
    color: #ccc;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.personalization-refresh:hover {
    background: #0f3460;
    color: #00d4ff;
    transform: rotate(180deg);
}

.personalization-close {
    background: none;
    border: none;
    color: #ccc;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.personalization-close:hover {
    background: #0f3460;
    color: #00d4ff;
}

/* Sidebar Content */
.personalization-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.personalization-section {
    margin-bottom: 30px;
    background: rgba(22, 33, 62, 0.3);
    border-radius: 8px;
    padding: 15px;
    border: 1px solid #0f3460;
}

.section-title {
    font-size: 14px;
    font-weight: bold;
    color: #00d4ff;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-content {
    font-size: 12px;
    line-height: 1.4;
}

/* Profile Info */
.profile-info {
    display: grid;
    gap: 8px;
}

.profile-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid rgba(15, 52, 96, 0.5);
}

.profile-item:last-child {
    border-bottom: none;
}

.profile-label {
    color: #a0aec0;
    font-size: 11px;
    min-width: 80px;
}

.profile-value {
    color: #eee;
    font-weight: 500;
    text-align: right;
    word-break: break-all;
    max-width: 200px;
}

/* Context Data */
.context-data {
    background: #0f1419;
    border: 1px solid #0f3460;
    border-radius: 6px;
    padding: 12px;
    margin-top: 10px;
}

.context-item {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(15, 52, 96, 0.3);
}

.context-item:last-child {
    margin-bottom: 0;
    border-bottom: none;
}

.context-key {
    font-size: 11px;
    color: #00d4ff;
    font-weight: bold;
    margin-bottom: 4px;
}

.context-value {
    font-size: 11px;
    color: #e0e0e0;
    background: rgba(0, 0, 0, 0.3);
    padding: 4px 8px;
    border-radius: 3px;
    word-break: break-all;
}

/* JSON Display */
.json-display {
    background: #0f1419;
    border: 1px solid #0f3460;
    border-radius: 6px;
    padding: 12px;
    margin-top: 10px;
    max-height: 200px;
    overflow-y: auto;
}

.json-display pre {
    margin: 0;
    font-size: 10px;
    line-height: 1.3;
    color: #e0e0e0;
    white-space: pre-wrap;
}

/* Segments & Scores */
.segments-list, .scores-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.segment-tag, .score-tag {
    background: #0f3460;
    color: #00d4ff;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 10px;
    border: 1px solid #16213e;
}

.score-tag {
    background: #2d1b69;
    color: #bb86fc;
    border-color: #3f2a7a;
}

/* Loading State */
.loading-state {
    text-align: center;
    padding: 20px;
    color: #a0aec0;
    font-style: italic;
}

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #0f3460;
    border-radius: 50%;
    border-top-color: #00d4ff;
    animation: spin 1s ease-in-out infinite;
    margin-right: 8px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error State */
.error-state {
    background: rgba(244, 67, 54, 0.1);
    border: 1px solid #f44336;
    border-radius: 6px;
    padding: 12px;
    color: #ffcdd2;
    font-size: 12px;
    margin-top: 10px;
}

/* Toggle Button */
.personalization-toggle {
    position: fixed;
    bottom: 80px; /* Above event log button */
    left: 20px;
    background: #16213e;
    color: #00d4ff;
    border: none;
    padding: 12px 16px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(22, 33, 62, 0.5);
    transition: all 0.3s ease;
    z-index: 999;
    display: block;
}

.personalization-toggle:hover {
    background: #0f3460;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(22, 33, 62, 0.6);
}

.personalization-toggle.active {
    background: #00d4ff;
    color: #1a1a2e;
}

.personalization-toggle.active:hover {
    background: #00b8e6;
}

/* Responsive Design */
@media (max-width: 768px) {
    .personalization-sidebar {
        width: 100%;
        left: -100%;
    }

    .personalization-toggle {
        bottom: 140px; /* Stack above other buttons */
        left: 20px;
        font-size: 12px;
        padding: 10px 14px;
    }
}

@media (max-width: 480px) {
    .personalization-sidebar {
        width: 100vw;
    }

    .personalization-header {
        padding: 12px 15px;
    }

    .personalization-header h2 {
        font-size: 14px;
    }

    .personalization-content {
        padding: 15px;
    }

    .personalization-toggle {
        bottom: 200px; /* More space on small screens */
        font-size: 11px;
        padding: 8px 12px;
    }
}

/* Scrollbar Styling */
.personalization-content::-webkit-scrollbar,
.json-display::-webkit-scrollbar {
    width: 6px;
}

.personalization-content::-webkit-scrollbar-track,
.json-display::-webkit-scrollbar-track {
    background: #1a1a2e;
}

.personalization-content::-webkit-scrollbar-thumb,
.json-display::-webkit-scrollbar-thumb {
    background: #0f3460;
    border-radius: 3px;
}

.personalization-content::-webkit-scrollbar-thumb:hover,
.json-display::-webkit-scrollbar-thumb:hover {
    background: #16213e;
}

/* Collapsible Context Section */
.context-collapsible {
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
}

.context-collapsible:hover {
    color: #74b9ff;
}

.collapse-icon {
    margin-left: auto;
    font-size: 12px;
    transition: transform 0.2s ease;
}

.context-collapsible.expanded .collapse-icon {
    transform: rotate(180deg);
}

.section-content.collapsed {
    display: none;
}

/* Animation for new data */
@keyframes fadeInUp {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.personalization-section.updated {
    animation: fadeInUp 0.3s ease-out;
}
