:root {
    --primary: #EF4444;
    /* Heat Red for high complexity */
    --primary-hover: #DC2626;
    --secondary: #F97316;
    /* Orange for warnings */
    --accent: #22C55E;
    /* Green for safe code */
    --bg-dark: #110A0A;
    /* Heat Map Dark Base */
    --bg-panel: rgba(30, 15, 15, 0.7);
    --bg-surface: rgba(45, 20, 20, 0.5);

    --text-main: #FDF4F4;
    --text-muted: #FCA5A5;
    --border-color: rgba(239, 68, 68, 0.2);
    --border-hover: rgba(239, 68, 68, 0.4);
    --radius: 12px;

    --safe-color: #22C55E;
    --warning-color: #F97316;
    --critical-color: #EF4444;
}

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

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
    background-image:
        radial-gradient(circle at 10% 20%, rgba(2ef, 68, 68, 0.05), transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(249, 115, 22, 0.05), transparent 40%);
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.2;
}

.badge {
    font-size: 0.7rem;
    background: rgba(239, 68, 68, 0.1);
    color: var(--primary);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    display: inline-block;
    margin-top: 0.2rem;
}

/* Buttons */
.btn {
    padding: 0.7rem 1.25rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.primary-btn {
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}

.primary-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.35);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.secondary-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    border-radius: 6px;
    padding: 0.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.1);
}

.full-width {
    width: 100%;
}

/* Panels */
.glass-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.main-layout {
    display: flex;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.panel-header h2 {
    font-size: 1.1rem;
    color: var(--text-main);
}

/* Left Panel: Code Input */
.code-panel {
    width: 45%;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.form-select {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    padding: 0.4rem;
    outline: none;
    font-size: 0.85rem;
}

.code-editor {
    flex: 1;
    width: 100%;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-main);
    padding: 1rem;
    font-family: 'Fira Code', ui-monospace, monospace;
    font-size: 0.85rem;
    resize: none;
    outline: none;
    transition: all 0.2s;
    margin-bottom: 1rem;
    white-space: pre;
    line-height: 1.5;
}

.code-editor:focus {
    border-color: var(--secondary);
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.2);
}

/* Right Panel: Visualization */
.viz-panel {
    width: 55%;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: 1rem;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.legend-color.safe {
    background: var(--safe-color);
}

.legend-color.warning {
    background: var(--warning-color);
}

.legend-color.critical {
    background: var(--critical-color);
}

.treemap-container {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    margin-bottom: 1.5rem;
    position: relative;
    overflow: hidden;
    padding: 0.5rem;
    /* Basic grid setup for mock treemap */
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 0.5rem;
}

.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
    width: 100%;
}

.empty-state svg {
    opacity: 0.5;
    margin-bottom: 0.5rem;
}

/* Base Treemap Blocks */
.tree-node {
    border-radius: 6px;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: zoomIn 0.4s ease forwards;
    opacity: 0;
    transform: scale(0.9);
}

.tree-node:hover {
    transform: scale(1.02) translateY(-2px);
    z-index: 10;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
}

.node-title {
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.node-score {
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
    align-self: flex-end;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}

.stat-card.alert {
    border-color: rgba(239, 68, 68, 0.3);
    background: rgba(239, 68, 68, 0.05);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-card.alert .stat-value {
    color: var(--primary);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    width: 90%;
    max-width: 700px;
    transform: translateY(20px);
    transition: transform 0.3s;
    display: flex;
    flex-direction: column;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-family: 'Fira Code', monospace;
    color: var(--secondary);
    font-size: 1.2rem;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    max-height: 70vh;
}

.detail-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.detail-stat {
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-name {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.stat-num {
    font-size: 1.5rem;
    font-weight: 700;
}

.suggestion-box {
    background: rgba(249, 115, 22, 0.1);
    border-left: 4px solid var(--secondary);
    padding: 1rem 1.5rem;
    border-radius: 0 8px 8px 0;
    margin-bottom: 1.5rem;
}

.suggestion-box h3 {
    font-size: 0.9rem;
    color: var(--secondary);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.suggestion-box p {
    font-size: 0.9rem;
    color: #fff;
    line-height: 1.5;
}

.code-preview {
    background: #000;
    border-radius: 8px;
    padding: 1rem;
    overflow-x: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.code-preview pre {
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    color: #e2e8f0;
}

@keyframes zoomIn {
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

    .code-panel,
    .viz-panel {
        width: 100%;
        height: 50vh;
    }
}