/* Gate Items */
.gate-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: grab;
    transition: all 0.2s ease;
    user-select: none;
}

.gate-item:hover {
    background: var(--border-color);
    transform: translateX(4px);
    border-color: var(--primary-color);
}

.gate-item:active {
    cursor: grabbing;
}

.gate-item.dragging {
    opacity: 0.5;
}

.gate-symbol {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--primary-color);
    color: white;
    border-radius: 0.375rem;
    font-weight: 600;
    font-size: 0.875rem;
    flex-shrink: 0;
}

/* Palette gate color families */
.gate-item[data-gate="X"] .gate-symbol,
.gate-item[data-gate="CX"] .gate-symbol,
.gate-item[data-gate="RX"] .gate-symbol {
    background: var(--gate-x-color);
}

.gate-item[data-gate="Y"] .gate-symbol,
.gate-item[data-gate="CY"] .gate-symbol,
.gate-item[data-gate="RY"] .gate-symbol {
    background: var(--gate-y-color);
}

.gate-item[data-gate="Z"] .gate-symbol,
.gate-item[data-gate="CZ"] .gate-symbol,
.gate-item[data-gate="RZ"] .gate-symbol {
    background: var(--gate-z-color);
}

.gate-item[data-gate="H"] .gate-symbol {
    background: var(--gate-h-color);
}

.gate-item[data-gate="S"] .gate-symbol,
.gate-item[data-gate="T"] .gate-symbol {
    background: var(--gate-phase-color);
}

.gate-item[data-gate="SWAP"] .gate-symbol {
    background: var(--gate-swap-color);
}

.gate-item[data-gate="MEASURE"] .gate-symbol {
    background: var(--gate-measure-color);
}

.gate-name {
    font-size: 0.875rem;
    color: var(--text-primary);
    flex: 1;
}

.gate-info-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.gate-info-icon:hover {
    background: var(--primary-dark);
    transform: scale(1.1);
}

/* Circuit Components */
.qubit-line {
    position: relative;
    height: 60px;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    min-width: fit-content;
}

.qubit-line::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--surface-light);
    opacity: 0.3;
}

.qubit-label {
    position: absolute;
    left: 0;
    width: 60px;
    text-align: center;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.qubit-wire {
    position: absolute;
    left: 60px;
    min-width: 100%;
    height: 2px;
    background: var(--primary-color);
    opacity: 0.6;
    top: 50%;
    transform: translateY(-50%);
}

.gate-container {
    position: absolute;
    left: 60px;
    display: block;
    min-height: 60px;
    height: 100%;
}

.gate-slot {
    position: absolute;
    width: 50px;
    height: 50px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.gate-slot:hover {
    background: rgba(99, 102, 241, 0.1);
    border-radius: 0.375rem;
}

.gate-slot.drag-over {
    background: rgba(99, 102, 241, 0.2);
    border-radius: 0.375rem;
}

.gate-on-wire {
    width: 50px;
    height: 50px;
    background: var(--primary-color);
    color: white;
    border: 2px solid var(--primary-dark);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

/* Gate color families */
.gate-on-wire.gate-x-family {
    background: var(--gate-x-color);
    border-color: var(--gate-x-dark);
}

.gate-on-wire.gate-y-family {
    background: var(--gate-y-color);
    border-color: var(--gate-y-dark);
}

.gate-on-wire.gate-z-family {
    background: var(--gate-z-color);
    border-color: var(--gate-z-dark);
}

.gate-on-wire.gate-h-family {
    background: var(--gate-h-color);
    border-color: var(--gate-h-dark);
}

.gate-on-wire.gate-phase-family {
    background: var(--gate-phase-color);
    border-color: var(--gate-phase-dark);
}

.gate-on-wire.gate-swap-family {
    background: var(--gate-swap-color);
    border-color: var(--gate-swap-dark);
}

.gate-on-wire.gate-measure-family {
    background: var(--gate-measure-color);
    border-color: var(--gate-measure-dark);
}

.gate-on-wire:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px var(--shadow);
}

.gate-on-wire.executing {
    animation: pulse-gate 0.5s ease infinite;
    box-shadow: 0 0 20px var(--primary-color);
}

@keyframes pulse-gate {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 0 20px var(--primary-color);
    }
    50% { 
        transform: scale(1.15);
        box-shadow: 0 0 30px var(--primary-color);
    }
}

.gate-on-wire.has-params {
    position: relative;
}

.gate-on-wire.has-params::after {
    content: attr(data-params);
    position: absolute;
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.65rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Measurement gate is handled by gate-measure-family class */

.gate-on-wire.controlled {
    background: var(--secondary-color);
    border-color: #7c3aed;
}

.control-block {
    background: var(--secondary-color) !important;
    border: 2px solid #9333ea !important;
    font-size: 0.7rem;
    padding: 0.25rem;
    min-width: 46px;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

/* Control block inherits target gate family color */
.control-block.gate-x-family {
    background: var(--gate-x-color) !important;
    border-color: var(--gate-x-dark) !important;
}

.control-block.gate-y-family {
    background: var(--gate-y-color) !important;
    border-color: var(--gate-y-dark) !important;
}

.control-block.gate-z-family {
    background: var(--gate-z-color) !important;
    border-color: var(--gate-z-dark) !important;
}

.control-block .control-label {
    font-size: 1rem;
    font-weight: 700;
    color: white;
}

.control-block .control-arrow {
    font-size: 0.6rem;
    color: rgba(255, 255, 255, 0.85);
    white-space: nowrap;
}

.controlled-target {
    box-shadow: 0 0 8px currentColor;
}

/* SWAP partner block */
.swap-block {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.swap-block .swap-symbol {
    font-size: 1rem;
    font-weight: 700;
    color: white;
}

.swap-block .swap-arrow {
    font-size: 0.6rem;
    color: rgba(255, 255, 255, 0.85);
    white-space: nowrap;
}

.control-line {
    position: absolute;
    width: 2px;
    background: var(--secondary-color);
    left: 50%;
    transform: translateX(-50%);
}

.control-line.above {
    top: -30px;
    height: 30px;
}

.control-line.below {
    bottom: -30px;
    height: 30px;
}

.control-dot {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--secondary-color);
    border: 2px solid var(--surface);
    border-radius: 50%;
    left: 50%;
    transform: translateX(-50%);
}

.control-dot.above {
    top: -12px;
}

.control-dot.below {
    bottom: -12px;
}

/* Qubit Visualization - Tabbed Interface */
.qubit-tabbed-container {
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.qubit-tabs-header {
    display: flex;
    flex-wrap: nowrap;
    gap: 2px;
    padding: 0.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
}

.qubit-tab {
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    white-space: nowrap;
}

.qubit-tab:hover {
    background: var(--surface-light);
    color: var(--text-primary);
}

.qubit-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: var(--background);
}

.qubit-tab-content {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 0;
}

.qubit-content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.qubit-content-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.state-summary {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    padding: 0.5rem;
    background: var(--surface-light);
    border-radius: 0.375rem;
}

/* 3D Bloch Sphere Container */
.bloch-sphere-3d-container {
    width: 100%;
    height: 100%;
    position: relative;
    border-radius: 0.5rem;
    overflow: hidden;
    cursor: grab;
    min-height: 150px;
}

.bloch-sphere-3d-container:active {
    cursor: grabbing;
}

.bloch-sphere-3d-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.bloch-labels {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 0.5rem;
}

.bloch-label-info {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* Legacy qubit state styles (kept for compatibility) */
.qubit-state {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
}

.qubit-state-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.qubit-state-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.state-probabilities {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.probability-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.probability-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
}

.probability-value {
    height: 8px;
    background: var(--surface-light);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.probability-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transition: width 0.3s ease;
    border-radius: 4px;
}

.probability-text {
    font-size: 0.75rem;
    color: var(--text-primary);
    text-align: center;
    margin-top: 0.25rem;
}

/* Measurement Results */
.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: var(--surface-light);
    border-radius: 0.375rem;
    margin-bottom: 0.5rem;
}

.result-binary {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    color: var(--text-primary);
}

.result-probability {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.result-bar {
    width: 40%;
    height: 6px;
    background: var(--background);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.result-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), var(--primary-color));
    transition: width 0.3s ease;
}

/* Parameter Inputs */
.parameter-group {
    margin-bottom: 1rem;
}

.parameter-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.parameter-group input {
    width: 100%;
    padding: 0.5rem;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.parameter-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Animations */
@keyframes gatePlace {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.gate-on-wire.placed {
    animation: gatePlace 0.3s ease;
}

@keyframes stateUpdate {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.state-vector.updating {
    animation: stateUpdate 0.5s ease;
}

/* Toolbar Separator */
.toolbar-separator {
    display: inline-block;
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 0.5rem;
    vertical-align: middle;
}

/* Control Flow Blocks (REPEAT/END) */
.control-flow-block {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 100;
    box-sizing: border-box;
    pointer-events: auto;
}

.control-flow-repeat {
    background: linear-gradient(180deg, rgba(168, 85, 247, 0.9), rgba(139, 92, 246, 0.9));
    border: 2px solid #7c3aed;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.control-flow-end {
    background: linear-gradient(180deg, rgba(239, 68, 68, 0.9), rgba(220, 38, 38, 0.9));
    border: 2px solid #dc2626;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.control-flow-block:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(139, 92, 246, 0.4);
}

.control-flow-end:hover {
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.4);
}

.control-flow-symbol {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.control-flow-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: white;
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 8px;
    border-radius: 4px;
}

.control-flow-end-label {
    font-size: 0.65rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    text-align: center;
    max-width: 46px;
    word-wrap: break-word;
    line-height: 1.2;
}

/* Control flow gate symbols in palette */
.gate-symbol.gate-control-flow {
    background: linear-gradient(135deg, #a855f7, #8b5cf6);
}

.gate-item[data-gate="END"] .gate-symbol.gate-control-flow {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

/* Export Modal Styles */
.export-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.export-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.export-option-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.25rem 1rem;
    background: var(--surface-light);
    border: 2px solid var(--border-color);
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.export-option-btn:hover {
    background: var(--border-color);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.export-option-btn:active {
    transform: translateY(0);
}

.export-option-btn.exporting {
    opacity: 0.6;
    pointer-events: none;
}

.export-icon {
    font-size: 2rem;
    line-height: 1;
}

.export-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.export-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.export-settings {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--surface-light);
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.export-settings .checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
}

.export-settings input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
    cursor: pointer;
}

/* Export Preview View */
.export-preview-view {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.export-preview-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.export-format-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.export-preview-container {
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1rem;
    min-height: 200px;
    max-height: 400px;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.export-preview-loading {
    color: var(--text-secondary);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.export-preview-loading::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--primary-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: exportSpinner 0.8s linear infinite;
}

.export-preview-image {
    max-width: 100%;
    max-height: 380px;
    border-radius: 0.375rem;
    box-shadow: 0 2px 8px var(--shadow);
}

@keyframes exportSpinner {
    to { transform: rotate(360deg); }
}

