header {
    flex-shrink: 0;
    height: calc(var(--header-height) + var(--safe-area-top));
    display: flex;
    align-items: flex-end;
    padding: 0 20px 10px 20px;
    z-index: 2000;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    width: 100%;
    position: relative;
    transition: height 0.2s ease;
}

/* App container: no page-level scroll, only main scrolls */
#app {
    height: var(--app-height, 100vh);
    overflow: hidden;
    min-height: 0;
}

/* Editor mode - taller header for 2 rows */
header.editor-mode {
    height: calc(110px + var(--safe-area-top));
    align-items: flex-start;
    padding-top: 10px;
}

main {
    height: calc(var(--app-height, 100vh) - var(--header-height) - var(--safe-area-top));
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    position: relative;
    padding: 20px 20px 20px 20px; /* Base padding */
    display: flex;
    flex-direction: column;
}

main::after {
    content: "";
    display: block;
    height: 120px;
    width: 100%;
    flex-shrink: 0;
}

#app.landing main {
    height: var(--app-height, 100vh);
    padding: 0;
}

main>.view {
    width: 100%;
    min-height: 100%;
    flex-grow: 1;
}

.header-content {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 15px;
    margin-bottom: 5px;
}

.badge-count {
    margin-left: 10px;
    background: var(--bg-elevated);
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    opacity: 0.8;
    display: none;
}

.back-btn-pos {
    display: none;
}

/* Floating nav button — fullscreen da ham ko'rinadi */
#webapp-nav-btn {
    position: fixed;
    top: calc(var(--safe-area-top, 0px) + 10px);
    left: 12px;
    z-index: 9999;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    display: none;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    cursor: pointer;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    transition: background 0.15s, transform 0.15s;
}

#webapp-nav-btn:active {
    background: rgba(255, 255, 255, 0.22);
    transform: scale(0.92);
}

.debug-overlay {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    pointer-events: none;
}

h1 {
    font-size: 1.2rem;
    font-weight: 700;
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    height: 68px;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--bg-elevated);
    border-radius: 24px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 10px;
    z-index: 2000;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

@media (min-width: 768px) {
    .bottom-nav {
        width: calc(600px - 40px);
        left: 50%;
        transform: translateX(-50%);
    }
}

.nav-item {
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 0;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex: 1;
    height: 52px;
    position: relative;
}

.nav-item svg {
    width: 28px;
    height: 28px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

@media (hover: hover) {
    .nav-item:hover svg {
        transform: translateY(-1px);
        filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    }
}

.nav-item:active {
    transform: scale(0.95);
    background: var(--bg-subtle);
}

.nav-item.active {
    color: var(--accent-color);
    background: rgba(56, 189, 248, 0.1);
}

.nav-item.active svg {
    transform: scale(1.1);
    filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.4));
}

/* Premium glow effect for active nav */
.nav-item.active::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    background: radial-gradient(circle, rgba(56, 189, 248, 0.2) 0%, transparent 70%);
    transform: translate(-50%, -50%);
    border-radius: 50%;
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% {
        opacity: 0.5;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        opacity: 0.8;
        transform: translate(-50%, -50%) scale(1.1);
    }
}

/* Footer Actions */
.footer-actions {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    padding: 16px 20px;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--bg-elevated);
    border-radius: 20px;
    z-index: 1000;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

@media (min-width: 768px) {
    .footer-actions {
        width: calc(600px - 40px);
        left: 50%;
        transform: translateX(-50%);
    }
}

/* Desktop Responsiveness & Background */
.bg-blobs {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    background: var(--bg-color);
    pointer-events: none;
}

.blob {
    position: absolute;
    width: 600px;
    height: 600px;
    background: rgba(56, 189, 248, 0.05);
    filter: blur(80px);
    border-radius: 50%;
    contain: strict;
    animation: blobFloat 20s ease-in-out infinite;
}

.blob-1 {
    top: -10%;
    left: -10%;
    animation-delay: 0s;
}

.blob-2 {
    bottom: -10%;
    right: -10%;
    background: rgba(236, 72, 153, 0.05);
}

.blob-3 {
    top: 40%;
    left: 60%;
    animation-delay: -10s;
    width: 400px;
    height: 400px;
}

@keyframes blobFloat {
    0% {
        transform: translate(0, 0) scale(1);
    }

    33% {
        transform: translate(30px, -50px) scale(1.1);
    }

    66% {
        transform: translate(-20px, 20px) scale(0.9);
    }

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

@media (min-width: 768px) {
    body {
        display: flex;
        justify-content: center;
        background-color: var(--bg-color);
    }

    #app {
        width: 100%;
        max-width: 600px;
        margin: 0 auto;
        height: var(--app-height, 100vh);
        min-height: 0;
        overflow: hidden;
        background-color: transparent;
        position: relative;
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
        transition: max-width 0.3s ease;
    }

    #app.landing {
        max-width: 100%;
        border-left: none;
        border-right: none;
    }

    header {
        width: 100%;
        max-width: 600px;
    }

    .bottom-nav {
        width: calc(600px - 40px);
        left: 50%;
        transform: translateX(-50%);
        bottom: 25px;
    }

    .footer-actions {
        width: 100%;
        max-width: 600px;
        left: 50%;
        transform: translateX(-50%);
    }

    .loader-container {
        left: 50%;
        transform: translate(-50%, -50%);
        max-width: 600px;
    }
}

/* Editor Header Controls */
#editor-header-controls {
    display: none;
    /* Controlled by JS */
    flex-direction: column;
    width: 100%;
    gap: 8px;
}

.editor-header-row {
    display: flex;
    align-items: center;
    width: 100%;
}

.editor-header-title-row {
    gap: 8px;
}

.editor-header-actions-row {
    gap: 10px;
}

.editor-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
    flex-grow: 1;
    margin: 0;
}

.header-search {
    flex-grow: 1;
}

.header-search input {
    background: var(--bg-inset);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 8px 12px;
    border-radius: 8px;
    width: 100%;
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s;
}

.header-search input:focus {
    background: var(--bg-elevated);
    border-color: var(--accent-color);
}

.add-q-sticky-btn {
    padding: 0 12px;
    width: auto;
    font-size: 0.9rem;
    height: 36px;
    white-space: nowrap;
}

.add-q-sticky-btn.compact {
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    font-size: 1.2rem;
    line-height: 1;
}

/* Mobile optimization for editor header */
@media (max-width: 400px) {
    .editor-title {
        font-size: 1rem;
    }

    .editor-header-actions-row .badge-count {
        display: none;
    }

    #header-add-btn span {
        font-size: 0.85rem;
    }

    .header-search input {
        font-size: 0.85rem;
    }
}
