/* 
   Quantum Composer: Lab-Specific Styles
   Extracted from lab.html for modularity
*/

/* ── Page Load & State ── */
body {
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

body.auth-verified {
    opacity: 1;
}

/* ── Demos Dropdown ── */
.demos-dropdown-wrapper {
    position: relative;
    display: inline-block;
}

.btn-demos {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: linear-gradient(135deg, #2544E3, #1e3a8a);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(37, 68, 227, 0.35);
    font-family: inherit;
}

.btn-demos:hover {
    background: linear-gradient(135deg, #1d4ed8, #2e1065);
    box-shadow: 0 4px 14px rgba(37, 68, 227, 0.5);
    transform: translateY(-1px);
}

.btn-demos svg {
    width: 16px;
    height: 16px;
    transition: transform 0.25s ease;
}

.btn-demos.open svg.chevron {
    transform: rotate(180deg);
}

.demos-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 260px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(37, 68, 227, 0.1);
    z-index: 9000;
    overflow: hidden;
    animation: dropdownFadeIn 0.18s ease;
}

.demos-dropdown-menu.open {
    display: block;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.demos-dropdown-category {
    padding: 8px 14px 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #9ca3af;
    background: #f9fafb;
    border-bottom: 1px solid #f3f4f6;
}

.demos-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.875rem;
    color: #1f2937;
    transition: background 0.15s ease;
}

.demos-dropdown-item:hover {
    background: #EEF2FF;
    color: #2544E3;
}

.demos-dropdown-item:hover .demo-item-icon {
    background: #2544E3;
    color: white;
}

.demo-item-icon {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    background: #EEF2FF;
    color: #2544E3;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.demo-item-icon svg,
.demo-item-icon i {
    width: 15px;
    height: 15px;
}

.demo-item-text {
    display: flex;
    flex-direction: column;
}

.demo-item-title {
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.2;
}

.demo-item-desc {
    font-size: 0.75rem;
    color: #6b7280;
    line-height: 1.2;
    margin-top: 1px;
}

.demos-dropdown-item:hover .demo-item-desc {
    color: #818cf8;
}

/* ── Pill Action Bar ── */
.pill-action-bar {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid rgba(37, 68, 227, 0.2);
    border-radius: 999px;
    padding: 4px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    gap: 2px;
}

.pill-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    border: 1px solid transparent;
    background: transparent;
    color: #2544E3;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.pill-btn:active {
    transform: scale(0.95);
}

.pill-btn:hover {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(37, 68, 227, 0.15);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
}

.pill-btn.primary {
    background: linear-gradient(135deg, #2544E3, #1e3a8a);
    color: white;
    box-shadow: 0 4px 12px rgba(37, 68, 227, 0.3);
}

.pill-btn.primary:hover {
    background: linear-gradient(135deg, #1d4ed8, #2e1065);
    box-shadow: 0 6px 16px rgba(37, 68, 227, 0.4);
}

.pill-sep {
    width: 1px;
    height: 20px;
    background: rgba(0, 0, 0, 0.1);
    margin: 0 4px;
}

.pill-input-group {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px;
    font-size: 0.8rem;
    color: #4b5563;
    font-weight: 600;
}

.pill-stepper {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #f1f5f9;
    padding: 2px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.pill-step-btn {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
}

.pill-step-btn:hover {
    border-color: #2544E3;
    color: #2544E3;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.pill-step-btn svg {
    width: 12px;
    height: 12px;
}

.pill-input {
    width: 50px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 3px 6px;
    font-size: 0.8rem;
    outline: none;
    transition: border-color 0.2s;
    background: white;
}

.pill-input:focus {
    border-color: #2544E3;
}

.circuit-header,
.qasm-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 24px;
}

.circuit-header h2,
.qasm-header h3 {
    margin: 0;
    white-space: nowrap;
    font-size: 1rem;
    letter-spacing: -0.01em;
    color: #334155;
}

/* Hide default number input spinners */
.pill-input::-webkit-outer-spin-button,
.pill-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.pill-input[type=number] {
    -webkit-appearance: none;
    -moz-appearance: textfield;
    appearance: none;
    text-align: center;
    padding: 0;
    border: none;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-weight: 700;
    color: #0f172a;
}

.pill-input#qubit-count {
    width: 30px;
}

.pill-input#shots-input {
    width: 65px;
}

/* ── Splash Screen ── */
#splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.8s ease, visibility 0.8s;
    overflow: hidden;
}

#splash-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    opacity: 0.8;
}

.splash-content {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#splash-screen.fade-out {
    opacity: 0;
    visibility: hidden;
}

.splash-img {
    width: 160px;
    height: 160px;
    object-fit: contain;
    margin-bottom: 30px;
    animation: splash-pulse 2.5s infinite ease-in-out;
    filter: drop-shadow(0 20px 40px rgba(37, 68, 227, 0.15));
}

.splash-title {
    font-size: 2.5rem;
    font-weight: 800;
    color: #0f172a;
    margin-bottom: 8px;
    letter-spacing: -0.025em;
}

.splash-subtitle {
    font-size: 1rem;
    color: #64748b;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.splash-loader {
    margin-top: 40px;
    width: 200px;
    height: 6px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.splash-loader-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 50%;
    background: #2544E3;
    border-radius: 10px;
    animation: splash-loading 1.5s infinite ease-in-out;
}

@keyframes splash-pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

@keyframes splash-loading {
    0% {
        left: -50%;
    }

    100% {
        left: 100%;
    }
}

/* ── Circuit Builder Scroll ── */
#circuit-container::-webkit-scrollbar {
    height: 0;
    display: none;
}

#circuit-container {
    scrollbar-width: none;
}

/* ── Modal Helpers ── */
.modal-close-x {
    position: absolute;
    top: 12px;
    right: 20px;
    background: rgba(0, 0, 0, 0.03);
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    cursor: pointer;
    transition: 0.2s;
    z-index: 100;
}

.modal-close-x:hover {
    color: #ef4444;
    background: #fee2e2;
    transform: scale(1.05);
}

/* ── Responsive Overrides (IBM Zoom-Perfect logic) ── */
@media (max-width: 1400px) {
    .container {
        max-width: 100%;
    }
}

@media (max-width: 1280px) {
    .lab-grid {
        grid-template-columns: 280px 1fr 1fr !important;
        grid-template-rows: auto auto !important;
        height: auto !important;
    }

    .results-section {
        grid-column: span 3;
    }
}

@media (max-width: 1100px) {
    .lab-grid {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        gap: 24px !important;
        padding: 16px !important;
    }

    .palette-section,
    .circuit-section,
    .editor-section,
    .probability-section,
    .results-section {
        width: 100% !important;
        grid-area: auto !important;
        min-height: auto !important;
    }

    .circuit-header,
    .qasm-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 16px !important;
    }

    .pill-action-bar {
        flex-wrap: wrap;
        width: 100%;
        border-radius: 16px;
        padding: 6px;
        justify-content: flex-start;
    }

    .pill-btn span {
        display: none;
    }

    .pill-btn {
        width: 42px;
        height: 42px;
    }

    .header-center {
        display: none !important;
    }

    .logo-text {
        font-size: 0.95rem !important;
    }
}

@media (max-width: 992px) {
    .header-center {
        display: none;
    }

    .logo-text {
        font-size: 1rem !important;
    }
}

@media (max-width: 768px) {
    #learn-quantum>div {
        grid-template-columns: 1fr !important;
    }

    .header {
        padding: 10px 16px !important;
    }

    .header-right .btn-help span,
    .header-right .btn-demos span,
    .premium-logout-btn span {
        display: none !important;
    }
}

@media (max-width: 600px) {
    .unified-gate-grid {
        grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)) !important;
    }

    .gate-btn {
        width: 48px !important;
        height: 48px !important;
        font-size: 0.8rem !important;
    }

    .header-right {
        gap: 8px !important;
    }

    .header-right .btn-help span,
    .header-right .btn-demos span {
        display: none;
    }

    .splash-title {
        font-size: 1.8rem !important;
    }

    .splash-subtitle {
        font-size: 0.65rem !important;
    }

    .footer p {
        font-size: 0.75rem !important;
    }
}

/* ── Gate Palette & Scrollable Grid ── */
.palette-section {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden !important;
}

.gate-palette-grid {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0; /* Critical for enabling nested scroll */
}

.unified-gate-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: min-content;
    align-content: start;
    gap: 16px;
    padding: 20px;
    padding-right: 12px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 16px;
    border: 1px solid rgba(0, 0, 0, 0.04);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(37, 68, 227, 0.2) transparent;
    transition: all 0.3s ease;
}

.unified-gate-grid .gate-btn {
    width: 100%;
    aspect-ratio: 1 / 1;
    height: auto;
    font-size: 1rem; /* Boosted for better visibility */
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.unified-gate-grid .gate-btn[data-gate="CNOT"],
.unified-gate-grid .gate-btn[data-gate="CCX"],
.unified-gate-grid .gate-btn[data-gate="SDG"],
.unified-gate-grid .gate-btn[data-gate="TDG"],
.unified-gate-grid .gate-btn[data-gate="SWAP"],
.unified-gate-grid .gate-btn[data-gate="CSWAP"] {
    font-size: 0.65rem;
}

/* Premium Scrollbar Styling */
.unified-gate-grid::-webkit-scrollbar {
    width: 5px;
}

.unified-gate-grid::-webkit-scrollbar-track {
    background: transparent;
}

.unified-gate-grid::-webkit-scrollbar-thumb {
    background: rgba(37, 68, 227, 0.1);
    border-radius: 10px;
    transition: background 0.2s;
}

.unified-gate-grid:hover::-webkit-scrollbar-thumb {
    background: rgba(37, 68, 227, 0.2);
}

.unified-gate-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(37, 68, 227, 0.4);
}

.unified-gate-grid:hover {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(37, 68, 227, 0.1);
}


/* ── QASM Editor Premium Enhancements ── */
.editor-section {
    display: flex;
    flex-direction: column;
}

.qasm-editor-container {
    flex: 1;
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    display: flex;
}

.qasm-editor-area {
    width: 100%;
    flex: 1;
    min-height: 150px;
    padding: 20px;
    font-family: 'IBM Plex Mono', 'Fira Code', monospace;
    font-size: 0.95rem;
    color: #0f172a;
    line-height: 1.6;
    background: #ffffff;
    border: none;
    outline: none;
    resize: none;
    tab-size: 4;
    transition: all 0.3s ease;
}

.qasm-editor-area:focus {
    background: #ffffff;
}

.qasm-editor-container:hover .qasm-editor-area {
    background: #ffffff;
}

.editor-error-msg {
    display: none;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fef2f2;
    color: #dc2626;
    font-size: 0.8rem;
    padding: 8px 16px;
    border-top: 1px solid #fee2e2;
    z-index: 10;
}

.qasm-helper-text {
    margin-top: 12px;
    font-size: 0.85rem;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 6px;
}

.qasm-helper-text code {
    background: #f1f5f9;
    color: var(--primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}

/* Modal Editor Enhancements */
.qasm-editor-modal-area {
    flex: 1;
    width: 100%;
    padding: 32px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 1rem;
    border: none;
    outline: none;
    resize: none;
    background: #ffffff;
    color: #0f172a;
    line-height: 1.8;
    tab-size: 4;
}

.qasm-editor-modal-area::placeholder {
    color: #94a3b8;
    font-style: italic;
}