/**
 * Mobile app shell — native-feel layout for viewports below lg (1024px).
 * Loaded after executive-v2.css / tailwind.css.
 */

@media (max-width: 1023px) {
  :root {
    --app-tabbar-h: 56px;
    --app-tabbar-total: calc(var(--app-tabbar-h) + env(safe-area-inset-bottom, 0px));
    --app-header-h: 52px;
    --app-shell-bg: #f0ebe3;
    --app-card-bg: #ffffff;
    --app-card-radius: 16px;
    --app-shadow: 0 1px 2px rgba(43, 35, 32, 0.06), 0 4px 16px -4px rgba(43, 35, 32, 0.1);
  }

  .ec-v2.ec-mobile-app {
    background: var(--app-shell-bg) !important;
    min-height: 100dvh;
    overflow-x: clip;
    -webkit-tap-highlight-color: transparent;
  }

  .ec-v2.ec-mobile-app #main-content {
    padding-bottom: calc(var(--app-tabbar-total) + 12px);
  }

  /* ── App header: flex row (logo left · actions right) ── */
  .ec-v2 .ec-site-nav {
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08), 0 4px 12px -6px rgba(0, 0, 0, 0.15) !important;
    padding-top: env(safe-area-inset-top, 0px);
  }

  .ec-v2 .ec-wrap.ec-nav-inner {
    padding-inline: 12px;
  }

  .ec-v2 .ec-nav-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: var(--app-header-h);
    width: 100%;
  }

  .ec-v2 .ec-nav-brand {
    flex: 0 0 auto;
    margin: 0;
    gap: 0;
    min-width: 0;
  }

  .ec-v2 .ec-nav-search-wrap {
    display: none !important;
  }

  .ec-v2 .ec-nav-actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
  }

  .ec-v2 .ec-nav-book-btn,
  .ec-v2 .ec-nav-menu-btn {
    display: none !important;
  }

  .ec-v2 .ec-nav-icon-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 8px;
    border-radius: 10px;
  }

  .ec-v2 .ec-nav-account summary {
    padding-inline: 4px;
  }

  .ec-v2 .ec-nav-avatar {
    width: 32px !important;
    height: 32px !important;
    font-size: 12px !important;
  }

  .ec-v2 .ec-nav-logo .ec-brand-logo__chip {
    padding: 4px 10px;
  }

  .ec-v2 .ec-nav-logo .ec-brand-logo__img {
    height: 36px;
    max-width: 112px;
  }

  /* ── Bottom tab bar ── */
  .ec-app-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    min-height: var(--app-tabbar-h);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(255, 252, 247, 0.92);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-top: 1px solid rgba(43, 35, 32, 0.08);
    box-shadow: 0 -4px 24px -8px rgba(43, 35, 32, 0.12);
  }

  .ec-app-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: var(--app-tabbar-h);
    padding: 6px 4px 8px;
    border: none;
    background: transparent;
    color: rgba(43, 35, 32, 0.52);
    text-decoration: none;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: color 0.15s ease, transform 0.12s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .ec-app-tab svg {
    width: 22px;
    height: 22px;
    stroke-width: 1.75;
    flex-shrink: 0;
  }

  .ec-app-tab:active {
    transform: scale(0.94);
  }

  .ec-app-tab.is-active {
    color: var(--maroon);
  }

  .ec-app-tab.is-active svg {
    stroke: var(--maroon);
  }

  .ec-app-tab.is-active::before {
    content: "";
    position: absolute;
    top: 0;
    width: 28px;
    height: 2px;
    border-radius: 0 0 2px 2px;
    background: var(--gold);
  }

  .ec-app-tab {
    position: relative;
  }

  .ec-app-tab--book.is-active {
    color: var(--maroon-dark);
  }

  .ec-app-tab--book.is-active svg {
    stroke: var(--maroon-dark);
  }

  /* ── More menu as bottom sheet ── */
  .ec-mobile-menu-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 110;
    background: rgba(20, 12, 14, 0.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.25s ease;
  }

  .ec-mobile-menu-backdrop.is-visible {
    display: block;
    opacity: 1;
  }

  .ec-mobile-menu {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    max-height: min(85dvh, 640px);
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    box-shadow: 0 -8px 40px -12px rgba(43, 35, 32, 0.35);
    transform: translateY(105%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .ec-mobile-menu:not(.hidden) {
    transform: translateY(0);
  }

  .ec-mobile-menu__handle {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 8px;
    border-bottom: 1px solid var(--line);
    background: var(--cream);
  }

  .ec-mobile-menu__handle-bar {
    position: absolute;
    left: 50%;
    top: 8px;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: rgba(43, 35, 32, 0.15);
  }

  .ec-mobile-menu__title {
    font-size: 15px;
    font-weight: 700;
    color: var(--ink);
    margin: 8px 0 0;
  }

  .ec-mobile-menu__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin-top: 4px;
    border: none;
    border-radius: 999px;
    background: rgba(43, 35, 32, 0.06);
    color: var(--ink-soft);
    cursor: pointer;
  }

  .ec-mobile-menu__scroll {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(var(--app-tabbar-total) + 8px);
  }

  .ec-mobile-menu__inner {
    padding: 8px 0 16px;
  }

  .ec-v2.ec-menu-open {
    overflow: hidden;
  }

  .ec-v2.ec-menu-open .ec-app-tabbar .ec-app-tab--more {
    color: var(--maroon);
  }

  /* ── App-style cards & surfaces ── */
  .ec-v2 .search-card,
  .ec-v2 .trip-card,
  .ec-v2 .card,
  .ec-v2 .admin-card,
  .ec-v2 .ec-panel {
    border-radius: var(--app-card-radius);
    background: var(--app-card-bg);
    box-shadow: var(--app-shadow);
    border-color: rgba(43, 35, 32, 0.06);
  }

  .ec-v2 .trip-card {
    padding: 16px;
  }

  .ec-v2 .btn,
  .ec-v2 .btn-primary {
    min-height: 44px;
    border-radius: 12px;
    font-weight: 600;
  }

  .ec-v2 .btn-sm {
    min-height: 40px;
  }

  .ec-v2 .form-input,
  .ec-v2 .form-select,
  .ec-v2 .form-textarea {
    min-height: 44px;
    border-radius: 12px;
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  .ec-v2 .ec-page,
  .ec-v2 .home-page {
    padding-top: 4px;
  }

  .ec-v2 .ec-section-head h2,
  .ec-v2 .ec-page-title {
    font-size: 20px;
    letter-spacing: -0.02em;
  }

  /* ── Home: edge-to-edge hero (no horizontal page scroll) ── */
  .ec-v2 .hero-banner-wrap {
    padding-inline: 0;
    width: 100%;
    max-width: 100%;
  }

  .ec-v2 .hero-banner-wrap .hero-carousel {
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .ec-v2 .hero-carousel__viewport {
    aspect-ratio: 16 / 10;
    max-height: 220px;
  }

  .ec-v2 .home-search-wrap {
    margin-top: -8px;
  }

  /* Home quick shortcuts — 2×2 app grid */
  .ec-app-shortcuts {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
  }

  .ec-app-shortcut {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 72px;
    padding: 10px 6px;
    border-radius: 14px;
    background: var(--app-card-bg);
    box-shadow: var(--app-shadow);
    border: 1px solid rgba(43, 35, 32, 0.06);
    text-decoration: none;
    color: var(--ink);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
  }

  .ec-app-shortcut:active {
    transform: scale(0.96);
  }

  .ec-app-shortcut__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(107, 16, 38, 0.08);
    color: var(--maroon);
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
  }

  .ec-app-shortcut__icon svg {
    stroke: var(--maroon);
  }

  .ec-app-shortcut__label {
    font-size: 10px;
    font-weight: 700;
    text-align: center;
    line-height: 1.2;
    color: var(--maroon);
  }

  .ec-v2 .search-card {
    margin-top: 0;
    border-radius: var(--app-card-radius);
  }

  /* Quick route chips — horizontal scroll row */
  .ec-v2 .home-quick-routes {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
    margin-bottom: 12px;
  }

  .ec-v2 .home-quick-routes::-webkit-scrollbar {
    display: none;
  }

  .ec-v2 .home-quick-routes .label-tag {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    background: rgba(107, 16, 38, 0.07);
    border: 1px solid rgba(107, 16, 38, 0.12);
  }

  /* ── Compact footer (legal strip only) ── */
  .ec-v2 .site-footer {
    padding: 16px 0 calc(var(--app-tabbar-total) + 8px);
    background: transparent !important;
    color: var(--ink-soft);
    box-shadow: none;
  }

  .ec-v2 .site-footer::before {
    display: none;
  }

  .ec-v2 .site-footer__grid {
    display: none;
  }

  .ec-v2 .site-footer .footer-rule {
    flex-direction: column;
    gap: 4px;
    text-align: center;
    font-size: 11px;
    color: rgba(43, 35, 32, 0.45);
    border-top: none;
    padding-top: 0;
  }

  /* Hide floating help — contact is in More menu */
  .ec-floating-help {
    display: none !important;
  }

  /* Toast above tab bar */
  #toast-container {
    bottom: calc(var(--app-tabbar-total) + 12px) !important;
    top: auto !important;
    right: 12px !important;
    left: 12px !important;
  }

  .ec-v2 .toast {
    top: auto;
    bottom: calc(var(--app-tabbar-total) + 12px);
    left: 12px;
    right: 12px;
  }

  /* HTMX loading bar below header (incl. safe area) */
  #htmx-loading {
    top: calc(var(--app-header-h) + env(safe-area-inset-top, 0px));
  }

  /* Section grouping like iOS lists */
  .ec-v2 .departures-grid,
  .ec-v2 .ec-stack {
    gap: 10px;
  }

  .ec-v2 .ec-section {
    padding-block: 20px;
  }

  .ec-v2 .ec-section-head {
    margin-bottom: 12px;
  }

  .ec-v2 .ec-section-sub {
    font-size: 13px;
    line-height: 1.45;
  }
}

@media (max-width: 380px) {
  .ec-app-tab span {
    font-size: 9px;
  }

  .ec-app-tab svg {
    width: 20px;
    height: 20px;
  }
}
