/* ===================================
   Web Performance Flame Graph — Styles
   Dark mode, Flame Orange palette
   =================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #F97316;
    --primary-light: #FB923C;
    --primary-dark: #EA580C;
    --accent: #8B5CF6;
    --accent-light: #A78BFA;
    --bg-900: #120D08;
    --bg-800: #1A1209;
    --bg-700: #22190E;
    --bg-600: #2E2214;
    --bg-500: #3D2E1C;
    --text-100: #FEF3E2;
    --text-200: #D4C4A8;
    --text-300: #9A8B72;
    --border: rgba(249, 115, 22, 0.1);
    --glass: rgba(18, 13, 8, 0.9);
    --glass-border: rgba(249, 115, 22, 0.15);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: 'JetBrains Mono', monospace;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);

    /* Flame colors */
    --color-scripting: #F97316;
    --color-rendering: #8B5CF6;
    --color-painting: #06B6D4;
    --color-long-task: #EF4444;
    --color-gc: #22C55E;
    --color-other: #6B7280;
}

html,
body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-900);
    color: var(--text-100);
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-500);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* --- Toolbar --- */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 16px;
    background: var(--bg-800);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    flex-shrink: 0;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    font-size: 22px;
    line-height: 1;
}

.app-title {
    font-size: 16px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}

.toolbar-center {
    display: flex;
    align-items: center;
    flex: 1;
    max-width: 400px;
    margin: 0 16px;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- Search --- */
.search-wrapper {
    position: relative;
    width: 100%;
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-300);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 7px 60px 7px 32px;
    background: var(--bg-700);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-100);
    font-family: var(--mono);
    font-size: 12px;
    outline: none;
    transition: var(--transition);
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
}

.search-input::placeholder {
    color: var(--text-300);
}

.search-count {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    color: var(--text-300);
    font-family: var(--mono);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    border: none;
    box-shadow: 0 2px 12px rgba(249, 115, 22, 0.25);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(249, 115, 22, 0.4);
}

.btn-secondary {
    background: var(--bg-700);
    color: var(--text-200);
}

.btn-secondary:hover {
    background: var(--bg-600);
    border-color: var(--primary);
    color: var(--text-100);
}

.btn-lg {
    padding: 12px 24px;
    font-size: 14px;
    border-radius: var(--radius);
}

/* --- Main Layout --- */
.main-layout {
    display: flex;
    height: calc(100vh - 53px);
    overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-800);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.panel {
    padding: 14px;
    border-bottom: 1px solid var(--border);
    animation: fadeIn 0.4s ease-out;
}

.panel-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-300);
    margin-bottom: 10px;
}

/* --- Stats --- */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stat-card {
    background: var(--bg-700);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-300);
}

.stat-value {
    font-family: var(--mono);
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-light);
}

.stat-value.warning {
    color: var(--color-long-task);
}

/* --- Legend --- */
.legend {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-200);
}

.legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* --- Top Functions --- */
.top-functions-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 200px;
    overflow-y: auto;
}

.top-fn-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    background: var(--bg-700);
    border-radius: var(--radius-sm);
    font-size: 11px;
    cursor: pointer;
    transition: var(--transition);
}

.top-fn-item:hover {
    background: var(--bg-600);
}

.top-fn-name {
    font-family: var(--mono);
    color: var(--text-200);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 140px;
}

.top-fn-time {
    font-family: var(--mono);
    color: var(--primary-light);
    font-weight: 500;
}

/* --- Selection Details --- */
.selection-details {
    font-size: 12px;
    color: var(--text-200);
}

.selection-details .detail-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
}

.selection-details .detail-label {
    color: var(--text-300);
}

.selection-details .detail-value {
    font-family: var(--mono);
    color: var(--primary-light);
}

.empty-hint {
    color: var(--text-300);
    font-style: italic;
    font-size: 12px;
}

/* --- Canvas Area --- */
.canvas-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(ellipse at 50% 20%, rgba(249, 115, 22, 0.03), transparent 60%),
        var(--bg-900);
}

.flame-container {
    width: 100%;
    height: 100%;
    overflow: auto;
    cursor: grab;
}

.flame-container:active {
    cursor: grabbing;
}

.flame-container canvas {
    display: block;
}

/* --- Empty State --- */
.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 10;
    animation: fadeIn 0.6s ease-out;
}

.empty-state.hidden {
    display: none;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 8px;
}

.empty-state h2 {
    font-size: 24px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.empty-state p {
    color: var(--text-300);
    max-width: 400px;
    text-align: center;
    line-height: 1.6;
}

.empty-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

/* --- Tooltip --- */
.tooltip {
    position: fixed;
    padding: 10px 14px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    backdrop-filter: blur(16px);
    font-size: 12px;
    color: var(--text-100);
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    max-width: 350px;
    box-shadow: var(--shadow);
}

.tooltip.visible {
    opacity: 1;
}

.tooltip .tt-name {
    font-family: var(--mono);
    font-weight: 600;
    color: var(--primary-light);
    margin-bottom: 4px;
    word-break: break-all;
}

.tooltip .tt-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    font-size: 11px;
    color: var(--text-200);
}

.tooltip .tt-value {
    font-family: var(--mono);
    color: var(--text-100);
}

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 10px 24px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    backdrop-filter: blur(16px);
    color: var(--primary-light);
    font-size: 13px;
    font-weight: 500;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* --- Animations --- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: 100%;
        max-height: 200px;
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow-x: auto;
    }

    .sidebar .panel {
        min-width: 200px;
    }

    .toolbar {
        flex-wrap: wrap;
        gap: 6px;
    }

    .toolbar-center {
        order: 3;
        flex: none;
        width: 100%;
        max-width: 100%;
        margin: 0;
    }
}

@media (max-width: 600px) {
    .app-title {
        display: none;
    }

    .toolbar-right {
        flex-wrap: wrap;
    }
}