/* Marathon Diet - Mobile WebView Optimizations */
/* Specifically designed for Android WebView integration */

/* 1. WEBVIEW-SPECIFIC OPTIMIZATIONS */
/* ================================== */

/* Hide all scrollbars to create native app feel */
::-webkit-scrollbar {
    display: none;
}

/* Firefox scrollbar hiding */
html {
    scrollbar-width: none;
}

/* Remove blue tap highlights that appear in WebView */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Disable text selection for app-like experience */
body {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Allow text selection only in specific input areas */
input,
textarea,
[contenteditable="true"] {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Improve touch responsiveness */
a,
button,
[role="button"],
.btn {
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

/* Prevent zoom on input focus in WebView */
input,
select,
textarea {
    font-size: 16px;
}

/* Remove default input styles that look browser-like */
input,
textarea,
select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 0.5rem;
}

/* 2. MOBILE NAVIGATION OPTIMIZATIONS */
/* ================================== */

/* =============================================================== */
/* НАЧАЛО ИЗМЕНЕНИЙ: Новый дизайн панели                           */
/* =============================================================== */
.mobile-nav {
    background: rgba(255, 255, 255, 0.7);
    /* Полупрозрачный фон */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
    /* Улучшенная, мягкая тень */
    padding-top: 8px;
    /* ИСПРАВЛЕНИЕ 1: Автоматический отступ снизу для iPhone и других устройств */
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 1050;
}

/* =============================================================== */
/* --- ИЗМЕНЕНИЕ: Исправлена точка переключения на мобильное меню --- */
/* =============================================================== */
@media (max-width: 768px) {

    /* COMPLETELY hide desktop navigation on mobile - Use high specificity to override Bootstrap */
    body .navbar.navbar-expand-lg.navbar-light.bg-white.sticky-top.border-bottom,
    .navbar.navbar-expand-lg,
    .navbar {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        overflow: hidden !important;
    }

    /* Hide all navbar-related elements with higher specificity */
    .navbar-nav.d-none.d-lg-flex,
    .navbar-nav {
        display: none !important;
    }

    /* Hide navbar toggle button */
    .navbar-toggler {
        display: none !important;
    }

    /* Hide navbar collapse */
    .navbar-collapse {
        display: none !important;
    }

    /* Hide navbar brand */
    .navbar-brand {
        display: none !important;
    }

    /* Ensure main content starts from top on mobile */
    main.container-fluid {
        padding-top: 0 !important;
        margin-top: 0 !important;
    }

    /* Enable mobile navigation display only within media query */
    .mobile-nav {
        display: flex;
    }

    /* Стили для кнопок навигации */
    .mobile-nav .nav-link {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: #6c757d;
        /* Приглушенный серый */
        font-size: 12px;
        font-weight: 500;
        transition: all 0.2s ease-in-out;
        border-radius: 16px;
        padding: 4px 0;
        border: none;
        background: none;
        width: 100%;
        text-decoration: none;
    }

    /* Стиль для АКТИВНОЙ кнопки в виде "таблетки" */
    .mobile-nav .nav-link.active {
        color: #fff;
        background-color: #0d6efd;
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(13, 110, 253, 0.3);
    }

    .mobile-nav .nav-link.active i {
        color: #fff;
    }

    .mobile-nav .nav-link i {
        font-size: 22px;
        /* Более крупные иконки */
        margin-bottom: 2px;
    }

    /* "More" menu button styling */
    .mobile-more-btn {
        cursor: pointer;
    }

    /* "More" dropdown menu */
    .mobile-more-menu {
        position: fixed;

        /* =============================================================== */
        /* --- ИСПРАВЛЕНИЕ №1: Увеличена высота, чтобы не было наложения --- */
        /* =============================================================== */
        bottom: 95px;

        right: 10px;
        background-color: white;
        border-radius: 12px;
        box-shadow: 0 -4px 20px rgb(0 0 0 / 49%);
        padding: 8px;
        display: none;
        flex-direction: column;
        gap: 4px;
        z-index: 1100;

        /* =============================================================== */
        /* --- ИСПРАВЛЕНИЕ №2: Ширина в половину экрана --- */
        /* =============================================================== */
        width: 50vw;
        /* vw = viewport width (ширина видимой области) */
    }

    .mobile-more-menu.show {
        display: flex !important;
        animation: slideUp 0.3s ease-out;
    }

    @keyframes slideUp {
        from {
            transform: translateY(10px);
            opacity: 0;
        }

        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    .more-menu-item {
        border-bottom: 1px solid #f8f9fa;
    }

    .more-menu-item:last-child {
        border-bottom: none;
    }

    .more-menu-item a {
        display: flex;
        align-items: center;
        padding: 10px 16px;
        text-decoration: none;
        border-radius: 8px;
        transition: background-color 0.2s;
        color: var(--dark-color);
    }

    .more-menu-item a:hover,
    .more-menu-item a.active {
        background-color: #3fc73273;
        color: #0067ff;
    }

    .more-menu-item i {
        margin-right: 12px;
        font-size: 18px;
        width: 20px;
        text-align: center;
    }

    /* Mobile page header (replaces breadcrumbs on mobile) */
    .mobile-page-header {
        display: flex;
        align-items: center;
        padding-top: 0.10rem !important;
        padding-bottom: 0.10rem !important;
        min-height: auto;
        border-bottom: 0px solid #e9ecef;
        background: #ffffff57;
        position: sticky;
        top: 0;
        z-index: 1000;
        margin-bottom: 1rem;
    }

    .mobile-back-btn {
        background: none;
        border: none;
        font-size: 1.5rem;
        color: #0d6efd;
        margin-right: 1rem;
        padding: 0.5rem;
        cursor: pointer;
        border-radius: 50%;
        transition: background-color 0.2s;
    }

    .mobile-back-btn:hover {
        background-color: #f8f9fa;
    }

    .mobile-page-title {
        font-size: 1.25rem;
        font-weight: 600;
        color: #212529;
        margin: 0;
        flex: 1;
        text-align: center;
        margin-right: 3rem;
        /* Balance the back button */
    }

    /* Hide desktop breadcrumbs on mobile */
    nav[aria-label="breadcrumb"] {
        display: none !important;
    }

    /* Hide footer on mobile to save space */
    footer {
        display: none;
    }

    /*
     * ===================================================================
     *   ФИНАЛЬНОЕ УНИВЕРСАЛЬНОЕ ИСПРАВЛЕНИЕ ДЛЯ КНОПОК В КАРТОЧКАХ (v5)
     * ===================================================================
    */
    /* 
     * ШАГ 1: Разрешаем перенос для всех контейнеров с кнопками.
    */
    .card-body .food-report-actions,
    .card-footer .d-flex {
        flex-wrap: wrap;
    }

    /* 
     * ШАГ 2: Заставляем кнопку "Сохранить" занять всю ширину новой строки.
    */
    .food-report-actions .save-recipe-btn,
    .card-footer .d-flex .save-recipe-btn {
        width: 100%;
        margin-top: 0.75rem;
    }
}

/* =============================================================== */
/* КОНЕЦ ИЗМЕНЕНИЙ                                                */
/* =============================================================== */

/* 3. WEBVIEW TOUCH OPTIMIZATIONS */
/* ============================== */

/* Improve button touch targets */
.btn {
    min-height: 44px;
    min-width: 44px;
    padding: 0.75rem 1.5rem;
}

/* Make cards more touch-friendly */
.card {
    transition: transform 0.1s ease-in-out;
}

/* Improve form field touch targets */
.form-control {
    min-height: 48px;
    padding: 0.75rem;
}

/* Better spacing for mobile interactions */
.btn+.btn {
    margin-left: 0.5rem;
}

@media (max-width: 576px) {
    .btn+.btn {
        margin-left: 0;
        margin-top: 0.5rem;
    }
}

/* 4. PERFORMANCE OPTIMIZATIONS */
/* ============================ */

/* Smooth scrolling for better UX */
html {
    scroll-behavior: smooth;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 5. ANDROID-SPECIFIC OPTIMIZATIONS */
/* ================================= */

/* Prevent overscroll bounce effect */
body {
    overscroll-behavior: contain;
}

/* Optimize for Android WebView rendering */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Improve form rendering in WebView */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea {
    background-color: #ffffff;
    border: 1px solid #ced4da;
    border-radius: 0.5rem;
}

/* Focus states optimized for touch */
input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

/* 6. LOADING AND ERROR STATES */
/* =========================== */

/* Loading spinner optimized for mobile */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e9ecef;
    border-top: 4px solid #0d6efd;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* 7. OFFLINE INDICATORS */
/* ==================== */

.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #dc3545;
    color: white;
    text-align: center;
    padding: 0.5rem;
    z-index: 9998;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.offline-indicator.show {
    transform: translateY(0);
}

/* 8. ACCESSIBILITY IMPROVEMENTS FOR MOBILE */
/* ======================================== */

/* Improve focus indicators for keyboard navigation */
a:focus,
button:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

/* =============================================================== */
/* --- ИЗМЕНЕНИЕ: Убираем синюю рамку фокуса для навигации ---      */
/* =============================================================== */
.mobile-nav .nav-link:focus,
.more-menu-item a:focus {
    outline: none !important;
}


/* Ensure sufficient color contrast */
.text-muted {
    color: #495057 !important;
}

/* Make sure interactive elements are large enough */
.nav-link,
.dropdown-item {
    min-height: 44px;
    display: flex;
    align-items: center;
}

/* =============================================================== */
/* ФИНАЛЬНЫЙ ФИКС: Правильная структура и фиксация панели          */
/* =============================================================== */
@media (max-width: 768px) {

    /* 1. Растягиваем body на весь экран и делаем его flex-контейнером */
    html,
    body {
        height: 100%;
        overflow: hidden;
        /* Запрещаем прокрутку */
    }

    body {
        display: flex;
        flex-direction: column;
    }

    /* 2. Заставляем контейнер страницы занимать всё доступное место и прокручиваться */
    .page-container {
        flex: 1;
        /* Растягивается на всё свободное пространство */
        overflow-y: auto;
        /* Включаем вертикальную прокрутку только для этого блока */
        -webkit-overflow-scrolling: touch;
        /* Плавный скроллинг на iOS */
    }

    /* 3. Мобильная навигация становится flex-элементом, который не сжимается и не растягивается */
    .mobile-nav {
        flex-shrink: 0;
        /* Запрещаем панели сжиматься */
    }
}

/* =============================================================== */
/* --- НАЧАЛО ИЗМЕНЕНИЯ: Стиль для тонких кнопок языка ---          */
/* =============================================================== */
/* 
 * Переопределяем глобальные стили .btn ТОЛЬКО для кнопок 
 * внутри блока .lang-switcher на странице входа.
 * Этот стиль будет применен, даже если у кнопки есть класс .btn-sm
*/
.lang-switcher .btn {
    min-height: auto !important;
    min-width: auto !important;
    padding: 0.35rem 1rem !important;
    /* Немного увеличим для текста */
    font-size: 0.9rem !important;
    line-height: 1.5 !important;
}

/* =============================================================== */
/* --- УДАЛЕНИЕ ХЛЕБНЫХ КРОШЕК --- */
/* =============================================================== */
nav[aria-label="breadcrumb"] {
    display: none !important;
}

/* =============================================================== */
/* --- УБИРАЕМ СТРЕЛКУ DROPDOWN --- */
/* =============================================================== */
.dropdown-toggle::after {
    display: none !important;
}

/* =============================================================== */
/* --- ГЛОБАЛЬНОЕ ИСПРАВЛЕНИЕ DROPDOWN (PC, TABLET, MOBILE) --- */
/* =============================================================== */
/* Применяем на странице отчетов и ленты для всех устройств */
body[data-page="reports"] .card-body,
body[data-page="reports"] .card,
body[data-page="feed"] .card-body,
body[data-page="feed"] .card {
    overflow: visible !important;
    /* Убеждаемся, что z-index не создает новый контекст наложения, который прячет меню */
    z-index: auto;
}

/* Супер высокий z-index для самого меню и position fixed для отрыва от контекста */
.dropdown-menu {
    z-index: 9999 !important;
    margin-bottom: 0 !important;
    /* Fix for dropup spacing */
}

@media (max-width: 991px) {

    /* Force Modal to be on top and centered on Mobile */
    .text-modal-overlay.show {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        z-index: 100000 !important;
        /* Ensure it is above everything including bottom nav */
        padding: 1rem;
    }

    .text-modal-content {
        width: 90% !important;
        max-width: 90% !important;
        max-height: 80vh !important;
        margin: auto !important;
        /* Helps with flex centering */
    }

    .text-modal-content.delete-confirmation-style {
        width: auto !important;
        min-width: 300px;
    }
}