/* ================================================================
   EDITOR LAYOUT (Left, Center, Right)
   ================================================================ */
.editor-main-layout {
    display: flex;
    flex-direction: row;
    flex: 1;
    width: 100%;
    margin-top: 0;
    background-color: var(--bg);
    overflow: hidden;
    /* PREVENT VERTICAL GROWTH */
    height: 0;
    /* Let flex-1 take over and stabilize height */
}


/* Center Stage (Override existing) */
.preview-stage {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--editor-bg, var(--bg));
    overflow: hidden;
    height: 100%;
    padding: 0;
    /* Removed padding to maximize canvas space */
}

.preview-wrapper-scrollable {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    display: flex;
    padding: 0;
    box-sizing: border-box;
    scrollbar-width: none;
    -ms-overflow-style: none;
    overscroll-behavior: none;
    /* Block browser's own swipe-to-navigate patterns */
    touch-action: none;
    /* Block browser's own swipe-to-navigate patterns */
}

.preview-wrapper-scrollable::-webkit-scrollbar {
    display: none;
}

.preview-wrapper {
    transition: transform 0.2s ease, width 0.2s ease, height 0.2s ease;
    flex-shrink: 0;
    margin: auto;
    /* Centering trick for scrollable flex items */
}

/* Right Tools Panel */
/* ================================================================
   RESPONSIVE HEADER ADJUSTMENTS
   ================================================================ */
@media (max-width: 1200px) {
    .preview-topic-label {
        max-width: 160px;
    }
}

@media (max-width: 1080px) {

    #t-finalize-text,
    #t-reset-text,
    .header-v-separator {
        display: none !important;
    }

    .preview-unified-header {
        padding: 0 0.5rem;
        gap: 0.25rem;
    }

    .preview-topic-label {
        max-width: 120px;
    }

    .action-btn {
        padding: 0.35rem 0.6rem;
    }
}

@media (max-width: 900px) {
    .preview-unified-center {
        display: none;
    }

    .preview-unified-header {
        grid-template-columns: 1fr 1fr;
    }

    .preview-topic-label {
        max-width: 100px;
    }
}

@media (max-width: 600px) {
    .preview-unified-header {
        min-height: 48px;
    }

    .preview-topic-label {
        display: none;
    }
}

/* Theme toggle circular transition */
html.theme-transitioning::view-transition-old(root),
html.theme-transitioning::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}

html.theme-transitioning::view-transition-old(root) {
    z-index: 1;
}

html.theme-transitioning::view-transition-new(root) {
    z-index: 2;
}

/* --- Synapse Style Chat Input --- */
.chat-input-wrapper.synapse-style {
    border-radius: 24px;
    padding: 1rem 1rem 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.chat-input-wrapper.synapse-style .chat-input {
    font-size: 1.05rem;
    min-height: 50px;
}

.dropdown-container {
    position: relative;
}

.action-pill-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px 10px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}

.action-pill-btn:hover {
    background: var(--surface-hover);
}

.dropdown-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    min-width: 150px;
    box-shadow: var(--shadow-lg);
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 250px;
    overflow-y: auto;

    /* Premium Animation */
    opacity: 1;
    transform: translateY(0) scale(1);
    transform-origin: bottom left;
    visibility: visible;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.dropdown-menu.hidden {
    display: flex !important;
    /* Keep in DOM for transitions */
    opacity: 0;
    transform: translateY(10px) scale(0.96);
    pointer-events: none;
    visibility: hidden;
}

.dropdown-item {
    background: transparent;
    border: none;
    padding: 8px 12px;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    color: var(--text);
    transition: background 0.2s;
    display: flex;
    flex-direction: column;
}

.dropdown-item:hover,
.dropdown-item.active {
    background: var(--surface-hover);
}

.dropdown-item-title {
    font-weight: 500;
    font-size: 0.9rem;
}

.dropdown-item-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.chat-actions-left,
.chat-actions-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-generate-submit {
    background: transparent;
    color: var(--text);
    border: none;
    border-radius: 12px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: color 0.2s, transform 0.1s;
}

.btn-generate-submit:hover:not(:disabled) {
    transform: scale(1.05);
}

.btn-generate-submit:disabled {
    color: var(--muted);
    opacity: 0.3;
    cursor: not-allowed;
}

.btn-generate-submit.is-generating .send-icon {
    display: none !important;
}

.btn-generate-submit.is-generating .stop-icon {
    display: inline-block !important;
    color: var(--accent) !important;
}

.btn-generate-submit.is-generating {
    cursor: pointer !important;
    opacity: 1 !important;
    background: transparent !important;
}

.btn-generate-submit.is-generating .stop-circle {
    transform-origin: center;
    animation: stop-circle-spin 2s linear infinite, stop-circle-dash 1.5s ease-in-out infinite;
    stroke-linecap: round;
}

@keyframes stop-circle-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes stop-circle-dash {
    0% {
        stroke-dasharray: 1, 63;
        stroke-dashoffset: 0;
    }

    50% {
        stroke-dasharray: 45, 63;
        stroke-dashoffset: -15;
    }

    100% {
        stroke-dasharray: 1, 63;
        stroke-dashoffset: -62;
    }
}

.action-icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.action-icon-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.suggestion-pills-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
    justify-content: center;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 220ms ease, transform 220ms ease, visibility 0s linear;
}

.suggestion-pills-row.is-dismissed {
    opacity: 0;
    transform: translateY(-7px);
    visibility: hidden;
    pointer-events: none;
    transition: opacity 220ms ease, transform 220ms ease, visibility 0s linear 220ms;
}

.suggestion-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion-pill:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--text-secondary);
    transform: translateY(-2px);
}

/* Drag and Drop Overlay Styling */
.drag-drop-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(10, 10, 10, 0.75);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s;
}

.drag-drop-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    display: flex !important;
    /* Keep display flex so transition works */
}

.drag-drop-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    text-align: center;
    padding: 2rem;
    animation: scaleInDrag 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes scaleInDrag {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.drag-drop-icon {
    color: var(--accent, #0066FF);
    display: flex;
    align-items: center;
    justify-content: center;
}

.drag-drop-icon svg {
    width: 96px;
    height: 96px;
    stroke-width: 1.1;
}

.drag-drop-text {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 700;
    color: #ffffff;
    max-width: 500px;
    letter-spacing: -0.01em;
    line-height: 1.4;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.drag-drop-overlay * {
    pointer-events: none;
}

/* Light mode adjustments */
:root[data-theme="light"] .drag-drop-overlay {
    background: rgba(255, 255, 255, 0.75);
}

:root[data-theme="light"] .drag-drop-text {
    color: #111827;
    text-shadow: none;
}

.suggestion-pill:disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
    filter: grayscale(100%);
}

@media (prefers-reduced-motion: reduce) {
    .suggestion-pills-row,
    .suggestion-pills-row.is-dismissed {
        transition: none;
        transform: none;
    }
}

#btn-attach-file:disabled {
    opacity: 0.3 !important;
    pointer-events: none !important;
    cursor: not-allowed;
    color: var(--muted) !important;
}

#btn-attach-file:disabled svg {
    stroke: var(--muted) !important;
}

/* ========================================== */
/* MODERN CHAT MODE FLOW & POSITIONING        */
/* ========================================== */

/* Chat Mode Layout (Claude/Perplexity Style) */
#chat-screen.chat-mode {
    align-items: flex-start !important;
    height: 100vh !important;
    max-height: 100vh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow-y: auto !important;
    scroll-padding-top: 5.3rem;
    scroll-padding-bottom: calc(var(--chat-composer-clearance, 12rem) + 3rem);
    scrollbar-gutter: stable both-edges;
    padding: 0 !important;
}

#chat-screen.chat-mode .chat-container {
    animation: none !important;
    transform: none !important;
    /* Keep the fixed composer above the fade instead of trapping it in
       the chat container's lower stacking context. */
    z-index: auto !important;
    height: auto !important;
    min-height: auto !important;
    /* let content determine height, not the viewport */
    flex-shrink: 0 !important;
    /* CRITICAL: grows with content, never shrinks */
    max-width: 760px !important;
    margin: 0 auto !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 5.3rem 1rem calc(var(--chat-composer-clearance, 12rem) + 3rem) !important;
    gap: 1.5rem !important;
    box-sizing: border-box !important;
}

/* Give a fresh reply enough scroll room to appear below the top bar while
   its thinking panel is active, even after a long previous outline. */
#chat-screen.chat-mode .chat-container:has(.chat-thinking-panel.is-active) {
    padding-bottom: max(12rem, calc(100dvh - 7rem)) !important;
}

#chat-screen.chat-mode #hero-zone {
    display: none !important;
}

#chat-screen.chat-mode #suggestion-pills-row,
#chat-screen.chat-mode .chat-counter-row,
#chat-screen.chat-mode .app-microcopy {
    display: none !important;
}

/* Float a cozy, narrow, blurred bubble at the bottom center of the screen */
#chat-screen.chat-mode .chat-input-wrapper {
    position: fixed !important;
    bottom: calc(1.5rem + env(safe-area-inset-bottom) + var(--chat-keyboard-inset, 0px)) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: calc(100% - 2rem) !important;
    max-width: 728px !important;
    /* Extremely elegant and perfectly aligned */
    background: rgba(12, 12, 12, 0.85) !important;
    backdrop-filter: blur(24px) !important;
    -webkit-backdrop-filter: blur(24px) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 18px !important;
    padding: 0.62rem 0.82rem 0.74rem !important;
    /* Restore cozy, default padding */
    box-shadow: none !important;
    z-index: 1000 !important;
    margin: 0 !important;
    box-sizing: border-box !important;
}

:root[data-theme="light"] #chat-screen.chat-mode .chat-input-wrapper {
    background: rgba(255, 255, 255, 0.85) !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08) !important;
}

#chat-screen.chat-mode .conversation-zone {
    flex: none !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* Webkit Scrollbar for Main Viewport */
#chat-screen.chat-mode::-webkit-scrollbar {
    width: 6px !important;
}

#chat-screen.chat-mode::-webkit-scrollbar-track {
    background: transparent !important;
}

#chat-screen.chat-mode::-webkit-scrollbar-thumb {
    background: var(--border, rgba(255, 255, 255, 0.1)) !important;
    border-radius: 10px !important;
}

/* ── Mobile: hide scrollbar (it clutters small screens) ── */
@media (max-width: 850px) {
    #chat-screen.chat-mode .chat-input {
        /* Leave room for the header, outline action and toolbar above a keyboard. */
        max-height: min(250px, max(64px, min(calc(var(--chat-viewport-height, 100dvh) * .25), calc(var(--chat-viewport-height, 100dvh) - 22rem - env(safe-area-inset-bottom))))) !important;
    }
    #chat-screen.chat-mode {
        scrollbar-gutter: auto;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
    }

    #chat-screen.chat-mode::-webkit-scrollbar {
        display: none !important;
    }
}

/* ── Top bar: gradient so text fades softly as it scrolls under the bar ── */
/* Only in chat-mode. Does not affect normal landing page. */
#chat-screen.chat-mode .top-control-bar {
    height: 85px !important;
    background: transparent !important;
    align-items: flex-start !important;
}

#chat-screen.chat-mode .top-control-panel {
    height: 54px;
}

#chat-screen.chat-mode .top-control-bar::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--bg);
    -webkit-mask-image: linear-gradient(to bottom, black 65%, transparent 100%);
    mask-image: linear-gradient(to bottom, black 65%, transparent 100%);
    pointer-events: none;
    z-index: -1;
}

/* ── Input wrapper: fully opaque so text behind it is not visible ── */
#chat-screen.chat-mode .chat-input-wrapper {
    background: var(--bg) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

:root[data-theme="light"] #chat-screen.chat-mode .chat-input-wrapper {
    background: var(--bg) !important;
}

/* ========================================== */
/* SUGGESTED FOLLOW-UP CHIPS                  */
/* ========================================== */
.outline-suggested-chips {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
    padding: 0.75rem 0 0.35rem !important;
    margin: 0 !important;
}

.suggested-chip {
    background: rgba(255, 255, 255, 0.04) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: #b3b3b3 !important;
    padding: 0.38rem 0.75rem !important;
    border-radius: 99px !important;
    font-size: 0.8rem !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    transition: background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.35rem !important;
}

.suggested-chip:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
    transform: translateY(-1px) !important;
}

.suggested-chip.chip-primary {
    background: rgba(0, 102, 255, 0.12) !important;
    border-color: rgba(0, 102, 255, 0.35) !important;
    color: #38bdf8 !important;
}

.suggested-chip.chip-primary:hover {
    background: rgba(0, 102, 255, 0.2) !important;
    border-color: rgba(0, 102, 255, 0.5) !important;
    color: #ffffff !important;
}

/* Light Mode Overrides for Suggested Chips */
:root[data-theme="light"] .suggested-chip {
    background: rgba(0, 0, 0, 0.04) !important;
    border: 1px solid rgba(0, 0, 0, 0.1) !important;
    color: #4b5563 !important;
}

:root[data-theme="light"] .suggested-chip:hover {
    background: rgba(0, 0, 0, 0.08) !important;
    border-color: rgba(0, 0, 0, 0.2) !important;
    color: #111827 !important;
}

:root[data-theme="light"] .suggested-chip.chip-primary {
    background: rgba(0, 102, 255, 0.08) !important;
    border-color: rgba(0, 102, 255, 0.2) !important;
    color: #0056d6 !important;
}

:root[data-theme="light"] .suggested-chip.chip-primary:hover {
    background: rgba(0, 102, 255, 0.15) !important;
    border-color: rgba(0, 102, 255, 0.3) !important;
    color: #003e99 !important;
}

/* Fade chat content before it reaches the fixed composer, then fully cover
   the area behind and below it. The clearance follows composer height. */
#chat-screen.chat-mode::after {
    content: '' !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: calc(var(--chat-composer-clearance, 12rem) + 2.5rem) !important;
    background: linear-gradient(to bottom, transparent, var(--bg) 2.5rem, var(--bg)) !important;
    z-index: 999 !important;
    pointer-events: none !important;
}
