:root {
    --primary: #00B894;
    --primary-hover: #00A383;
    --secondary: #55EFC4;
    --accent: #FDCB6E;
    --bg: #0A1F1C;
    --surface: #102A26;
    --surface-hover: #173B35;
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --border: rgba(0, 184, 148, 0.2);
    --border-focus: rgba(85, 239, 196, 0.6);
    --radius: 12px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --transition: 250ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Treemap colors */
    --tm-node-modules: #6c5ce7;
    --tm-src: #0984e3;
    --tm-assets: #e17055;
    --tm-other: #636e72;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg);
    background-image:
        radial-gradient(circle at 100% 0%, rgba(0, 184, 148, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 0% 100%, rgba(85, 239, 196, 0.05) 0%, transparent 40%);
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    padding: 1.5rem;
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: calc(100vh - 3rem);
}

/* Glassmorphism */
.glass-panel {
    background: rgba(16, 42, 38, 0.65);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-left h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.accent-text {
    color: var(--accent);
    background: linear-gradient(135deg, var(--secondary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-left p {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-top: 0.25rem;
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    outline: none;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: var(--bg);
    box-shadow: 0 4px 15px rgba(0, 184, 148, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 184, 148, 0.4);
}

.secondary-btn {
    background: rgba(85, 239, 196, 0.1);
    color: var(--secondary);
    border: 1px solid rgba(85, 239, 196, 0.3);
}

.secondary-btn:hover:not(:disabled) {
    background: rgba(85, 239, 196, 0.2);
}

.outline-btn {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

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

.btn:disabled,
.btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.icon-btn {
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

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

/* Main Layout */
.main-content {
    display: flex;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
    /* needed for flex child scrolling */
}

/* Sidebar */
.sidebar {
    width: 280px;
    flex-shrink: 0;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
}

.control-group h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 0.65rem 1rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
}

.form-input:focus {
    border-color: var(--border-focus);
}

.range-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.range-wrapper label {
    font-size: 0.9rem;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
}

.form-range {
    width: 100%;
    accent-color: var(--primary);
}

.export-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1.5rem;
    margin-top: auto;
}

.stats-summary {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.stats-summary h3 {
    color: var(--secondary);
    margin-bottom: 0.5rem;
}

.summary-line {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}

/* Custom Toggle */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 100%;
    height: 44px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch label {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: .4s;
    border-radius: 8px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1;
}

.toggle-switch label::before {
    position: absolute;
    content: "";
    height: calc(100% - 6px);
    width: calc(50% - 3px);
    left: 3px;
    bottom: 3px;
    background-color: var(--primary);
    transition: .4s;
    border-radius: 6px;
    z-index: -1;
}

.toggle-switch input:checked+label::before {
    transform: translateX(100%);
    background-color: var(--secondary);
}

.toggle-text {
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 2;
    color: var(--text-primary);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Visualization Area */
.viz-area {
    flex: 1;
    position: relative;
    display: flex;
    min-width: 0;
}

.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: opacity var(--transition);
}

.empty-icon {
    color: var(--secondary);
    opacity: 0.5;
    margin-bottom: 1.5rem;
    background: rgba(85, 239, 196, 0.1);
    padding: 1.5rem;
    border-radius: 50%;
}

.empty-state h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--text-secondary);
}

.empty-state code {
    background: rgba(0, 0, 0, 0.5);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    color: var(--accent);
}

.treemaps-wrapper {
    display: flex;
    gap: 1.5rem;
    width: 100%;
    height: 100%;
}

.treemap-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    min-width: 0;
}

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

.treemap-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.zoom-path {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.zoom-path:hover {
    color: var(--primary);
}

.d3-canvas {
    flex: 1;
    position: relative;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

/* Treemap SVG Styles */
.node rect {
    cursor: pointer;
    stroke: var(--bg);
    stroke-width: 1.5px;
    transition: opacity 0.2s;
}

.node:hover rect {
    opacity: 0.8;
}

.node text {
    font-family: 'Inter', sans-serif;
    fill: #fff;
    pointer-events: none;
    font-size: 11px;
}

.node .label-name {
    font-weight: 500;
}

.node .label-size {
    fill: rgba(255, 255, 255, 0.7);
    font-size: 10px;
}

/* Tooltip */
.d3-tooltip {
    position: absolute;
    padding: 0.75rem;
    pointer-events: none;
    z-index: 1000;
    font-size: 0.85rem;
    max-width: 300px;
    word-break: break-all;
}

.d3-tooltip strong {
    display: block;
    color: var(--accent);
    margin-bottom: 4px;
}

/* Responsive */
@media (max-width: 900px) {
    .app-container {
        height: auto;
    }

    .main-content {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        order: -1;
    }

    .viz-area {
        height: 600px;
        /* fixed height on mobile */
    }

    .treemaps-wrapper {
        flex-direction: column;
    }
}