@import url('theme.css');

/* Mobile View Toggle (Hidden on Desktop) */
.mobile-view-toggle {
    display: none;
}

/* AI Builder Specific Layout */
.ai-builder-body {
    height: auto;
    overflow-y: auto;
}

.ai-builder-hero {
    padding: 80px 20px 40px;
    text-align: center;
    max-width: 900px;
    margin: 0 auto;
}

.ai-builder-hero h1 {
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: 800;
    margin-bottom: 20px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    /* Prevent flash before JS runs */
    opacity: 0;
    visibility: hidden;
}

.ai-builder-hero p {
    color: var(--text-muted);
    font-size: 1.2rem;
    margin-bottom: 40px;
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
    /* Prevent flash before JS runs */
    opacity: 0;
    visibility: hidden;
}

.instruction-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    text-align: left;
    margin-top: 40px;
}

.instruction-step {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    padding: 24px;
    border-radius: 16px;
    position: relative;
    backdrop-filter: blur(10px);
    /* Animation init */
    opacity: 0;
    transform: translateY(20px);
}

.step-number {
    position: absolute;
    top: -12px;
    left: 20px;
    width: 32px;
    height: 32px;
    background: var(--primary-gradient);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.9rem;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.4);
}

.instruction-step p {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-main);
}

/* Upload Area */
.upload-container {
    max-width: 900px;
    margin: 0 auto 80px auto;
    width: 90%;
    /* Animation init */
    opacity: 0;
    transform: translateY(20px);
}

.drop-zone {
    border: 2px dashed var(--glass-border);
    border-radius: 24px;
    padding: 80px 40px;
    text-align: center;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    backdrop-filter: blur(5px);
}

@keyframes pulse-border {
    0% {
        border-color: var(--glass-border);
        box-shadow: 0 0 0 rgba(99, 102, 241, 0);
    }

    50% {
        border-color: #6366f1;
        box-shadow: 0 0 20px rgba(99, 102, 241, 0.2);
    }

    100% {
        border-color: var(--glass-border);
        box-shadow: 0 0 0 rgba(99, 102, 241, 0);
    }
}

.drop-zone.is-empty:not(:hover):not(.drag-over) {
    animation: pulse-border 2s infinite ease-in-out;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: #6366f1;
    background: rgba(99, 102, 241, 0.05);
    transform: translateY(-2px);
    animation: none;
    /* Stop blinking on hover/drag */
}

.drop-zone-icon {
    font-size: 4rem;
    margin-bottom: 24px;
    display: block;
    opacity: 0.8;
}

.drop-zone-text {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 12px;
    display: block;
}

.drop-zone-subtext {
    color: var(--text-muted);
    font-size: 1rem;
}

#pdfInput {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0;
    cursor: pointer;
}

.selected-file-name {
    margin-top: 20px;
    font-weight: 700;
    color: #14b8a6;
    display: none;
    font-size: 0.95rem;
    padding: 8px 16px;
    background: rgba(20, 184, 166, 0.1);
    border-radius: 8px;
    display: inline-block;
}

.action-buttons-container {
    display: flex;
    justify-content: center;
    margin-top: 32px;
    gap: 20px;
    align-items: center;
}

/* Workspace Overrides to match Editor */
@media (min-width: 1024px) {
    .ai-builder-workspace {
        height: calc(100vh - 120px) !important;
        min-height: 750px;
        overflow: hidden !important;
    }
}

@media (min-width: 1500px) {
    .ai-builder-workspace {
        height: calc(100vh - 140px) !important;
        min-height: 850px;
    }
}

.ai-builder-workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
    background: var(--darker-bg);
    /* Animation init */
    opacity: 0;
    transform: translateY(25px);
}

.ai-builder-workspace .editor-panel {
    width: 50%;
    /* Initial width as in Editor */
    flex: none;
    height: 100%;
}

.ai-builder-workspace .preview-panel {
    flex: 1;
    height: 100%;
    min-width: 0;
}

.ai-builder-workspace .editor-panel,
.ai-builder-workspace .preview-panel {
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
    height: 100%;
    overflow: hidden;
}

.ai-builder-workspace .editor-panel {
    flex: none;
}

.ai-builder-workspace .preview-panel {
    flex: 1;
}

.ai-builder-workspace .editor-view.active {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.ai-builder-workspace .CodeMirror {
    flex: 1;
    height: 100% !important;
}

.ai-builder-workspace .preview-toolbar {
    order: -1;
    /* Ensure it stays at the top */
    background: #2f3a4c;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    height: 44px;
    /* Exact size as Editor */
}

.ai-builder-workspace .pdf-viewer {
    flex: 1;
    background: #2f3a4c;
    overflow: auto;
}

@media (max-width: 768px) {
    .ai-builder-workspace .pdf-inner-container {
        padding: 0px !important;
    }
}

.ai-builder-workspace .panel-label {
    background: #2f3a4c;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    height: 40px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    color: #b1bdce;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.ai-builder-workspace .resizer-dots-top,
.ai-builder-workspace .resizer-dots-bottom {
    width: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    line-height: 1;
}

.ai-builder-workspace .resizer-handle {
    width: 18px;
    height: 36px;
    background: #334155;
    /* Default state as in Editor */
}

/* Adjustments for AI Builder specific flow */
.status-badge {
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 700;
}

.status-ready {
    background: rgba(99, 102, 241, 0.1);
    color: #a5b4fc;
}

.status-generating {
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
}

/* Hyper-Premium Start Generation Button */
.btn-premium-gen {
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #6366f1 100%);
    background-size: 200% auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
    transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
    box-shadow: 0 10px 25px -5px rgba(99, 102, 241, 0.5),
        0 0 0 1px rgba(99, 102, 241, 0.2);
    color: white !important;
}

.btn-premium-gen::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -100%;
    width: 100px;
    height: 200%;
    background: linear-gradient(to right,
            transparent,
            rgba(255, 255, 255, 0.3),
            transparent);
    transform: rotate(25deg);
    animation: premiumShimmer 3s infinite;
}

@keyframes premiumShimmer {
    0% {
        left: -100%;
    }

    25% {
        left: 150%;
    }

    100% {
        left: 150%;
    }
}

.btn-premium-gen:hover {
    transform: translateY(-5px) scale(1.03);
    background-position: right center;
    box-shadow: 0 25px 50px -12px rgba(99, 102, 241, 0.7),
        0 0 30px rgba(168, 85, 247, 0.4);
    border-color: rgba(255, 255, 255, 0.3);
}

.btn-premium-gen:active {
    transform: translateY(-1px) scale(0.98);
}

@media (max-width: 400px) {

    .ai-builder-workspace .editor-panel,
    .ai-builder-workspace .preview-panel {
        min-height: 300px;
    }

    .ai-builder-workspace .panel-label {
        background: #2f3a4c;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        height: 40px;
        display: flex;
        align-items: center;
        padding: 0px 3px;
        color: #b1bdce;
        font-size: 0.7rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 1.5px;
    }
}

@media (max-width: 1147px) {
    .mobile-view-toggle {
        display: none !important;
    }

    /* Force panels to be visible by default */
    .ai-builder-workspace .editor-panel:not(.mobile-active),
    .ai-builder-workspace .preview-panel:not(.mobile-active) {
        display: flex !important;
    }

    .editor-body,
    .ai-builder-body {
        height: auto;
        overflow: auto;
    }

    .ai-builder-workspace {
        flex-direction: column !important;
        height: auto !important;
        overflow: visible !important;
        min-height: 100vh;
    }

    .ai-builder-workspace .editor-panel {
        width: 100% !important;
        height: 50vh;
        min-height: 50px;
        border-right: none;
        border-bottom: 1px solid var(--glass-border);
        display: flex !important;
        flex: none !important;
        /* Reset horizontal animation for mobile */
        transform: translateY(20px) !important;
        opacity: 0 !important;
        transition: opacity 0.8s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) !important;
    }

    .ai-builder-workspace .preview-panel {
        width: 100% !important;
        height: auto;
        min-height: 1200px;
        display: flex !important;
        flex: none !important;
        /* Reset horizontal animation for mobile */
        transform: translateY(20px) !important;
        opacity: 0 !important;
        transition: opacity 0.8s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) !important;
        transition-delay: 0.2s !important;
    }

    /* Ensure they return to 0 transform when visible */
    .scroll-animate-on .editor-panel,
    .scroll-animate-on .preview-panel,
    .scroll-animate-on .resizer,
    .panels-visible .editor-panel,
    .panels-visible .preview-panel,
    .panels-visible .resizer {
        transform: translateY(0) !important;
        opacity: 1 !important;
    }

    .ai-builder-workspace .resizer {
        display: flex !important;
        width: 100% !important;
        height: 32px !important;
        cursor: row-resize !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: center !important;
        background: #0f172a !important;
        border-left: none !important;
        border-right: none !important;
        border-top: 1px solid rgba(255, 255, 255, 0.05) !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
        position: relative !important;
        z-index: 10 !important;
        padding: 0 10px !important;
        touch-action: none !important;
    }

    .ai-builder-workspace .resizer-dots-top,
    .ai-builder-workspace .resizer-dots-bottom {
        display: block !important;
        writing-mode: horizontal-tb !important;
        color: rgba(255, 255, 255, 0.2) !important;
        font-size: 1.2rem !important;
        letter-spacing: 2px !important;
        flex: 1 !important;
        pointer-events: none !important;
    }

    .ai-builder-workspace .resizer-dots-top {
        text-align: right !important;
        padding-right: 20px !important;
    }

    .ai-builder-workspace .resizer-dots-bottom {
        text-align: left !important;
        padding-left: 20px !important;
    }

    .ai-builder-workspace .resizer-handle {
        width: 100px !important;
        height: 36px !important;
        background: #7063f3 !important;
        border-radius: 20px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        transform: none !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5) !important;
        touch-action: none !important;
        transition: transform 0.2s, background 0.2s;
    }

    .ai-builder-workspace .resizer.resizer-active .resizer-handle {
        background: #8b80f9 !important;
        transform: scale(1.1) !important;
        box-shadow: 0 0 20px rgba(112, 99, 243, 0.4) !important;
    }

    .ai-builder-workspace .resizer.resizer-active {
        background: #1e293b !important;
    }

    .ai-builder-workspace .resizer-handle span {
        line-height: 0.6 !important;
        font-size: 1.2rem !important;
        color: white !important;
    }

    .ai-builder-workspace .resizer-handle .left-arrow {
        transform: rotate(90deg) !important;
    }

    .ai-builder-workspace .resizer-handle .right-arrow {
        transform: rotate(90deg) !important;
    }

}

@media (max-width: 545px) {

    /* Hide specific tools as requested */
    .ai-builder-workspace #fitWidthBtn,
    .ai-builder-workspace #fitPageBtn,
    .ai-builder-workspace .page-controls,
    .ai-builder-workspace .divider {
        display: none !important;
    }

    /* Shrink buttons but keep text visible */
    /* Shrink buttons but keep text visible */
    .ai-builder-workspace .btn-recompile {
        padding: 6px 9px !important;
        font-size: 0.75rem !important;
        min-width: unset !important;
        gap: 4px !important;
    }

    .ai-builder-workspace .btn-recompile i,
    .ai-builder-workspace .btn-recompile svg {
        width: 12px !important;
        height: 12px !important;
    }

    .ai-builder-workspace .btn-icon {
        padding: 4px !important;
    }

    .ai-builder-workspace .btn-icon svg {
        width: 14px !important;
        height: 14px !important;
    }

    .ai-builder-workspace .preview-toolbar {
        padding: 0 8px !important;
        height: 40px !important;
        justify-content: space-between !important;
    }

    .ai-builder-workspace .toolbar-left,
    .ai-builder-workspace .toolbar-middle,
    .ai-builder-workspace .toolbar-right {
        gap: 4px !important;
    }

}

@media (max-width: 768px) {

    .editor-toggle-pill {
        display: flex;
        background: #242e3c;
        padding: 4px 5px;
        border-radius: 20px;
        gap: 3px;
        border: 1px solid rgba(255, 255, 255, 0.05);
    }

    .toggle-btn {
        padding: 4px 8px;
    }

    .action-buttons-container {
        flex-direction: column;
        gap: 15px;
        width: 100%;
    }

    .action-buttons-container button,
    .action-buttons-container span {
        width: 100%;
        max-width: 280px;
        /* Prevent being too wide on tablet */
        display: flex;
        justify-content: center;
    }

    .btn-recompile {
        min-width: unset;
        padding: 6px 9px !important;
    }


    .ai-builder-hero,
    .upload-container {
        padding-left: 16px;
        padding-right: 16px;
    }

    .ai-builder-hero h1 {
        font-size: 2rem;
    }

    .drop-zone {
        padding: 40px 20px;
    }

    /* Override for Mobile Links/Toggles */
    .ai-builder-workspace {
        height: auto;
        flex-direction: column !important;
    }

    .ai-builder-workspace .editor-panel {
        width: 100% !important;
        display: flex !important;
        height: auto;
        min-height: 50px;
    }

    .ai-builder-workspace .preview-panel {
        width: 100% !important;
        display: flex !important;
        height: auto;
        min-height: 400px;
    }

    .mobile-view-toggle {
        display: none !important;
    }

    .ai-builder-workspace .btn-recompile {
        min-width: unset;
        padding: 1px 6px;
    }
}



.mobile-toggle-btn {
    padding: 8px 20px;
    border-radius: 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.mobile-toggle-btn.active {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* Global Animation Utility */
.scroll-animate-on {
    opacity: 1 !important;
    transform: translateY(0) !important;
    visibility: visible !important;
    transition: opacity 0.8s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Word Reveal Logic */
.word {
    display: inline-block;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: opacity, transform;
    background: inherit;
    -webkit-background-clip: inherit;
    background-clip: inherit;
    -webkit-text-fill-color: inherit;
}

.word.visible {
    opacity: 1;
    transform: translateY(0);
}

.word:last-child {
    margin-right: 0;
}

/* Workspace Error Panel - Full Width at Bottom */
.workspace-error-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 300px;
    z-index: 100;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.3);
}

.ai-builder-workspace {
    position: relative;
}

/* Ensure workspace has space for error panel when visible */
.ai-builder-workspace.has-error {
    padding-bottom: 250px;
}

@media (max-width: 1147px) {
    .workspace-error-panel {
        position: relative;
        border-radius: 0;
        max-height: 400px;
    }
}