/**
 * Mobile-first layer: touch targets, safe area, bottom navigation.
 * Load after style.css. Base rules target small viewports; min-width for larger.
 */

/* Touch target minimum (WCAG / iOS HIG) */
:root {
    --touch-target: 44px;
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0);
    --safe-area-inset-top: env(safe-area-inset-top, 0);
}

/* Предотвращение горизонтального скролла; контент на полную ширину */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden;
        min-width: 0;
        box-sizing: border-box;
    }
    .container,
    .vc-container,
    main.main-content {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
    }
    /* Контент на всю ширину: у контейнеров с vc-layout убираем боковые отступы, отступы внутри .vc-center */
    .container.vc-container,
    .vc-container {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    .vc-layout {
        width: 100%;
        min-width: 0;
    }
    /* Отступы переносим внутрь контента, чтобы карточки/текст не прилипали к краям */
    .vc-center {
        min-width: 0;
        padding-left: var(--space-3);
        padding-right: var(--space-3);
    }
    .market-page,
    .author-profile {
        width: 100%;
        max-width: 100%;
    }
    .dashboard-content {
        width: 100%;
        max-width: 100%;
    }
}

/* Bottom nav: строго на всю ширину viewport, без белой полосы; safe-area только снизу у панели */
.mobile-bottom-nav {
    --bottom-nav-height: 50px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    z-index: 900;
    height: calc(var(--bottom-nav-height) + var(--safe-area-inset-bottom));
    padding-bottom: var(--safe-area-inset-bottom);
    padding-left: 0;
    padding-right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
    display: none;
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
        align-items: stretch;
        /* Жёстко на всю ширину viewport — убираем белую полосу справа */
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        min-width: 100vw !important;
        max-width: 100vw !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box !important;
    }

    /* Контент не уходит под нижнюю панель; отступ с учётом safe-area */
    body.has-mobile-bottom-nav {
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-inset-bottom) + 20px);
    }
    body.has-mobile-bottom-nav .main-content,
    body.has-mobile-bottom-nav .vc-container {
        padding-bottom: 0; /* отступ задаётся у body */
    }
}

.mobile-bottom-nav__inner {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    height: var(--bottom-nav-height);
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    padding: 0;
    padding-left: max(var(--space-2), env(safe-area-inset-left, 0));
    padding-right: max(var(--space-2), env(safe-area-inset-right, 0));
    gap: var(--space-1);
    box-sizing: border-box;
}

.mobile-bottom-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1 1 0;
    min-width: 0;
    padding: var(--space-2) var(--space-1);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 10px;
    font-weight: var(--font-medium);
    line-height: 1.2;
    transition: color var(--transition-fast), background var(--transition-fast);
    border: none;
    background: transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    min-height: var(--touch-target);
}

.mobile-bottom-nav__item:hover,
.mobile-bottom-nav__item:focus {
    color: var(--accent);
    background: transparent;
}

.mobile-bottom-nav__item.active {
    color: var(--accent);
}

.mobile-bottom-nav__icon {
    width: 22px;
    height: 22px;
    margin-bottom: 1px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
}

.mobile-bottom-nav__icon svg {
    width: 22px;
    height: 22px;
}

.mobile-bottom-nav__label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    font-size: 10px;
    text-align: center;
}

/* Badge on nav item (e.g. unread count) */
.mobile-bottom-nav__badge {
    position: absolute;
    top: 4px;
    right: 50%;
    transform: translate(calc(50% - 12px), 0);
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    font-size: 10px;
    font-weight: var(--font-semibold);
    line-height: 16px;
    text-align: center;
    color: var(--text-inverse);
    background: var(--danger);
    border-radius: var(--radius-full);
}

.mobile-bottom-nav__item {
    position: relative;
}

/* Dashboard bottom nav (office) */
.mobile-bottom-nav--dashboard .mobile-bottom-nav__inner {
    height: var(--bottom-nav-height);
}

/* Burger button: ensure 44x44 on mobile */
@media (max-width: 768px) {
    .burger-menu-btn {
        width: var(--touch-target) !important;
        height: var(--touch-target) !important;
        min-width: var(--touch-target);
        min-height: var(--touch-target);
        padding: 0;
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
}

/* Mobile drawer (burger menu) — в стиле мобильного приложения */
@media (max-width: 768px) {
    .mobile-menu-overlay.active {
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }
    #main-nav {
        padding-top: var(--safe-area-inset-top);
        padding-right: var(--space-4);
        padding-bottom: calc(var(--space-6) + var(--safe-area-inset-bottom));
        padding-left: var(--space-4);
        max-width: min(400px, 88vw) !important;
    }
    #main-nav .mobile-menu-close {
        align-self: flex-end;
        margin-bottom: var(--space-2);
    }
    #main-nav .nav-links-wrapper {
        gap: 0;
    }
    #main-nav .nav-links-wrapper .nav-link,
    #main-nav .header-actions-mobile .btn-link {
        min-height: var(--touch-target);
        padding: var(--space-3) var(--space-4);
        border-radius: var(--radius-lg);
        font-size: var(--text-base);
        margin-bottom: var(--space-1);
    }
    #main-nav .header-actions-mobile {
        margin-top: var(--space-4);
        padding-top: var(--space-4);
        border-top: 1px solid var(--border);
    }
}

/* Generic touch target for buttons and links on mobile */
@media (max-width: 768px) {
    .btn,
    button:not(.burger-menu-btn):not(.mobile-menu-close):not(.dashboard-sidebar-close),
    .nav-link,
    .header-actions-mobile .btn-link {
        min-height: var(--touch-target);
        min-width: var(--touch-target);
        padding: var(--space-2) var(--space-3);
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .header-actions-mobile .btn-link {
        min-height: var(--touch-target);
        justify-content: flex-start;
        padding: var(--space-3) var(--space-4);
    }
}

/* Более лаконичные кнопки и поля в мобильной версии (как в приложении) */
@media (max-width: 768px) {
    .btn {
        padding: var(--space-2) var(--space-4);
        font-size: var(--text-sm);
        border-radius: var(--radius-md);
    }
    .btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="number"],
    input[type="url"],
    select,
    textarea {
        padding: var(--space-2) var(--space-3);
        font-size: var(--text-base);
        border-radius: var(--radius-md);
        min-height: 44px;
    }
    textarea { min-height: 88px; }
    .form-group label,
    .form-label { font-size: var(--text-sm); }
}

/* Skeleton placeholder (for future use) */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 25%,
        var(--bg-tertiary) 50%,
        var(--bg-secondary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shine 1.2s ease-in-out infinite;
    border-radius: var(--radius-md);
}

@keyframes skeleton-shine {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 1em;
}

.skeleton-title {
    height: 1.5em;
    max-width: 80%;
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
}

/* Лента: карусель кнопок (Популярное, Свежее, …) на мобилке */
@media (max-width: 768px) {
    .top-nav-bar .container {
        padding-left: 0;
        padding-right: 0;
        overflow: hidden;
    }
    .top-nav-links {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        gap: var(--space-2);
        padding: 0 var(--space-4);
        scrollbar-width: none;
    }
    .top-nav-links::-webkit-scrollbar {
        display: none;
    }
    .top-nav-link {
        flex-shrink: 0;
        min-width: max-content;
        padding: var(--space-2) var(--space-3);
        font-size: var(--text-sm);
    }
}

/* Маркет: фильтры по кнопке на мобилке */
@media (min-width: 769px) {
    .market-filters-wrap .market-filters-toggle { display: none; }
}
@media (max-width: 768px) {
    .market-filters-wrap {
        position: relative;
    }
    .market-filters-toggle {
        margin-bottom: var(--space-3);
        min-height: 44px;
    }
    .market-filters-wrap .market-filters {
        display: none;
        margin-top: var(--space-2);
        padding-top: var(--space-3);
        border-top: 1px solid var(--border);
    }
    .market-filters-wrap.market-filters-open .market-filters {
        display: block;
    }
    .market-filters-wrap.market-filters-open .market-filters-toggle {
        margin-bottom: var(--space-2);
    }
}
