/* CSS Variables */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --border-color: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent-primary: #58a6ff;
    --accent-secondary: #238636;
    --accent-warning: #d29922;
    --accent-danger: #f85149;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

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

/* Base */
html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Layout */
.container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Input Panel */
.input-panel {
    width: 380px;
    min-width: 320px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    padding: 24px 20px 16px;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--accent-primary), #a371f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Input Section */
.input-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px 20px;
    gap: 12px;
    overflow: hidden;
}

.input-section label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

#json-input {
    flex: 1;
    min-height: 200px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-primary);
    resize: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    line-height: 1.5;
}

#json-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

#json-input::placeholder {
    color: var(--text-muted);
}

/* Controls */
.controls {
    display: flex;
    gap: 8px;
}

button {
    padding: 10px 18px;
    font-size: 0.85rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

#analyze-btn {
    flex: 1;
    background: linear-gradient(135deg, var(--accent-primary), #388bfd);
    color: #fff;
}

#analyze-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(88, 166, 255, 0.4);
}

#analyze-btn:active:not(:disabled) {
    transform: translateY(0);
}

#analyze-btn:disabled {
    opacity: 0.7;
    cursor: wait;
}

button.secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

button.secondary:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

/* Error Message */
.error-message {
    font-size: 0.8rem;
    color: var(--accent-danger);
    padding: 10px 12px;
    background: rgba(248, 81, 73, 0.1);
    border: 1px solid rgba(248, 81, 73, 0.3);
    border-radius: var(--radius-sm);
    display: none;
}

.error-message.visible {
    display: block;
}

/* Stats Panel */
.stats-panel {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.stats-panel h3 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
}

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

.stat-value {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--accent-primary);
}

/* Visualization Panel */
.visualization-panel {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-primary);
}

#treemap-container {
    width: 100%;
    height: 100%;
    display: none;
}

#treemap-container.active {
    display: block;
}

/* Empty State */
.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
}

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

.empty-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
    filter: grayscale(0.5);
}

.empty-state p {
    font-size: 0.95rem;
    max-width: 280px;
    line-height: 1.6;
}

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

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 14px;
    background: radial-gradient(120% 120% at 50% 50%, rgba(13, 17, 23, 0.7), rgba(13, 17, 23, 0.9));
    backdrop-filter: blur(4px);
    z-index: 12;
    pointer-events: none;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    position: relative;
    width: 78px;
    height: 78px;
}

.loading-spinner .ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 4px solid rgba(88, 166, 255, 0.18);
    border-top-color: #58a6ff;
    animation: spin 1.1s linear infinite;
    box-shadow: 0 0 16px rgba(88, 166, 255, 0.35), inset 0 0 12px rgba(88, 166, 255, 0.15);
}

.loading-spinner .dot {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    margin: -7px;
    border-radius: 50%;
    background: linear-gradient(135deg, #58a6ff, #a371f7);
    box-shadow: 0 0 16px rgba(88, 166, 255, 0.8);
    animation: pulse 1.2s ease-in-out infinite;
}

.loading-text {
    font-size: 0.95rem;
    color: var(--text-primary);
    letter-spacing: 0.02em;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

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

@keyframes pulse {
    0%, 100% { transform: scale(0.9); opacity: 0.7; }
    50% { transform: scale(1.05); opacity: 1; }
}

/* Plotly Overrides */
.js-plotly-plot .plotly .modebar {
    top: 8px !important;
    right: 8px !important;
}

.js-plotly-plot .plotly .modebar-btn {
    fill: var(--text-muted) !important;
}

.js-plotly-plot .plotly .modebar-btn:hover {
    fill: var(--text-primary) !important;
}

/* Force white text with stroke outline on treemap for readability */
.js-plotly-plot .slice text,
.js-plotly-plot .slicetext,
.js-plotly-plot g.treemap text:not(.hoverlayer text),
.js-plotly-plot .pathbar text,
.js-plotly-plot .surface text,
.js-plotly-plot text.slicetext {
    fill: #ffffff !important;
    stroke: rgba(0, 0, 0, 0.6) !important;
    stroke-width: 3px !important;
    paint-order: stroke fill !important;
}

/* Tooltip styling - clean text without stroke */
.js-plotly-plot .hoverlayer text,
.js-plotly-plot .hovertext text {
    fill: #ffffff !important;
    stroke: none !important;
    stroke-width: 0 !important;
}

.js-plotly-plot .hoverlayer .hovertext path {
    fill: #1a1f26 !important;
    stroke: #30363d !important;
}

/* Responsive */
@media (max-width: 900px) {
    .container {
        flex-direction: column;
    }
    
    .input-panel {
        width: 100%;
        min-width: unset;
        max-height: 45vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .visualization-panel {
        min-height: 55vh;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

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

/* Selection */
::selection {
    background: rgba(88, 166, 255, 0.3);
}

