* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

body {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    height: 100vh;
    padding: 0;
    margin: 0;
    color: #333;
    overflow: hidden;
}

.container {
    max-width: 100%;
    margin: 0;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 0;
    padding: 5px;
    box-shadow: none;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.back-button {
    position: absolute;
    top: 10px;
    left: 10px;
    padding: 8px 16px;
    background: rgba(102, 126, 234, 0.9);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    z-index: 1000;
    transition: all 0.3s ease;
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.back-button:hover {
    background: rgba(102, 126, 234, 1);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.back-button:active {
    transform: translateY(0);
}

h1 {
    text-align: center;
    color: #667eea;
    margin-bottom: 20px;
    font-size: 24px;
}

.io-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    margin-bottom: 5px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding-bottom: 240px; /* Space for fixed pipeline area */
}

.panel {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 8px;
    border: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Panel titles for desktop (transform pipeline, etc.) */
.panel-title {
    font-weight: bold;
    color: #666;
    margin-bottom: 5px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Hide panel titles inside IO panels on tablets/mobile since we use collapsible headers */
@media (max-width: 1024px) {
    .input-panel .panel-title,
    .output-panel .panel-title {
        display: none;
    }
}

.structure-view {
    background: white;
    border-radius: 6px;
    padding: 6px;
    margin-bottom: 6px;
    border: 1px solid #e0e0e0;
    max-height: 120px;
    overflow-y: auto;
}

.structure-label {
    font-size: 10px;
    color: #888;
    margin-bottom: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Tab controls */
.tab-controls {
    display: flex;
    gap: 5px;
    margin-bottom: 8px;
    background: #e0e0e0;
    padding: 4px;
    border-radius: 8px;
}

.tab-btn {
    flex: 1;
    padding: 8px 12px;
    background: transparent;
    color: #666;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    font-size: 12px;
    transition: all 0.2s;
    min-height: 36px;
}

.tab-btn:hover {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
}

.tab-btn.active {
    background: white;
    color: #667eea;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.tab-content {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.tab-pane {
    display: none;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.tab-pane.active {
    display: flex;
    flex-direction: column;
}

/* Full-height structure and data views */
.structure-view-full,
.data-view-full {
    flex: 1;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background: #fafafa;
    padding: 8px;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.structure-view-full {
    background: white;
}

.tab-pane textarea {
    flex: 1;
    min-height: 0;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px;
    font-family: inherit;
    font-size: 13px;
    resize: none;
    background: white;
    display: block;
}

.schema-tree {
    font-size: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
}

.schema-node {
    padding: 6px 10px;
    margin: 2px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-block;
    border: 2px solid transparent;
    background: #f8f9fa;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
}

.schema-node:hover {
    background: #f0f7ff;
    border-color: #667eea;
}

.schema-node:active {
    transform: scale(0.95);
    background: #e0efff;
}

.schema-node.selected {
    background: #667eea;
    color: white;
    border-color: #5568d3;
}

.schema-type {
    color: #888;
    font-size: 11px;
    margin-left: 4px;
}

.schema-indent {
    padding-left: 20px;
}

.data-view {
    max-height: 120px;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background: #fafafa;
    padding: 6px;
}

.data-item {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
    padding: 6px;
    margin-bottom: 4px;
    font-size: 11px;
}

.data-field {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}

.field-key {
    color: #667eea;
    font-weight: 500;
}

.field-value {
    color: #333;
}

.transform-chain {
    background: white;
    border-radius: 8px;
    padding: 6px;
    margin-bottom: 6px;
    border: 2px solid #667eea;
}

.chain-container {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    padding: 5px 0;
    position: relative;
    min-height: 44px;
}

.operator {
    min-width: 46px;
    height: 46px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.operator:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

.operator-lens {
    position: absolute;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%) scale(0);
    background: rgba(0, 0, 0, 0.95);
    color: white;
    padding: 12px;
    border-radius: 8px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
    transition: transform 0.2s ease;
    max-width: 250px;
}

.operator-lens.visible {
    transform: translateX(-50%) scale(1);
}

.lens-title {
    font-weight: bold;
    margin-bottom: 4px;
    color: #ffd700;
}

.lens-params {
    font-family: monospace;
    color: #90ee90;
}

.op-m { background: linear-gradient(135deg, #667eea, #764ba2); }
.op-f { background: linear-gradient(135deg, #f093fb, #f5576c); }
.op-r { background: linear-gradient(135deg, #fa709a, #fee140); }
.op-s { background: linear-gradient(135deg, #30cfd0, #330867); }
.op-t { background: linear-gradient(135deg, #a8edea, #fed6e3); }
.op-g { background: linear-gradient(135deg, #ff9a9e, #fecfef); }
.op-u { background: linear-gradient(135deg, #ffecd2, #fcb69f); }
.op-p { background: linear-gradient(135deg, #a1c4fd, #c2e9fb); }

.arrow {
    color: #ccc;
    font-size: 20px;
}

.operator-palette {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 5px;
    margin-bottom: 6px;
    padding: 6px;
    background: #f8f9fa;
    border-radius: 8px;
}

.palette-op {
    padding: 4px 3px;
    border-radius: 6px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
    min-height: 48px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.palette-op:hover {
    border-color: #667eea;
    transform: translateY(-2px);
}

.palette-op:active {
    transform: scale(0.95);
}

.op-symbol {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 2px;
    display: inline-block;
    padding: 3px 7px;
    border-radius: 5px;
    color: white;
}

.op-desc {
    font-size: 8px;
    color: #666;
    line-height: 1;
}

.builder-panel {
    background: white;
    border-radius: 8px;
    padding: 8px;
    border: 2px solid #667eea;
    display: none;
    position: relative;
    width: 100%;
    margin-bottom: 8px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

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

.builder-title {
    font-weight: bold;
    margin-bottom: 6px;
    color: #667eea;
    font-size: 13px;
    text-align: center;
    padding-bottom: 6px;
    border-bottom: 1px solid #e0e0e0;
}

.path-builder {
    background: #f0f7ff;
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 8px;
    min-height: 40px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.path-segment {
    background: white;
    border: 2px solid #667eea;
    border-radius: 5px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    color: #667eea;
}

.operator-selector,
.value-picker {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.op-button,
.value-option {
    padding: 8px 14px;
    background: white;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 36px;
}

.op-button:hover,
.value-option:hover {
    border-color: #667eea;
    background: #f0f7ff;
}

.op-button.selected,
.value-option.selected {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.custom-input {
    width: 100%;
    padding: 8px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 8px;
}

button {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s;
    font-size: 14px;
}

button:hover {
    background: #5568d3;
}


.cancel-btn {
    background: #888;
}

.cancel-btn:hover {
    background: #666;
}

.delete-btn {
    background: #e63946;
}

.delete-btn:hover {
    background: #d62839;
}

.delete-btn:active {
    background: #c1232d;
}

.toggle-btn {
    margin-top: 10px;
    font-size: 12px;
    padding: 5px 10px;
}

.builder-actions {
    margin-top: 8px;
    display: flex;
    gap: 6px;
    justify-content: center;
}

.builder-actions button {
    padding: 8px 14px;
    font-size: 12px;
}

.step h4 {
    color: #667eea;
    font-size: 12px;
    margin-bottom: 6px;
    padding: 6px;
    background: #f0f7ff;
    border-radius: 5px;
    text-align: center;
}


textarea {
    width: 100%;
    min-height: 150px;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px;
    font-family: inherit;
    font-size: 13px;
    resize: vertical;
    background: white;
    display: none;
}

/* Collapsible sections */
.collapsible-header {
    display: none; /* Hidden on desktop */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 15px;
    cursor: pointer;
    border-radius: 8px;
    margin-bottom: 10px;
    font-weight: bold;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    user-select: none;
    position: relative;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    transition: all 0.3s ease;
    align-items: center;
    justify-content: space-between;
}

/* Show collapsible headers on tablets and mobile */
@media (max-width: 1024px) {
    .collapsible-header {
        display: flex !important;
    }
}

.collapsible-header:active {
    transform: scale(0.98);
    box-shadow: 0 1px 4px rgba(102, 126, 234, 0.2);
}

.collapsible-header::after {
    content: '▼';
    position: absolute;
    right: 15px;
    transition: transform 0.3s ease;
    font-size: 12px;
}

.collapsible-header.collapsed {
    background: linear-gradient(135deg, #a0a0a0 0%, #808080 100%);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

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

.collapsible-content {
    transition: max-height 0.3s ease, opacity 0.3s ease, margin 0.3s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.collapsible-content.collapsed {
    max-height: 0 !important;
    opacity: 0;
    margin-bottom: 0;
    padding: 0;
}

/* Quick summary badge on collapsed headers */
.collapsible-header .badge {
    display: inline-block;
    background: rgba(255, 255, 255, 0.3);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    margin-left: 10px;
    font-weight: normal;
}

/* Pulse animation for first-time users */
@keyframes pulse {
    0%, 100% {
        box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    }
    50% {
        box-shadow: 0 4px 16px rgba(102, 126, 234, 0.6);
    }
}

.collapsible-header.hint {
    animation: pulse 2s ease-in-out 3;
}

/* Quick action floating button for tablets */
.quick-action-btn {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.5);
    z-index: 1000;
    font-size: 20px;
    transition: all 0.3s ease;
    border: none;
    color: white;
    cursor: pointer;
}

.quick-action-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4);
}

/* Pipeline fixed area - ALWAYS visible at bottom */
.pipeline-fixed-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.98);
    padding: 8px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
    flex-shrink: 0;
}

/* Tablet landscape (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    body {
        padding: 5px;
        overflow: hidden;
    }

    .container {
        padding: 10px;
        padding-bottom: 0;
        height: 100vh;
        max-height: 100vh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    h1 {
        font-size: 18px;
        margin-bottom: 10px;
        flex-shrink: 0;
    }

    /* Adjust collapsible headers for landscape */
    .collapsible-header {
        padding: 8px 12px;
        margin-bottom: 8px;
        font-size: 13px;
    }

    /* Scrollable content area for IO panels */
    .io-container {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        margin-bottom: 10px;
        overflow-y: auto;
        min-height: 0;
        flex: 1;
        padding-bottom: 240px; /* Space for fixed pipeline area */
    }

    /* Remove panel padding on tablet for input/output - collapsible header provides structure */
    .input-panel,
    .output-panel {
        padding: 0;
        background: transparent;
        border: none;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .collapsible-content {
        background: #f8f9fa;
        border-radius: 8px;
        padding: 10px;
        border: 1px solid #e0e0e0;
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
    }

    .panel-title {
        font-size: 12px;
        margin-bottom: 5px;
    }

    /* Collapsible sections with constrained heights */
    .structure-view,
    .data-view {
        max-height: 150px;
        overflow-y: auto;
    }

    .data-view {
        max-height: 120px;
    }

    /* Tab system in landscape */
    .tab-controls {
        flex-shrink: 0;
    }

    .tab-content {
        flex: 1;
        min-height: 0;
    }

    /* Fixed pipeline area at bottom */
    .pipeline-fixed-area {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(255, 255, 255, 0.98);
        padding: 8px;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
        z-index: 100;
        flex-shrink: 0;
    }

    /* Pipeline always visible - no shrink */
    .transform-chain {
        margin-bottom: 10px;
        padding: 10px;
        flex-shrink: 0;
    }

    .chain-container {
        padding: 5px 0;
        min-height: 70px;
    }

    .operator {
        min-width: 50px;
        height: 50px;
        font-size: 20px;
    }

    /* Operator palette - always visible at bottom */
    .operator-palette {
        padding: 10px;
        margin-bottom: 10px;
        flex-shrink: 0;
        grid-template-columns: repeat(8, 1fr);
        gap: 8px;
    }

    .palette-op {
        padding: 8px 4px;
    }

    .op-symbol {
        font-size: 18px;
        padding: 3px 6px;
    }

    .op-desc {
        font-size: 9px;
    }

    /* Builder panel - use default overlay positioning */
    .builder-panel {
        padding: 10px;
        max-height: 60vh;
        max-width: 95%;
    }


    button {
        padding: 8px 15px;
        font-size: 12px;
    }

    /* Show quick action button on landscape tablets */
    .quick-action-btn {
        display: block;
    }
}

/* Tablet portrait (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    body {
        padding: 8px;
        overflow: hidden;
    }

    .container {
        padding: 12px;
        padding-bottom: 0;
        height: 100vh;
        max-height: 100vh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    h1 {
        font-size: 20px;
        margin-bottom: 12px;
        flex-shrink: 0;
    }

    /* Adjust collapsible headers for portrait */
    .collapsible-header {
        padding: 10px 15px;
    }

    /* Stack IO panels vertically - scrollable if needed */
    .io-container {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 12px;
        overflow-y: auto;
        min-height: 0;
        flex: 1;
        padding-bottom: 260px; /* Space for fixed pipeline area */
    }

    /* Remove panel padding on tablet portrait for input/output */
    .input-panel,
    .output-panel {
        padding: 0;
        background: transparent;
        border: none;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .collapsible-content {
        background: #f8f9fa;
        border-radius: 8px;
        padding: 12px;
        border: 1px solid #e0e0e0;
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
    }

    /* Collapsible sections - compact */
    .structure-view,
    .data-view {
        max-height: 180px;
        overflow-y: auto;
    }

    /* Tab system in portrait */
    .tab-controls {
        flex-shrink: 0;
    }

    .tab-content {
        flex: 1;
        min-height: 0;
    }

    /* Fixed pipeline area at bottom */
    .pipeline-fixed-area {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(255, 255, 255, 0.98);
        padding: 8px;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
        z-index: 100;
        flex-shrink: 0;
    }

    /* Pipeline prominent and always visible */
    .transform-chain {
        margin-bottom: 12px;
        padding: 12px;
        flex-shrink: 0;
    }

    .chain-container {
        min-height: 70px;
    }

    /* Builder panel - use default overlay positioning */
    .builder-panel {
        padding: 12px;
        max-height: 65vh;
    }

    /* Operator palette - grid layout, always visible at bottom */
    .operator-palette {
        grid-template-columns: repeat(4, 1fr);
        gap: 10px;
        padding: 12px;
        margin-bottom: 12px;
        flex-shrink: 0;
    }

    .palette-op {
        padding: 12px 8px;
    }


    /* Show quick action button on portrait tablets */
    .quick-action-btn {
        display: block;
    }
}

/* Mobile phones (max-width: 767px) */
@media (max-width: 767px) {
    body {
        overflow: hidden;
        padding: 5px;
    }

    .container {
        padding: 10px;
        padding-bottom: 0;
        height: 100vh;
        max-height: 100vh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    h1 {
        font-size: 18px;
        margin-bottom: 10px;
        flex-shrink: 0;
    }

    .io-container {
        grid-template-columns: 1fr;
        overflow-y: auto;
        flex: 1;
        min-height: 0;
        margin-bottom: 10px;
        padding-bottom: 280px; /* Space for fixed pipeline area */
    }

    .operator-selector,
    .value-picker {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .structure-view,
    .data-view {
        max-height: 200px;
    }

    /* Fixed pipeline area at bottom on mobile */
    .pipeline-fixed-area {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(255, 255, 255, 0.98);
        padding: 8px;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
        z-index: 100;
        flex-shrink: 0;
    }

    .transform-chain {
        margin-bottom: 10px;
        padding: 10px;
    }

    .operator-palette {
        grid-template-columns: repeat(4, 1fr);
        padding: 10px;
        margin-bottom: 10px;
    }


    /* Builder panel - use default overlay positioning */
    .builder-panel {
        max-height: 75vh;
        max-width: 95%;
    }

    /* Quick action button on mobile */
    .quick-action-btn {
        display: block;
    }
}
