/* 
 * Reset & Base Styles
 * Modern CSS reset with Liquid Glass foundation
 * Поддержка темной и светлой темы
 */

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

:root {
    /* На мобильной ширине app-loader подключает viewport-app-vh.js и может задать px с visualViewport */
    --app-vh: 100vh;
    --app-vw: 100vw;
}

@supports (height: 100dvh) {
    :root {
        --app-vh: 100dvh;
        --app-vw: 100dvw;
    }
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    scroll-behavior: smooth;
    min-height: 100%;
    min-height: -webkit-fill-available;
    background: var(--bg-gradient);
}

body {
    min-height: 100vh;
    min-height: var(--app-vh);
    min-height: -webkit-fill-available;
    background: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    letter-spacing: var(--tracking-normal);
    overflow-x: hidden;
}

/* Lit SPA (CRM, Sync, RAG, Flows): iOS не должен скроллить document — иначе «едет» весь экран с хедером */
html:has(body.platform-shell) {
    height: 100%;
    overflow: hidden;
    /*
     * Иначе window.scrollTo(0,0) из viewport-app-vh.js наследует scroll-behavior: smooth у html
     * и визуально «тянет» экран вниз после скачка клавиатуры.
     */
    scroll-behavior: auto;
}

body.platform-shell {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

/*
 * Узкая ширина: высота документа = var(--app-vh) из visualViewport (viewport-app-vh.js).
 * Иначе на iOS Safari height: 100% цепляется к layout viewport (полный экран), а shell — к
 * уменьшенной видимой области при клавиатуре: пустой зазор и «улёт» композера вверх.
 */
@media (max-width: 767px) {
    html:has(body.platform-shell) {
        height: var(--app-vh, 100%);
        min-height: var(--app-vh, 100%);
        max-height: var(--app-vh, 100%);
    }

    body.platform-shell {
        height: var(--app-vh, 100%);
        min-height: var(--app-vh, 100%);
        max-height: var(--app-vh, 100%);
    }
}

/* Animated background orbs for depth */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.15;
    pointer-events: none;
    z-index: -1;
}

body::before {
    width: 600px;
    height: 600px;
    background: var(--accent);
    top: -200px;
    right: -200px;
    animation: float 20s ease-in-out infinite;
}

body::after {
    width: 500px;
    height: 500px;
    background: var(--accent-tertiary);
    bottom: -150px;
    left: -150px;
    animation: float 25s ease-in-out infinite reverse;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -30px) scale(1.05); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(20px, 10px) scale(1.02); }
}

/* Light theme - subtle background */
[data-theme="light"] body::before {
    background: var(--accent);
    opacity: 0.08;
}

[data-theme="light"] body::after {
    background: var(--accent-secondary);
    opacity: 0.06;
}

/* Links */
a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--duration-fast) var(--easing-default);
}

a:hover {
    color: var(--accent-hover);
}

/* Images */
img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Form elements */
input, button, textarea, select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    background: none;
    border: none;
}

/* Lists */
ul, ol {
    list-style: none;
}

/* Tables */
table {
    border-collapse: collapse;
    border-spacing: 0;
}

/* Focus styles */
:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* Selection */
::selection {
    background: var(--accent);
    color: white;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--glass-border-medium);
    border-radius: var(--radius-full);
    transition: background var(--duration-fast);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--glass-border-strong);
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border-medium) transparent;
}

/* Hidden elements */
[hidden] {
    display: none !important;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    body::before,
    body::after {
        animation: none;
    }
}

/* Print styles */
@media print {
    body::before,
    body::after {
        display: none;
    }
    
    body {
        background: white;
        color: black;
    }
}
