/* ============================================
   SQL Visualizer - Modern Stylish Theme
   ============================================ */

:root {
    /* Colors - Modern Theme */
    --bg-primary: #fafbfc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f2f5;
    --bg-card-hover: #f0f2f5;
    --bg-glass: rgba(255, 255, 255, 0.7);

    --text-primary: #1a1d23;
    --text-secondary: #4a5568;
    --text-tertiary: #718096;
    --text-muted: #0e0e0e;

    --border-color: #e2e8f0;
    --border-hover: #cbd5e0;
    --border-glass: rgba(255, 255, 255, 0.3);

    --accent-primary: #3b82f6;
    --accent-secondary: #10b981;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-error: #ef4444;
    --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.15);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.3);

    --step-from: #E6B84D;
    --step-where: #D4706E;
    --step-group: #911eb4;
    --step-having: #f032e6;
    --step-select: #3cb44b;
    --step-window: #000075;
    --step-order: #2DBDB8;
    --step-limit: #008080;
    --step-join: #f97316;
    --step-result: #8AB86A;
    --step-cte: #9a6324;
    --step-create: #808000;
    --step-insert: #ffe119;
    --step-update: #808080;
    --step-delete: #e6194b;
    
    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    
    /* Radius */
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
    
    /* Font */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    
    /* Font sizes — scaled up ~20% so the UI reads well at 100% zoom */
    --text-xs: 13px;
    --text-sm: 15px;
    --text-base: 16px;
    --text-lg: 19px;
    --text-xl: 22px;
    
    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

body {
    font-family: var(--font-sans);
    font-size: 16px;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Prevent double-tap-to-zoom on mobile */
    touch-action: manipulation;
}

/* ── Mobile: prevent auto-zoom on input focus ─────────────────────────── */
/* iOS Safari auto-zooms when an input/textarea has font-size < 16px.
   Setting 16px on all inputs prevents this. Monaco editor also needs
   16px (handled in app.js via the fontSize option). */
@media (max-width: 768px) {
    input, textarea, select {
        font-size: 16px !important;
    }
    /* Monaco editor: ensure the textarea inside it also uses 16px */
    .monaco-editor .inputarea {
        font-size: 16px !important;
    }
    /* Prevent text selection callouts from appearing on long press */
    .sql-editor, .monaco-editor {
        -webkit-touch-callout: none;
        -webkit-user-select: text;
        user-select: text;
    }
    /* Allow normal panning on the editor area but disable pinch-zoom */
    .editor-container {
        touch-action: pan-x pan-y;
    }
}

/* ============================================
   Page Layout
   ============================================ */
.sql-page {
    background: linear-gradient(135deg, #f5f7fa 0%, #e4e8ec 100%);
    flex-direction: column;
    height: 100dvh;
    display: flex;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
}

/* Ambient background glow */
.sql-page::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at center, rgba(59, 130, 246, 0.03) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
    animation: ambientFloat 20s ease-in-out infinite;
}

@keyframes ambientFloat {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(2%, 1%) rotate(1deg); }
    66% { transform: translate(-1%, 2%) rotate(-1deg); }
}

/* ============================================
   Toolbar / Header
   ============================================ */
/* ── Codesor Logo ───────────────────────────────────────────────────── */
.codesor-logo {
    height: 70px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(59, 130, 246, 0.15));
    transition: transform var(--transition-bounce);
    display: block;
}

.codesor-logo:hover {
    transform: scale(1.05);
}

/* ── Welcome Banner ─────────────────────────────────────────────────── */
.welcome-banner {
    flex-shrink: 0;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 50%, #dbeafe 100%);
    border-bottom: 1px solid rgba(59, 130, 246, 0.2);
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
    max-height: 144px;
    position: relative;
    z-index: 9;
}

.welcome-banner.collapsed {
    max-height: 44px;
}

.welcome-banner-content {
    padding: 10px var(--space-xl);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.welcome-banner-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.welcome-banner-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #1e40af;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.welcome-banner-toggle {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.7);
    color: #1e40af;
    cursor: pointer;
    transition: all 0.2s ease;
}

.welcome-banner-toggle:hover {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.5);
}

.welcome-banner-toggle svg {
    transition: transform 0.3s ease;
}

.welcome-banner.collapsed .welcome-banner-toggle svg {
    transform: rotate(180deg);
}

.welcome-banner-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: opacity 0.3s ease, max-height 0.4s ease;
    max-height: 100px;
    overflow: hidden;
}

.welcome-banner.collapsed .welcome-banner-body {
    opacity: 0;
    max-height: 0;
}

.welcome-banner-text {
    margin: 0;
    font-size: 15px;
    line-height: 1.5;
    color: #3730a3;
    min-height: 22px;
}

.welcome-banner-text strong {
    color: #1e3a8a;
    font-weight: 600;
}

/* Typewriter cursor */
.typewriter-cursor {
    display: inline-block;
    width: 2px;
    height: 15px;
    background: #1e40af;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: typewriterBlink 0.8s steps(2) infinite;
}

@keyframes typewriterBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.playground-toolbar {
    padding: 6px var(--space-xl);
    border-bottom: 1px solid var(--border-color);
    background: #032f62;
    flex-shrink: 0;
    justify-content: space-between;
    align-items: center;
    min-height: 82px;
    display: flex;
    position: relative;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

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

.logo-icon {
    color: var(--accent-primary);
    filter: drop-shadow(0 2px 4px rgba(59, 130, 246, 0.3));
    transition: transform var(--transition-bounce);
}

.logo-icon:hover {
    transform: scale(1.1) rotate(-5deg);
}

.playground-title {
    font-size: var(--text-lg);
    color: var(--text-primary);
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #1a1d23 0%, #4a5568 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.trace-step-info {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    font-family: var(--font-mono);
}

/* ── Contact Us Link Button ─────────────────────────────────────────── */
.toolbar-link-btn {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    background: transparent;
    color: var(--text-secondary);
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
}

.toolbar-link-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(59, 130, 246, 0.05);
}

/* ── User Profile Dropdown ──────────────────────────────────────────── */
.user-profile-dropdown {
    position: relative;
}

.user-profile-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1.5px solid var(--border-color);
    border-radius: 24px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.user-profile-btn:hover {
    border-color: var(--accent-primary);
    background: rgba(59, 130, 246, 0.05);
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
    padding: 8px;
    display: none;
    z-index: 10001;
}

.user-dropdown-menu.show {
    display: block;
    animation: dropdownFade 0.2s ease;
}

@keyframes dropdownFade {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
}

.dropdown-item:hover {
    background: var(--bg-tertiary);
}

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

.dropdown-logout {
    color: #ef4444;
}

.dropdown-logout:hover {
    background: rgba(239, 68, 68, 0.08);
}

/* ── Pricing Button ─────────────────────────────────────────────────── */
.pricing-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.25, 0.1, 0.25, 1);
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
    white-space: nowrap;
}

.pricing-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
    background: linear-gradient(135deg, #d97706 0%, #dc2626 100%);
}

/* ── Pricing Modal ──────────────────────────────────────────────────── */
.pricing-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    pointer-events: none;
    transition: background 0.4s ease, backdrop-filter 0.4s ease;
}

.pricing-modal-overlay.active {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    pointer-events: auto;
}

.pricing-modal {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 16px;
    padding: 28px 32px;
    width: 95%;
    max-width: 1000px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    transform: scale(0.9);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.3);
}

.pricing-modal-overlay.active .pricing-modal {
    transform: scale(1);
    opacity: 1;
}

.pricing-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: #94a3b8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.pricing-modal-close svg {
    width: 18px;
    height: 18px;
}

.pricing-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #f8fafc;
}

.pricing-modal-header {
    text-align: center;
    margin-bottom: 24px;
}

.pricing-modal-header h2 {
    margin: 0 0 6px;
    font-size: 26px;
    font-weight: 800;
    color: #f8fafc;
}

.pricing-modal-header p {
    margin: 0;
    color: #94a3b8;
    font-size: 15px;
}

.pricing-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
}

.pricing-card {
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, border-color 0.2s ease;
    position: relative;
}

.pricing-card:hover {
    transform: translateY(-5px);
    border-color: #38bdf8;
}

.pricing-card.featured {
    border: 2px solid #38bdf8;
}

.plan-badge {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: #38bdf8;
    color: #0f172a;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
    white-space: nowrap;
}

.plan-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 12px;
}

.plan-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin-bottom: 10px;
    background: #1e293b;
    border: 2px solid #334155;
}

.featured .plan-icon {
    border-color: #38bdf8;
}

.plan-title {
    margin: 0;
    font-size: 19px;
    font-weight: 700;
    color: #f8fafc;
    text-transform: capitalize;
}

.plan-price {
    font-size: 32px;
    font-weight: 800;
    color: #38bdf8;
    text-align: center;
    margin-bottom: 12px;
}

.plan-period {
    font-size: 14px;
    color: #94a3b8;
    font-weight: 400;
}

.plan-features {
    list-style: none;
    padding: 0;
    margin: 0 0 18px 0;
    flex-grow: 1;
}

.plan-features li {
    padding: 6px 0;
    border-bottom: 1px solid #334155;
    color: #94a3b8;
    font-size: 13px;
    line-height: 1.4;
    display: flex;
    align-items: flex-start;
}

.plan-features li::before {
    content: "\2713";
    color: #38bdf8;
    font-weight: bold;
    margin-right: 8px;
    flex-shrink: 0;
}

.plan-features li:last-child {
    border-bottom: none;
}

.plan-btn {
    display: block;
    width: 100%;
    padding: 10px;
    background: #38bdf8;
    color: #0f172a;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-family: inherit;
    transition: background 0.2s ease;
}

.plan-btn:hover {
    background: #0284c7;
    color: #f8fafc;
}

@media (max-width: 768px) {
    .pricing-grid {
        grid-template-columns: 1fr;
    }
}

/* ── Auth Button (Signup / Login) ───────────────────────────────────── */
.auth-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.25, 0.1, 0.25, 1);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
    white-space: nowrap;
}

.auth-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    background: linear-gradient(135deg, #2563eb 0%, #4f46e5 100%);
}

.auth-btn:active {
    transform: translateY(0);
}

.auth-btn svg {
    flex-shrink: 0;
}

/* ── Auth Modal ─────────────────────────────────────────────────────── */
.auth-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    pointer-events: none;
    transition: background 0.4s ease, backdrop-filter 0.4s ease;
}

.auth-modal-overlay.active {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: auto;
}

.auth-modal {
    background: white;
    border-radius: 16px;
    padding: 40px 36px;
    width: 90%;
    max-width: 420px;
    position: relative;
    transform: translateX(100vw) scale(0.9);
    opacity: 0;
    transition: transform 0.45s cubic-bezier(0.25, 0.1, 0.25, 1), opacity 0.35s ease;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.auth-modal-overlay.active .auth-modal {
    transform: translateX(0) scale(1);
    opacity: 1;
}

.auth-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.auth-modal-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

.auth-modal-content {
    text-align: center;
}

.auth-modal-title {
    margin: 0 0 16px 0;
    font-size: 22px;
    font-weight: 700;
    color: #1a1a2e;
    line-height: 1.3;
    letter-spacing: -0.02em;
}

.auth-modal-disclaimer {
    margin: 0 0 28px 0;
    font-size: 13px;
    color: #6b7280;
    line-height: 1.5;
}

.auth-link {
    color: #3b82f6;
    text-decoration: underline;
    font-weight: 500;
}

.auth-link:hover {
    color: #2563eb;
}

.auth-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-provider-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.auth-provider-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.auth-provider-google {
    background: #1f1f1f;
    color: white;
}

.auth-provider-google:hover {
    background: #2a2a2a;
}

.auth-provider-apple {
    background: #f5f5f5;
    color: #1a1a1a;
}

.auth-provider-apple:hover {
    background: #ebebeb;
}

.auth-divider {
    display: flex;
    align-items: center;
    margin: 24px 0 20px 0;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e5e7eb;
}

.auth-divider-text {
    padding: 0 16px;
    font-size: 13px;
    color: #9ca3af;
    font-weight: 500;
}

.auth-email-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-email-input {
    width: 100%;
    padding: 14px 16px;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.auth-email-input:focus {
    border-color: #3b82f6;
}

.auth-provider-email {
    background: #f9fafb;
    color: #6b7280;
    border: 1.5px solid #e5e7eb;
}

.auth-provider-email:hover {
    background: #f3f4f6;
    color: #4b5563;
}

.auth-footer {
    margin-top: 24px;
    font-size: 13px;
}

.auth-close-link {
    margin-top: 16px;
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    padding: 8px;
    transition: color 0.2s ease;
}

.auth-close-link:hover {
    color: #6b7280;
}

/* ── Auth Button (logged-in state) ──────────────────────────────────── */
.auth-btn.logged-in {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.auth-btn.logged-in:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

/* ============================================
   SQL Body (Grid Layout)
   ============================================ */
.sql-body {
    grid-template-columns: var(--left-width, 280px) 6px 1fr;
    flex: 1;
    display: grid;
    position: relative;
    overflow: visible;
}

/* ============================================
   Left Panel
   ============================================ */
.sql-left-panel {
    flex-direction: column;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-glass);
    overflow-y: auto;
    display: flex;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.05);
}

/* Panel Tabs */
.panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: rgba(245, 247, 250, 0.5);
}

.panel-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    border: none;
    background: transparent;
}

.panel-tab::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) scaleX(0);
    width: 60%;
    height: 2px;
    background: var(--accent-primary);
    border-radius: 2px 2px 0 0;
    transition: transform var(--transition-base);
}

.panel-tab:hover {
    color: var(--text-primary);
    background: rgba(59, 130, 246, 0.05);
}

.panel-tab:hover::after {
    transform: translateX(-50%) scaleX(0.7);
}

.panel-tab.active {
    color: var(--accent-primary);
    font-weight: 600;
}

.panel-tab.active::after {
    transform: translateX(-50%) scaleX(1);
}
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.panel-tab:hover {
    background: var(--bg-tertiary);
}

.panel-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

/* Example Queries */
.example-queries {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
}

.section-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-sm);
}

.query-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    padding: 5px 10px;
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.chip:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

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

/* Question Card */
.question-card {
    margin-top: var(--space-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    overflow: hidden;
}

.question-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.question-card-header:hover {
    background: var(--bg-tertiary);
}

.question-card-number {
    font-weight: 700;
    color: var(--text-primary);
    font-size: var(--text-sm);
}

.question-card-title {
    font-weight: 700;
    color: var(--text-primary);
    font-size: var(--text-sm);
    flex: 1;
}

.question-card-arrow {
    color: var(--text-muted);
    transition: transform var(--transition-fast);
}

.question-card.expanded .question-card-arrow {
    transform: rotate(180deg);
}

.question-card-body {
    display: none;
    padding: 0 12px 12px 12px;
    border-top: 1px solid var(--border-color);
}

.question-card.expanded .question-card-body {
    display: block;
}

.question-card-description {
    margin: 10px 0;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.5;
}

.question-card-section {
    margin-top: var(--space-sm);
}

.question-card-section-title {
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--accent-primary);
    text-transform: uppercase;
    margin-bottom: 6px;
}

.question-card-table-item {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    line-height: 1.5;
}

.question-card-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    margin-top: 5px;
    flex-shrink: 0;
}

.question-card-table-name {
    font-weight: 600;
    color: var(--text-primary);
}

.question-card-table-count {
    color: var(--text-muted);
}

.question-card-table-cols {
    color: var(--text-secondary);
}

.question-card-run-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding: 8px 16px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.question-card-run-btn:hover {
    background: #2563eb;
}

/* Editor Section */
.editor-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.editor-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.editor-dots {
    display: flex;
    gap: 6px;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot.red { background: #ff5f56; }
.dot.yellow { background: #ffbd2e; }
.dot.green { background: #27c93f; }

.editor-filename {
    font-size: var(--text-xs);
    font-family: var(--font-mono);
    color: var(--text-secondary);
}

/* Language Select Dropdown */
.lang-select {
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s ease;
}

.lang-select:hover {
    border-color: var(--accent-primary);
}

.lang-select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.editor-shortcut {
    margin-left: auto;
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* Editor Run Button (inside editor-header) */
.editor-run-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 12px;
    height: 24px;
    font-size: 11px;
    font-weight: 600;
    color: white;
    background: var(--accent-primary);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.editor-run-btn:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.editor-container {
    display: flex;
    overflow: hidden;
    position: relative;
    flex: none;
}

/* Monaco editor host (replaces the old textarea + .line-numbers sidecar).
   Monaco renders its own gutter/line numbers; automaticLayout adapts to
   whatever size this host fills inside .editor-container. */
.sql-editor {
    flex: 1;
    min-width: 0;
    min-height: 100px;
    max-height: 300px;
    position: relative;
    overflow: hidden;
    background: #fafbfc;
    /* Prevent mobile auto-zoom: ensure font-size >= 16px on touch devices */
    font-size: 16px;
}

/* Fallback textarea editor (when Monaco fails to load) */
.sql-editor textarea,
.sql-editor.editing {
    font-size: 16px !important;
}

/* Editor Resize Handle */
.editor-resize-handle {
    height: 6px;
    background: var(--border-color);
    cursor: ns-resize;
    transition: background var(--transition-fast);
    position: relative;
}

.editor-resize-handle:hover {
    background: var(--accent-primary);
}

.editor-resize-handle::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 2px;
    background: var(--text-muted);
    border-radius: 1px;
}

.editor-resize-handle:hover::after {
    background: white;
}

/* Fold chevrons live in the gutter's folding margin, but the step-line arrow
   takes that spot — slide the chevrons right into the content area. The
   translate is set per-editor via --ow-fold-translate so it stays correct as
   the gutter grows (lineDecorationsWidth reserves the space to the left of
   the text, giving the chevron a clickable gap). */
.monaco-editor .cldr.codicon-folding-expanded,
.monaco-editor .cldr.codicon-folding-collapsed {
    transform: translateX(var(--ow-fold-translate, 24px));
    z-index: 5;
    /* Monaco stretches the fold icon to span the reserved decorations gutter
       (62px with lineDecorationsWidth 46) and centers the glyph in it; pin
       the icon to its real size so it neither overlaps the text nor makes
       clicks near the line start fold instead of placing the cursor. */
    width: 26px !important;
}

/* .margin has `contain: strict` — `contain: paint` would clip the relocated
   chevron (it extends past the 67px gutter box) and `contain: layout` traps
   its stacking context under the line text. Neutralizing the containment
   makes the chevron paint and receive clicks above the code. !important is
   required: monaco's own editor.main.css is linked after styles.css and wins
   the equal-specificity cascade. */
.monaco-editor .margin {
    contain: none !important;
    z-index: 3;
}

/* SQL Editor Line Indicator Arrow */
.line-indicator {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 28px; /* matches Monaco lineHeight */
    pointer-events: none;
    z-index: 10;
    transition: top 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
    display: none;
}

.line-indicator.active {
    display: block;
}

.line-indicator-arrow {
    position: absolute;
    left: 2px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 8px solid #ff9800;
    filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.3));
}

.line-indicator-bar {
    position: absolute;
    left: 12px;
    top: 0;
    right: 0;
    height: 100%;
    background: rgba(255, 152, 0, 0.08);
    border-left: 2px solid #ff9800;
    border-radius: 0 3px 3px 0;
}

/* New Database Button (in left panel below schema) */
.new-db-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px;
    margin-top: var(--space-sm);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--accent-primary);
    background: transparent;
    border: 1px dashed var(--accent-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.new-db-btn:hover {
    background: color-mix(in srgb, var(--accent-primary) 8%, transparent);
    border-style: solid;
}

/* Schema Panel */
.schema-panel {
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.schema-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: var(--space-sm) var(--space-md);
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.add-table-btn {
    margin-left: auto;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-success);
    color: white;
    border: none;
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    transition: all var(--transition-fast);
}

.add-table-btn:hover {
    background: #059669;
}

.schema-tables {
    padding: var(--space-sm);
}

/* Schema Group */
.schema-group {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-sm);
    background: var(--bg-primary);
}

.schema-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    cursor: default;
}

.schema-group-header .schema-icon {
    width: 14px;
    height: 14px;
    color: var(--accent-primary);
}

.schema-group-header .schema-name {
    flex: 1;
}

.schema-group-header .schema-table-count {
    font-size: var(--text-xs);
    font-weight: 400;
    color: var(--text-muted);
}

.schema-group-header .schema-add-btn {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-success);
    color: white;
    border: none;
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    transition: all var(--transition-fast);
}

.schema-group-header .schema-add-btn:hover {
    background: #059669;
}

.schema-group-header .schema-delete-btn {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-size: 12px;
    transition: all var(--transition-fast);
}

.schema-group-header .schema-delete-btn:hover {
    background: var(--accent-danger);
    color: white;
}

/* Schema Group Tables */
.schema-group-tables {
    padding: var(--space-xs) 0;
}

.schema-table {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px 6px 20px;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.schema-table:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.schema-table.selected {
    background: var(--accent-primary);
    color: white;
}

.schema-table .table-icon {
    width: 12px;
    height: 12px;
    color: var(--text-muted);
}

.schema-table:hover .table-icon {
    color: var(--accent-primary);
}

.schema-table.selected .table-icon {
    color: white;
}

.schema-table .schema-table-name {
    flex: 1;
}

.schema-table .row-count {
    margin-left: auto;
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.schema-table:hover .row-count {
    color: var(--accent-primary);
}

.schema-table.selected .row-count {
    color: rgba(255,255,255,0.8);
}

.schema-table .table-delete-btn {
    width: 16px;
    height: 16px;
    display: none;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-size: 10px;
    transition: all var(--transition-fast);
}

.schema-table:hover .table-delete-btn {
    display: flex;
}

.schema-table .table-delete-btn:hover {
    background: var(--accent-danger);
    color: white;
}

.schema-table .schema-dropdown-btn {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.schema-table .schema-dropdown-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Empty Schema */
.schema-empty {
    padding: 12px 20px;
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-style: italic;
}

/* SQL Hint */
.sql-hint {
    margin-top: var(--space-sm);
    padding: var(--space-sm);
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    color: var(--text-muted);
    line-height: 1.5;
}

/* Modal Sizes */
.modal-sm {
    max-width: 400px;
}

.modal-md {
    max-width: 480px;
}

/* Danger Button */
.btn-danger {
    padding: 8px 16px;
    background: var(--accent-danger);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-danger:hover {
    background: #dc2626;
}

/* Column Details Panel */
.column-details {
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.column-details-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.close-btn {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-muted);
    border: none;
    cursor: pointer;
    font-size: 16px;
    border-radius: var(--radius-xs);
    transition: all var(--transition-fast);
}

.close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.column-list {
    padding: var(--space-sm);
}

.column-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    font-size: var(--text-xs);
    border-radius: var(--radius-xs);
}

.column-item:hover {
    background: var(--bg-tertiary);
}

.column-item .col-key {
    color: var(--accent-warning);
    font-size: 10px;
}

.column-item .col-name {
    font-weight: 600;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.column-item .col-type {
    color: var(--accent-primary);
    font-family: var(--font-mono);
    margin-left: auto;
}

/* ============================================
   Resizer
   ============================================ */
.playground-resizer {
    background: var(--border-color);
    cursor: col-resize;
    z-index: 100;
    justify-content: center;
    align-items: center;
    width: 6px;
    transition: background var(--transition-fast), width var(--transition-fast);
    display: flex;
    position: relative;
}

.playground-resizer:hover {
    background: var(--accent-primary);
    width: 4px;
}

/* ============================================
   Right Panel
   ============================================ */
.sql-right-panel {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    flex-direction: column;
    display: flex;
    overflow: visible;
    min-width: 0;
}

/* ============================================
   Right Panel Tab Bar
   ============================================ */
.right-tab-bar {
    display: flex;
    align-items: stretch;
    gap: 0;
    background: rgba(249, 250, 251, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    min-height: 36px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-shrink: 0;
}

.right-tab-bar::-webkit-scrollbar {
    height: 3px;
}

.right-tab-bar::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}

.right-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-right: 1px solid var(--border-color);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
    position: relative;
    font-family: inherit;
}

.right-tab-lang-icon {
    width: 16px;
    height: 16px;
    object-fit: contain;
    flex-shrink: 0;
    border-radius: 2px;
}

.right-tab:hover {
    background: rgba(255, 255, 255, 0.8);
    color: var(--text-primary);
}

.right-tab.active {
    background: rgba(255, 255, 255, 0.95);
    color: var(--accent-primary);
    font-weight: 600;
    box-shadow: inset 0 2px 0 var(--accent-primary);
}

.right-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent-primary), #8b5cf6);
}

.right-tab-title {
    display: flex;
    align-items: center;
    gap: 6px;
}

.right-tab-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    font-size: 14px;
    line-height: 1;
    color: var(--text-tertiary);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    opacity: 0;
    transition: all var(--transition-fast);
    padding: 0;
}

.right-tab-close:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-error);
}

.right-tab:hover .right-tab-close,
.right-tab.active .right-tab-close {
    opacity: 1;
}

.right-tab-close:hover {
    background: var(--accent-error);
    color: white;
}

.right-tab-add {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    min-width: 28px;
    height: 100%;
    font-size: 16px;
    color: var(--text-tertiary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
}

.right-tab-add:hover {
    background: var(--bg-primary);
    color: var(--accent-primary);
}

.right-tab-contents {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-width: 0;
}

.right-tab-content {
    display: none;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.right-tab-content.active {
    display: flex;
}

/* Editor in right panel - constrained height */
.sql-right-panel .editor-section {
    flex: 0 0 auto;
    min-height: 80px;
}

.sql-right-panel .editor-container {
    overflow: hidden;
    position: relative;
}

/* Phase Progress Bar */
.phase-bar {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    min-width: 0;
}

.phase-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
    /* All phases stay visible: long pipelines (e.g. pandas chains with many
       steps) wrap onto additional rows instead of being cut off by a
       horizontal scrollbar. */
    flex: 1 1 auto;
}

/* Row below the phase bar showing the current sub-step pill */
.phase-sub-bar {
    display: none;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 0 var(--space-lg) var(--space-sm);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.phase-sub-bar:not(:empty) {
    display: flex;
}

.phase-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 12px;
    font-size: var(--text-xs);
    font-weight: 600;
    font-family: var(--font-mono);
    color: #fff;
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
}

.phase-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: var(--text-xs);
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--text-muted);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    --phase-color: var(--accent-primary);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.phase-item::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.4s ease, height 0.4s ease;
}

.phase-item:hover {
    border-color: var(--phase-color);
    color: var(--phase-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.phase-item:hover::before {
    width: 200%;
    height: 200%;
}

.phase-item.active {
    background: var(--phase-color);
    color: white;
    border-color: var(--phase-color);
    box-shadow: 0 4px 15px color-mix(in srgb, var(--phase-color) 40%, transparent);
    animation: phasePulse 2s ease-in-out infinite;
}

@keyframes phasePulse {
    0%, 100% { box-shadow: 0 4px 15px color-mix(in srgb, var(--phase-color) 40%, transparent); }
    50% { box-shadow: 0 4px 25px color-mix(in srgb, var(--phase-color) 60%, transparent); }
}

.phase-item.completed {
    background: color-mix(in srgb, var(--phase-color) 15%, transparent);
    color: var(--phase-color);
    border-color: color-mix(in srgb, var(--phase-color) 30%, transparent);
}

.phase-arrow {
    color: var(--text-secondary);
    font-size: 16px;
    font-weight: 500;
    opacity: 0.8;
}

/* Arrow bridging a row wrap inside .phase-progress: instead of a plain "›"
   pointing into thin air at the end of a row, it bends down to the first
   item of the next row so the phase flow reads continuously. */
.phase-arrow-wrap {
    font-family: 'Segoe UI Symbol', 'Segoe UI', 'DejaVu Sans', sans-serif;
    font-size: 18px;
    opacity: 1;
    color: var(--text-secondary);
}

/* Playback Bar */
.playback-bar {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-lg);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.playback-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.control-btn:hover {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border-color: transparent;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.control-btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

.control-btn.play-btn {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border: none;
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}

.control-btn.play-btn:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

.control-btn.play-btn:active {
    transform: scale(1.05);
}

/* Pulse animation for play button */
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5); }
    70% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); }
    100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}

.control-btn.play-btn {
    animation: pulse 2s infinite;
}

.phase-counter {
    font-size: var(--text-xs);
    font-family: var(--font-mono);
    color: var(--text-tertiary);
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.phase-progress-bar-visual {
    flex: 1;
    max-width: 180px;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    border-radius: var(--radius-full);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Schema Tables Display */
.schema-tables-display {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    flex-shrink: 0;
    margin-left: auto;
}

.schema-tables-row {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.schema-label {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    font-size: 14px;
    font-weight: 700;
    border-radius: var(--radius-sm);
    letter-spacing: 0.03em;
    flex-shrink: 0;
    text-transform: uppercase;
    box-shadow: var(--shadow-sm);
}

.schema-tables-list {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
}

.schema-table-item {
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    position: relative;
    font-weight: 500;
    font-size: 14px;
}

.schema-table-item::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 2px;
    background: currentColor;
    transform: translateX(-50%);
    transition: width var(--transition-fast);
    border-radius: 1px;
}

.schema-table-item:hover {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
}

.schema-table-item:hover::before {
    width: 80%;
}

/* Schema color variants with gradients */
.schema-color-0 {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(59, 130, 246, 0.1) 100%);
    color: #3b82f6;
}

.schema-color-1 {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2) 0%, rgba(139, 92, 246, 0.1) 100%);
    color: #8b5cf6;
}

.schema-color-2 {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2) 0%, rgba(16, 185, 129, 0.1) 100%);
    color: #10b981;
}

.schema-color-3 {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(245, 158, 11, 0.1) 100%);
    color: #f59e0b;
}

.schema-color-4 {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.2) 0%, rgba(239, 68, 68, 0.1) 100%);
    color: #ef4444;
}

.schema-color-5 {
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.2) 0%, rgba(236, 72, 153, 0.1) 100%);
    color: #ec4899;
}

.schema-color-6 {
    background: linear-gradient(135deg, rgba(20, 184, 166, 0.2) 0%, rgba(20, 184, 166, 0.1) 100%);
    color: #14b8a6;
}

.schema-color-7 {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2) 0%, rgba(99, 102, 241, 0.1) 100%);
    color: #6366f1;
}

/* Schema Info Popup (kept for table data popup) */
.schema-info-popup {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    margin-right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    min-width: 220px;
    max-width: 350px;
    z-index: 1000;
    overflow: hidden;
}

.schema-info-popup::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 12px;
    transform: rotate(45deg);
    width: 10px;
    height: 10px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.schema-info-popup-header {
    padding: 8px 12px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.schema-info-popup-body {
    padding: 8px 12px;
}

.schema-info-schema-name {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.schema-info-schema-name svg {
    color: var(--accent-primary);
    flex-shrink: 0;
}

.schema-info-schema-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.schema-info-schema-item svg {
    color: var(--accent-primary);
    flex-shrink: 0;
}

.schema-info-tables-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 4px;
}

.schema-info-tables-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.schema-info-table-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    font-size: 11px;
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--accent-primary);
    background: color-mix(in srgb, var(--accent-primary) 10%, transparent);
    border-radius: 3px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.schema-info-table-tag:hover {
    background: color-mix(in srgb, var(--accent-primary) 25%, transparent);
    transform: scale(1.02);
}

.schema-info-table-tag svg {
    width: 10px;
    height: 10px;
}

.schema-info-empty {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
}

/* ============================================
   Content Area
   ============================================ */
.sql-content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: visible;
}

/* ============================================
   Step Info Panel (DevVizor Style)
   ============================================ */
.sql-step-panel {
    padding: var(--space-xs) var(--space-lg);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.step-info-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: 2px;
}

.step-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    font-size: 10px;
    font-weight: 700;
    font-family: var(--font-mono);
    color: white;
    background: var(--accent-primary);
    border-radius: var(--radius-full);
    flex-shrink: 0;
    letter-spacing: 0.03em;
}

.step-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.1;
}

.step-subtitle {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-style: italic;
}

.step-detail-row {
    display: flex;
    gap: var(--space-md);
    align-items: center;
}

.what-happening {
    flex: 1;
    min-width: 0;
}

.wh-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    font-weight: 700;
    color: var(--accent-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

.wh-summary {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.wh-summary strong {
    font-weight: 700;
}

.wh-row-count {
    color: #2ecc71;
    font-weight: 700;
}

.wh-detail {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    line-height: 1.4;
    margin: 0;
}

/* Step Stats */
.step-stats {
    display: flex;
    flex-direction: row;
    gap: var(--space-sm);
    flex-shrink: 0;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
}

.stat-value {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    color: var(--text-muted);
    font-size: 10px;
}

.text-filtered {
    color: var(--accent-error) !important;
}

.stat-filtered {
    background: color-mix(in srgb, var(--accent-error) 8%, transparent);
}

/* ============================================
   Table + Timeline Container (Side by Side)
   ============================================ */
.table-timeline-container {
    display: flex;
    flex: 1;
    min-height: 350px;
}

/* Vertical Execution Timeline */
.exec-timeline-vertical {
    width: 180px;
    min-width: 180px;
    min-height: 430px;
    max-height: 430px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.exec-timeline-vertical .exec-timeline-header {
    padding: 10px 12px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 6px;
}

.exec-timeline-vertical .exec-timeline-body {
    flex: 1;
    overflow-y: scroll;
    scrollbar-gutter: stable;
    padding: 8px;
    padding-right: 4px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
}

.exec-timeline-vertical .exec-timeline-body::-webkit-scrollbar {
    width: 12px;
}

.exec-timeline-vertical .exec-timeline-body::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-left: 1px solid #e2e8f0;
}

.exec-timeline-vertical .exec-timeline-body::-webkit-scrollbar-thumb {
    background: #64748b;
    border-radius: 6px;
    border: 2px solid #f1f5f9;
}

.exec-timeline-vertical .exec-timeline-body::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

.exec-timeline-vertical .custom-scroll-track {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    z-index: 5;
}

.exec-timeline-vertical .custom-scroll-thumb {
    position: absolute;
    right: 0;
    width: 6px;
    min-height: 20px;
    background: #94a3b8;
    border-radius: 3px;
    transition: background 0.15s;
}

.exec-timeline-vertical .custom-scroll-thumb:hover {
    background: #64748b;
}

/* ── If/elif/return chain & try/except breakdown column styles ─────────── */
.py-stage-combined-tbl th span.py-stage-th-label {
    font-size: 11px;
}

/* Condition column header styling */
.py-stage-combined-tbl th:has(span.py-stage-th-label[title]) {
    background: var(--bg-secondary);
}

/* Condition cell value badges */
.py-stage-combined-tbl td {
    font-size: 12px;
}

/* Try/except column headers */
.py-stage-combined-tbl th {
    white-space: nowrap;
}

/* Exception triggered cell styling */
.py-stage-combined-tbl td[style*="background"] {
    font-weight: 600;
}

.exec-timeline-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
}

.exec-timeline-item:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
}

.exec-timeline-item.active {
    background: color-mix(in srgb, var(--step-color, var(--accent-primary)) 8%, transparent);
    border-color: var(--step-color, var(--accent-primary));
    border-left-color: var(--step-color, var(--accent-primary));
}

.exec-timeline-item.done {
    opacity: 0.7;
}

.exec-timeline-item.recursive-cte {
    background: rgba(255, 165, 0, 0.08);
    border-left: 3px solid #f97316;
}

.exec-timeline-item.recursive-cte .exec-node {
    background: rgba(255, 165, 0, 0.15);
    color: #f97316;
    border-color: #f97316;
}

.exec-timeline-item.recursive-cte .exec-item-label {
    color: #f97316;
    font-weight: 600;
}

.exec-timeline-item.recursive-cte.active {
    background: rgba(255, 165, 0, 0.15);
    border-color: #f97316;
}

.exec-node {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    border: 1.5px solid var(--border-color);
    transition: all var(--transition-fast);
}

.exec-timeline-item.done .exec-node {
    background: color-mix(in srgb, var(--step-color, var(--accent-primary)) 15%, transparent);
    color: var(--step-color, var(--accent-primary));
    border-color: var(--step-color, var(--accent-primary));
}

.exec-timeline-item.active .exec-node {
    background: var(--step-color, var(--accent-primary));
    color: white;
    border-color: var(--step-color, var(--accent-primary));
}

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

.exec-item-label {
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.exec-timeline-item.active .exec-item-label {
    color: var(--step-color, var(--accent-primary));
}

.exec-timeline-item.done .exec-item-label {
    color: var(--text-tertiary);
}

.exec-item-stats {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.exec-stat-active {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--accent-success);
}

.exec-stat-filtered {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--accent-error);
}

/* CTE collapsible dropdown styles */
.cte-item {
    padding: 0 !important;
    flex-direction: column !important;
    align-items: stretch !important;
}

.cte-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.cte-header:hover {
    background: var(--bg-secondary);
}

.cte-arrow {
    font-size: 20px;
    color: var(--text-muted);
    width: 20px;
    flex-shrink: 0;
}

.cte-sub-steps {
    padding: 4px 8px 8px 12px;
    margin: 0;
}

.cte-sub-step {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0 3px 10px;
    position: relative;
    cursor: pointer;
}

.cte-sub-step:hover {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
}

/* Active sub-step highlight when a sub-step is selected via click */
.cte-sub-step.active {
    background: color-mix(in srgb, var(--step-color, var(--accent-primary)) 12%, transparent);
    border-radius: 4px;
    outline: 1px solid color-mix(in srgb, var(--step-color, var(--accent-primary)) 40%, transparent);
}

.cte-sub-step.active .cte-sub-label {
    color: var(--step-color, var(--accent-primary));
    font-weight: 600;
}

.cte-sub-step.active .cte-sub-dot {
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--step-color, var(--accent-primary)) 30%, transparent);
}

.cte-sub-step.has-nested {
    font-weight: 500;
}

.nested-sub-steps {
    padding-left: 20px;
    border-left: 1px dashed var(--border-color);
    margin-left: 6px;
}

.cte-sub-step::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 8px;
    height: 1px;
    background: var(--border-color);
}

.cte-sub-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cte-sub-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.cte-sub-count {
    font-size: 10px;
    color: var(--text-muted);
    margin-left: auto;
    white-space: nowrap;
}

/* ============================================
   Data Table
   ============================================ */
.sql-table-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* allow shrinking so inner horizontal scrollbars work inside the panel */
}

/* ============================================
   JOIN View - Side-by-side input tables
   ============================================ */
.join-view {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px;
}

.join-inputs {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    overflow-x: scroll; /* always-visible horizontal scrollbar */
}

.join-input-table {
    flex: 1;
    min-width: 250px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: visible;        /* changed from hidden so scrollbars inside aren't clipped */
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
}

.join-input-table .join-table-scroll {
    /* Use fixed height (not max-height) so the scroll area is always 280px
       and scrollbars always have a reason to render. */
    height: 280px;
    overflow-x: scroll !important;
    overflow-y: scroll !important;
    scrollbar-gutter: stable both-edges;
    flex: 1;
}

.join-table-label {
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    flex-shrink: 0;
}

.join-table-scroll {
    height: 280px;
    overflow-x: scroll !important;
    overflow-y: scroll !important;
    scrollbar-gutter: stable both-edges;
}

/* Expanded state - no max-height, full table visible */
.join-scroll-expanded {
    max-height: none !important;
}

/* Hidden rows in collapsed state */
.join-row-hidden {
    display: none;
}

.join-table-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}

.join-truncated {
    text-align: center;
    color: var(--text-muted);
    font-size: 11px;
    font-style: italic;
    padding: 6px !important;
}

/* Highlight ON condition columns in light orange */
.col-highlight {
    background: rgba(255, 152, 0, 0.15) !important;
}

.col-highlight .col-dot {
    box-shadow: 0 0 0 2px rgba(255, 152, 0, 0.5);
}

/* Highlight matching columns (same name in both tables) */
.col-match {
    background: rgba(33, 150, 243, 0.15) !important;
}

.col-match .col-dot {
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.5);
}

/* WHERE step styles */
.where-fail {
    background: rgba(244, 67, 54, 0.08) !important;
}

.where-strike {
    text-decoration: line-through;
    color: #999 !important;
    opacity: 0.6;
}

/* Show more/less rows button for JOIN input tables */
.join-toggle-btn {
    display: block;
    width: 100%;
    padding: 8px 12px;
    margin-top: 4px;
    border: 1px dashed var(--border-primary);
    border-radius: 0 0 6px 6px;
    background: var(--bg-secondary);
    color: var(--accent-primary);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
}

.join-toggle-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

/* ON condition label between tables */
.join-on-label {
    font-size: 11px;
    font-weight: 600;
    color: #111827;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    padding: 2px 6px;
    margin-top: 4px;
    word-break: break-word;
    white-space: normal;
    text-align: center;
}

.join-arrow {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 20px 4px 0;
    color: var(--accent-primary);
    flex-shrink: 0;
}

.join-arrow-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--accent-primary);
    white-space: nowrap;
}

.join-output {
    border: 2px solid var(--accent-primary);
    border-radius: 6px;
    overflow: visible;        /* changed from hidden so scrollbars inside aren't clipped */
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
}

.join-output-table {
    height: 280px;
    overflow-x: scroll !important;
    overflow-y: scroll !important;
    scrollbar-gutter: stable both-edges;
    flex: 1;
}

.join-output-table .sql-table,
.join-input-table .sql-table,
.union-sub-table .sql-table {
    min-width: max-content;
}

.join-output-label {
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 600;
    color: white;
    background: var(--accent-primary);
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Always-visible scrollbar styling for JOIN / UNION / WHERE tables ── */
/* Forces classic (non-overlay) scrollbars on macOS by setting explicit
   width/height on ::-webkit-scrollbar. The !important flags ensure these
   override any OS-level overlay scrollbar behavior. */
.join-table-scroll::-webkit-scrollbar,
.join-output-table::-webkit-scrollbar,
.union-sub-table .join-table-scroll::-webkit-scrollbar {
    width: 16px !important;
    height: 16px !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    background: #e2e8f0 !important;
}

.join-table-scroll::-webkit-scrollbar-track,
.join-output-table::-webkit-scrollbar-track,
.union-sub-table .join-table-scroll::-webkit-scrollbar-track {
    background: #f1f5f9 !important;
    border-left: 1px solid #cbd5e1 !important;
    border-top: 1px solid #cbd5e1 !important;
}

.join-table-scroll::-webkit-scrollbar-thumb,
.join-output-table::-webkit-scrollbar-thumb,
.union-sub-table .join-table-scroll::-webkit-scrollbar-thumb {
    background: #64748b !important;
    border-radius: 8px !important;
    border: 3px solid #f1f5f9 !important;
    min-width: 30px !important;
    min-height: 30px !important;
}

.join-table-scroll::-webkit-scrollbar-thumb:hover,
.join-output-table::-webkit-scrollbar-thumb:hover,
.union-sub-table .join-table-scroll::-webkit-scrollbar-thumb:hover {
    background: #475569 !important;
}

.join-table-scroll::-webkit-scrollbar-corner,
.join-output-table::-webkit-scrollbar-corner,
.union-sub-table .join-table-scroll::-webkit-scrollbar-corner {
    background: #f1f5f9 !important;
}

/* Firefox: force always-visible scrollbars */
.join-table-scroll,
.join-output-table,
.union-sub-table .join-table-scroll {
    scrollbar-width: auto !important;
    scrollbar-color: #64748b #f1f5f9 !important;
}

/* ── Custom JS-driven scrollbar indicators (guaranteed visible) ── */
/* These are absolutely-positioned divs added by JavaScript that overlay
   the table containers. They provide a visual scrollbar that's always
   visible, regardless of OS overlay scrollbar settings. */
.custom-scrollbar-container {
    position: relative;
}

.custom-h-scrollbar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 14px;
    background: #f1f5f9;
    border-top: 1px solid #cbd5e1;
    overflow: hidden;
    z-index: 10;
    display: none; /* shown via JS when content overflows */
}

.custom-h-scrollbar-thumb {
    position: absolute;
    top: 2px;
    height: 10px;
    background: #64748b;
    border-radius: 5px;
    cursor: pointer;
    min-width: 30px;
    transition: background 0.15s;
}

.custom-h-scrollbar-thumb:hover {
    background: #475569;
}

.custom-v-scrollbar {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    background: #f1f5f9;
    border-left: 1px solid #cbd5e1;
    overflow: hidden;
    z-index: 10;
    display: none; /* shown via JS when content overflows */
}

.custom-v-scrollbar-thumb {
    position: absolute;
    left: 2px;
    width: 10px;
    background: #64748b;
    border-radius: 5px;
    cursor: pointer;
    min-height: 30px;
    transition: background 0.15s;
}

.custom-v-scrollbar-thumb:hover {
    background: #475569;
}

.custom-scrollbar-corner {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background: #e2e8f0;
    border-top: 1px solid #cbd5e1;
    border-left: 1px solid #cbd5e1;
    z-index: 11;
    display: none;
}

/* UNION view styles */
.union-view {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px;
}

.union-inputs {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    overflow-x: scroll; /* always-visible horizontal scrollbar */
}

.union-sub-table {
    flex: 1;
    min-width: 250px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: visible;        /* changed from hidden so scrollbars inside aren't clipped */
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
}

.union-sub-table .join-table-scroll {
    height: 280px;
    overflow-x: scroll !important;
    overflow-y: scroll !important;
    scrollbar-gutter: stable both-edges;
    flex: 1;
}

.union-sub-label {
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.union-arrow {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 20px 4px 0;
    color: var(--accent-warning);
    flex-shrink: 0;
}

.union-arrow-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--accent-warning);
    white-space: nowrap;
}

.sql-table-scroll {
    flex: 1;
    /* Always-visible horizontal scrollbar so wide tables can be scrolled left/right */
    overflow-x: scroll;
    overflow-y: auto;
}

.sql-table {
    border-collapse: collapse;
    width: 100%;
    font-size: var(--text-base);
    font-family: var(--font-mono);
}

.sql-table th {
    padding: 14px 18px;
    text-align: left;
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--text-secondary);
    background: linear-gradient(180deg, rgba(249, 250, 251, 0.9) 0%, rgba(243, 244, 246, 0.9) 100%);
    border-bottom: 2px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sql-table th .col-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
}

.sql-table td {
    padding: 12px 18px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.5);
    color: var(--text-primary);
    white-space: nowrap;
    transition: background var(--transition-fast);
}

/* Python print() / scalar output rendered inside the result table.
   Specificity above .sql-table td so white-space/padding actually apply. */
.sql-table td.py-output-text {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.65;
    padding: 1rem;
    color: var(--text-primary);
    background: transparent;
}

.sql-table td.py-output-error {
    color: #ef4444;
    font-weight: 500;
}

/* Computation expression box shown above the result table for PY_COMPUTE steps */
.py-breakdown-expression {
    margin: 0 0 12px;
    padding: 14px 18px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.04) 0%, rgba(139, 92, 246, 0.04) 100%);
    border-left: 3px solid var(--step-select);
    border-radius: 0 8px 8px 0;
    font-size: var(--text-sm);
}

.py-compute-title {
    margin-bottom: 8px;
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--step-select);
}

.py-compute-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 6px;
}

.py-compute-col-label {
    color: var(--text-secondary);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.py-compute-col-name {
    font-weight: 700;
    font-size: 14px;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.py-compute-formula {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-all;
}

.py-compute-inputs {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.py-compute-badge {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--step-select);
}

/* Mini-table inside the expression box: input → computed output per row */
.py-compute-mini-table {
    margin-top: 10px;
    overflow-x: auto;
    border-radius: 6px;
    border: 1px solid rgba(226, 232, 240, 0.6);
}

.py-mini-tbl {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 11px;
}

.py-mini-tbl th {
    padding: 6px 10px;
    text-align: left;
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    background: linear-gradient(180deg, rgba(249, 250, 251, 0.95) 0%, rgba(243, 244, 246, 0.95) 100%);
    border-bottom: 1px solid var(--border-color);
}

.py-mini-tbl th:last-child {
    color: var(--step-select);
}

.py-mini-tbl td {
    padding: 5px 10px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.4);
    color: var(--text-primary);
    white-space: nowrap;
}

.py-mini-tbl td:last-child {
    font-weight: 600;
    color: var(--step-select);
}

/* Stages box - side-by-side column view */
.py-stages-side-by-side {
    margin-top: 10px;
    overflow-x: auto;
}

.py-stage-combined-tbl {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.4;
    border: 1px solid rgba(59, 130, 246, 0.15);
    border-radius: 6px;
    overflow: hidden;
}

.py-stage-combined-tbl th {
    text-align: left;
    padding: 6px 10px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.08) 0%, rgba(139, 92, 246, 0.08) 100%);
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid rgba(59, 130, 246, 0.15);
    border-right: 1px solid rgba(59, 130, 246, 0.1);
    white-space: nowrap;
    vertical-align: top;
}

.py-stage-combined-tbl th:last-child {
    border-right: none;
}

.py-stage-th-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--step-select);
    font-weight: 700;
}

.py-stage-th-expr {
    font-size: 9px;
    color: var(--text-muted);
    font-weight: 400;
    word-break: break-all;
}

.py-stage-combined-tbl td {
    padding: 4px 10px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    border-right: 1px solid rgba(0, 0, 0, 0.04);
    color: var(--text-primary);
    white-space: nowrap;
}

.py-stage-combined-tbl td:last-child {
    border-right: none;
}

.py-stage-combined-tbl tr:last-child td {
    border-bottom: none;
}

.py-stage-combined-tbl tr:hover td {
    background: rgba(59, 130, 246, 0.03);
}

/* Last column (result) gets accent highlight */
.py-stage-combined-tbl td:last-child {
    font-weight: 600;
    color: var(--step-select);
    background: rgba(59, 130, 246, 0.03);
}

/* Stage table — full rows for each intermediate step */
.py-stage-table-wrap {
    width: 100%;
    margin-top: 6px;
    overflow-x: auto;
}

.py-stage-tbl {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.4;
}

.py-stage-tbl th {
    text-align: left;
    padding: 4px 8px;
    background: rgba(59, 130, 246, 0.08);
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    white-space: nowrap;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.py-stage-tbl td {
    padding: 3px 8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    color: var(--text-primary);
    white-space: nowrap;
}

.py-stage-tbl tr:last-child td {
    border-bottom: none;
}

.py-stage-tbl tr:hover td {
    background: rgba(59, 130, 246, 0.03);
}

.sql-table tbody tr {
    transition: all var(--transition-fast);
}

.sql-table tbody tr:hover {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.05) 0%, transparent 100%);
}

.sql-table tbody tr:hover td {
    background: transparent;
}

.sql-table .col-num {
    color: var(--text-muted);
    font-size: var(--text-xs);
    width: 40px;
    font-weight: 500;
}

.sql-table .col-id {
    font-weight: 600;
    color: var(--text-primary);
}

.sql-table-footer {
    background: linear-gradient(180deg, rgba(243, 244, 246, 0.9) 0%, rgba(249, 250, 251, 0.9) 100%);
    border-top: 1px solid var(--border-color);
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    display: flex;
    flex-shrink: 0;
}

.table-stat {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.table-stat strong {
    color: var(--text-primary);
}

/* ============================================
   Modals
   ============================================ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: overlayFadeIn 0.3s ease;
}

@keyframes overlayFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255, 255, 255, 0.5) inset;
    width: 400px;
    max-width: 90vw;
    animation: modalSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-lg {
    width: 500px;
}

.modal-xl {
    width: 700px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-xl);
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(180deg, rgba(249, 250, 251, 0.8) 0%, rgba(255, 255, 255, 0) 100%);
}

.modal-header h3 {
    font-size: var(--text-xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #1a1d23 0%, #4a5568 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-body {
    padding: var(--space-xl);
}

.modal-body label {
    display: block;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
    margin-top: var(--space-md);
}

.modal-body label:first-child {
    margin-top: 0;
}

.modal-input,
.modal-textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: var(--text-sm);
    font-family: var(--font-mono);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition-fast);
}

.modal-input:focus,
.modal-textarea:focus {
    border-color: var(--accent-primary);
}

.modal-textarea {
    min-height: 100px;
    resize: vertical;
}

.modal-divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 12px 0;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-lg);
    border-top: 1px solid var(--border-color);
    background: linear-gradient(0deg, rgba(249, 250, 251, 0.8) 0%, rgba(255, 255, 255, 0) 100%);
}

.btn-cancel {
    padding: 10px 20px;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.btn-cancel::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.4s ease, height 0.4s ease;
}

.btn-cancel:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.btn-cancel:hover::before {
    width: 200%;
    height: 200%;
}

.btn-cancel:active {
    transform: translateY(0);
}

.btn-primary {
    padding: 10px 20px;
    font-size: var(--text-sm);
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.3);
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .sql-body {
        grid-template-columns: 1fr;
    }
    
    .sql-left-panel {
        display: none;
    }
    
    .playground-resizer {
        display: none;
    }
    
    .step-detail-row {
        flex-direction: column;
    }
    
    .step-stats {
        flex-direction: row;
    }
    
    .exec-timeline-vertical {
        width: 120px;
        min-width: 120px;
    }
}

/* ============================================
   Schema Table Dropdown
   ============================================ */
.schema-table {
    position: relative;
}

.schema-table-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.schema-dropdown-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: transparent;
    border: none;
    border-radius: var(--radius-xs);
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.schema-dropdown-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.schema-edit-btn {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 3px;
    padding: 0;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.schema-edit-btn:hover {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
}

.column-details {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin: 4px 8px;
    overflow: hidden;
}

.column-details-header {
    padding: 6px 10px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.column-list {
    padding: 4px;
    max-height: 200px;
    overflow-y: auto;
}

.column-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    font-size: 11px;
    border-radius: var(--radius-xs);
}

.column-item:hover {
    background: var(--bg-tertiary);
}

.column-item .col-key {
    width: 14px;
    font-size: 10px;
}

.column-item .col-name {
    font-weight: 600;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.column-item .col-type {
    color: var(--accent-primary);
    font-family: var(--font-mono);
    margin-left: auto;
    font-size: 10px;
}

/* Edit Table Modal Styles */
.edit-table-modal {
    width: 550px;
    max-width: 90vw;
}

.edit-table-modal .modal-body {
    max-height: 60vh;
    overflow-y: auto;
}

.edit-table-header-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    margin-bottom: 4px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
}

.edit-table-header-row span:nth-child(1) { width: 30px; text-align: center; }
.edit-table-header-row span:nth-child(2) { flex: 1; }
.edit-table-header-row span:nth-child(3) { width: 100px; }
.edit-table-header-row span:nth-child(4) { width: 30px; }

.edit-table-col-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    border-bottom: 1px solid var(--border-color);
}

.edit-table-col-row:last-child {
    border-bottom: none;
}

.edit-table-col-row .pk-cell {
    width: 30px;
    display: flex;
    justify-content: center;
}

.edit-table-col-row .pk-cell input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: var(--accent-primary);
}

.edit-table-col-row .name-cell {
    flex: 1;
}

.edit-table-col-row .name-cell input[type="text"] {
    width: 100%;
    padding: 4px 8px;
    font-size: 12px;
    font-family: var(--font-mono);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
}

.edit-table-col-row .name-cell input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.edit-table-col-row .type-cell {
    width: 100px;
}

.edit-table-col-row .type-cell select {
    width: 100%;
    padding: 4px 6px;
    font-size: 11px;
    font-family: var(--font-mono);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--accent-primary);
    cursor: pointer;
}

.edit-table-col-row .type-cell select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.edit-table-col-row .delete-cell {
    width: 30px;
    display: flex;
    justify-content: center;
}

.edit-table-col-row .delete-cell button {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 3px;
    font-size: 14px;
    line-height: 1;
    padding: 0;
}

.edit-table-col-row .delete-cell button:hover {
    background: var(--accent-error);
    color: white;
}

.edit-table-add-row {
    display: flex;
    justify-content: center;
    padding: 8px 0;
}

.edit-table-add-row button {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-primary);
    background: transparent;
    border: 1px dashed var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.edit-table-add-row button:hover {
    background: color-mix(in srgb, var(--accent-primary) 10%, transparent);
    border-color: var(--accent-primary);
}

/* ============================================
   Table Data Popup
   ============================================ */
.modal-xl {
    width: 90vw;
    max-width: 1200px;
}

.popup-table-body {
    max-height: 70vh;
    overflow: auto;
    padding: 0;
}

.popup-table-body .sql-table {
    width: 100%;
}

.popup-table-body .sql-table th {
    position: sticky;
    top: 0;
    z-index: 10;
}

.col-type-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 500;
    color: var(--accent-primary);
    background: color-mix(in srgb, var(--accent-primary) 10%, transparent);
    padding: 1px 4px;
    border-radius: 3px;
    margin-left: 4px;
    text-transform: none;
    letter-spacing: 0;
}

/* ── Try/Except Split/Merge Toggle ──────────────────────────────── */
.try-except-toggle-container {
    position: relative;
}

.try-except-toggle-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
    padding: 3px;
    background: var(--bg-secondary, #f5f5f5);
    border-radius: 6px;
    width: fit-content;
}

.try-except-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: none;
    border-radius: 4px;
    background: var(--bg-secondary, #e8e8e8);
    color: var(--text-muted, #888);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.try-except-toggle-btn:hover {
    color: var(--text-primary, #333);
    background: color-mix(in srgb, var(--bg-secondary, #e8e8e8) 80%, #ccc);
}

.try-except-toggle-btn.active {
    color: #166534;
    background: #bbf7d0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.try-except-toggle-btn svg {
    opacity: 0.7;
}

.try-except-toggle-btn.active svg {
    opacity: 1;
}

.try-except-view-merged .py-stage-combined-tbl {
    min-width: max-content;
}

/* ============================================
   v23 — Feature Pack 7 (Import / Export / EXPLAIN / DISTINCT / INTERSECT-EXCEPT / Window frames / PIVOT)
   ============================================ */

/* Editor secondary buttons (Explain / Export) */
.editor-secondary-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 10px;
    height: 24px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}
.editor-secondary-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-hover);
}
.editor-secondary-btn:active {
    transform: translateY(1px);
}

/* Schema actions row (Import button) */
.schema-actions-row {
    padding: 0 var(--space-sm) var(--space-sm);
}
.import-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--accent-success);
    background: transparent;
    border: 1px dashed var(--accent-success);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}
.import-btn:hover {
    background: color-mix(in srgb, var(--accent-success) 8%, transparent);
    border-style: solid;
}

/* Import preview */
.import-preview-scroll {
    max-height: 240px;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
}
.import-meta {
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
}

/* Export format radios */
.export-format-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 8px 0 12px;
}
.export-format-option {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.export-format-option:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}
.export-format-option input[type="radio"] {
    cursor: pointer;
}
.export-format-option input[type="radio"]:checked + span {
    color: var(--accent-primary);
    font-weight: 600;
}

/* EXPLAIN modal */
.explain-query-box {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 12px;
    overflow-x: auto;
}
.explain-query-box pre {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-primary);
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}
.explain-tree {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    background: var(--bg-secondary);
    max-height: 50vh;
    overflow: auto;
    font-family: var(--font-mono);
    font-size: 12px;
}
.explain-root, .explain-node {
    list-style: none;
    margin: 0;
    padding: 0;
}
.explain-node {
    margin: 4px 0;
}
.explain-bullet {
    color: var(--text-tertiary);
    margin-right: 6px;
    display: inline-block;
    min-width: 12px;
}
.explain-detail {
    color: var(--text-primary);
}
.explain-scan .explain-detail {
    color: #dc2626;
    font-weight: 600;
}
.explain-search .explain-detail {
    color: var(--accent-success);
    font-weight: 600;
}
.explain-temp .explain-detail {
    color: var(--accent-warning);
}
.explain-btree .explain-detail {
    color: var(--accent-primary);
}
.explain-sort .explain-detail {
    color: #c2410c;
}
.explain-correlated .explain-detail {
    color: #9333ea;
}

/* DISTINCT step badge (reuses step-distinct variable) */
:root {
    --step-distinct: #6366f1;
    --step-intersect: #0891b2;
    --step-except: #be185d;
    --step-pivot: #7c3aed;
    --step-unpivot: #db2777;
}

/* EXPLAIN modal-action footer spacing (reuse existing modal-footer) */

/* PySpark Init button pulse animation */
@keyframes pyspark-init-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(242, 216, 13, 0.4);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(242, 216, 13, 0);
    }
}

/* ── PySpark Window Specification breakdown ──────────────────────────── */
.py-window-breakdown {
    border-left-color: var(--step-window);
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.04) 0%, rgba(139, 92, 246, 0.04) 100%);
}

.py-window-breakdown .py-compute-title {
    color: var(--step-window);
}

.py-window-code {
    margin-bottom: 10px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-all;
}

.py-window-breakdown-table {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.py-window-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.55);
    border-radius: 6px;
    border: 1px solid rgba(226, 232, 240, 0.6);
}

.py-window-key {
    flex: 0 0 130px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--step-window);
    padding-top: 2px;
}

.py-window-val {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.py-window-col-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid rgba(168, 85, 247, 0.25);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--step-window);
}

.py-window-dir {
    display: inline-block;
    padding: 1px 5px;
    background: rgba(168, 85, 247, 0.18);
    border-radius: 3px;
    font-size: 9px;
    font-weight: 700;
    color: var(--step-window);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.py-window-empty {
    font-style: italic;
    color: var(--text-muted);
    font-size: 12px;
}

.py-window-frame {
    display: inline-block;
    padding: 4px 10px;
    background: rgba(99, 102, 241, 0.08);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-primary);
}

.py-window-frame-bound {
    color: var(--step-window);
    font-weight: 600;
}

.py-window-schematic {
    margin-top: 8px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.5);
    border: 1px dashed rgba(168, 85, 247, 0.35);
    border-radius: 6px;
}

.py-window-schematic-title {
    margin-bottom: 8px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.py-window-schematic-diagram {
    display: flex;
    align-items: stretch;
    gap: 8px;
    flex-wrap: wrap;
}

.py-window-partition {
    flex: 1 1 180px;
    padding: 8px 10px;
    background: rgba(168, 85, 247, 0.06);
    border: 1px solid rgba(168, 85, 247, 0.2);
    border-radius: 4px;
}

.py-window-partition-label {
    margin-bottom: 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    color: var(--step-window);
}

.py-window-row-mini {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 3px 6px;
    margin-bottom: 2px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-primary);
}

.py-window-row-mini-ord {
    color: var(--text-muted);
    font-size: 9px;
    text-transform: uppercase;
}

.py-window-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--step-window);
    padding: 0 4px;
}

.py-window-schematic-note {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ── Composed Multi-Operation Stage View ────────────────────────────── */
.composed-stage-view {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 12px 0;
}

.composed-segment {
    background: rgba(255, 255, 255, 0.4);
    border-radius: 8px;
    overflow: hidden;
}

.composed-segment-title {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: linear-gradient(180deg, rgba(249, 250, 251, 0.95) 0%, rgba(243, 244, 246, 0.95) 100%);
    border-left: 4px solid var(--accent-primary);
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    flex-wrap: wrap;
}

.composed-segment-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: white;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

.composed-segment-op {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    color: var(--accent-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.composed-segment-formula {
    flex: 1;
    min-width: 0;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.composed-segment-count {
    flex-shrink: 0;
    padding: 2px 8px;
    background: rgba(34, 197, 94, 0.1);
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    color: #16a34a;
    white-space: nowrap;
}

.composed-segment .sql-table-scroll {
    border-radius: 0 0 8px 8px;
}

.composed-segment .py-stages-side-by-side {
    margin: 8px 14px;
}

.composed-segment .join-toggle-btn {
    margin: 0 14px 8px;
}

/* ── Close Tab Confirmation Modal ───────────────────────────────────── */
.close-tab-confirm-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20000;
    pointer-events: none;
    transition: background 0.3s ease, backdrop-filter 0.3s ease;
}

.close-tab-confirm-overlay.active {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: auto;
}

.close-tab-confirm-modal {
    background: white;
    border-radius: 16px;
    padding: 32px 28px 24px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    transform: scale(0.85);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.close-tab-confirm-overlay.active .close-tab-confirm-modal {
    transform: scale(1);
    opacity: 1;
}

.close-tab-confirm-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    background: #fef3c7;
    border-radius: 50%;
    color: #f59e0b;
}

.close-tab-confirm-title {
    margin: 0 0 8px 0;
    font-size: 19px;
    font-weight: 700;
    color: #1a1a2e;
}

.close-tab-confirm-text {
    margin: 0 0 24px 0;
    font-size: 14px;
    color: #6b7280;
    line-height: 1.5;
}

.close-tab-confirm-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.close-tab-confirm-btn {
    padding: 10px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.close-tab-confirm-no {
    background: #f3f4f6;
    color: #4b5563;
}

.close-tab-confirm-no:hover {
    background: #e5e7eb;
    color: #374151;
}

.close-tab-confirm-yes {
    background: #ef4444;
    color: white;
}

.close-tab-confirm-yes:hover {
    background: #dc2626;
}
