/* ═══════════════════════════════════════════════════════
   Phone fixes — iPhone / Android (≤480px, ≤390px)
   Loaded last so it can override shell + landing styles.
   ═══════════════════════════════════════════════════════ */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body.bn-va,
body.pilot-aev-shell,
body.pilot-auth-layout {
    overflow-x: hidden;
    max-width: 100vw;
}

/* ─── Pilot Center topbar ─── */

@media (max-width: 640px) {
    .pilot-aev-topbar-dropdown--activity,
    .pilot-aev-navbar__right > li:has(a[title="Discord"]) {
        display: none;
    }

    /* Mobile table cards (labels via mobile-phone.js) — skip compact dash tables */
    .pilot-aev-table-wrap,
    .pilot-aev-dash-boards__table-wrap,
    .pilot-aev-rankings-page__table-wrap {
        overflow-x: visible;
    }

    .pilot-aev-table:not(.pilot-aev-dash-newest-table):not(.pilot-aev-dash-booked-table),
    .pilot-aev-dash-flights-table,
    .pilot-aev-rankings-page__table {
        display: block;
        min-width: 0 !important;
        width: 100%;
        border-collapse: separate;
    }

    .pilot-aev-table:not(.pilot-aev-dash-newest-table):not(.pilot-aev-dash-booked-table) thead,
    .pilot-aev-dash-flights-table thead,
    .pilot-aev-rankings-page__table thead {
        display: none;
    }

    .pilot-aev-table:not(.pilot-aev-dash-newest-table):not(.pilot-aev-dash-booked-table) tbody,
    .pilot-aev-dash-flights-table tbody,
    .pilot-aev-rankings-page__table tbody {
        display: block;
    }

    .pilot-aev-table:not(.pilot-aev-dash-newest-table):not(.pilot-aev-dash-booked-table) tbody tr,
    .pilot-aev-dash-flights-table tbody tr,
    .pilot-aev-rankings-page__table tbody tr {
        display: block;
        margin-bottom: 10px;
        border: 1px solid #3d3d3d;
        border-radius: 8px;
        overflow: hidden;
        background: #282828;
    }

    .pilot-aev-table:not(.pilot-aev-dash-newest-table):not(.pilot-aev-dash-booked-table) tbody td,
    .pilot-aev-dash-flights-table tbody td,
    .pilot-aev-rankings-page__table tbody td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 10px 12px;
        border: none;
        border-bottom: 1px solid #3d3d3d;
        text-align: right;
        background: transparent !important;
    }

    .pilot-aev-table:not(.pilot-aev-dash-newest-table):not(.pilot-aev-dash-booked-table) tbody td:last-child,
    .pilot-aev-dash-flights-table tbody td:last-child,
    .pilot-aev-rankings-page__table tbody td:last-child {
        border-bottom: none;
    }

    .pilot-aev-table:not(.pilot-aev-dash-newest-table):not(.pilot-aev-dash-booked-table) tbody td::before,
    .pilot-aev-dash-flights-table tbody td::before,
    .pilot-aev-rankings-page__table tbody td::before {
        content: attr(data-label);
        flex: 1 1 auto;
        min-width: 0;
        font-size: 10px;
        font-weight: 700;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        color: #888;
        text-align: left;
    }

    .pilot-aev-table:not(.pilot-aev-dash-newest-table):not(.pilot-aev-dash-booked-table) tbody td:empty,
    .pilot-aev-dash-flights-table tbody td:empty,
    .pilot-aev-rankings-page__table tbody td:empty {
        display: none;
    }

    .pilot-aev-dash-flights-table tbody td:nth-child(1),
    .pilot-aev-dash-flights-table tbody td:nth-child(11) {
        display: none;
    }

    .pilot-aev-dash-flights-table__pilot span:not(.pilot-aev-dash-flights-table__avatar) {
        display: inline;
    }

    /* Dashboard community widgets — top pilot / newest / VATSIM */
    .pilot-aev-dash-community__top {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .pilot-aev-dash-community__top .card {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    .pilot-aev-dash-community .card-header {
        flex-wrap: nowrap;
        align-items: center;
        gap: 8px;
        padding: 10px 12px;
    }

    .pilot-aev-dash-community .card-header:has(.card-header-action) {
        display: grid;
        grid-template-columns: auto 1fr auto;
        align-items: center;
        column-gap: 8px;
    }

    .pilot-aev-dash-community .card-header h4 {
        font-size: 13px;
        line-height: 1.25;
        margin: 0;
        min-width: 0;
    }

    .pilot-aev-dash-community .card-header .card-header-action {
        margin-left: 0;
        width: auto !important;
        flex-shrink: 0;
    }

    .pilot-aev-dash-community .card-header .card-header-action .btn {
        width: auto !important;
        padding: 5px 10px;
        font-size: 11px;
        white-space: nowrap;
    }

    .pilot-aev-dash-top-pilot .card-body {
        min-height: 0;
        padding: 16px 12px;
        gap: 12px;
    }

    .pilot-aev-dash-top-pilot__name {
        flex-wrap: wrap;
        justify-content: center;
        max-width: 100%;
        gap: 4px 6px;
        padding: 8px 10px;
        box-sizing: border-box;
    }

    .pilot-aev-dash-top-pilot__name .fa-star {
        order: 1;
    }

    .pilot-aev-dash-top-pilot__name strong {
        order: 2;
        flex: 0 1 100%;
        max-width: 100%;
        word-break: break-word;
        font-size: 14px;
        line-height: 1.3;
        text-align: center;
    }

    .pilot-aev-dash-top-pilot__avatar {
        width: 96px;
        height: 96px;
    }

    .pilot-aev-dash-top-pilot__miles {
        font-size: 13px;
        padding: 0 10px;
        line-height: 1.45;
        max-width: 100%;
    }

    .pilot-aev-dash-community .pilot-aev-table-wrap {
        overflow-x: visible;
        width: 100%;
    }

    .pilot-aev-dash-newest-table {
        display: table !important;
        width: 100% !important;
        min-width: 0 !important;
        border-collapse: collapse;
        table-layout: fixed;
    }

    .pilot-aev-dash-newest-table thead {
        display: table-header-group !important;
    }

    .pilot-aev-dash-newest-table tbody {
        display: table-row-group !important;
    }

    .pilot-aev-dash-newest-table tr {
        display: table-row !important;
        margin: 0 !important;
        border: none !important;
        border-radius: 0 !important;
        background: transparent !important;
    }

    .pilot-aev-dash-newest-table th,
    .pilot-aev-dash-newest-table td {
        display: table-cell !important;
        padding: 10px 12px !important;
        border-bottom: 1px solid #3d3d3d;
        text-align: left !important;
        vertical-align: middle;
    }

    .pilot-aev-dash-newest-table td::before {
        display: none !important;
        content: none !important;
    }

    .pilot-aev-dash-newest-table th:last-child,
    .pilot-aev-dash-newest-table td:last-child {
        text-align: right !important;
        white-space: nowrap;
        width: 34%;
    }

    .pilot-aev-dash-newest-table__pilot {
        max-width: 100%;
        min-width: 0;
    }

    .pilot-aev-dash-newest-table__pilot span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .pilot-aev-dash-vatsim-cal__body {
        min-height: 0;
        width: 100%;
    }

    .pilot-aev-dash-vatsim-cal__body iframe {
        width: 100%;
        height: 260px;
        min-height: 220px;
    }

    .pilot-aev-dash-vatsim-cal__fallback {
        min-height: 200px;
        padding: 20px 16px;
        width: 100%;
        box-sizing: border-box;
    }
}

@media (max-width: 480px) {
    .pilot-aev-navbar {
        overflow: hidden;
        gap: 4px;
    }

    .pilot-aev-topbar__center {
        min-width: 0;
        flex: 1 1 auto;
        padding-right: 4px;
    }

    .pilot-aev-topbar__clock {
        font-size: 12px;
        max-width: 96px;
    }

    .pilot-aev-navbar__right {
        flex-shrink: 0;
        gap: 0;
        max-width: min(52vw, 220px);
    }

    .pilot-aev-navbar .nav-link {
        padding: 6px 7px;
        font-size: 14px;
    }

    .pilot-aev-user-toggle {
        gap: 4px !important;
        padding: 6px 7px !important;
    }

    .pilot-aev-user-caret {
        display: none;
    }

    .pilot-aev-topbar-avatar-img {
        width: 28px;
        height: 28px;
    }

    .pilot-aev-topbar-dropdown__menu,
    .pilot-aev-user-dropdown {
        position: fixed;
        top: calc(var(--pilot-topbar-height, 60px) + 6px);
        right: max(12px, env(safe-area-inset-right));
        left: auto;
        width: min(360px, calc(100vw - 24px));
        max-height: min(70vh, 520px);
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* KPI cards: 2×2 grid instead of full-width stack */
    .pilot-aev-dash > .pilot-aev-row:first-of-type > .pilot-aev-col-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .card-statsfpm4,
    .card-statstime4,
    .card-statsflights4,
    .card-statsmoney4 {
        height: 108px;
        min-height: 108px;
        margin-bottom: 10px;
    }

    .card-statsfpm2 span:after,
    .card-statstime2 span:after,
    .card-statsflights2 span:after,
    .card-statsmoney2 span:after {
        font-size: 42px;
        right: 10px;
        top: -4px;
    }

    .card-statsfpm2 span:after {
        font-size: 52px;
        top: -8px;
    }

    .pilot-aev-stat-num {
        font-size: 22px !important;
    }

    .pilot-aev-stat-label {
        font-size: 11px !important;
    }

    .pilot-aev-rankings-page__podium {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .pilot-aev-rankings-page__podium-card--1 {
        transform: none;
        order: -1;
    }

    .pilot-aev-dash-boards__tabs {
        flex-wrap: wrap;
        gap: 6px;
    }

    .pilot-aev-dash-boards__tabs .btn {
        flex: 1 1 calc(50% - 6px);
        min-width: 0;
        font-size: 11px;
        padding: 8px 6px;
        white-space: normal;
        line-height: 1.25;
    }

    .pilot-aev-schedules__layout {
        gap: 12px;
    }

    .pilot-aev-schedules__sidebar .form-group,
    .pilot-aev-schedules__sidebar select,
    .pilot-aev-schedules__sidebar input {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .pilot-aev-messages-page__tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }

    .pilot-aev-messages-page__tab {
        flex: 0 0 auto;
    }

    .pilot-aev-shop-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }

    .pilot-aev-shop-tabs__item {
        flex: 0 0 auto;
    }

    .pilot-aev-community-page__btn,
    .pilot-aev-community-page__donate-btn {
        min-width: 0;
        width: 100%;
        font-size: 18px;
        padding: 12px 20px;
    }
}

@media (max-width: 390px) {
    body.pilot-aev-shell {
        --pilot-topbar-height: 56px;
    }

    .navbar-bg {
        height: 56px;
    }

    .pilot-aev-navbar {
        height: 56px;
        padding: 6px 10px;
    }

    .pilot-aev-topbar__clock {
        display: none;
    }

    .pilot-aev-navbar__right {
        max-width: min(58vw, 200px);
    }

    .pilot-aev-navbar__right > li:has(a[title="Admin"]) {
        display: none;
    }
}

/* ─── VA landing (homepage) ─── */

@media (max-width: 480px) {
    .bn-va .container {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    .bn-nav__inner {
        gap: 8px;
        padding: 0 10px;
    }

    .bn-logo__img {
        height: 28px;
        max-width: 120px;
        padding: 2px 8px;
    }

    .bn-nav__tools .bn-nav__icon {
        display: none;
    }

    .bn-nav__cta .bn-btn--glow {
        padding: 8px 10px;
        font-size: 11px;
        white-space: nowrap;
    }

    .bn-nav__cta .bn-nav__dash {
        display: none;
    }

    .bn-hero {
        min-height: auto;
        padding: calc(var(--bn-nav-h) + 16px) 0 40px;
    }

    .bn-hero__title {
        font-size: clamp(1.65rem, 8vw, 2.25rem);
        line-height: 1.12;
    }

    .bn-hero__lead {
        font-size: 15px;
        line-height: 1.55;
    }

    .bn-flight-card {
        padding: 14px;
        border-radius: 14px;
    }

    .bn-flight-card__route {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        margin-bottom: 18px;
    }

    .bn-flight-card__arc {
        order: -1;
        padding: 4px 0;
    }

    .bn-flight-card__apt {
        text-align: center;
    }

    .bn-flight-card__apt strong {
        font-size: 1.5rem;
    }

    .bn-flight-card__meta {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .bn-hero-stats {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .bn-hero-stats > * {
        flex: 1 1 calc(50% - 6px);
        min-width: 120px;
    }

    .bn-stats-band__item {
        padding: 14px 12px;
    }

    .bn-footer__links {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }

    .bn-footer__logo {
        height: 40px;
        max-width: 260px;
    }

    .bn-bento__item,
    .bn-pill-card,
    .bn-crew-card {
        padding: 16px;
    }

    .bn-section-head h2 {
        font-size: clamp(1.35rem, 6vw, 1.75rem);
    }

    .bn-live-row {
        gap: 10px;
    }

    .bn-contact textarea,
    .bn-contact input,
    .bn-contact select {
        font-size: 16px;
    }
}

@media (max-width: 390px) {
    .bn-nav__cta .bn-btn--glow span,
    .bn-nav__cta .bn-btn--glow {
        font-size: 10px;
        padding: 7px 8px;
    }

    .bn-hero-stats > * {
        flex: 1 1 100%;
    }

    .bn-flight-card__apt strong {
        font-size: 1.35rem;
    }
}

/* ─── Auth pages (login / register / rules) ─── */

@media (max-width: 480px) {
    .pilot-header__inner--auth {
        padding: 10px 12px;
        gap: 8px;
    }

    .pilot-brand__tag {
        display: none;
    }

    .pilot-header__actions {
        gap: 6px;
        flex-shrink: 0;
    }

    .pilot-header__actions .pilot-btn {
        padding: 7px 10px;
        font-size: 12px;
    }

    .pilot-header__auth-link {
        display: none;
    }

    .pilot-auth-visual {
        min-height: 180px;
    }

    .pilot-auth-visual__title {
        font-size: clamp(1.25rem, 6vw, 1.6rem);
    }
}

@media (max-width: 390px) {
    .pilot-header__actions .lang-switch--compact {
        display: none;
    }

    .pilot-auth-card--login.pilot-auth-card--elevated,
    .pilot-auth-card--register.pilot-auth-card--elevated,
    .pilot-auth-card--elevated,
    .pilot-auth-card--rules.pilot-auth-card--elevated {
        padding: 16px 12px;
    }
}
