/**
 * Preference Distillation - Stili condivisi per index.html e run_detail.html
 * D-One Agent Layout System
 */

/* === Layout Base === */
#main-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.content-section {
    flex: 1;
    padding: 2rem 0;
    background: var(--color-bg-section, #f8fafc);
}

.content-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* === Page Header === */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 2rem;
    margin-bottom: 3rem;
    flex-wrap: wrap;
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.page-header-leading h1.page-title {
    font-size: 2rem;
    font-weight: 800;
    color: var(--color-text-primary, #1e293b);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.page-header-leading .page-subtitle {
    font-size: 1rem;
    color: var(--color-text-secondary, #64748b);
    margin: 0.5rem 0 0 0;
    line-height: 1.5;
}

.page-header-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Run detail: Run ID e Data Source display */
#runIdDisplay {
    color: var(--color-primary, #7c3aed);
}

#dataSourceDisplay {
    font-size: 0.8rem;
    color: var(--color-text-secondary, #64748b);
}

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--color-bg-surface, white);
    border: 1px solid var(--color-border-subtle, rgba(0, 0, 0, 0.08));
    border-radius: 8px;
    padding: 0.75rem;
    text-align: center;
    transition: all 0.3s ease;
}

.stat-card:hover {
    border-color: var(--color-primary, #7c3aed);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.1);
}

.stat-card .stat-value {
    display: block;
    font-size: 1rem;
    font-weight: 800;
    color: var(--color-primary, #7c3aed);
    margin-bottom: 0.25rem;
}

.stat-card .stat-label {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--color-text-secondary, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* === Action Bar (index.html) === */
.action-bar {
    margin-bottom: 2rem;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    background: var(--color-bg-surface, white);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--color-border-subtle, rgba(0, 0, 0, 0.08));
}

.filter-btn {
    padding: 0.5rem 1rem !important;
    font-size: 0.85rem;
    border-radius: 999px !important;
    white-space: nowrap;
    transition: all 0.2s;
}

.filter-btn.active {
    background: var(--color-primary, #7c3aed) !important;
    color: white !important;
}

.sort-group .sort-btn.active {
    background: var(--color-primary, #7c3aed) !important;
    color: white !important;
}

.search-box {
    flex: 1;
    min-width: 250px;
    margin-left: auto;
}

.search-box input {
    border-radius: 999px;
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-border-subtle, rgba(0, 0, 0, 0.08));
}

/* === Preferences Grid (index.html) === */
.preferences-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.preference-card {
    background: var(--color-bg-surface, white);
    border: 1px solid var(--color-border-subtle, rgba(0, 0, 0, 0.08));
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    cursor: pointer;
}

.preference-card:hover {
    border-color: var(--color-primary, #7c3aed);
    box-shadow: 0 8px 16px rgba(124, 58, 237, 0.12);
    transform: translateY(-2px);
}

.cluster-tag {
    display: inline-block;
    background: rgba(124, 58, 237, 0.1);
    color: var(--color-primary, #7c3aed);
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 700;
    margin-bottom: 1rem;
    width: fit-content;
}

/* === Cluster Separator (index.html) === */
.cluster-separator {
    grid-column: 1 / -1;
    margin: 2rem 0 1.5rem 0;
    padding: 0;
}

.cluster-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-text-primary, #1e293b);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 1rem 1.5rem;
    background: linear-gradient(90deg, rgba(124, 58, 237, 0.08) 0%, rgba(99, 102, 241, 0.05) 50%, transparent 100%);
    border-left: 4px solid var(--color-primary, #7c3aed);
    border-radius: 8px;
    position: relative;
}

.cluster-header::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 1px;
    background: linear-gradient(90deg, var(--color-primary, #7c3aed), transparent);
}

.cluster-header i {
    font-size: 1.1rem;
    color: var(--color-primary, #7c3aed);
}

.cluster-count {
    margin-left: auto;
    background: rgba(124, 58, 237, 0.1);
    color: var(--color-primary, #7c3aed);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
}

/* === Run Status === */
.run-status-PENDING {
    color: var(--color-text-secondary, #64748b);
}

.run-status-RUNNING {
    color: #3b82f6;
    font-weight: 600;
}

.run-status-COMPLETED {
    color: #10b981;
    font-weight: 600;
}

.run-status-FAILED {
    color: #ef4444;
    font-weight: 600;
}

/* === Sidebar (index.html) === */
.preferences-sidebar {
    background: var(--color-bg-surface, white);
    border: 1px solid var(--color-border-subtle, rgba(0, 0, 0, 0.08));
    border-radius: 12px;
    padding: 1.5rem;
    transition: all 0.3s ease;
}

.preferences-sidebar:hover {
    border-color: var(--color-primary, #7c3aed);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.08);
}

.sidebar-section-label {
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--color-text-secondary, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
}

.run-history {
    max-height: 400px;
    overflow-y: auto;
    border-radius: 8px;
}

.run-history-item {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--color-bg-section, #f8fafc);
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.run-history-item:hover {
    background: rgba(124, 58, 237, 0.1);
    border-left: 3px solid var(--color-primary, #7c3aed);
    padding-left: 1rem;
}

/* === Modal Overrides === */
.modal-content {
    border: 1px solid var(--color-border-subtle, rgba(0, 0, 0, 0.08));
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--color-text-secondary, #64748b);
}

.empty-state-icon {
    font-size: 4rem;
    opacity: 0.2;
    margin-bottom: 1rem;
}

/* === Timeline (run_detail.html) === */
.timeline-container {
    position: relative;
    padding-left: 40px;
}

.timeline-line {
    position: absolute;
    left: 18px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(180deg, var(--color-primary, #7c3aed) 0%, rgba(99, 102, 241, 0.5) 100%);
}

.timeline-item {
    position: relative;
    margin-bottom: 0.5rem;
}

#timelineContainer .timeline-item .card .card-body {
    padding: 0.2rem 0.4rem !important;
}

#timelineContainer .timeline-item .card .card-body .d-flex {
    margin-bottom: 0.2rem !important;
}

#timelineContainer .timeline-item .card .card-body h6 {
    font-size: 0.7rem;
}

#timelineContainer .timeline-item .card .card-body p.text-muted {
    font-size: 0.6rem;
    margin-bottom: 0.1rem !important;
    line-height: 1.15;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

#timelineContainer .timeline-item .card .card-body small {
    font-size: 0.55rem;
}

.timeline-dot {
    position: absolute;
    left: -28px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    border: 3px solid var(--color-primary, #7c3aed);
}

.timeline-dot.success {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.15);
}

.timeline-dot.error {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.15);
}

/* === Cluster Cards (run_detail.html) === */
.cluster-card {
    transition: all 0.3s ease;
    cursor: pointer;
    border: 1px solid var(--color-border-subtle, rgba(0, 0, 0, 0.08));
    border-radius: 12px;
}

.cluster-card:hover {
    transform: translateY(-2px);
    border-color: var(--color-primary, #7c3aed);
    box-shadow: 0 8px 16px rgba(124, 58, 237, 0.12);
}

/* === Preference Items (run_detail.html) === */
.preference-item {
    background: var(--color-bg-section, #f8fafc);
    border-left: 4px solid var(--color-primary, #7c3aed);
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 6px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.preference-item:hover {
    background: rgba(124, 58, 237, 0.06);
    border-left-color: var(--color-primary, #7c3aed);
}

.preference-item .confidence-badge {
    font-size: 0.75rem;
    padding: 0.15rem 0.4rem;
}

.preference-content {
    display: none;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--color-border-subtle, rgba(0, 0, 0, 0.08));
    font-size: 0.8rem;
    color: var(--color-text-secondary, #64748b);
    line-height: 1.5;
}

.preference-content.show {
    display: block;
}

.preference-toggle-icon {
    transition: transform 0.2s ease;
    font-size: 0.7rem;
    margin-left: 0.25rem;
}

.preference-item.expanded .preference-toggle-icon {
    transform: rotate(180deg);
}

.preferences-list {
    max-height: 200px;
    overflow-y: auto;
    margin-top: 0.75rem;
}

/* === Message Bubbles (run_detail.html) === */
.message-bubble {
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-radius: 8px;
}

.message-bubble.user {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.9) 0%, rgba(99, 102, 241, 0.9) 100%);
    color: white;
    margin-left: 10%;
}

.message-bubble.assistant {
    background: var(--color-bg-section, #f8fafc);
    border-left: 4px solid var(--color-primary, #7c3aed);
    margin-right: 10%;
}

/* === Section Cards (run_detail.html) === */
.section-card {
    border: 1px solid var(--color-border-subtle, rgba(0, 0, 0, 0.08));
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.section-card .card-header {
    background: linear-gradient(90deg, rgba(124, 58, 237, 0.08) 0%, transparent 100%);
    border-left: 4px solid var(--color-primary, #7c3aed);
    border-bottom: 1px solid var(--color-border-subtle, rgba(0, 0, 0, 0.08));
    font-weight: 700;
    color: var(--color-text-primary, #1e293b);
}

.section-card .card-header i {
    color: var(--color-primary, #7c3aed);
}

/* === Logs Container (run_detail.html) === */
.logs-container {
    max-height: 500px;
    overflow-y: auto;
    background: #1e293b;
    color: #e2e8f0;
    padding: 1.5rem;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
}

/* === Run Detail Utilities === */
#mainContent.distillation-hidden {
    display: none;
}

.loading-spinner-lg {
    width: 3rem;
    height: 3rem;
}

/* === Responsive === */
@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
    }

    .page-header-actions {
        width: 100%;
    }

    .page-header-actions button {
        flex: 1;
    }

    .preferences-grid {
        grid-template-columns: 1fr;
    }

    .filter-group {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-btn {
        flex: 1;
    }

    .search-box {
        min-width: 100%;
        margin-left: 0;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 576px) {
    .content-container {
        padding: 0 1rem;
    }

    .page-header-leading h1.page-title {
        font-size: 1.5rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* === Custom Scrollbar === */
.run-history::-webkit-scrollbar,
#preferencesList::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
#messagesContent::-webkit-scrollbar {
    width: 8px;
}

.run-history::-webkit-scrollbar-track,
#preferencesList::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track,
#messagesContent::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

.run-history::-webkit-scrollbar-thumb,
#preferencesList::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb,
#messagesContent::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.run-history::-webkit-scrollbar-thumb:hover,
#preferencesList::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover,
#messagesContent::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary, #7c3aed);
}

.run-history,
#preferencesList,
.modal-body,
#messagesContent {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.05);
}
