/* CSS Variables */
:root {
    --bg-primary: #f7f7fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f2f5;
    --text-primary: #222;
    --text-secondary: #555;
    --accent-primary: #2563eb;
    --accent-secondary: #e0e7ef;
    --border-color: #d1d5db;
    --hover-bg: #e0e7ef;
    --selection-bg: #c7d2fe;
    --success: #22c55e;
    --warning: #f59e42;
}

/* Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--bg-primary);
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.header h1 {
    font-size: 1.4rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 10px;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.btn:hover {
    background: var(--accent-secondary);
    border-color: var(--accent-primary);
}

.btn-primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #fff;
}

.btn-primary:hover {
    background: #1746a2;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--accent-secondary);
}

.file-input-label {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.file-input-label:hover {
    background: var(--accent-secondary);
    border-color: var(--accent-primary);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Toolbar */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    gap: 16px;
}

.mode-controls {
    display: flex;
    align-items: center;
}

.mode-toggle {
    display: flex;
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
}

.btn-mode {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.btn-mode:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.btn-mode.active {
    background: var(--accent-primary);
    color: white;
}

.btn-mode .mode-icon {
    font-size: 1rem;
}

.zoom-controls, .selection-controls, .track-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.zoom-level {
    font-size: 0.85rem;
    color: var(--text-secondary);
    min-width: 50px;
}

.view-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Viewer Container */
.viewer-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    padding-bottom: 36px; /* Space for collapsed bottom panel */
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Selection Time Bar */
.selection-time-bar {
    position: absolute;
    top: 0;
    left: 200px; /* Same as track labels width */
    right: 0;
    height: 28px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    z-index: 15;
    display: block;
}

/* Time Ruler (tick marks and labels) */
.time-ruler {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100%;
    pointer-events: none;
}

.time-ruler-tick {
    position: absolute;
    bottom: 0;
    width: 1px;
    background: var(--border-color);
}

.time-ruler-tick.major {
    height: 12px;
}

.time-ruler-tick.minor {
    height: 6px;
    opacity: 0.5;
}

.time-ruler-label {
    position: absolute;
    top: 4px;
    font-size: 10px;
    color: var(--text-secondary);
    transform: translateX(-50%);
    white-space: nowrap;
}

/* Selection markers overlay */
.time-bar-content {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.time-marker {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #4FC3F7;
}

.time-marker::after {
    content: attr(data-time);
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    color: #4FC3F7;
    white-space: nowrap;
    padding: 2px 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
}

.time-marker.start::after {
    left: 6px;
}

.time-marker.end::after {
    right: 6px;
}

.time-delta-line {
    position: absolute;
    top: 50%;
    height: 2px;
    background: #4FC3F7;
    transform: translateY(-50%);
}

.time-delta-badge {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #0288D1;
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 10px;
    white-space: nowrap;
    z-index: 5;
}

.time-delta-arrows {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-style: solid;
}

.time-delta-arrows.left {
    border-width: 5px 6px 5px 0;
    border-color: transparent #4FC3F7 transparent transparent;
}

.time-delta-arrows.right {
    border-width: 5px 0 5px 6px;
    border-color: transparent transparent transparent #4FC3F7;
}

/* Track Labels */
.track-labels {
    position: absolute;
    left: 0;
    top: 28px;
    bottom: 30px;
    width: 200px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    z-index: 10;
}

.track-label {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    min-height: 28px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.track-label:hover {
    background: var(--hover-bg);
}

.track-label.selected {
    background: var(--selection-bg);
}

.track-label.hidden-track {
    opacity: 0.5;
    background: var(--bg-primary);
}

.track-visibility-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.9rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.track-visibility-btn:hover {
    background: var(--bg-tertiary);
}

.hidden-tracks-summary {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    position: sticky;
    bottom: 0;
}

.hidden-tracks-summary .btn-show-all {
    padding: 4px 8px;
    font-size: 0.75rem;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.hidden-tracks-summary .btn-show-all:hover {
    background: #1976D2;
}

.track-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.track-name {
    font-weight: 600;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.track-process {
    font-size: 0.7rem;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Canvas Container */
.canvas-container {
    position: absolute;
    top: 28px;
    left: 200px;
    right: 0;
    bottom: 30px;
    overflow: hidden;
    cursor: grab;
    background: var(--bg-secondary);
}

.canvas-container.pan-mode {
    cursor: grab;
}

.canvas-container.pan-mode:active {
    cursor: grabbing;
}

.canvas-container.select-mode {
    cursor: crosshair;
}

.canvas-container.select-mode:active {
    cursor: crosshair;
}

#traceCanvas {
    position: absolute;
    top: 0;
    left: 0;
    background: var(--bg-secondary);
}

/* Selection Overlay */
.selection-overlay {
    position: absolute;
    background: var(--selection-bg);
    border: 2px solid var(--accent-primary);
    pointer-events: none;
    display: none;
}

/* Hover Tooltip */
.hover-tooltip {
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.8rem;
    max-width: 400px;
    z-index: 100;
    pointer-events: none;
    display: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.hover-tooltip .tooltip-title {
    font-weight: 600;
    color: var(--accent-primary);
    margin-bottom: 4px;
}

.hover-tooltip .tooltip-details {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* Timeline Ruler */
.timeline-ruler {
    height: 30px;
    margin-left: 200px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
}

#rulerCanvas {
    width: 100%;
    height: 100%;
}

/* Bottom Panel (Collapsible) */
.bottom-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    z-index: 30;
    display: flex;
    flex-direction: column;
    height: 250px;
    min-height: 100px;
    max-height: 70%;
}

.bottom-panel.collapsed {
    height: 36px !important;
    min-height: 36px;
}

.bottom-panel.collapsed .bottom-panel-content {
    display: none;
}

.bottom-panel.collapsed .toggle-icon {
    transform: rotate(180deg);
}

.bottom-panel.collapsed .bottom-panel-resize-handle {
    display: none;
}

.bottom-panel-resize-handle {
    position: absolute;
    top: -4px;
    left: 0;
    right: 0;
    height: 8px;
    cursor: ns-resize;
    background: transparent;
    z-index: 10;
}

.bottom-panel-resize-handle:hover,
.bottom-panel-resize-handle.active {
    background: var(--accent-primary);
    opacity: 0.5;
}

.bottom-panel.resizing {
    transition: none;
    user-select: none;
}

.bottom-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 12px;
    height: 36px;
    min-height: 36px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
}

.bottom-panel-tabs {
    display: flex;
    gap: 4px;
}

.bottom-panel-tab {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 6px 12px;
    font-size: 0.8rem;
    cursor: pointer;
    border-radius: 4px 4px 0 0;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.bottom-panel-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.bottom-panel-tab.active {
    color: var(--accent-primary);
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--accent-primary);
}

.bottom-panel-tab .tab-icon {
    font-size: 0.9rem;
}

.bottom-panel-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.selection-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 8px;
    border-radius: 10px;
}

.bottom-panel-toggle {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bottom-panel-toggle:hover {
    color: var(--text-primary);
}

.toggle-icon {
    transition: transform 0.3s ease;
}

.bottom-panel-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

.bottom-tab-content {
    display: none;
    flex: 1;
    overflow: auto;
    padding: 12px 16px;
}

.bottom-tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Slice Details Grid */
.slice-details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    flex: 1;
}

.slice-details-grid .placeholder {
    grid-column: 1 / -1;
    color: var(--text-secondary);
    text-align: center;
    padding: 40px;
}

.detail-card {
    background: var(--bg-tertiary);
    border-radius: 6px;
    padding: 12px;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.detail-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.detail-card-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--accent-primary);
    word-break: break-word;
}

.detail-card-duration {
    font-size: 0.75rem;
    color: #1976d2;
    background: rgba(25, 118, 210, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

.detail-card-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--text-primary);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
}

.detail-row label {
    color: var(--text-secondary);
}

.detail-row .value {
    color: var(--text-primary);
    text-align: right;
    word-break: break-word;
    max-width: 60%;
    font-weight: 500;
}

.detail-row.args {
    flex-direction: column;
    gap: 4px;
}

.detail-row.args pre {
    margin: 0;
    font-size: 0.7rem;
    background: var(--bg-primary);
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    max-width: 100%;
}

.detail-card.single-slice {
    width: 100%;
    max-width: none;
}

.detail-card.single-slice .detail-card-body {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px 24px;
}

.detail-card.single-slice .detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.detail-card.single-slice .detail-row.args {
    grid-column: 1 / -1;
    flex-direction: column;
    align-items: stretch;
}

/* Summary View (Multiple Slices) */
.slice-details-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-start;
}

.summary-container {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    width: 100%;
}

.summary-table-section {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    flex: 1;
    min-width: 280px;
}

.summary-table-section h4 {
    margin: 0 0 10px 0;
    font-size: 0.85rem;
    color: var(--accent-primary);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.table-count {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.table-scroll {
    max-height: 180px;
    overflow-y: auto;
}

/* Summary Stats Table */
.summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.summary-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-color);
}

.summary-table td.label {
    color: var(--text-secondary);
    width: 25%;
}

.summary-table td.value {
    color: var(--text-primary);
    font-weight: 500;
    width: 25%;
}

.summary-table td.value.highlight {
    color: var(--accent-secondary);
    font-weight: 700;
}

.summary-table tr:last-child td {
    border-bottom: none;
}

/* Breakdown Tables */
.breakdown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
}

.breakdown-table thead {
    position: sticky;
    top: 0;
    background: var(--bg-tertiary);
}

.breakdown-table th {
    text-align: left;
    padding: 6px 8px;
    color: var(--text-secondary);
    font-weight: 500;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.breakdown-table td {
    padding: 5px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.breakdown-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.breakdown-table .col-name {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}

.breakdown-table .col-count {
    text-align: center;
    color: var(--text-secondary);
    width: 50px;
}

.breakdown-table .col-total {
    text-align: right;
    color: var(--text-secondary);
    font-weight: 600;
    white-space: nowrap;
}

.breakdown-table .col-avg {
    text-align: right;
    color: var(--text-secondary);
    white-space: nowrap;
}

.breakdown-table .col-range {
    text-align: right;
    color: var(--text-secondary);
    font-size: 0.7rem;
    white-space: nowrap;
}

.breakdown-table .col-pct {
    text-align: right;
    color: var(--accent-primary);
    font-weight: 500;
    width: 60px;
}

.breakdown-table .more-row td {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    padding: 8px;
}

/* LLM Tab Styles */
#llmTab {
    gap: 12px;
}

.llm-toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
}

.llm-toolbar select {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
}

#llmOutput {
    flex: 1;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.8rem;
    resize: none;
    min-height: 120px;
}

#llmOutput:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Status Bar */
.status-bar {
    display: flex;
    justify-content: space-between;
    padding: 6px 20px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Scrollbar */
::-webkit-scrollbar {
    background: #e5e7eb;
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 5px;
}

/* Slice colors */
.slice-color-0 { background: #4285f4; }
.slice-color-1 { background: #ea4335; }
.slice-color-2 { background: #fbbc04; }
.slice-color-3 { background: #34a853; }
.slice-color-4 { background: #ff6d01; }
.slice-color-5 { background: #46bdc6; }
.slice-color-6 { background: #7baaf7; }
.slice-color-7 { background: #f07b72; }

/* Animations */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.loading {
    animation: pulse 1.5s infinite;
}

/* Copy success notification */
.copy-success {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--success);
    color: white;
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 0.9rem;
    z-index: 100;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}
