/* ==========================================================================
   TESAIoT - MicroPython Blockly IDE
   Theme: Matches tesaiot.com admin UI
   Primary: #7239ea | TESA Blue: #3c54a4 | Success: #50cd89
   ========================================================================== */

:root {
    /* TESAIoT Brand Colors */
    --tesa-primary: #7239ea;
    --tesa-primary-hover: #5f2bc7;
    --tesa-primary-light: #e3d6ff;
    --tesa-primary-subtle: #f5f0ff;
    --tesa-blue: #3c54a4;
    --tesa-red: #e9292a;
    --tesa-navy: #231f20;

    /* Semantic Colors */
    --color-success: #50cd89;
    --color-success-hover: #43b578;
    --color-info: #009ef7;
    --color-info-hover: #0085d1;
    --color-warning: #ffc700;
    --color-danger: #f1416c;
    --color-danger-hover: #d9365d;

    /* Surface & Background */
    --bg-body: #f5f8fa;
    --bg-surface: #ffffff;
    --bg-elevated: #ffffff;
    --bg-muted: #f1f3f5;
    --bg-code: #1e1e2d;
    --bg-terminal: #1a1a2e;

    /* Text */
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --text-inverse: #f9fafb;
    --text-code: #d4d4d4;

    /* Borders */
    --border-color: #e5e7eb;
    --border-hover: #d1d5db;
    --border-focus: var(--tesa-primary);

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);

    /* Layout */
    --header-height: 54px;
    --toolbar-height: 40px;
    --statusbar-height: 26px;
    --border-radius: 8px;
    --border-radius-sm: 6px;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', 'Consolas', monospace;

    /* Transitions */
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   Base Reset
   ========================================================================== */

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

body {
    font-family: var(--font-sans);
    background: var(--bg-body);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   Header
   ========================================================================== */

#header {
    height: var(--header-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

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

/* Logo */
.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.logo-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--tesa-navy);
    letter-spacing: -0.3px;
}

.logo-subtitle {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-tertiary);
    letter-spacing: 0.01em;
}

/* View Toggle */
.view-toggle {
    display: flex;
    background: var(--bg-muted);
    border-radius: var(--border-radius-sm);
    padding: 2px;
    gap: 2px;
}

.view-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition);
}

.view-btn:hover {
    color: var(--text-primary);
}

.view-btn.active {
    background: var(--bg-surface);
    color: var(--tesa-primary);
    box-shadow: var(--shadow-sm);
}

/* Connection Badge */
.connection-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--bg-muted);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.connection-badge.connected {
    background: #ecfdf5;
    color: #065f46;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    transition: all var(--transition);
}

.status-dot.connected {
    background: var(--color-success);
    box-shadow: 0 0 0 3px rgba(80, 205, 137, 0.2);
}

.status-dot.connecting {
    background: var(--color-warning);
    animation: pulse 1.2s ease-in-out infinite;
}

.status-dot.disconnected {
    background: var(--color-danger);
    opacity: 0.6;
}

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

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 6px 14px;
    border: 1px solid transparent;
    border-radius: var(--border-radius-sm);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    user-select: none;
}

.btn:hover { filter: brightness(0.95); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

.btn-primary {
    background: var(--tesa-primary);
    color: white;
    box-shadow: 0 1px 2px rgba(114, 57, 234, 0.3);
}
.btn-primary:hover { background: var(--tesa-primary-hover); }

.btn-success {
    background: var(--color-success);
    color: white;
    box-shadow: 0 1px 2px rgba(80, 205, 137, 0.3);
}
.btn-success:hover { background: var(--color-success-hover); }

.btn-danger {
    background: var(--color-danger);
    color: white;
}
.btn-danger:hover { background: var(--color-danger-hover); }

.btn-outline {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border-color: var(--border-color);
}
.btn-outline:hover {
    background: var(--bg-muted);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover {
    background: var(--bg-muted);
    color: var(--text-primary);
}

.btn-xs { padding: 3px 8px; font-size: 11px; }

.hidden { display: none !important; }

/* ==========================================================================
   Toolbar
   ========================================================================== */

#toolbar {
    height: var(--toolbar-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    flex-shrink: 0;
    gap: 8px;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border-color);
    margin: 0 4px;
}

/* ==========================================================================
   Main Layout
   ========================================================================== */

#main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.panel {
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Blockly Panel */
#blocklyPanel {
    flex: 1;
    min-width: 300px;
    position: relative;
}

#blocklyDiv {
    position: absolute;
    inset: 0;
}

/* ==========================================================================
   Welcome Modal Overlay (floating, reopenable)
   ========================================================================== */

.welcome-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(6px);
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.welcome-modal-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.welcome-card {
    position: relative;
    background: var(--bg-surface);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 8px 20px rgba(0, 0, 0, 0.1);
    padding: 32px 36px;
    max-width: 540px;
    width: 92%;
    max-height: 90vh;
    overflow-y: auto;
    animation: welcomeFadeIn 0.4s ease-out;
}

/* Close Button - top-right corner */
.welcome-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 30px;
    height: 30px;
    border: none;
    background: var(--bg-muted);
    color: var(--text-secondary);
    font-size: 20px;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    z-index: 1;
}

.welcome-close:hover {
    background: var(--color-danger);
    color: white;
    transform: scale(1.1);
}

@keyframes welcomeFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.welcome-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
}

.welcome-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.2;
}

.welcome-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 2px 0 0;
}

/* Architecture Diagram */
.welcome-arch {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 20px;
    padding: 16px 12px;
    background: var(--bg-muted);
    border-radius: var(--border-radius);
}

.arch-core {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 16px;
    border-radius: var(--border-radius-sm);
    flex: 1;
    text-align: center;
}

.arch-cm33 {
    background: #e3d6ff;
    border: 1px solid #c4b0f0;
}

.arch-cm55 {
    background: #d1fae5;
    border: 1px solid #a3e4c5;
}

.arch-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

.arch-desc {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-top: 2px;
}

.arch-detail {
    font-size: 9px;
    color: var(--text-tertiary);
    margin-top: 3px;
}

.arch-ipc {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 0 6px;
    flex-shrink: 0;
}

.arch-ipc span {
    font-size: 8px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* Feature Cards */
.welcome-features {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.feature-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.feature-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-sm);
}

.feature-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feature-sensors .feature-icon { background: #e0f2fe; color: #0284c7; }
.feature-connectivity .feature-icon { background: #e8dcff; color: #7c3aed; }
.feature-security .feature-icon { background: #fce4de; color: #e9292a; }
.feature-display .feature-icon { background: #fef3c7; color: #d97706; }

.feature-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.feature-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

.feature-desc {
    font-size: 9px;
    color: var(--text-tertiary);
    line-height: 1.4;
    margin-top: 2px;
}

/* Quick Start */
.welcome-quickstart {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.quickstart-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
}

.quickstart-btn {
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 500;
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid var(--tesa-primary);
    background: var(--tesa-primary-subtle);
    color: var(--tesa-primary);
    cursor: pointer;
    transition: all var(--transition);
}

.quickstart-btn:hover {
    background: var(--tesa-primary);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.welcome-footer {
    text-align: center;
    font-size: 11px;
    color: var(--text-tertiary);
    margin: 0;
}

/* Quick Links */
.welcome-links {
    margin-bottom: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.welcome-links-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.welcome-links-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.welcome-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    transition: all var(--transition);
}

.welcome-link:hover {
    background: var(--tesa-primary-subtle);
    border-color: var(--tesa-primary);
    color: var(--tesa-primary);
    box-shadow: var(--shadow-sm);
}

.welcome-link svg {
    flex-shrink: 0;
    color: var(--text-tertiary);
    transition: color var(--transition);
}

.welcome-link:hover svg {
    color: var(--tesa-primary);
}

/* Status Bar Divider */
.status-divider {
    opacity: 0.3;
    margin: 0 2px;
}

/* Resize Handle */
.resize-handle {
    width: 5px;
    background: var(--border-color);
    cursor: col-resize;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

.resize-handle:hover,
.resize-handle.active {
    background: var(--tesa-primary);
}

.resize-dots {
    width: 3px;
    height: 20px;
    background: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent 2px,
        rgba(255,255,255,0.4) 2px,
        rgba(255,255,255,0.4) 4px
    );
    opacity: 0;
    transition: opacity var(--transition);
}

.resize-handle:hover .resize-dots,
.resize-handle.active .resize-dots {
    opacity: 1;
}

/* Vertical Resize Handle (between code and terminal) */
.v-resize-handle {
    height: 5px;
    background: var(--border-color);
    cursor: row-resize;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

.v-resize-handle:hover,
.v-resize-handle.active {
    background: var(--tesa-primary);
}

.v-resize-handle::after {
    content: '';
    width: 24px;
    height: 3px;
    background: repeating-linear-gradient(
        to right,
        transparent,
        transparent 2px,
        rgba(255,255,255,0.4) 2px,
        rgba(255,255,255,0.4) 4px
    );
    opacity: 0;
    transition: opacity var(--transition);
}

.v-resize-handle:hover::after,
.v-resize-handle.active::after {
    opacity: 1;
}

/* Right Panel */
#rightPanel {
    width: 420px;
    min-width: 280px;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
}

/* ==========================================================================
   Code Panel
   ========================================================================== */

.code-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    height: 34px;
    background: var(--bg-muted);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.panel-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.panel-badge {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-tertiary);
    background: var(--bg-surface);
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.code-output {
    flex: 1;
    margin: 0;
    padding: 16px;
    background: var(--bg-code);
    color: var(--text-code);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    overflow: auto;
    tab-size: 4;
    white-space: pre;
}

.code-output code {
    display: block;
}

/* Syntax Highlighting (VS Code Dark+ inspired) */
.code-output .hl-keyword { color: #c586c0; }
.code-output .hl-string { color: #ce9178; }
.code-output .hl-number { color: #b5cea8; }
.code-output .hl-comment { color: #6a9955; font-style: italic; }
.code-output .hl-builtin { color: #4ec9b0; }
.code-output .hl-module { color: #9cdcfe; }

/* ==========================================================================
   Terminal Panel
   ========================================================================== */

.terminal-panel {
    height: 220px;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border-color);
}

.terminal-header {
    background: #16162a;
    border-bottom: 1px solid #2d2d4a;
}

.terminal-header .panel-title {
    color: #a0a0c0;
}

.terminal-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.terminal-info {
    font-size: 10px;
    color: #666;
    font-family: var(--font-mono);
}

.terminal-output {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-terminal);
    color: #c0c0e0;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.terminal-output .line-ok { color: var(--color-success); }
.terminal-output .line-error { color: var(--color-danger); }
.terminal-output .line-info { color: var(--color-info); }
.terminal-output .line-prompt { color: #dcdcaa; }

.terminal-input-row {
    display: flex;
    align-items: center;
    padding: 6px 14px;
    background: #16162a;
    border-top: 1px solid #2d2d4a;
    flex-shrink: 0;
}

.prompt {
    color: var(--tesa-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    margin-right: 8px;
    user-select: none;
}

.terminal-input {
    flex: 1;
    background: transparent;
    border: none;
    color: #e0e0f0;
    font-family: var(--font-mono);
    font-size: 12px;
    outline: none;
}

.terminal-input::placeholder {
    color: #4a4a6a;
}

/* ==========================================================================
   Status Bar
   ========================================================================== */

#statusBar {
    height: var(--statusbar-height);
    background: var(--tesa-primary);
    color: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    font-size: 11px;
    font-weight: 500;
    flex-shrink: 0;
}

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

.status-item {
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0.85;
}

/* ==========================================================================
   Blockly Theme Overrides
   ========================================================================== */

.blocklyToolboxDiv {
    background: var(--bg-surface) !important;
    border-right: 1px solid var(--border-color) !important;
    padding: 6px 0 !important;
}

.blocklyTreeRow {
    padding: 4px 12px !important;
    margin: 1px 4px !important;
    border-radius: var(--border-radius-sm) !important;
    transition: background 0.15s ease !important;
    height: auto !important;
    line-height: 1.4 !important;
}

.blocklyTreeRow:hover {
    background-color: var(--bg-muted) !important;
}

.blocklyTreeSelected {
    background-color: var(--tesa-primary-subtle) !important;
}

.blocklyTreeSelected .blocklyTreeLabel {
    color: var(--tesa-primary) !important;
    font-weight: 600 !important;
}

/* Toolbox Category Labels - multi-layered override for Blockly's injected CSS
   Blockly injects <style> with .blocklyTreeLabel { font-size:16px; font-family:sans-serif }
   We use higher specificity selectors + !important + JS inline style backup (see app.js) */
.blocklyToolboxDiv .blocklyToolboxCategory .blocklyTreeRow .blocklyTreeLabel,
.blocklyToolboxDiv .blocklyTreeRow .blocklyTreeLabel,
.blocklyToolboxDiv span.blocklyTreeLabel,
div.blocklyToolboxDiv .blocklyTreeLabel,
.blocklyTreeLabel {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    letter-spacing: 0.02em !important;
    color: var(--text-primary) !important;
}

/* Override any Blockly span/text inside tree labels */
.blocklyToolboxDiv .blocklyTreeRow span {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    font-size: 13px !important;
    font-weight: 500 !important;
}

/* Flyout label text (CM33_NS / CM55 group headers) */
.blocklyFlyoutLabelText {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    fill: var(--text-tertiary) !important;
    letter-spacing: 0.08em !important;
    text-transform: uppercase;
    transform: translateX(20px);
}

/* Toolbox container spacing */
.blocklyToolboxContents {
    padding: 4px 0 !important;
}

/* Category icon dot size */
.blocklyTreeIcon {
    margin-right: 4px !important;
}

/* Hover state text color */
.blocklyTreeRow:hover .blocklyTreeLabel {
    color: var(--text-primary) !important;
}

.blocklyTreeSeparator {
    border-bottom: 1px solid var(--border-color) !important;
    margin: 6px 12px !important;
}

.blocklyFlyoutBackground {
    fill: var(--bg-muted) !important;
    fill-opacity: 0.98 !important;
}

.blocklyScrollbarHandle {
    rx: 4 !important;
    ry: 4 !important;
    fill: var(--text-tertiary) !important;
    opacity: 0.25 !important;
}

.blocklyScrollbarHandle:hover {
    opacity: 0.45 !important;
}

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

.blocklySelected > .blocklyPath {
    stroke: var(--tesa-primary) !important;
    stroke-width: 2.5px !important;
}

.blocklyTrash {
    opacity: 0.4 !important;
    transition: opacity 0.2s !important;
}

.blocklyTrash:hover {
    opacity: 0.8 !important;
}

.blocklyTreeIcon {
    margin-right: 2px !important;
}

/* ==========================================================================
   Scrollbar Styling
   ========================================================================== */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

.terminal-output::-webkit-scrollbar-thumb,
.code-output::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
}

.terminal-output::-webkit-scrollbar-thumb:hover,
.code-output::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   Help Panel (API Reference Slide-out)
   ========================================================================== */

.help-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.help-overlay.open {
    opacity: 1;
    visibility: visible;
}

.help-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 520px;
    min-width: 380px;
    max-width: 700px;
    height: 100vh;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.help-resize-handle {
    position: absolute;
    left: -3px;
    top: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 10;
    background: transparent;
    transition: background 0.2s ease;
}

.help-resize-handle:hover,
.help-resize-handle.active {
    background: var(--tesa-primary);
    opacity: 0.5;
}

.help-panel.open {
    transform: translateX(0);
}

.help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.help-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.help-close {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--bg-muted);
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.help-close:hover {
    background: var(--color-danger);
    color: white;
}

.help-search {
    padding: 10px 18px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.help-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-family: var(--font-sans);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
    background: var(--bg-muted);
    color: var(--text-primary);
}

.help-search input:focus {
    border-color: var(--tesa-primary);
    box-shadow: 0 0 0 3px rgba(114, 57, 234, 0.1);
}

.help-search input::placeholder {
    color: var(--text-tertiary);
}

.help-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px 18px;
}

/* Module Section */
.help-module {
    margin-bottom: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    overflow: hidden;
}

.help-module-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg-muted);
    cursor: pointer;
    user-select: none;
    transition: background var(--transition);
}

.help-module-chevron {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.help-module-chevron::before {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    border-right: 2px solid var(--text-tertiary);
    border-bottom: 2px solid var(--text-tertiary);
    transform: rotate(-45deg);
    transition: transform 0.2s ease;
}

.help-module.collapsed .help-module-chevron::before {
    transform: rotate(45deg);
}

.help-module-name {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.help-module-header:hover {
    background: var(--tesa-primary-subtle);
}

.help-import {
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--tesa-primary);
    background: rgba(114, 57, 234, 0.08);
    padding: 2px 8px;
    border-radius: 4px;
}

.help-module-body {
    padding: 10px 14px;
}

.help-module.collapsed .help-module-body {
    display: none;
}

.help-module-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 0 0 12px;
    line-height: 1.5;
}

/* Function Entry */
.help-fn-entry {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.help-fn-entry:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.help-fn-sig {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.help-fn-sig code {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--tesa-primary);
}

.help-fn-returns {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--color-success);
    background: rgba(80, 205, 137, 0.1);
    padding: 1px 6px;
    border-radius: 3px;
}

.help-fn-params {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.help-fn-desc {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.help-example {
    margin: 6px 0 0;
    padding: 8px 10px;
    background: var(--bg-code);
    border-radius: 4px;
    overflow-x: auto;
}

.help-example code {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-code);
    line-height: 1.5;
    white-space: pre;
}

/* Submodule */
.help-submodule-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 10px 0 6px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

.help-fn-compact {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
    padding: 4px 0;
}

.help-fn-compact .help-fn-name {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--tesa-primary);
}

.help-fn-compact .help-fn-desc {
    font-size: 11px;
    flex: 1;
    min-width: 120px;
}

/* Constants */
.help-constants {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.help-constants code {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-secondary);
    background: var(--bg-muted);
    padding: 2px 6px;
    border-radius: 3px;
}

/* Empty state */
.help-empty {
    text-align: center;
    padding: 40px 20px;
    font-size: 13px;
    color: var(--text-tertiary);
}

/* ==========================================================================
   Notification Toast
   ========================================================================== */

.notification-toast {
    position: fixed;
    bottom: 40px;
    right: 20px;
    padding: 10px 20px;
    border-radius: var(--border-radius-sm);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    z-index: 10000;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.notification-toast.show {
    opacity: 1;
    transform: translateY(0);
}

.notification-success { background: var(--color-success); }
.notification-error { background: var(--color-danger); }
.notification-info { background: var(--color-info); }

/* ==========================================================================
   Example Explorer Overlay
   ========================================================================== */

.examples-overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.examples-overlay.hidden {
    display: none;
}

.examples-container {
    background: var(--bg-surface);
    border-radius: 16px;
    max-width: 900px;
    width: 95%;
    max-height: 90vh;
    box-shadow: var(--shadow-lg), 0 0 40px rgba(114, 57, 234, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: welcomeCardIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.examples-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.examples-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.examples-count {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-tertiary);
    background: var(--bg-muted);
    padding: 2px 8px;
    border-radius: 10px;
}

/* Filters Toolbar */
.examples-toolbar {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.examples-filter-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.examples-filter-group {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

.filter-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: 2px;
}

.examples-chip {
    padding: 4px 12px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    outline: none;
}

.examples-chip:hover {
    border-color: var(--tesa-primary);
    color: var(--tesa-primary);
    background: var(--tesa-primary-subtle);
}

.examples-chip.active {
    background: var(--tesa-primary);
    color: white;
    border-color: var(--tesa-primary);
}

/* Search */
.examples-search-row {
    display: flex;
}

.examples-search-input {
    width: 100%;
    padding: 7px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-family: var(--font-sans);
    font-size: 12px;
    outline: none;
    background: var(--bg-muted);
    color: var(--text-primary);
    transition: border-color var(--transition);
}

.examples-search-input:focus {
    border-color: var(--tesa-primary);
    box-shadow: 0 0 0 3px rgba(114, 57, 234, 0.1);
}

.examples-search-input::placeholder {
    color: var(--text-tertiary);
}

/* Card Grid */
.examples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

/* Example Card */
.example-card {
    padding: 14px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    cursor: pointer;
    transition: all 0.2s ease;
}

.example-card:hover {
    border-color: var(--tesa-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.example-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.example-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 4px;
    line-height: 1.3;
}

.example-card-desc {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0 0 10px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.example-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.example-card-tags {
    font-size: 10px;
    color: var(--text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Difficulty Badges */
.difficulty-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.difficulty-beginner {
    background: #ecfdf5;
    color: #065f46;
}

.difficulty-intermediate {
    background: #e0f2fe;
    color: #075985;
}

.difficulty-advanced {
    background: #fef2f2;
    color: #991b1b;
}

/* Domain Label */
.domain-label {
    font-size: 10px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* Domain Icon */
.domain-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 14px;
    flex-shrink: 0;
}

/* Empty state */
.examples-empty {
    text-align: center;
    padding: 60px 20px;
    font-size: 13px;
    color: var(--text-tertiary);
    grid-column: 1 / -1;
}

/* ==========================================================================
   Example Preview Modal
   ========================================================================== */

.example-preview {
    position: fixed;
    inset: 0;
    z-index: 950;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.example-preview.hidden {
    display: none;
}

.preview-card {
    background: var(--bg-surface);
    border-radius: 16px;
    max-width: 800px;
    width: 92%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: welcomeCardIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.preview-meta {
    flex: 1;
    min-width: 0;
}

.preview-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 4px;
}

.preview-description {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 0 0 8px;
    line-height: 1.5;
}

.preview-badges {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Preview Tabs */
.preview-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.preview-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
}

.preview-tab:hover {
    color: var(--text-primary);
}

.preview-tab.active {
    color: var(--tesa-primary);
    border-bottom-color: var(--tesa-primary);
}

/* Preview Content */
.preview-content {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-height: 300px;
}

.preview-blocks-container {
    width: 100%;
    height: 100%;
    position: absolute;
    inset: 0;
}

#previewBlocklyDiv {
    width: 100%;
    height: 100%;
}

.preview-code-container {
    position: absolute;
    inset: 0;
    background: var(--bg-code);
    color: var(--text-code);
    overflow: auto;
    padding: 0;
}

.preview-code-container pre {
    margin: 0;
    padding: 16px;
    padding-top: 40px;
}

.preview-code-container code {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    white-space: pre;
}

.btn-copy-code {
    position: absolute;
    top: 8px;
    right: 12px;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.6);
    font-family: var(--font-sans);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-copy-code:hover {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.9);
    border-color: rgba(255, 255, 255, 0.3);
}

/* Preview Actions */
.preview-actions {
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 768px) {
    .header-center { display: none; }
    .logo-subtitle { display: none; }
    #rightPanel { width: 320px; min-width: 250px; }
    .terminal-panel { height: 180px; }

    .examples-container { width: 98%; max-height: 95vh; }
    .examples-grid { grid-template-columns: 1fr; }
    .examples-filter-row { flex-direction: column; gap: 8px; }
    .preview-card { width: 98%; max-height: 90vh; }
}
