/**
 * Profiling Panel Styles
 * 
 * Includes:
 * - Panel layout
 * - Toolbar and controls
 * - Summary cards
 * - Session list table
 * - vis.js Timeline customization for profiling events
 * - Event details panel
 * 
 * Location: /src/app/client/style/profiling.css
 */

/* =============================================================================
   Layout
   ============================================================================= */

.profiling-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 8px;
    padding: 0;
    font-family: 'Roboto', sans-serif;
    font-size: 12px;
}

/* =============================================================================
   Toolbar
   ============================================================================= */

.profiling-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 3px 3px 0 0;
    display: none;
}

.profiling-toolbar-left,
.profiling-toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.profiling-toolbar-center {
    flex: 1;
    text-align: center;
}

.profiling-session-select {
    padding: 6px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 11px;
    min-width: 200px;
    background: #fff;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23333333' viewBox='0 0 20 20'%3e%3cpolygon fill='%23333333' points='10,14 4,6 16,6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 10px;
    padding-right: 29px;
    cursor: pointer;
}

.profiling-session-select:focus {
    outline: none;
    border-color: #80bdff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.15);
}

.profiling-btn {
    padding: 6px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
}

.profiling-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
}

.profiling-btn-refresh {
    padding: 4px;
    background-color: #aee7b4;
    border-radius: 20px;
    border: 0.5px solid #999999;
    display: none;
}

.profiling-btn-delete {
    padding: 6px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: var(--hud-warm, #FB2C36);
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
}

.profiling-btn-delete:hover:not(:disabled) {
    background: #ffffff;
    border-color: #e63946;
    color: #e63946;
}

/* =============================================================================
   Status Indicator
   ============================================================================= */

.profiling-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 3px;
}

.profiling-status-loading {
    color: #856404;
    background: #fff3cd;
}

.profiling-status-success {
    color: #155724;
    background: #d4edda;
}

.profiling-status-error {
    color: #721c24;
    background: #f8d7da;
}

/* =============================================================================
   Summary Cards
   ============================================================================= */

.profiling-summary {
    display: none;
    gap: 10px;
}

.profiling-card {
    flex: 1;
    background: linear-gradient(to bottom, #ffffff, #f8f9fa);
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 8px 12px;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.profiling-card-value {
    font-size: 18px;
    font-weight: 600;
    color: #212529;
    line-height: 1.2;
}

.profiling-card-label {
    font-size: 10px;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

/* =============================================================================
   Filters
   ============================================================================= */

.profiling-filters {
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 3px;
    margin-top: 4px;
}

.profiling-filter-group {
    display: flex;
    flex-direction: column;
    align-items: start;
    gap: 3px;
}

.profiling-filter-group > label {
    font-size: 10px;
    font-weight: 600;
    color: #1d1d1d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding-left: 4px;
}

.profiling-groupby-select {
    padding: 6px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 11px;
    min-width: 200px;
    background: #fff;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23333333' viewBox='0 0 20 20'%3e%3cpolygon fill='%23333333' points='10,14 4,6 16,6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 10px;
    padding-right: 29px;
    cursor: pointer;
}

.profiling-category-filters {
    display: flex;
    flex-direction: row;
    gap: 10px;
    margin-top: 20px;
}

.profiling-filter-checkbox {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font-size: 11px;
    user-select: none;
}

.profiling-filter-checkbox input {
    width: 12px;
    height: 12px;
    margin-right: 0px;
    cursor: pointer;
    accent-color: #ffa537e2;
    margin-bottom: 2.5px;
}

.profiling-filter-color {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.2);
}

/* =============================================================================
   Timeline Wrapper
   ============================================================================= */

.profiling-timeline-wrapper {
    flex: 1;
    min-height: 200px;
    border: 1px solid #dee2e6;
    border-radius: 3px;
    overflow: hidden;
}

.profiling-timeline {
    width: 100%;
    height: 100%;
}

/* =============================================================================
   vis.js Timeline Customization
   ============================================================================= */

#profiling-timeline-container .vis-timeline {
    border: none !important;
    font-family: 'Roboto', sans-serif;
}

#profiling-timeline-container .vis-panel {
    border-color: #dee2e6 !important;
}

#profiling-timeline-container .vis-panel.vis-left {
    background-color: rgba(248, 249, 250, 0.95) !important;
    border-right: 1px solid #dee2e6 !important;
    min-width: 100px;
    max-width: 120px;
}

#profiling-timeline-container .vis-labelset .vis-label {
    font-size: 10px;
    font-weight: 500;
    color: #495057;
    padding: 4px 8px;
    border-bottom: 1px solid #e9ecef;
}

#profiling-timeline-container .vis-time-axis .vis-text {
    font-size: 10px;
    color: #6c757d;
}

#profiling-timeline-container .vis-time-axis .vis-grid.vis-major {
    border-color: #adb5bd !important;
}

#profiling-timeline-container .vis-time-axis .vis-grid.vis-minor {
    border-color: #dee2e6 !important;
}

/* Timeline items base */
#profiling-timeline-container .vis-item {
    border-radius: 2px !important;
    border-width: 1px !important;
    font-size: 9px;
    line-height: 1.2;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    cursor: pointer;
}

#profiling-timeline-container .vis-item .vis-item-content {
    padding: 2px 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Category-specific colors */
#profiling-timeline-container .vis-item.profiling-item-cuda_kernel {
    background-color: rgba(231, 76, 60, 0.85) !important;
    border-color: rgba(192, 57, 43, 1) !important;
    color: #fff !important;
}

#profiling-timeline-container .vis-item.profiling-item-cuda_memcpy_h2d {
    background-color: rgba(52, 152, 219, 0.85) !important;
    border-color: rgba(41, 128, 185, 1) !important;
    color: #fff !important;
}

#profiling-timeline-container .vis-item.profiling-item-cuda_memcpy_d2h {
    background-color: rgba(46, 204, 113, 0.85) !important;
    border-color: rgba(39, 174, 96, 1) !important;
    color: #fff !important;
}

#profiling-timeline-container .vis-item.profiling-item-cuda_memcpy_d2d {
    background-color: rgba(243, 156, 18, 0.85) !important;
    border-color: rgba(211, 84, 0, 1) !important;
    color: #fff !important;
}

#profiling-timeline-container .vis-item.profiling-item-cuda_sync {
    background-color: rgba(149, 165, 166, 0.85) !important;
    border-color: rgba(127, 140, 141, 1) !important;
    color: #fff !important;
}

#profiling-timeline-container .vis-item.profiling-item-nvtx_range {
    background-color: rgba(155, 89, 182, 0.85) !important;
    border-color: rgba(142, 68, 173, 1) !important;
    color: #fff !important;
}

/* Hover state */
#profiling-timeline-container .vis-item:hover {
    box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.8), 0 2px 4px rgba(0, 0, 0, 0.2) !important;
    z-index: 10 !important;
}

/* Selected state */
#profiling-timeline-container .vis-item.vis-selected {
    box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.9), 0 2px 6px rgba(0, 0, 0, 0.3) !important;
    z-index: 11 !important;
}

/* Group row backgrounds */
#profiling-timeline-container .vis-group.profiling-group-cuda_kernel {
    background: rgba(231, 76, 60, 0.05);
}

#profiling-timeline-container .vis-group.profiling-group-cuda_memcpy_h2d {
    background: rgba(52, 152, 219, 0.05);
}

#profiling-timeline-container .vis-group.profiling-group-cuda_memcpy_d2h {
    background: rgba(46, 204, 113, 0.05);
}

#profiling-timeline-container .vis-group.profiling-group-nvtx_range {
    background: rgba(155, 89, 182, 0.05);
}

/* Tooltip styling */
#profiling-timeline-container .vis-tooltip {
    background: rgba(33, 37, 41, 0.95) !important;
    color: #fff !important;
    border: none !important;
    border-radius: 4px !important;
    padding: 8px 10px !important;
    font-size: 11px !important;
    line-height: 1.5 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
    max-width: 300px;
}

#profiling-timeline-container .vis-tooltip strong {
    color: #ffc107;
}

/* =============================================================================
   Session List
   ============================================================================= */

.profiling-sessions-details {
    background: transparent;
}

.profiling-sessions-details summary {
    background: #ffca83b3;
    cursor: pointer;
    font-size: 10px;
    font-weight: 600;
    color: #333;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    user-select: none;
    border-radius: 6px 6px 0px 0px !important;
    list-style: none;
    justify-content: left;
    height: 18px;
    line-height: 2;
    gap: 4px;
    align-items: flex-start;
}

.profiling-sessions-details summary::-webkit-details-marker {
    display: none;
}

.profiling-sessions-details summary::before {
    content: "\25BC";
    display: inline-block;
    margin-left: 6px;
    font-size: 9px;
    transition: transform 0.2s ease;
}

.profiling-sessions-details:not([open]) summary::before {
    transform: rotate(-90deg);
}

.profiling-sessions-details[open] summary {
    border-radius: 0px;
}

.profiling-session-list {
    font-size: 11px;
}

.profiling-session-header {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    background: #ffebc5;
    font-weight: 600;
    color: #1d1d1d;
    border-bottom: 1px solid #f9c790;
    position: sticky;
    top: 0;
    z-index: 1;
}

.profiling-session-row {
    display: flex;
    align-items: center;
    padding: 3px 8px;
    border-bottom: 1px solid #cecece;
    cursor: pointer;
    transition: background 0.1s;
    background-color: #ffffffcc;
}

.profiling-session-row:hover {
    background: #aee7b4cc;
}

.profiling-session-row.selected {
    background: #aee7b499;
}

.profiling-session-row.selected:hover {
    background: #aee7b4cc;
}

.profiling-session-col-checkbox {
    width: 30px;
    flex-shrink: 0;
}

.profiling-session-col-checkbox input {
    width: 12px;
    height: 12px;
    margin-right: 6px;
    cursor: pointer;
    accent-color: #ffa537e2;
    margin-top: 1.5px;
}

.profiling-session-col-date {
    width: 130px;
    flex-shrink: 0;
}

.profiling-session-col-solver {
    width: 120px;
    flex-shrink: 0;
}

.profiling-session-col-mesh {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profiling-session-col-nodes,
.profiling-session-col-elements {
    width: 70px;
    flex-shrink: 0;
    text-align: right;
}

.profiling-session-col-duration {
    width: 70px;
    flex-shrink: 0;
    text-align: right;
}

.profiling-session-col-kernels {
    width: 60px;
    flex-shrink: 0;
    text-align: right;
}

.profiling-session-col-memcpy {
    width: 60px;
    flex-shrink: 0;
    text-align: right;
}

.profiling-session-col-nvtx {
    width: 60px;
    flex-shrink: 0;
    text-align: right;
}

.profiling-session-col-status {
    width: 90px;
    text-align: center;
}

.profiling-status-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 500;
}

.profiling-status-badge.success {
    background: #d8f7df;
    color: #0a2710;
    border: 0.5px solid #999999;
}

.profiling-status-badge.error {
    background: #f8d7da;
    color: #721c24;
}

.profiling-status-badge.pending {
    background: #fff3cd;
    color: #856404;
}

.profiling-session-empty {
    padding: 20px;
    text-align: center;
    color: #6c757d;
    font-style: italic;
}


/* =============================================================================
   Event Details Panel
   ============================================================================= */

.profiling-details-panel {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 280px;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
}

.profiling-details-header {
    padding: 6px 10px;
    color: #333;
    font-weight: 500;
    font-size: 11px;
    border-radius: 3px 3px 0 0;
}

.profiling-details-content {
    padding: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.profiling-details-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

.profiling-details-table th {
    text-align: left;
    padding: 3px 8px 3px 0;
    color: #6c757d;
    font-weight: 500;
    width: 100px;
    vertical-align: top;
}

.profiling-details-table td {
    padding: 3px 0;
    color: #212529;
    word-break: break-all;
}

/* =============================================================================
   Responsive Adjustments
   ============================================================================= */

@media (max-width: 800px) {
    .profiling-summary {
        flex-wrap: wrap;
    }
    
    .profiling-card {
        flex: 1 1 45%;
        min-width: 100px;
    }
    
    .profiling-filters {
        flex-wrap: wrap;
    }
    
    .profiling-category-filters {
        width: 100%;
        margin-top: 6px;
    }
}

.hud.profiling {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 1100px;
    min-width: 920px;
    height: 550px;
    min-height: 460px;
    background-color: #fff4e5c5;
}

.hud.profiling:hover {
    background-color: #fff4e5;
}

.hud.profiling .profiling-container {
    height: calc(100% - 48px);
    overflow: hidden;
    margin: 10px;
}

/* Ensure timeline has enough height */
.hud.profiling .profiling-timeline-wrapper {
    min-height: 180px;
}

/* Adjust session list height based on panel size */
.hud.profiling .profiling-sessions-details {
    max-height: 140px;
}

.hud.profiling .profiling-session-list {
    max-height: 98px;
    overflow-y: auto;
}

/* Width */
.hud.profiling .profiling-session-list::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
  
/* Track */
.hud.profiling .profiling-session-list::-webkit-scrollbar-track {
    box-shadow: inset 0 0 5px #73b0ce;
    border-radius: 8px;
    margin: 3px 0px 3px 3px;
}
   
/* Handle */
.hud.profiling .profiling-session-list::-webkit-scrollbar-thumb {
    background-color: #3a96c4;
    border-radius: 10px;
}
  
/* Handle on hover */
.hud.profiling .profiling-session-list::-webkit-scrollbar-thumb:hover {
    background-color: #3a96c4;
    cursor: pointer;
}



/**
 * CSS Additions for Profiling Active Run Indicator
 * 
 * Add these styles to your profiling panel CSS file.
 * Location: /src/app/client/style/profiling.css (or similar)
 */

/* ============================================================================
   Active Run Indicator - Shows when profiling is in progress
   ============================================================================ */

.profiling-active-run {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.1) 0%, rgba(59, 130, 246, 0.05) 100%);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 8px;
}

.profiling-active-run-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(59, 130, 246, 0.2);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: profiling-spin 1s linear infinite;
}

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

.profiling-active-run-info {
    flex: 1;
    min-width: 0;
}

.profiling-active-run-title {
    font-weight: 600;
    color: #3b82f6;
    font-size: 14px;
}

.profiling-active-run-details {
    font-size: 12px;
    color: #64748b;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profiling-active-run-stage {
    font-size: 12px;
    color: #3b82f6;
    background: rgba(59, 130, 246, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
}

/* ============================================================================
   Gallery Button Styles - For "Run Profiling" button
   ============================================================================ */

.gallery-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.gallery-buttons-right {
    display: flex;
    gap: 10px;
}

.gallery-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.gallery-btn.cancel-btn {
    background: transparent;
    color: #94a3b8;
    border: 1px solid #334155;
}

.gallery-btn.cancel-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #e2e8f0;
}

.gallery-btn.profiling-btn {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
}

.gallery-btn.profiling-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    transform: translateY(-1px);
}

.gallery-btn.profiling-btn:disabled {
    background: #334155;
    color: #64748b;
    cursor: not-allowed;
    opacity: 0.6;
}

.gallery-btn.select-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.gallery-btn.select-btn:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    transform: translateY(-1px);
}

/* Dark theme adjustments */
@media (prefers-color-scheme: dark) {
    .profiling-active-run {
        background: linear-gradient(90deg, rgba(59, 130, 246, 0.15) 0%, rgba(59, 130, 246, 0.05) 100%);
    }
    
    .profiling-active-run-title {
        color: #60a5fa;
    }
    
    .profiling-active-run-details {
        color: #94a3b8;
    }
}

/**
 * Active Run Indicator Styles
 * 
 * Append these styles to profiling.css
 */

/* =============================================================================
   Active Profiling Run Indicator
   ============================================================================= */

.profiling-active-run {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 15px;
    background: linear-gradient(135deg, #e8f4fd 0%, #d1e8fa 100%);
    border: 1px solid #90caf9;
    border-radius: 6px;
}

.profiling-active-run-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #90caf9;
    border-top-color: #71ca9d;
    border-radius: 50%;
    animation: profiling-active-spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

.profiling-active-run-info {
    flex: 1;
    min-width: 0;
}

.profiling-active-run-title {
    font-weight: 600;
    font-size: 13px;
    color: #1565c0;
    margin-bottom: 2px;
}

.profiling-active-run-details {
    font-size: 11px;
    color: #546e7a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profiling-active-run-stage {
    font-size: 11px;
    color: #1976d2;
    background: rgba(25, 118, 210, 0.1);
    padding: 3px 8px;
    border-radius: 10px;
    white-space: nowrap;
}


/* =============================================================================
   Footer Actions
   ============================================================================= */

.profiling-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 29px;
}

.profiling-footer-left,
.profiling-footer-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.profiling-btn-export {
    background: #0f9ce2;
    color: #ffffff;
    padding: 6px 10px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;    
}

.profiling-btn-export:hover  {
    background: #2da8e6;
    border-color: #117a8b;
}

.profiling-btn-close:hover {
    background: #2da8e6;
    border-color: #117a8b;
}

.profiling-btn-export:disabled {
    background: #6c757d;
    border-color: #6c757d;
    color: #fff;
    opacity: 0.6;
}

.profiling-btn-close {
    background: #0f9ce2;
    color: #ffffff;
    padding: 6px 10px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;  
}

/* =============================================================================
   Timeline Cursor Indicator
   ============================================================================= */

.timeline-cursor-line {
    position: absolute;
    top: 0;
    width: 0;
    border-left: 0.5px solid rgba(0, 0, 0, 0.6);
    pointer-events: none;
    display: none;
    z-index: 500;
}

.timeline-cursor-badge {
    position: absolute;
    top: 0;
    background: #666666ee;
    color: #fff;
    padding: 2px 6px 2.5px 6px;
    border-radius: 2px;
    font-size: 10px;
    font-weight: 500;
    font-family: system-ui, sans-serif;
    pointer-events: none;
    display: none;
    z-index: 501;
    white-space: nowrap;
    transform: translateX(-50%);
    box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
}
