/* Глобальное правило: .hidden должно всегда скрывать элементы */
.hidden {
    display: none !important;
}

body {
    overflow-x: hidden;
}

.app-shell {
    display: grid;
    grid-template-columns: clamp(16rem, 20vw, 20rem) minmax(0, 1fr);
    position: relative;
    height: 100%;
    min-height: 100dvh;
}

.app-workspace {
    display: grid;
    grid-column: 2;
    grid-template-columns: minmax(0, 1fr) clamp(14rem, 18vw, 16rem);
    height: 100%;
    min-height: 100dvh;
}

.app-shell.projects-collapsed {
    grid-template-columns: 0 minmax(0, 1fr);
}

.chat-workspace {
    display: flex;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
}

.projects-sidebar,
.stages-sidebar {
    min-height: 100dvh;
}

.projects-sidebar {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
}

.stages-sidebar {
    grid-column: 2;
    grid-row: 1;
    position: relative;
    min-width: 0;
    display: flex;
    overflow-y: auto;
}

.app-workspace.stages-collapsed .stages-sidebar {
    min-width: 0;
}

.chat-workspace {
    grid-column: 1;
    grid-row: 1;
}

.app-workspace.stages-collapsed {
    grid-template-columns: minmax(0, 1fr) 4rem;
}

.projects-sidebar,
.stages-sidebar,
.brainstorm-panel,
.mobile-stages-drawer,
.app-backdrop {
    transition: transform 0.2s ease-in-out, opacity 0.15s ease-in-out, width 0.2s ease-in-out;
}

.app-shell.projects-collapsed .projects-sidebar {
    visibility: hidden;
    overflow: hidden;
}

.projects-sidebar.is-open {
    visibility: visible;
}

.app-workspace.stages-collapsed .stage-text,
.app-workspace.stages-collapsed #stage-sidebar-title {
    display: none;
}

.app-workspace.stages-collapsed .stages-sidebar > :first-child {
    justify-content: center;
    padding-right: 0.5rem;
    padding-left: 0.5rem;
}

.app-workspace.stages-collapsed #vertical-stages-container {
    padding-right: 0.5rem;
    padding-left: 0.5rem;
}

.brainstorm-panel {
    display: none;
    position: static !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    z-index: auto !important;
    border-left: 2px solid #818cf8 !important;
    border-radius: 0 !important;
}

.layout-tablet #mobile-stage-drawer,
.layout-desktop #mobile-stage-drawer {
    display: none !important;
}

.mobile-bottom-zone {
    display: none;
}

.layout-tablet .mobile-bottom-zone,
.layout-desktop .mobile-bottom-zone {
    display: none !important;
}

.app-backdrop {
    display: none;
}

.context-menu-chevron {
    position: absolute;
    top: 50%;
    right: 8px;
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    opacity: 0.7;
    transform: translateY(-50%);
}

.composer-input {
    min-height: 56px;
    max-height: 160px;
}

.auth-status-success {
    color: var(--success, #10b981);
}

.auth-status-error {
    color: var(--danger, #ef4444);
}

.msg-row.system-message {
    justify-content: center;
}

.thinking-dots {
    display: inline-block;
    width: 1.25rem;
    overflow: hidden;
    vertical-align: bottom;
    animation: thinking-dots 1.2s steps(4, end) infinite;
}

@keyframes thinking-dots {
    from { width: 0; }
    to { width: 1.25rem; }
}

.message-image-preview {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    cursor: pointer;
}

.generated-image-card {
    position: relative;
    display: inline-block;
    max-width: 100%;
    margin-top: 12px;
}

.generated-image-preview {
    max-width: 100%;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
}

.generated-image-download {
    text-decoration: none;
    backdrop-filter: blur(4px);
}

@media (min-width: 1280px) {
    .stages-sidebar {
        display: flex;
    }

    .brainstorm-panel {
        display: flex;
        grid-column: 2;
        grid-row: 1;
        position: relative !important;
        z-index: 30 !important;
        min-height: 0;
        background-color: rgba(255, 255, 255, 0.97) !important;
        border-width: 0 0 0 2px;
        border-radius: 0;
        box-shadow: -12px 0 32px -8px rgba(99, 102, 241, 0.25), -4px 0 8px -2px rgba(99, 102, 241, 0.12);
    }

    .dark .brainstorm-panel {
        background-color: rgba(17, 24, 39, 0.97) !important;
    }

    .brainstorm-panel:not(.is-open) {
        display: none;
    }

    .brainstorm-panel.collapsed {
        align-self: end;
        height: 40px;
        min-height: 40px;
        border-width: 2px 0 0;
    }

    .brainstorm-panel.collapsed #brainstorm-content {
        display: none;
    }
}

@media (min-width: 768px) and (max-width: 1279px) {
    .app-shell {
        grid-template-columns: minmax(10rem, 13rem) minmax(0, 1fr);
    }

    .app-shell.projects-collapsed {
        grid-template-columns: 0 minmax(0, 1fr);
    }

    .app-workspace,
    .app-workspace.stages-collapsed {
        grid-template-columns: minmax(0, 1fr) minmax(3rem, 4rem);
    }

    .stages-sidebar {
        display: flex;
    }

    .stages-sidebar .stage-text,
    .stages-sidebar #stage-sidebar-title {
        display: none;
    }

    .stages-sidebar > :first-child {
        justify-content: center;
        padding-right: 0.5rem;
        padding-left: 0.5rem;
    }

    #vertical-stages-container {
        padding-right: 0.5rem;
        padding-left: 0.5rem;
    }

    .brainstorm-panel {
    display: none;
    position: static !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    z-index: auto !important;
    border-left: 2px solid #818cf8 !important;
    border-radius: 0 !important;
}
}

@media (max-width: 767px) {
    #stats-display,
    #current-project-name,
    .app-header-status {
        display: none !important;
    }

    .app-header-brand {
        flex: 1 1 auto;
        gap: 0.5rem;
        overflow: visible;
    }

    .app-header-mark {
        width: 1.5rem;
        height: 1.5rem;
        border-radius: 0.5rem;
        font-size: 0.75rem;
    }

    .app-header-title {
        font-size: 0.75rem;
        line-height: 1rem;
        overflow: visible;
        text-overflow: clip;
        white-space: nowrap;
    }

    /* Основная оболочка — вертикальная колонка на всю высоту */
    .app-shell {
        display: flex;
        flex-direction: column;
        height: 100dvh;
        min-height: 100dvh;
        overflow-y: scroll;
        scroll-snap-type: y mandatory;
        scroll-behavior: smooth;
    }

    .app-workspace {
        display: flex;
        flex: 0 0 auto;
        flex-direction: column;
        min-height: 0;
        overflow: visible;
    }

    .chat-workspace {
        display: flex;
        flex: 0 0 100dvh;
        flex-direction: column;
        height: 100dvh;
        min-height: 100dvh;
        overflow: visible;
        scroll-snap-align: start;
        scroll-snap-stop: always;
    }

    .mobile-bottom-zone {
        position: relative;
        display: flex;
        flex: 0 0 100dvh;
        flex-direction: column;
        min-height: 100dvh;
        overflow: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-align: start;
        scroll-snap-stop: always;
        background: var(--mobile-bottom-bg, #f9fafb);
        border-top: 1px solid #e5e7eb;
    }

    .dark .mobile-bottom-zone {
        background: #030712;
        border-top-color: #1f2937;
    }

    .mobile-stages-drawer {
        position: static !important;
        display: flex !important;
        flex: 1 1 50%;
        flex-direction: column;
        box-sizing: border-box;
        width: 100% !important;
        min-height: 0 !important;
        transform: none !important;
        box-shadow: none !important;
        border-top: none !important;
        border-right: none !important;
        border-left: none !important;
    }

    .mobile-stage-header {
        flex-shrink: 0;
    }

    #brainstorm-overlay:not(.hidden) {
        display: flex !important;
        position: absolute;
        inset: auto 0 0;
        z-index: 10;
        flex: none;
        flex-direction: column;
        width: 100%;
        height: 40px;
        min-height: 40px;
        overflow: hidden;
        transition: height 220ms ease;
    }

    #brainstorm-overlay:not(.hidden):not(.collapsed) {
        inset: 0;
        height: 100%;
        min-height: 100%;
    }

    #brainstorm-overlay:not(.hidden):not(.collapsed) #brainstorm-messages-mobile {
        max-height: none !important;
    }

    .mobile-brainstorm-header {
        flex-shrink: 0;
    }

    #brainstorm-messages-mobile {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #brainstorm-overlay.collapsed {
        height: 40px;
        min-height: 40px;
    }

    #brainstorm-overlay.collapsed #brainstorm-messages-mobile {
        display: none;
    }

    #brainstorm-overlay.collapsed .mobile-brainstorm-header {
        box-sizing: border-box;
        height: 40px;
        min-height: 40px;
        padding: 0.5rem 1rem;
    }

    .mobile-stages-drawer #mobile-stages-container {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Правый сайдбар и десктопная панель мозгового штурма — скрыты */
    .stages-sidebar,
    .brainstorm-panel {
        display: none !important;
    }

    /* Проекты — шторка слева (прежнее поведение) */
    .projects-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 40;
        width: min(20rem, calc(100vw - 2rem));
        min-height: 100dvh;
        box-shadow: 0 18px 36px rgba(15, 23, 42, 0.24);
        transform: translateX(-100%);
    }

    .projects-sidebar.is-open {
        transform: translateX(0);
    }

    /* Backdrop для проектов */
    .app-backdrop {
        position: fixed;
        inset: 0;
        z-index: 30;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        opacity: 0;
        pointer-events: none;
    }

    .app-backdrop.is-visible {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    /* Шапка — фиксированная высота, без переноса */
    .app-header-actions {
        gap: 0.25rem;
    }

    .header-control {
        padding-right: 0.5rem;
        padding-left: 0.5rem;
    }

    .header-control-label {
        display: none;
    }

    #chat-composer {
        position: sticky;
        bottom: 0;
        z-index: 20;
        box-sizing: border-box;
        padding-bottom: 0 !important;
    }

    #messages {
        flex: none;
        height: calc(100dvh - 14rem);
        overflow-y: auto;
        padding-bottom: 0;
        -webkit-overflow-scrolling: touch;
    }

    #profile-popover {
        position: fixed;
        top: 3.5rem;
        left: 50%;
        right: auto;
        width: min(24rem, calc(100vw - 2rem));
        max-width: none;
        box-sizing: border-box;
        margin-top: 0.5rem;
        margin-bottom: env(safe-area-inset-bottom);
        transform: translateX(-50%);
    }

}

.landing-page {
    grid-column: 2;
    display: grid;
    min-width: 0;
    min-height: 100dvh;
    padding: 2rem;
    overflow-y: auto;
    place-items: center;
    background: radial-gradient(circle at 50% 12%, rgba(129, 140, 248, 0.15), transparent 38%), var(--landing-background, #f9fafb);
}

.dark .landing-page {
    background: radial-gradient(circle at 50% 12%, rgba(99, 102, 241, 0.2), transparent 38%), var(--landing-background, #030712);
}

.chat-workspace > .landing-page {
    grid-column: auto;
    min-height: 0;
    flex: 1 1 auto;
}

.chat-workspace:not(.has-project) #messages,
.chat-workspace:not(.has-project) #chat-composer {
    display: none !important;
}

.chat-workspace:not(.has-project) #landing-placeholder {
    display: grid !important;
    pointer-events: auto;
}

.chat-workspace.has-project #landing-placeholder {
    display: none !important;
    pointer-events: none;
}

.chat-workspace.has-project #messages {
    display: flex !important;
    flex-direction: column;
}

.chat-workspace.has-project #chat-composer {
    display: block !important;
}

.landing-card {
    width: min(100%, 70rem);
    padding: 3rem;
    border: 1px solid var(--landing-border, #e5e7eb);
    border-radius: 1.5rem;
    background: rgba(255, 255, 255, 0.78);
    box-shadow: 0 24px 60px -30px rgba(79, 70, 229, 0.3);
    text-align: center;
}

.dark .landing-card {
    border-color: var(--landing-border, #1f2937);
    background: rgba(17, 24, 39, 0.78);
}

.landing-illustration {
    display: flex;
    align-items: center;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    color: #9ca3af;
    font-size: 0.75rem;
    font-weight: 500;
}

.landing-illustration svg {
    width: 11rem;
    height: 8rem;
}

.landing-illustration-panel {
    fill: #eef2ff;
}

.dark .landing-illustration-panel {
    fill: #312e81;
}

.landing-illustration-path,
.landing-illustration-spark {
    stroke: #6366f1;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 4;
}

.landing-illustration-dot {
    fill: #818cf8;
    stroke: #fff;
    stroke-width: 4;
}

.dark .landing-illustration-dot {
    stroke: #1f2937;
}

.landing-eyebrow {
    margin: 0 0 0.75rem;
    color: #6366f1;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.landing-title {
    margin: 0;
    color: #111827;
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
}

.dark .landing-title {
    color: #f9fafb;
}

.landing-description {
    margin: 1rem 0 2.5rem;
    color: #6b7280;
    font-size: clamp(1rem, 2vw, 1.25rem);
}

.dark .landing-description,
.landing-hint {
    color: #9ca3af;
}

.landing-pipeline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 2.5rem;
}

.pipeline-stage {
    display: flex;
    min-width: 0;
    align-items: center;
    flex: 1 1 0;
    flex-direction: column;
    gap: 0.4rem;
    padding: 1rem 0.5rem;
    border: 1px solid #e0e7ff;
    border-radius: 0.875rem;
    background: #f8faff;
    color: #374151;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.dark .pipeline-stage {
    border-color: #3730a3;
    background: rgba(49, 46, 129, 0.24);
    color: #e0e7ff;
}

.pipeline-number {
    color: #818cf8;
    font-size: 0.625rem;
    letter-spacing: 0.08em;
}

.pipeline-arrow {
    color: #a5b4fc;
    font-size: 1.125rem;
    font-weight: 700;
}

.landing-actions {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}

.landing-create-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.8rem 1.25rem;
    border-radius: 0.75rem;
    background: #4f46e5;
    color: #fff;
    font-size: 0.875rem;
    font-weight: 700;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.landing-create-button:hover {
    background: #4338ca;
}

.landing-create-button:active {
    transform: scale(0.98);
}

.landing-create-button svg {
    width: 1rem;
    height: 1rem;
}

.landing-hint {
    margin: 1rem 0 0;
    font-size: 0.75rem;
}

@media (max-width: 1023px) {
    .landing-page {
        padding: 1.5rem;
    }

    .landing-card {
        padding: 2.5rem 2rem;
    }

    .landing-pipeline {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.75rem;
    }

    .pipeline-arrow {
        display: none;
    }
}

@media (max-width: 767px) {
    .landing-page {
        display: grid;
        padding: 1rem;
    }

    .landing-card {
        padding: 2rem 1.25rem;
        border-radius: 1.25rem;
    }

    .landing-illustration {
        margin-bottom: 1rem;
    }

    .landing-illustration svg {
        width: 9rem;
        height: 6.5rem;
    }

    .landing-description {
        margin-bottom: 2rem;
    }

    .landing-pipeline {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        margin-bottom: 2rem;
    }

    .landing-hint {
        display: none;
    }
}
