/* ═══════════════════════════════════════════════════════════════════════════════
   MGraph HTML Graph - Render UI - Playground Styles
   v0.2.0 - Consolidated from v0.1.x
   
   Merged from:
   - v0.1.1: Base playground layout
   - v0.1.3: Stats toolbar positioning
   - v0.1.4: Renderer-specific styles
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────────────────────────
   Base Layout (from v0.1.1)
   ───────────────────────────────────────────────────────────────────────────────── */

/* Playground Layout */
.playground {
    display: grid;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
    background: var(--color-bg-muted);
}

.playground-main {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    overflow: hidden;
}

/* Left Panel - Input & Config */
.left-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    overflow-y: auto;
    max-height: calc(100vh - 80px);
}

/* Right Panel - Canvas */
.right-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    overflow: hidden;
}

/* Panel Headers */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--spacing-sm);
}

.panel-title {
    font-size: 1.0em;
    font-weight: 600;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.panel-title-icon {
    font-size: 1.2em;
}

/* Sample Selector */
.sample-selector {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.sample-selector label {
    font-size: var(--font-size-small);
    color: var(--color-text-secondary);
}

.sample-selector select {
    padding: var(--spacing-xs) var(--spacing-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-small);
    background: white;
    cursor: pointer;
}

/* HTML Input */
.html-input-area {
    width: 100%;
    min-height: 200px;
    max-height: 300px;
    padding: var(--spacing-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-code);
    font-size: 0.9em;
    line-height: 1.5;
    resize: vertical;
    background: var(--color-bg-muted);
}

.html-input-area:focus {
    outline: none;
    border-color: var(--color-primary);
    background: white;
}

/* Config Options */
.config-section {
    margin-bottom: var(--spacing-md);
}

.config-section-title {
    font-size: var(--font-size-small);
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--spacing-sm);
}

.config-row {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-xs);
}

.config-row label {
    flex: 1;
    font-size: var(--font-size-small);
}

.config-row select {
    width: 150px;
}

/* Stats Display */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-sm);
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--color-bg-muted);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-small);
}

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

.stat-value {
    font-weight: 600;
    color: var(--color-text-primary);
}

/* Graph Canvas */
.graph-canvas-container {
    flex: 1;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.canvas-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-muted);
}

.canvas-toolbar-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.canvas-toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.renderer-selector {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.renderer-selector label {
    font-size: var(--font-size-small);
    color: var(--color-text-secondary);
}

.renderer-selector select {
    padding: var(--spacing-xs) var(--spacing-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-small);
    background: white;
}

.canvas-area {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
    background: white;
}

.canvas-area svg {
    max-width: 100%;
    height: auto;
}

/* Canvas States */
.canvas-empty {
    color: var(--color-text-muted);
    text-align: center;
    padding: var(--spacing-xl);
}

.canvas-empty-icon {
    font-size: 4em;
    margin-bottom: var(--spacing-md);
    opacity: 0.3;
}

.canvas-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    color: var(--color-text-secondary);
}

.canvas-error {
    color: var(--color-error);
    text-align: center;
    padding: var(--spacing-md);
}

.canvas-error pre {
    margin-top: var(--spacing-sm);
    text-align: left;
    font-size: var(--font-size-small);
    max-width: 100%;
    overflow-x: auto;
}

/* Render Button */
.render-button {
    width: 100%;
    padding: var(--spacing-md);
    font-size: 1.1em;
    font-weight: 600;
}

.render-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ─────────────────────────────────────────────────────────────────────────────────
   Stats Toolbar Layout (from v0.1.3)
   ───────────────────────────────────────────────────────────────────────────────── */

/* Full height layout */
.playground {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.playground-main {
    flex: 1;
    min-height: 0;  /* Important for flex children to shrink */
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    overflow: hidden;
}

/* Left panel - scrollable */
.left-panel {
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* Right panel layout: toolbar at top, canvas fills rest */
.right-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

/* Stats toolbar - fixed height */
.stats-toolbar {
    flex-shrink: 0;
}

/* Graph canvas - fills remaining space */
graph-canvas {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

graph-canvas .graph-canvas-container,
graph-canvas .canvas-area {
    flex: 1;
    min-height: 0;
    height: 100%;
}

/* Canvas area styling for panning */
graph-canvas .canvas-area {
    overflow: auto;
    cursor: grab;
    position: relative;
}

graph-canvas .canvas-area:active {
    cursor: grabbing;
}

/* Make SVG fill the space but allow overflow for panning */
graph-canvas .canvas-area svg {
    min-width: 100%;
    min-height: 100%;
    display: block;
}

/* Hide the old stats panel and render button when using new layout */
.left-panel stats-panel,
.left-panel .render-button {
    display: none;
}

/* ─────────────────────────────────────────────────────────────────────────────────
   Renderer Styles (from v0.1.4)
   ───────────────────────────────────────────────────────────────────────────────── */

/* Renderer selector styling */
.renderer-selector select {
    min-width: 160px;
}

/* Canvas area - ensure it works with all renderers */
.canvas-area {
    position: relative;
    background: #fafafa;
}

/* vis.js container needs full dimensions */
#vis-container {
    width: 100%;
    height: 100%;
    min-height: 400px;
}

/* D3 SVG should fill container */
.canvas-area > svg {
    width: 100%;
    height: 100%;
}

/* Renderer info in empty state */
.renderer-info {
    text-align: left;
    max-width: 320px;
    margin: 15px auto 0;
    line-height: 1.6;
}

/* Loading state for async renderer loading */
.renderer-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #666;
}

.renderer-loading .spinner {
    margin-bottom: 10px;
}

/* Interactive renderer hint */
.canvas-area::after {
    content: '';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 0;
    height: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

/* Show hint for interactive renderers */
.canvas-area.interactive::after {
    content: '🖱️ Drag to pan, scroll to zoom';
    width: auto;
    height: auto;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border-radius: 4px;
    font-size: 0.75em;
    opacity: 1;
}

/* Force-directed layout animation */
@keyframes pulse {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 0.4; }
}

.d3-simulating .canvas-area::before {
    content: 'Physics simulation running...';
    position: absolute;
    top: 10px;
    left: 10px;
    padding: 4px 8px;
    background: rgba(99, 102, 241, 0.9);
    color: white;
    border-radius: 4px;
    font-size: 0.75em;
    animation: pulse 1.5s ease-in-out infinite;
    z-index: 10;
}

/* Node hover effects for D3 */
.canvas-area svg g.nodes rect:hover {
    filter: brightness(1.1);
    cursor: grab;
}

.canvas-area svg g.nodes rect:active {
    cursor: grabbing;
}

/* Link hover effects for D3 */
.canvas-area svg g.links line:hover {
    stroke-opacity: 1;
    stroke-width: 2.5;
}

/* Tooltip styling for vis.js */
.vis-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.85em;
    max-width: 250px;
    word-wrap: break-word;
    pointer-events: none;
    z-index: 1000;
}

/* ─────────────────────────────────────────────────────────────────────────────────
   Responsive Adjustments
   ───────────────────────────────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
    .playground-main {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        overflow: auto;
    }

    .left-panel {
        height: auto;
        max-height: 50vh;
    }

    .right-panel {
        min-height: 400px;
    }
}

@media (max-width: 768px) {
    .playground-main {
        padding: var(--spacing-sm);
    }

    .left-panel {
        max-height: 40vh;
    }
}
