/**
 * VineAcademy Block Playground Styles
 * Scratch-like visual programming interface
 */

/* ============================================
   LAYOUT
   ============================================ */

.main-container {
    height: calc(100vh - 52px);
    display: flex;
    overflow: hidden;
}

/* ============================================
   TOP NAV ADDITIONS
   ============================================ */

.beta-badge {
    font-size: 11px;
    background: linear-gradient(135deg, #7C3AED, #5B21B6);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
}

/* Pipeline Status Bar */
.pipeline-status-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    font-size: 11px;
}

.pipeline-stage {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.pipeline-stage span {
    color: var(--text-secondary);
}

.stage-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.stage-dot.pending {
    background: #6B7280;
}

.stage-dot.active {
    background: #F59E0B;
    animation: pulse 1s infinite;
}

.stage-dot.complete {
    background: #10B981;
}

.stage-dot.error {
    background: #EF4444;
}

.pipeline-connector {
    width: 20px;
    height: 2px;
    background: var(--border-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.2); }
}

/* User Level Badge */
.user-level-badge {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #7C3AED, #5B21B6);
    border-radius: 50%;
    overflow: hidden;
}

.user-level-badge .level-icon {
    color: white;
    font-weight: 700;
    font-size: 14px;
    z-index: 1;
}

.user-level-badge .xp-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px;
    background: rgba(255, 255, 255, 0.5);
}

/* ============================================
   LEFT SIDEBAR: BLOCK PALETTE
   ============================================ */

.block-palette-sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.palette-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.sidebar-hint {
    padding: 8px 12px;
    background: color-mix(in srgb, #7C3AED 10%, transparent);
    border-bottom: 1px solid var(--border-color);
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
}

.sidebar-hint span {
    display: block;
}

.block-categories {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* Category Section */
.category-section {
    margin-bottom: 12px;
}

.category-section.collapsed .category-blocks {
    display: none;
}

.category-section.collapsed .category-header::after {
    transform: rotate(-90deg);
}

.category-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: color-mix(in srgb, var(--category-color) 15%, transparent);
    border-left: 3px solid var(--category-color);
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.2s ease;
}

.category-header:hover {
    background: color-mix(in srgb, var(--category-color) 25%, transparent);
}

.category-header::after {
    content: '▼';
    font-size: 8px;
    color: var(--text-secondary);
    margin-left: auto;
    transition: transform 0.2s ease;
}

.category-icon {
    font-size: 16px;
}

.category-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.category-badge {
    font-size: 10px;
    padding: 2px 6px;
    background: var(--category-color);
    color: white;
    border-radius: 4px;
    font-weight: 500;
}

/* Block Previews in Palette */
.category-blocks {
    padding-left: 8px;
}

.block-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin: 4px 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.block-preview:hover {
    border-color: var(--category-color, #7C3AED);
    transform: translateX(4px);
    background: var(--bg-secondary);
}

.block-preview:active,
.block-preview.clicked {
    transform: scale(0.95);
    background: var(--category-color, #7C3AED);
    border-color: var(--category-color, #7C3AED);
}

.block-preview.clicked .block-label {
    color: white;
}

.block-preview .block-icon {
    font-size: 16px;
}

.block-preview .block-label {
    font-size: 12px;
    color: var(--text-primary);
    line-height: 1.3;
}

/* Datasets Section */
.datasets-section {
    border-top: 1px solid var(--border-color);
    padding: 12px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.datasets-list {
    max-height: 150px;
    overflow-y: auto;
}

.dataset-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.dataset-item:hover {
    border-color: #10B981;
}

.dataset-item.selected {
    border-color: #10B981;
    background: rgba(16, 185, 129, 0.1);
}

.dataset-icon {
    font-size: 18px;
}

.dataset-info {
    flex: 1;
    min-width: 0;
}

.dataset-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dataset-meta {
    font-size: 10px;
    color: var(--text-secondary);
}

.empty-state {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 12px;
}

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

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

/* ============================================
   CENTER: WORKSPACE AREA
   ============================================ */

.workspace-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    position: relative;
    overflow: hidden;
}

.blockly-container {
    flex: 1;
    min-height: 0;
}

/* Blockly Theme Overrides */
.blocklyToolboxDiv {
    background: var(--bg-secondary) !important;
}

.blocklyFlyoutBackground {
    fill: var(--bg-secondary) !important;
    fill-opacity: 0.95;
}

.blocklyMainBackground {
    fill: var(--bg-primary) !important;
}

[data-theme="dark"] .blocklyMainBackground {
    fill: #1a1a2e !important;
}

/* Action Bar */
.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.action-left,
.action-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.action-center {
    display: flex;
    justify-content: center;
}

.mode-select {
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
}

.run-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 32px;
    font-size: 15px;
    font-weight: 600;
    background: linear-gradient(135deg, #7C3AED, #5B21B6);
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.run-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
}

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

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner.large {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

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

/* ============================================
   RIGHT PANEL: OUTPUT & CODE
   ============================================ */

.output-panel {
    width: 380px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

/* Panel Tabs */
.panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.panel-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.panel-tab:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.panel-tab.active {
    color: #7C3AED;
    border-bottom-color: #7C3AED;
}

.lock-badge,
.peek-badge {
    font-size: 10px;
}

/* Panel Content */
.panel-content {
    flex: 1;
    overflow: hidden;
}

.panel-pane {
    display: none;
    height: 100%;
    overflow-y: auto;
}

.panel-pane.active {
    display: block;
}

/* Output Container */
.output-container {
    padding: 16px;
}

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    gap: 16px;
    color: var(--text-secondary);
}

.error-state {
    text-align: center;
    padding: 40px 20px;
}

.error-state .error-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.error-state h3 {
    color: #EF4444;
    margin-bottom: 8px;
}

/* Results Container */
.results-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.artifact-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.artifact-card.primary {
    border-color: #10B981;
    box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.2);
}

.artifact-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.artifact-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 12px;
}

.artifact-title {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.confidence-badge {
    font-size: 11px;
    padding: 2px 8px;
    background: rgba(124, 58, 237, 0.1);
    color: #7C3AED;
    border-radius: 4px;
}

.artifact-explanation {
    padding: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    border-bottom: 1px solid var(--border-color);
}

.artifact-code {
    max-height: 200px;
    overflow: auto;
}

.artifact-code pre {
    margin: 0;
}

.artifact-code code {
    font-family: 'Fira Code', monospace;
    font-size: 12px;
    padding: 12px !important;
}

.artifact-actions {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border-color);
}

/* CommDAAF Summary */
.commdaaf-summary {
    padding: 12px;
    background: rgba(59, 130, 246, 0.05);
    border-top: 1px solid var(--border-color);
}

.commdaaf-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 4px 0;
    font-size: 11px;
}

.commdaaf-icon {
    flex-shrink: 0;
}

.commdaaf-text {
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Output Card */
.output-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.output-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
    font-weight: 500;
}

.output-content {
    padding: 12px;
    font-family: 'Fira Code', monospace;
    font-size: 12px;
    overflow-x: auto;
}

.output-content pre {
    margin: 0;
    white-space: pre-wrap;
}

/* Images */
.images-container {
    display: grid;
    gap: 12px;
}

.result-image {
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

/* ============================================
   CODE PANEL STATES
   ============================================ */

/* Locked State */
.locked-code-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    height: 100%;
}

.locked-code-panel .lock-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.locked-code-panel h3 {
    color: var(--text-primary);
    margin-bottom: 8px;
}

.locked-code-panel p {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 16px;
}

.unlock-progress {
    width: 100%;
    max-width: 200px;
    margin-bottom: 16px;
}

.progress-bar {
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #7C3AED, #10B981);
    transition: width 0.3s ease;
}

.unlock-progress span {
    font-size: 11px;
    color: var(--text-secondary);
}

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

/* Peek State */
.peek-code-panel {
    height: 100%;
    display: flex;
    flex-direction: column;
}

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

.peek-badge {
    font-size: 12px;
    padding: 4px 10px;
    background: rgba(124, 58, 237, 0.1);
    color: #7C3AED;
    border-radius: 4px;
}

.peek-hint {
    font-size: 11px;
    color: var(--text-secondary);
}

.code-display {
    flex: 1;
    overflow: auto;
}

.code-display pre {
    margin: 0;
    height: 100%;
}

.code-display code {
    font-family: 'Fira Code', monospace;
    font-size: 12px;
    padding: 16px !important;
    min-height: 100%;
}

/* Full Code Editor */
.full-code-panel {
    height: 100%;
    display: flex;
    flex-direction: column;
}

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

.full-badge {
    font-size: 12px;
    padding: 4px 10px;
    background: rgba(16, 185, 129, 0.1);
    color: #10B981;
    border-radius: 4px;
}

.code-actions {
    display: flex;
    gap: 8px;
}

.code-editor {
    flex: 1;
    overflow: hidden;
}

.code-editor textarea {
    width: 100%;
    height: 100%;
    padding: 16px;
    border: none;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
    resize: none;
}

.code-editor textarea:focus {
    outline: none;
}

/* ============================================
   REASONING PANEL
   ============================================ */

.reasoning-container {
    padding: 16px;
}

.reasoning-entry {
    padding: 10px 12px;
    margin-bottom: 8px;
    background: var(--bg-primary);
    border-radius: 8px;
    border-left: 3px solid #6B7280;
}

.reasoning-entry.GLM-5 {
    border-left-color: #8B5CF6;
}

.reasoning-entry.Qwen3 {
    border-left-color: #6366F1;
}

.reasoning-entry.Consensus {
    border-left-color: #10B981;
}

.reasoning-entry.error {
    border-left-color: #EF4444;
}

.entry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.entry-actor {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
}

.entry-phase {
    font-size: 10px;
    color: var(--text-secondary);
}

.entry-content {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* ============================================
   NUDGE MODAL
   ============================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.nudge-modal {
    text-align: center;
}

.nudge-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.nudge-modal h3 {
    color: var(--text-primary);
    margin-bottom: 12px;
}

.nudge-modal p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 20px;
}

.nudge-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* ============================================
   XP NOTIFICATION
   ============================================ */

.xp-notification {
    position: fixed;
    top: 70px;
    right: 20px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #7C3AED, #5B21B6);
    color: white;
    font-weight: 600;
    border-radius: 8px;
    animation: xpPop 0.5s ease, xpFade 0.5s ease 1.5s forwards;
    z-index: 1000;
}

@keyframes xpPop {
    0% { transform: translateY(-20px) scale(0.8); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes xpFade {
    to { opacity: 0; transform: translateY(-10px); }
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 1024px) {
    .block-palette-sidebar {
        width: 220px;
    }

    .output-panel {
        width: 320px;
    }

    .pipeline-status-bar {
        display: none;
    }
}

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

    .block-palette-sidebar {
        width: 100%;
        height: auto;
        max-height: 200px;
    }

    .output-panel {
        width: 100%;
        height: 300px;
    }

    .action-bar {
        flex-wrap: wrap;
        gap: 8px;
    }
}

/* ============================================
   TEMPLATE MODAL
   ============================================ */

.template-modal {
    max-width: 700px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.modal-header h2 {
    margin: 0 0 4px 0;
    font-size: 18px;
    color: var(--text-primary);
}

.modal-header p {
    margin: 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.template-list {
    padding: 16px 24px 24px;
    overflow-y: auto;
    flex: 1;
}

.template-section {
    margin-bottom: 24px;
}

.template-section:last-child {
    margin-bottom: 0;
}

.template-section h3 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.template-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.template-card:hover {
    border-color: #7C3AED;
    background: color-mix(in srgb, #7C3AED 5%, var(--bg-secondary));
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.template-icon {
    font-size: 28px;
    line-height: 1;
    flex-shrink: 0;
}

.template-info {
    flex: 1;
    min-width: 0;
}

.template-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.template-description {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 8px;
}

.template-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.template-difficulty {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 4px;
    color: white;
}

.template-time {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Responsive template modal */
@media (max-width: 768px) {
    .template-modal {
        max-width: 95%;
        max-height: 90vh;
    }

    .template-grid {
        grid-template-columns: 1fr;
    }
}
