/* Оптимизация для мобильных устройств - ТОЛЬКО для экранов <= 768px */

/* Убираем синее выделение при нажатии на мобильных */
@media (max-width: 768px) {
    * {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
    }

    button, a, input, textarea, select {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        outline: none;
    }

    body {
        overflow-x: hidden;
        width: 100%;
        max-width: 100vw;
        min-height: 100vh; /* Минимальная высота экрана */
        height: auto; /* Автоматическая высота */
    }

    .container {
        overflow-x: hidden;
        width: 100%;
        max-width: 100vw;
        padding-top: 0;
        min-height: 100vh; /* Минимальная высота экрана */
        height: auto; /* Автоматическая высота */
    }

    .nav-bar {
        position: sticky;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        margin: 0;
        border-radius: 0;
        padding: 12px 16px;
        height: auto;
        min-height: 56px;
        background: rgba(20, 20, 20, 0.85) !important;
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3) !important;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        z-index: 1000;
        -ms-overflow-style: none;
        overscroll-behavior-x: contain;
    }

    .nav-bar::-webkit-scrollbar {
        display: none;
        width: 0;
        height: 0;
    }

    .nav-inner {
        display: flex;
        align-items: center;
        gap: 12px;
        min-width: max-content;
        width: max-content;
        transform: none !important;
        padding: 0;
        height: 100%;
        box-sizing: border-box;
    }

    .nav-brand {
        flex-shrink: 0;
        margin-right: 8px;
    }

    .nav-brand h1 {
        font-size: 16px;
        font-weight: 600;
        white-space: nowrap;
    }

    .nav-bar a {
        font-size: 14px;
        padding: 8px 12px;
        white-space: nowrap;
        flex-shrink: 0;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .nav-login {
        padding: 8px 16px;
        font-size: 14px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .nav-avatar {
        flex-shrink: 0;
        min-width: 38px;
    }

    /* Контент */
    .content {
        width: 94%;
        max-width: 100%;
        margin: 20px auto 0;
        padding-bottom: 40px;
        overflow-x: hidden;
        overflow-y: visible; /* Разрешаем вертикальную прокрутку */
        min-height: auto;
        height: auto;
    }

    /* Карточки */
    .card {
        width: 100% !important;
        max-width: 100%;
        margin: 0 !important;
        padding: 20px !important;
        border-radius: 16px;
        transform: none !important;
        --shift: 0px !important;
        --tilt: 0deg !important;
        --tilt-x: 0deg !important;
        --tilt-y: 0deg !important;
        box-sizing: border-box;
        overflow: visible !important;
        min-height: auto !important;
        height: auto !important;
    }

    /* Жестко ограничиваем ширину ВСЕХ элементов внутри card-inner */
    .card-inner > *,
    .card-inner form,
    .card-inner form > *,
    .card-inner .form-grid,
    .card-inner .form-grid > * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Поля ввода принудительно не шире контейнера */
    .profile-page .auth-panel input[type="text"],
    .profile-page .auth-panel input[type="email"],
    .profile-page .auth-panel input[type="password"],
    .profile-page .auth-panel .link-btn,
    .profile-page .auth-panel .captcha-box {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .card-primary {
        width: 100% !important;
        max-width: 100%;
        padding: 24px 20px;
        text-align: center;
        box-sizing: border-box;
    }

    .cards {
        gap: 20px;
        margin-top: 24px;
        width: 100%;
        max-width: 100%;
        overflow: visible; /* Убираем обрезание */
        min-height: auto;
        height: auto;
    }

    .cards .card {
        align-self: stretch !important;
        width: 100% !important;
        overflow: visible !important; /* Убираем обрезание */
    }

    /* Заголовки */
    .hero-title {
        font-size: 32px;
        line-height: 1.2;
        margin-bottom: 12px;
    }

    .card h2 {
        font-size: 20px;
        line-height: 1.3;
        margin-bottom: 12px;
    }

    .card h3 {
        font-size: 18px;
        margin-bottom: 10px;
    }

    .card p {
        font-size: 15px;
        line-height: 1.6;
        margin-bottom: 16px;
    }

    /* Кнопки */
    .link-btn {
        width: 100%;
        max-width: 100%;
        padding: 12px 20px;
        font-size: 15px;
        min-height: 44px;
        border-radius: 12px;
        font-weight: 600;
        touch-action: manipulation;
        display: flex !important;
        align-items: center;
        justify-content: center;
        text-align: center;
        margin-left: auto;
        margin-right: auto;
        margin-top: 8px;
        margin-bottom: 8px;
        box-sizing: border-box;
    }

    /* Скрытые кнопки на мобильных */
    .login-required-btn:not(.show),
    .auth-only-btn:not(.show) {
        display: none !important;
    }

    /* Видимые кнопки на мобильных */
    .login-required-btn.show,
    .auth-only-btn.show {
        display: flex !important;
    }

    .card-primary .link-btn {
        margin-left: auto;
        margin-right: auto;
    }

    .card-inner {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        width: 100%;
        max-width: 100%;
        overflow: visible;
        min-height: auto;
        height: auto;
        box-sizing: border-box;
    }

    .card-primary .card-inner {
        align-items: center;
        justify-content: center;
    }

    .card-primary .card-inner > * {
        text-align: center;
        width: 100%;
    }

    /* Метрики */
    .server-metrics {
        grid-template-columns: 1fr;
        gap: 10px;
        margin: 16px 0;
    }

    .metric {
        padding: 16px;
        text-align: center;
    }

    .metric-value {
        font-size: 20px;
        font-weight: 700;
    }

    .metric-label {
        font-size: 13px;
        margin-top: 4px;
    }

    /* Логотипы */
    .logo-cloud {
        min-height: 140px;
        margin-top: 20px;
        width: 100%;
        max-width: 100%;
        overflow: hidden;
    }

    .logo-link {
        width: 44px;
        height: 44px;
    }

    .logo-link img {
        width: 44px;
        height: 44px;
    }

    .logo-badges {
        gap: 8px;
        margin-top: 16px;
        justify-content: center;
        flex-wrap: wrap;
        width: 100%;
        max-width: 100%;
    }

    .logo-badges .badge {
        font-size: 12px;
        padding: 6px 12px;
    }

    /* Чат */
    .bubble {
        font-size: 14px;
        padding: 12px 16px;
        max-width: 85%;
    }

    .chat {
        gap: 12px;
        margin-top: 12px;
    }

    /* Контакты */
    .contact-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .contact-card {
        padding: 16px;
    }

    /* Футер */
    .footer {
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        padding: 24px 20px;
        margin: 60px 0 0;
        box-sizing: border-box;
    }

    .footer-inner {
        width: 100%;
        max-width: 100%;
    }

    /* Скрыть декоративные элементы */
    .notice-layer {
        display: none;
    }

    .notice-layer * {
        display: none !important;
    }

    /* Профиль */
    .profile-header {
        grid-template-columns: 1fr;
        gap: 16px;
        text-align: center;
        padding: 20px 16px;
    }

    .avatar-preview {
        width: 80px !important;
        height: 80px !important;
        margin: 0 auto;
        border: 3px solid rgba(255, 255, 255, 0.2);
    }

    .profile-name {
        font-size: 20px;
        font-weight: 700;
        margin-top: 12px;
    }

    .profile-email {
        font-size: 14px;
        opacity: 0.7;
        margin-top: 4px;
    }

    .profile-name-wrapper {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }

    .profile-badge {
        margin-top: 8px;
    }

    .profile-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 0 16px;
    }

    .profile-stat {
        padding: 16px;
        text-align: center;
        border-radius: 16px;
        background: rgba(255, 255, 255, 0.05);
    }

    .stat-label {
        font-size: 12px;
        opacity: 0.7;
        margin-bottom: 6px;
    }

    .stat-value {
        font-size: 18px;
        font-weight: 700;
    }

    .profile-grid {
        padding: 0 16px;
    }

    .profile-grid .card {
        border-radius: 20px;
        padding: 20px;
    }

    /* Уменьшаем отступы для панелей авторизации на мобильных */
    .profile-page .auth-panel .card-inner {
        padding: 0 !important; /* Убираем padding, так как он уже есть у .card */
        overflow: visible;
        min-height: auto;
        height: auto;
    }

    .profile-page .auth-panel h2 {
        font-size: 20px; /* Уменьшаем размер заголовка */
        margin-bottom: 6px; /* Уменьшаем отступ */
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        word-wrap: break-word;
    }

    .profile-page .auth-panel p {
        font-size: 13px; /* Уменьшаем размер текста */
        margin-bottom: 10px; /* Уменьшаем отступ */
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        word-wrap: break-word;
    }

    .auth-panel {
        overflow: visible !important; /* Убираем обрезание */
        min-height: auto !important;
        height: auto !important;
    }

    /* Убираем ограничения для bg-liquid-glass на мобильных */
    .bg-liquid-glass {
        overflow: visible !important;
        min-height: auto !important;
        height: auto !important;
    }

    /* Отключаем декоративную псевдо-границу, которая визуально обрезает контент */
    .profile-page .auth-panel.bg-liquid-glass::before,
    .profile-page .auth-panel.bg-liquid-glass::after {
        display: none !important;
    }

    /* Убираем contain для card на мобильных */
    .card {
        contain: none !important;
    }

    /* Уменьшаем отступы у auth-switch */
    .auth-switch {
        margin-top: 8px;
        font-size: 13px;
        line-height: 1.4;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        text-align: center;
    }

    /* Уменьшаем отступы у form-hint */
    .form-hint {
        margin-top: 6px;
        font-size: 12px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        text-align: center;
    }

    /* Формы */
    .form-grid {
        gap: 10px;
        overflow: visible;
        min-height: auto;
        height: auto;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        margin: 0 auto;
    }

    .form-grid label {
        margin-bottom: 0;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .form-grid label > span {
        display: block;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        word-wrap: break-word;
        text-align: left;
        margin-bottom: 4px;
    }

    .form-grid input {
        padding: 12px 14px;
        font-size: 16px;
        border-radius: 12px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .password-field {
        gap: 8px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        display: grid;
        grid-template-columns: 1fr 44px; /* Фиксированная ширина для кнопки */
        align-items: center;
    }

    .password-field input {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        min-width: 0; /* Позволяет input сжиматься */
    }

    .toggle-pass {
        width: 40px; /* Уменьшаем с 44px до 40px */
        height: 40px;
        flex-shrink: 0;
    }

    /* Капча - динамическое масштабирование через JavaScript */
    .captcha-box {
        padding: 4px;
        gap: 2px;
        margin: 4px auto;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
        overflow: visible !important;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .captcha-prompt {
        font-size: 11px;
        margin-bottom: 2px;
    }

    .captcha-visual {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        display: flex;
        justify-content: center;
        overflow: visible !important;
    }

    /* Контейнер reCAPTCHA - размеры устанавливаются JavaScript динамически */
    .captcha-visual-recaptcha {
        margin: 0 auto;
        padding: 0;
        overflow: hidden;
        box-sizing: border-box;
        position: relative;
        /* width и height устанавливаются JavaScript */
    }

    /* Слот внутри - масштабируется через transform */
    .captcha-visual-recaptcha .recaptcha-slot {
        /* transform и размеры устанавливаются JavaScript */
        box-sizing: border-box;
    }

    /* Скрываем textarea reCAPTCHA */
    .captcha-visual-recaptcha textarea,
    .captcha-visual-recaptcha .g-recaptcha-response {
        display: none !important;
    }

    /* Компактные зоны прогрузки капчи */
    .captcha-skeleton,
    .captcha-fallback {
        height: 55px !important;
        width: 100% !important;
    }

    /* Настройки */
    .settings-tabs {
        gap: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .settings-tabs::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        font-size: 14px;
        padding: 10px 16px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Улучшение touch targets */
    button, a, input, select {
        min-height: 44px;
        touch-action: manipulation;
    }

    /* Оптимизация анимаций */
    .card, .link-btn, .nav-bar a {
        transition: transform 0.2s ease, opacity 0.2s ease;
    }
}


/* Очень маленькие экраны */
@media (max-width: 480px) {
    body {
        font-size: 14px;
    }

    .nav-bar {
        padding: 10px 12px;
        min-height: 52px;
    }

    .nav-inner {
        padding: 0;
    }

    .nav-brand h1 {
        font-size: 15px;
    }

    .nav-bar a {
        font-size: 13px;
        padding: 6px 10px;
    }

    .nav-login {
        font-size: 13px;
        padding: 6px 12px;
    }

    .content {
        width: 96%;
        margin: 16px auto 0;
    }

    .hero-title {
        font-size: 28px;
    }

    .card {
        padding: 18px;
    }

    .card-primary {
        padding: 20px 18px;
    }

    .card h2 {
        font-size: 18px;
    }

    .card h3 {
        font-size: 16px;
    }

    .card p {
        font-size: 14px;
    }

    .link-btn {
        padding: 12px 20px;
        font-size: 14px;
        min-height: 44px;
        display: flex !important;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .metric {
        padding: 14px;
    }

    .metric-value {
        font-size: 18px;
    }

    .logo-link {
        width: 40px;
        height: 40px;
    }

    .logo-link img {
        width: 40px;
        height: 40px;
    }

    .logo-badges .badge {
        font-size: 11px;
        padding: 5px 10px;
    }

    .bubble {
        font-size: 13px;
        padding: 10px 14px;
    }

    .footer {
        padding: 20px 16px;
        margin: 50px 0 0;
    }

    /* Капча на очень маленьких экранах - размер управляется JavaScript */
    .captcha-box {
        padding: 2px;
        gap: 2px;
        margin: 2px auto;
    }

    /* Компактные зоны прогрузки на маленьких экранах */
    .captcha-skeleton,
    .captcha-fallback {
        height: 45px !important;
    }

    /* Панели авторизации на очень маленьких экранах */
    .profile-page .auth-panel .card-inner {
        padding: 14px 12px 12px; /* Еще меньше padding */
    }

    .profile-page .auth-panel h2 {
        font-size: 18px; /* Еще меньше заголовок */
        margin-bottom: 4px;
    }

    .profile-page .auth-panel p {
        font-size: 12px; /* Еще меньше текст */
        margin-bottom: 8px;
    }

    /* Формы на очень маленьких экранах */
    .form-grid {
        gap: 8px; /* Еще меньше gap */
    }

    .form-grid input {
        padding: 10px 12px; /* Меньше padding */
        font-size: 15px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Кнопки на очень маленьких экранах */
    .link-btn {
        padding: 10px 18px;
        font-size: 14px;
        min-height: 42px;
        margin-top: 6px;
        margin-bottom: 6px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
}

/* Ландшафтная ориентация на мобильных */
@media (max-width: 768px) and (orientation: landscape) {
    .hero-title {
        font-size: 28px;
    }

    .card {
        padding: 16px;
    }

    .server-metrics {
        grid-template-columns: repeat(3, 1fr);
    }
}
