/**
 * Мобильная навигация и layout кабинета.
 */

@media (max-width: 767px) {
    body.dashboard-page {
        padding-bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
    }

    body.dashboard-page .dashboard {
        padding: 0.75rem 0 0;
        min-height: auto;
    }

    body.dashboard-page .dashboard > .container {
        flex-direction: column;
        gap: 0.75rem;
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
        padding-bottom: 0.5rem;
        max-width: 100%;
    }

    body.dashboard-page .dashboard-content {
        min-width: 0;
        width: 100%;
    }

    /* Сайдбар на мобилке скрыт — навигация снизу, аккаунт в аватарке */
    body.dashboard-page .sidebar,
    body.dashboard-page .sidebar-backdrop,
    body.dashboard-page .dashboard-nav-toggle {
        display: none !important;
    }

    body.dashboard-page .navbar-toggle {
        display: none !important;
    }

    body.dashboard-page .navbar-actions {
        gap: 0.35rem;
        flex-shrink: 0;
        position: relative;
        z-index: 5;
    }

    body.dashboard-page .account-toggle {
        width: 2.5rem;
        height: 2.5rem;
        min-width: 2.5rem;
        min-height: 2.5rem;
    }

    /* Нижняя панель */
    .dashboard-bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 180;
        display: flex;
        align-items: stretch;
        justify-content: space-around;
        gap: 0.15rem;
        padding: 0.35rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
        background: rgba(255, 255, 255, 0.97);
        border-top: 1px solid var(--gray-200);
        box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }

    .bottom-nav-item {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.15rem;
        padding: 0.35rem 0.2rem;
        border: none;
        background: none;
        color: var(--gray-500);
        text-decoration: none;
        font-family: inherit;
        font-size: 0.625rem;
        font-weight: 500;
        line-height: 1.15;
        border-radius: var(--radius);
        cursor: pointer;
        transition: color 0.15s ease, background 0.15s ease;
        -webkit-tap-highlight-color: transparent;
    }

    .bottom-nav-item:hover,
    .bottom-nav-item:focus-visible {
        color: var(--primary-600);
        background: var(--primary-50);
        outline: none;
    }

    .bottom-nav-item.is-active {
        color: var(--primary-600);
        font-weight: 600;
    }

    .bottom-nav-icon {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 1.65rem;
        height: 1.65rem;
        font-size: 1.05rem;
    }

    .bottom-nav-label {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: center;
    }

    .bottom-nav-badge {
        position: absolute;
        top: -0.2rem;
        right: -0.45rem;
        min-width: 1rem;
        height: 1rem;
        padding: 0 0.25rem;
        border-radius: 999px;
        background: var(--error);
        color: #fff;
        font-size: 0.55rem;
        font-weight: 700;
        line-height: 1rem;
        text-align: center;
    }

    .bottom-nav-badge[hidden] {
        display: none !important;
    }

    /* Заголовки страниц */
    body.dashboard-page .dashboard-page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        min-height: auto;
    }

    body.dashboard-page .dashboard-page-header > div:first-child {
        min-height: auto;
    }

    body.dashboard-page .dashboard-page-header h1 {
        font-size: 1.25rem;
    }

    body.dashboard-page .garage-header .garage-actions,
    body.dashboard-page .diary-header .garage-actions,
    body.dashboard-page .dashboard-page-header .garage-actions {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.5rem;
        width: 100%;
    }

    /* Текстовые кнопки тянутся; шестерёнка — фиксированный квадрат той же высоты */
    body.dashboard-page .dashboard-page-header .garage-actions .btn:not(.btn-icon) {
        flex: 1 1 auto;
        min-width: 0;
        height: 2.5rem;
        min-height: 2.5rem;
        padding: 0 0.85rem;
    }

    body.dashboard-page .dashboard-page-header .garage-actions .btn.btn-icon {
        flex: 0 0 2.5rem;
        width: 2.5rem;
        height: 2.5rem;
        min-width: 2.5rem;
        min-height: 2.5rem;
        max-width: 2.5rem;
        padding: 0;
    }

    /* Модалка полей карточки: кнопки не вылезают за край */
    body.dashboard-page .fields-modal-content {
        width: calc(100vw - 1.25rem);
        max-width: calc(100vw - 1.25rem);
        margin: 0.5rem;
        padding: 1.25rem 1rem 1rem;
    }

    body.dashboard-page .fields-actions {
        flex-direction: column;
    }

    body.dashboard-page .fields-actions .btn {
        flex: 1 1 auto;
        width: 100%;
    }

    /* Карточки и сетки */
    body.dashboard-page .garage-grid {
        grid-template-columns: 1fr;
    }

    body.dashboard-page .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    body.dashboard-page .stat-card {
        padding: 1rem;
        gap: 0.75rem;
    }

    body.dashboard-page .stat-icon {
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1.1rem;
    }

    body.dashboard-page .stat-info h3 {
        font-size: 1.35rem;
    }

    body.dashboard-page .welcome-card {
        padding: 1.5rem 1.25rem;
    }

    body.dashboard-page .activity-section {
        padding: 1.25rem;
    }

    body.dashboard-page .card {
        max-width: 100%;
        overflow-x: hidden;
    }

    body.dashboard-page .card:has(.custom-select.is-open),
    body.dashboard-page #feed-filters:has(.custom-select.is-open) {
        overflow: visible;
    }

    body.dashboard-page .garage-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    body.dashboard-page .garage-toolbar .btn {
        width: 100%;
        justify-content: center;
    }

    body.dashboard-page .settings-row {
        flex-direction: column;
        gap: 0.25rem;
    }

    body.dashboard-page .avatar-edit {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (min-width: 768px) {
    body:not(.pwa-standalone) .dashboard-bottom-nav,
    body.dashboard-page:not(.pwa-standalone) .sidebar-backdrop {
        display: none !important;
    }
}

@media (max-width: 380px) {
    .bottom-nav-label {
        font-size: 0.55rem;
    }
}

/* ===== PWA / Android: вертикальный скролл контента, без overflow-x:hidden на body ===== */
html.pwa-standalone,
html.atcarnet-app {
    overflow-x: hidden;
    overflow-y: auto;
    height: auto;
    min-height: 100%;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

html.pwa-standalone body,
html.atcarnet-app body,
html.pwa-standalone body.dashboard-page,
html.atcarnet-app body.dashboard-page,
body.pwa-standalone.dashboard-page {
    overflow-x: visible !important;
    overflow-y: visible !important;
    max-width: none;
    touch-action: pan-y;
    overscroll-behavior-y: auto;
    -webkit-overflow-scrolling: touch;
}

html.pwa-standalone body.dashboard-page .dashboard,
html.pwa-standalone body.dashboard-page .dashboard > .container,
html.pwa-standalone body.dashboard-page .dashboard-content,
html.atcarnet-app body.dashboard-page .dashboard,
html.atcarnet-app body.dashboard-page .dashboard > .container,
html.atcarnet-app body.dashboard-page .dashboard-content {
    overflow-x: visible !important;
    overflow-y: visible !important;
    touch-action: pan-y;
}

/* ===== PWA standalone: низ + лого/аватар (без сайдбара и бургера) ===== */
html.pwa-standalone body.dashboard-page,
body.pwa-standalone.dashboard-page {
    padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
}

html.pwa-standalone body.dashboard-page .dashboard > .container,
body.pwa-standalone.dashboard-page .dashboard > .container {
    flex-direction: column;
    gap: 0.75rem;
    max-width: 100%;
}

html.pwa-standalone body.dashboard-page .dashboard-content,
body.pwa-standalone.dashboard-page .dashboard-content {
    min-width: 0;
    width: 100%;
}

html.pwa-standalone body.dashboard-page .sidebar,
html.pwa-standalone body.dashboard-page .sidebar-backdrop,
html.pwa-standalone body.dashboard-page .dashboard-nav-toggle,
body.pwa-standalone.dashboard-page .sidebar,
body.pwa-standalone.dashboard-page .sidebar-backdrop,
body.pwa-standalone.dashboard-page .dashboard-nav-toggle {
    display: none !important;
}

html.pwa-standalone body.dashboard-page .dashboard-bottom-nav,
body.pwa-standalone.dashboard-page .dashboard-bottom-nav {
    display: flex !important;
    overflow: visible;
}

/* PWA мобильный + Android: без верхнего хедера, аватар справа внизу вместо «Записи» */
@media (max-width: 767px) {
    html.pwa-standalone body.dashboard-page .header.header-dashboard {
        display: none !important;
    }
    html.pwa-standalone body.dashboard-page.has-fixed-header {
        padding-top: env(safe-area-inset-top, 0px);
    }
    html.pwa-standalone .bottom-nav-item--appointments {
        display: none !important;
    }
    html.pwa-standalone .bottom-nav-account {
        display: flex;
    }
}

html.atcarnet-app body.dashboard-page .header.header-dashboard {
    display: none !important;
}
html.atcarnet-app body.dashboard-page.has-fixed-header {
    padding-top: env(safe-area-inset-top, 0px);
}
html.atcarnet-app .bottom-nav-item--appointments {
    display: none !important;
}
html.atcarnet-app .bottom-nav-account {
    display: flex;
}

.bottom-nav-account {
    display: none;
    flex: 1;
    min-width: 0;
    align-items: center;
    justify-content: center;
    position: relative;
}

html.pwa-standalone .bottom-nav-account .account-menu,
html.atcarnet-app .bottom-nav-account .account-menu {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    position: static;
}

/* Как остальные вкладки: иконка 1.65rem + подпись */
html.pwa-standalone .bottom-nav-account .account-toggle,
html.atcarnet-app .bottom-nav-account .account-toggle {
    display: inline-flex;
    width: auto;
    height: auto;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.35rem 0.2rem;
    border: none;
    border-radius: var(--radius);
    background: none;
    box-shadow: none;
    overflow: visible;
    color: var(--gray-500);
}

html.pwa-standalone .bottom-nav-account .account-toggle-face,
html.atcarnet-app .bottom-nav-account .account-toggle-face {
    width: 1.65rem;
    height: 1.65rem;
    font-size: 1.05rem;
    overflow: hidden;
    border-radius: 50%;
    background: var(--gray-100, #f1f5f9);
}

html.pwa-standalone .bottom-nav-account .account-toggle-burger,
html.atcarnet-app .bottom-nav-account .account-toggle-burger {
    display: none !important;
}

html.pwa-standalone .bottom-nav-account .bottom-nav-account-label,
html.atcarnet-app .bottom-nav-account .bottom-nav-account-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.625rem;
    font-weight: 500;
    line-height: 1.15;
    color: inherit;
}

@media (max-width: 767px) {
    html.pwa-standalone body.dashboard-page .bottom-nav-account .dropdown-menu,
    html.atcarnet-app body.dashboard-page .bottom-nav-account .dropdown-menu {
        top: auto;
        bottom: calc(4.35rem + env(safe-area-inset-bottom, 0px));
        right: max(0.4rem, env(safe-area-inset-right, 0px));
        left: auto;
        max-height: calc(100dvh - 6rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        transform-origin: bottom right;
    }
}

html.atcarnet-app body.dashboard-page .bottom-nav-account .dropdown-menu {
    top: auto;
    bottom: calc(4.35rem + env(safe-area-inset-bottom, 0px));
    right: max(0.4rem, env(safe-area-inset-right, 0px));
    left: auto;
    max-height: calc(100dvh - 6rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    transform-origin: bottom right;
}

