:root {
    font-size: 16px;
    color-scheme: light;
    /* Aligned to ФотоИИшка tokens (see partials/_brand_head.html). */
    --brand: #7c3aed;
    --brand-dark: #6d28d9;
    --text-primary: #15121f;
    --text-muted: #6b6580;
    --bg-soft: #f5f3fb;
    --surface: #ffffff;
    --border: #e9e6f0;
    --shadow: 0 18px 50px -18px rgba(79, 70, 229, .45);
    /* App-shell stacking tokens. The chrome (topbar z-40, bottom nav z-50) is
       fixed/sticky; a fullscreen media viewer must rise ABOVE both but stay
       below toast notifications (#notification-container, z-[60]) so downloads
       still surface. Lift the VIEWER here — never the chrome. */
    --z-appbar: 40;
    --z-tabbar: 50;
    --z-viewer: 55;
    --z-viewer-close: 56;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-ui, "Nunito"), "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-soft);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a {
    text-decoration: none;
    color: inherit;
}

a:focus-visible,
button:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* Telegram Mini App: force visible text cursor & text color.
   TMA WebView inherits caret-color from Telegram theme vars,
   making the cursor invisible on some themes. */
input,
textarea,
select,
[contenteditable="true"] {
    caret-color: #1e293b !important;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="tel"],
input[type="number"],
textarea,
select {
    color: #1e293b !important;
    -webkit-text-fill-color: #1e293b;
}

input::placeholder,
textarea::placeholder {
    color: #94a3b8 !important;
    -webkit-text-fill-color: #94a3b8;
    opacity: 1;
}

input:disabled,
textarea:disabled,
select:disabled {
    color: #94a3b8 !important;
    -webkit-text-fill-color: #94a3b8;
}

.container {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
}

.logo {
    font-family: var(--font-display, 'Comfortaa'), sans-serif;
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: inherit;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: var(--grad, #6C3CE0);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 16px;
    font-weight: 900;
    transform: rotate(-3deg);
    flex-shrink: 0;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-weight: 500;
}

.main-nav a {
    padding: 0.4rem 0.8rem;
    border-radius: 999px;
    color: var(--text-muted);
    transition: color 0.15s ease, background 0.15s ease;
}

.main-nav a:hover {
    color: var(--brand);
    background: rgba(90, 70, 255, 0.08);
}

.site-main {
    padding-top: 2rem;
}

/* App shell (editor / gallery / account): one locked-viewport scroll context.
   The body becomes a fixed-height flex column — topbar stays pinned at the top,
   the fixed bottom nav stays pinned at the bottom, and <main> is the ONLY
   scroller. Uses 100dvh so the mobile address-bar show/hide can't shift the
   topbar. Scoped to .app-shell so normal site pages keep document scroll. */
body.app-shell {
    height: 100vh;        /* fallback for browsers without dvh */
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Topbar (the only direct <header> in the shell) is a locked, non-scrolling item. */
body.app-shell > header {
    flex: 0 0 auto;
    /* Telegram Mini App fullscreen: the device status bar + Telegram's native
       controls (Закрыть / collapse / ⋯) overlay the top edge. Pad the header
       down by the Telegram top insets so its bg-white/90 backdrop paints the
       inset zone and the logo/credits clear the controls. The --tg-* vars are
       maintained by the SDK and are 0 outside TMA fullscreen → zero change in a
       browser. max() with env() also covers a non-TMA notch without double
       counting the same physical inset. */
    padding-top: max(
        calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)),
        env(safe-area-inset-top, 0px)
    );
}

body.app-shell > main.site-main {
    flex: 1 1 auto;
    min-height: 0;            /* allow the flex item to shrink so it scrolls */
    overflow-y: auto;
    /* The app shell never scrolls horizontally. overflow-x MUST be set explicitly:
       with only overflow-y:auto, overflow-x computes to `auto` too, so any child
       wider than the viewport gives the whole page a horizontal scrollbar. `hidden`
       both prevents that and (as a scroll container) stops a wide child's
       min-content from widening the page — wide rows must scroll themselves. */
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-top: 0;          /* topbar is a real flex item — no extra offset */
    /* Clear the fixed bottom nav (h-14 = 56px) + iOS safe area. */
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
}

.main-wrapper {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Fullscreen media viewer (#mediaPreviewModal). It lives inside <main> but no
   ancestor creates a stacking context (main is a flex item with z-index:auto,
   no transform/opacity/filter), so a plain z-index lifts it correctly. The bug
   was a z-index TIE with the bottom nav (both 50): the later-in-DOM nav painted
   on top. Token raises the viewer above the chrome without touching the chrome. */
.media-viewer {
    z-index: var(--z-viewer);
}

/* Close (X): pinned to the viewport top-right, clear of the notch via the iOS
   safe-area inset. Child of the viewer root (not the shell header) so it rides
   the viewer's stacking level. 44px min tap target. In TMA fullscreen the same
   --tg-* top insets keep the X below Telegram's ⋯ control row (vars are 0
   elsewhere, so the env()/12px floor governs as before). */
.media-viewer-close {
    position: absolute;
    top: max(
        calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px) + 12px),
        calc(env(safe-area-inset-top, 0px) + 12px),
        12px
    );
    right: 12px;
    z-index: var(--z-viewer-close);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hero {
    background: linear-gradient(135deg, rgba(90, 70, 255, 0.08), rgba(236, 229, 255, 0.7));
    border-radius: 32px;
    margin-top: 1rem;
    overflow: hidden;
}

.hero-inner {
    padding: 4rem 2rem;
}

.hero-content {
    text-align: center;
    max-width: 680px;
    margin: 0 auto;
}

.badge {
    display: inline-block;
    padding: 0.35rem 1rem;
    border-radius: 999px;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
    background: rgba(19, 17, 28, 0.08);
    color: var(--brand);
    margin-bottom: 1.2rem;
}

.hero h1 {
    font-weight: 800;
    letter-spacing: -0.02em;
    font-size: clamp(2.3rem, 5vw, 3.6rem);
    line-height: 1.2;
    margin-bottom: 1rem;
}

.hero .subtitle {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 1.8rem;
}

.hero-actions {
    display: flex;
    justify-content: center;
}

.cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.9rem 2.8rem;
    border-radius: var(--pill, 999px);
    font-weight: 700;
    background: var(--grad, var(--brand));
    color: #fff;
    box-shadow: var(--shadow, 0 18px 35px rgba(90, 70, 255, 0.3));
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 25px 45px rgba(90, 70, 255, 0.35);
}

.section {
    padding: 2rem 0;
}

.section.alt {
    background: var(--surface);
    border-radius: 32px;
    box-shadow: var(--shadow);
}

.section-inner {
    padding: 2rem 0;
}

.section-heading {
    margin-bottom: 2rem;
}

.section-heading h2 {
    font-weight: 800;
    letter-spacing: -0.02em;
    font-size: 2rem;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
}

.card {
    background: var(--card, var(--surface));
    border-radius: var(--r-card, 1.2rem);
    padding: 1.6rem;
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow: var(--shadow);
}

.card h3 {
    font-weight: 700;
    letter-spacing: -0.01em;
    font-size: 1.2rem;
    margin-bottom: 0.75rem;
}

.card p,
.card li {
    color: var(--text-muted);
}

.benefits-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.paragraph-card {
    border-radius: 1.2rem;
    background: var(--surface);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    color: var(--text-muted);
}

.faq {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 0.6rem;
    margin-bottom: 1rem;
    font-size: 0.95rem;
    font-weight: 500;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
}

.alert-info {
    background: #e0f2fe;
    color: #075985;
}

.auth-form label {
    display: block;
    margin-top: 1rem;
    margin-bottom: 0.3rem;
    font-weight: 600;
}

.auth-form input {
    width: 100%;
    padding: 0.7rem;
    border-radius: 0.6rem;
    border: 1px solid var(--border);
    font-size: 1rem;
    transition: border 0.15s ease, box-shadow 0.15s ease;
}

.auth-form input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(90, 70, 255, 0.15);
    outline: none;
}

.site-footer {
    background: #0f0c1f;
    color: rgba(255, 255, 255, 0.8);
    margin-top: 3rem;
}

.footer-inner {
    padding: 2rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    text-align: center;
}

@media (max-width: 768px) {
    .header-inner {
        flex-direction: column;
        gap: 0.7rem;
        padding: 0.8rem 0;
    }

    .main-nav {
        flex-wrap: wrap;
        justify-content: center;
    }

    .hero-inner {
        padding: 3rem 1.5rem;
    }

    .section.alt {
        border-radius: 20px;
    }
}

@media (max-width: 600px) {
    .cards {
        grid-template-columns: 1fr;
    }

    .main-wrapper {
        gap: 1.5rem;
    }
}

/* ============================================ */
/* Mobile-Adaptive Responsive Styles */
/* ============================================ */

/* Mobile-specific styles for product detail page */
@media (max-width: 767px) {
    /* Touch-friendly tap targets */
    button, a, input, select, textarea {
        min-height: 44px;
    }

    /* Standalone "Мои правки" card actions (Изменить / скачать / удалить): the
       44px tap-target floor above over-inflates these compact icon/label buttons
       on mobile; let their padding define the height (matches desktop/iPad). */
    .edit-card button {
        min-height: 0;
    }

    /* Prevent text selection on buttons */
    button {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }

    /* Smooth scrolling */
    .overflow-y-auto {
        -webkit-overflow-scrolling: touch;
    }

    /* Hide scrollbar but keep functionality */
    .overflow-x-auto::-webkit-scrollbar {
        display: none;
    }
    .overflow-x-auto {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    /* Safe area for iOS */
    .safe-area-bottom {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* iOS auto-zoom prevention — iOS Safari zooms into inputs with font < 16px */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="url"],
    input[type="tel"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px !important;
    }
}

/* Animation utilities */
@keyframes slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@keyframes slide-in-right {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.animate-slide-up {
    animation: slide-up 0.3s ease-out;
}

.animate-slide-in-right {
    animation: slide-in-right 0.3s ease-out;
}

.animate-fade-in {
    animation: fade-in 0.2s ease-out;
}

/* Mobile menu transitions */
#mobileMenuBackdrop {
    transition: opacity 0.3s ease;
}

#mobileMenuDrawer {
    transition: transform 0.3s ease;
}

/* Selection action bar mobile positioning */
@media (max-width: 767px) {
    #selectionActionBar {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
}

/* ==========================================
   Balance Badge & Credit Styles
   ========================================== */

/* Tabular numbers for balance display */
.tabular-nums {
    font-variant-numeric: tabular-nums;
}

/* Balance badge hover effect */
.balance-badge:hover {
    transform: translateY(-1px);
}

/* Pulse animation for low balance indicator */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.animate-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Credit cost badge on buttons */
.credit-cost-badge {
    font-size: 0.7rem;
    white-space: nowrap;
}

/* Button with credit cost */
.btn-with-cost {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

/* Disabled state for zero balance */
.btn-disabled-no-credits {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Low balance warning in sidebar */
.low-balance-warning {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Modal backdrop blur */
.backdrop-blur-sm {
    backdrop-filter: blur(4px);
}

/* ==========================================
   Generation Retry Notifications
   ========================================== */

/* Slide in animation for retry notification */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

#generation-retry-notification {
    animation: slideInRight 0.3s ease-out;
}

/* Generation loading states */
.generation-loading {
    position: relative;
    pointer-events: none;
}

.generation-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    border-radius: inherit;
}

.generation-loading-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    background: white;
    padding: 1rem 2rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Spinner animation */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.animate-spin {
    animation: spin 1s linear infinite;
}

/* Notification toast base styles */
.notification-toast {
    animation: slideInRight 0.3s ease-out;
    max-width: 400px;
}

/* Notification mobile adjustments */
@media (max-width: 767px) {
    #notification-container {
        top: 4.5rem; /* Clear mobile header */
        right: 0.75rem;
        left: auto;
        max-width: calc(100vw - 1.5rem);
    }

    #notification-container > div {
        width: 100%;
        max-width: 100%;
    }
}

/* ==========================================
   Balance Update Animations
   ========================================== */

@keyframes balance-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.balance-updated {
    animation: balance-pulse 0.4s ease-out;
}

.balance-decreased {
    color: #ef4444 !important; /* red-500 */
    transition: color 0.3s ease;
}

.balance-increased {
    color: #22c55e !important; /* green-500 */
    transition: color 0.3s ease;
}

/* Restore original color after animation */
.sidebar-balance-count,
#header-balance-count,
.mobile-balance-count {
    transition: color 0.3s ease 0.3s;
}

/* ==========================================
   Selection Action Bar Stacking Fix
   ========================================== */

/* Force selection bar to top of stacking order */
#selectionActionBar {
    /* Create a new stacking context at the root level */
    isolation: isolate;
    /* Use very high z-index */
    z-index: 9999 !important;
}

/* Ensure buttons inside are clickable */
#selectionActionBar button {
    position: relative;
    z-index: 1;
    cursor: pointer;
}

/* When hidden, don't intercept events */
#selectionActionBar.opacity-0 {
    pointer-events: none !important;
}

#selectionActionBar:not(.opacity-0) {
    pointer-events: auto !important;
}

/* ============================================ */
/* TMA / narrow viewport button fixes           */
/* ============================================ */
@media (max-width: 500px) {
    /* Action buttons: prevent text overflow */
    #apply-edit-btn,
    #generate-submit-btn,
    #video-generate-btn,
    [id$="-action-btn"],
    [id$="-generate-btn"] {
        font-size: 15px !important;
        padding-left: 12px !important;
        padding-right: 12px !important;
        flex-wrap: wrap !important;
        gap: 4px !important;
    }

    /* Credit badges: keep compact */
    #apply-edit-btn .credit-cost-badge,
    #generate-submit-btn .credit-cost-badge,
    #video-generate-btn .credit-cost-badge,
    [id$="-action-btn"] .credit-cost-badge {
        font-size: 12px !important;
        white-space: nowrap !important;
    }
}

/* ==========================================================================
   In-flight feedback bottom sheet (Prompt W) — feedback-sheet.js
   Budget: fits 390x667 with no internal scroll (total sheet ≤ ~470px).
   ========================================================================== */
.uf-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;                 /* above app chrome; sheet closes before toasts */
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(21, 18, 31, .45);
    animation: uf-fade .18s ease-out;
}

@keyframes uf-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes uf-rise { from { transform: translateY(16px); } to { transform: translateY(0); } }
@keyframes uf-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.uf-sheet {
    width: 100%;
    max-width: 480px;
    max-height: calc(100dvh - 12px);
    overflow-y: auto;            /* defensive: no scroll at 390x667, only on tinier */
    box-sizing: border-box;
    background: var(--surface, #fff);
    color: var(--text-primary, #15121f);
    border-radius: 20px 20px 0 0;
    padding: 16px;
    /* Respect the BOTTOM safe area in TMA fullscreen (SDK vars) and iOS notch. */
    padding-bottom: max(
        calc(16px + var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px)),
        calc(16px + env(safe-area-inset-bottom, 0px))
    );
    box-shadow: 0 -18px 50px -18px rgba(79, 70, 229, .45);
    animation: uf-rise .22s ease-out;
}

.uf-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.uf-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted, #6b6580);
}
.uf-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--brand, #7c3aed);
    animation: uf-pulse 1.2s ease-in-out infinite;
}
.uf-close {
    border: 0;
    background: transparent;
    color: var(--text-muted, #6b6580);
    font-size: 16px;
    line-height: 1;
    padding: 4px 6px;
    cursor: pointer;
    border-radius: 8px;
}
.uf-close:hover { background: var(--bg-soft, #f5f3fb); }

.uf-title {
    font-size: 17px;
    font-weight: 700;
    margin: 0 0 2px;
    line-height: 1.25;
}
.uf-sub {
    font-size: 13px;
    color: var(--text-muted, #6b6580);
    margin: 0 0 12px;
}
.uf-q {
    font-size: 13px;
    font-weight: 600;
    margin: 0 0 6px;
}
.uf-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}
.uf-chip {
    font-size: 13px;
    line-height: 1.2;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--border, #e9e6f0);
    background: var(--surface, #fff);
    color: var(--text-primary, #15121f);
    cursor: pointer;
    transition: background .12s, border-color .12s, color .12s;
}
.uf-chip--on {
    background: var(--brand, #7c3aed);
    border-color: var(--brand, #7c3aed);
    color: #fff;
}
.uf-text {
    width: 100%;
    box-sizing: border-box;
    resize: none;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.35;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid var(--border, #e9e6f0);
    background: var(--surface, #fff);
    color: var(--text-primary, #15121f);
}
.uf-text:focus {
    outline: none;
    border-color: var(--brand, #7c3aed);
}
.uf-hint {
    font-size: 12px;
    color: var(--brand-dark, #6d28d9);
    margin: 6px 0 12px;
}
.uf-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.uf-submit {
    flex: 1 1 auto;
    font-size: 15px;
    font-weight: 700;
    padding: 11px 16px;
    border-radius: 12px;
    border: 0;
    background: var(--brand, #7c3aed);
    color: #fff;
    cursor: pointer;
}
.uf-submit:disabled {
    opacity: .45;
    cursor: not-allowed;
}
.uf-skip {
    flex: 0 0 auto;
    font-size: 14px;
    font-weight: 600;
    padding: 11px 12px;
    border: 0;
    background: transparent;
    color: var(--text-muted, #6b6580);
    cursor: pointer;
}
.uf-foot {
    font-size: 11px;
    color: var(--text-muted, #6b6580);
    text-align: center;
    margin: 10px 0 0;
}

