/**
 * Mobile shell: app footer (Help + AI Tools), prime-state CTA, header hide state.
 * Scoped to max-width 768px to match EmailLayout mobile breakpoint.
 * Alternate footer row (#appMobileFooterAlternate) reserved for future action groups.
 */

:root {
  --app-mobile-footer-height: 48px;
}

/* Mobile shell markup lives in the header for all breakpoints; hide unless mobile + connected (see below). */
.header__mobile-nav {
  display: none;
}

@media (max-width: 768px) {
  .app--mobile-email-connected {
    --app-mobile-footer-height: 56px;
  }

  .header__mobile-nav {
    display: none;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex-shrink: 1;
    margin-inline-end: 4px;
  }

  .app--mobile-email-connected .header__mobile-nav {
    display: flex;
  }

  .app--mobile-email-connected .header__brand {
    display: none !important;
  }

  .header__side-pane-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: #3b82f6;
    cursor: pointer;
  }

  .header__side-pane-btn:hover {
    background: rgba(255, 255, 255, 0.12);
  }

  .header__side-pane-icon {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .header__folder-label {
    font-weight: 600;
    font-size: 16px;
    line-height: 1.2;
    color: #3b82f6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: min(42vw, 200px);
  }

  .app-mobile-footer__primary--four-up {
    --app-footer-nav-icon-size: 22px;
    --app-footer-nav-label-fs: 10px;
    --app-footer-nav-label-fw: 500;
    --app-footer-nav-label-color: var(--color-text, #1a1a1a);
    --app-footer-nav-icon-color: var(--color-text, #1a1a1a);
    --app-footer-nav-stack-gap: 4px;
    justify-content: space-between;
    gap: 2px;
    padding-left: 6px;
    padding-right: 6px;
  }

  .app-mobile-footer__primary--four-up .app-mobile-footer__cell {
    flex: 1 1 0;
    min-width: 0;
    justify-content: center;
  }

  /* Settings | Calendar | AI: same column layout (icon, gap, label) */
  .app-mobile-footer__primary--four-up #appMobileFooterCellSettings,
  .app-mobile-footer__primary--four-up #appMobileFooterCellCalendar,
  .app-mobile-footer__primary--four-up #appMobileFooterCellAi {
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: var(--app-footer-nav-stack-gap);
    padding-bottom: 2px;
  }

  .app-mobile-footer__cell--nav {
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: var(--app-footer-nav-stack-gap, 4px);
    padding-bottom: 2px;
  }

  .app-mobile-footer__nav-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: var(--app-footer-nav-icon-size, 22px);
  }

  .app-mobile-footer__primary--four-up .app-mobile-footer__nav-caption {
    font-size: var(--app-footer-nav-label-fs);
    font-weight: var(--app-footer-nav-label-fw);
    line-height: 1.15;
    color: var(--app-footer-nav-label-color);
    text-align: center;
    max-width: 88px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .app-mobile-footer__nav-caption {
    font-size: 10px;
    line-height: 1.15;
    font-weight: 500;
    color: var(--color-text, #1a1a1a);
    text-align: center;
    max-width: 88px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Settings: icon size matches Calendar / AI */
  .app-mobile-footer__primary--four-up #appMobileFooterDockSettings .header__icon-btn {
    width: var(--app-footer-nav-icon-size);
    height: var(--app-footer-nav-icon-size);
    min-width: var(--app-footer-nav-icon-size);
    min-height: var(--app-footer-nav-icon-size);
    margin: 0;
    padding: 0;
    color: var(--app-footer-nav-icon-color);
  }

  .app-mobile-footer__primary--four-up #appMobileFooterDockSettings .header__icon-btn-svg {
    width: var(--app-footer-nav-icon-size);
    height: var(--app-footer-nav-icon-size);
  }

  .app-mobile-footer .header__icon-btn {
    width: 36px;
    height: 36px;
    margin: 0;
  }

  /* Calendar footer: show data-i18n caption (like Settings); hide duplicate label inside docked folder row */
  .app-mobile-footer__primary--four-up #appMobileFooterDockCalendar .email-nav__folder-row .email-nav__folder-name {
    display: none !important;
  }

  .app-mobile-footer__primary--four-up #appMobileFooterDockCalendar .email-nav__folder-row {
    width: 100%;
    margin: 0;
  }

  .app-mobile-footer__primary--four-up #appMobileFooterDockCalendar .email-nav__folder-item.email-nav__action-item {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--app-footer-nav-stack-gap);
    min-height: 0;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: var(--app-footer-nav-icon-color);
  }

  .app-mobile-footer__primary--four-up #appMobileFooterCellCalendar .app-mobile-footer__nav-caption {
    font-size: var(--app-footer-nav-label-fs);
    font-weight: var(--app-footer-nav-label-fw);
    line-height: 1.15;
    color: var(--app-footer-nav-label-color);
    max-width: 88px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .app-mobile-footer__primary--four-up #appMobileFooterDockCalendar .email-nav__folder-chevron-spacer {
    display: none;
  }

  .app-mobile-footer__primary--four-up #appMobileFooterDockCalendar .email-nav__folder-icon {
    width: var(--app-footer-nav-icon-size);
    height: var(--app-footer-nav-icon-size);
    min-width: var(--app-footer-nav-icon-size);
    color: var(--app-footer-nav-icon-color);
  }

  .app-mobile-footer__primary--four-up #appMobileFooterDockCalendar .email-nav__folder-icon .email-nav__folder-svg,
  .app-mobile-footer__primary--four-up #appMobileFooterDockCalendar .email-nav__folder-icon-svg svg {
    width: var(--app-footer-nav-icon-size);
    height: var(--app-footer-nav-icon-size);
  }

  .email-folder-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(15, 23, 42, 0.45);
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
  }

  .email-folder-drawer-backdrop[hidden] {
    display: none !important;
  }

  /* Inline-end of viewport (right in LTR, left in RTL) — mirrors folder drawer edge */
  .mobile-compose-fab-host {
    position: fixed;
    right: 16px;
    left: auto;
    bottom: calc(var(--app-mobile-footer-height) + 12px + env(safe-area-inset-bottom, 0px));
    z-index: 10;
    pointer-events: none;
  }

  [dir="rtl"] .mobile-compose-fab-host,
  body.rtl .mobile-compose-fab-host {
    right: auto;
    left: 16px;
  }

  .mobile-compose-fab-host[hidden] {
    display: none !important;
  }

  .mobile-compose-fab-host .email-folder-panel__compose-wrap {
    pointer-events: auto;
  }

  .mobile-compose-fab-host .email-folder-panel__compose-btn {
    width: 56px;
    height: 56px;
    min-height: 56px;
    padding: 0;
    border-radius: 50%;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
  }

  .mobile-compose-fab-host .email-folder-panel__compose-label {
    display: none;
  }

  .app.email-folder-panel-drawer-open .mobile-compose-fab-host {
    visibility: hidden;
    pointer-events: none;
  }

  .email-folder-panel.email-folder-panel--mobile-drawer .email-folder-panel__toggle,
  .email-folder-panel.email-folder-panel--mobile-drawer .email-folder-panel__resize-handle {
    display: none !important;
  }

  /* Compose lives in .mobile-compose-fab-host only — two grid rows: nav, feedback */
  .email-folder-panel.email-folder-panel--mobile-drawer:not(.email-folder-panel--collapsed) {
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .email-folder-panel.email-folder-panel--mobile-drawer:not(.email-folder-panel--collapsed) > .sidebar__nav {
    grid-row: 1;
  }

  .email-folder-panel.email-folder-panel--mobile-drawer:not(.email-folder-panel--collapsed) > .email-folder-panel__feedback-wrap {
    grid-row: 2;
  }

  .email-folder-panel.email-folder-panel--mobile-drawer {
    position: fixed !important;
    inset-block: 0;
    inset-inline-start: 0;
    width: min(88vw, 320px) !important;
    min-width: min(88vw, 320px) !important;
    max-width: min(88vw, 320px) !important;
    z-index: 1001;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    flex: none !important;
  }

  .email-folder-panel.email-folder-panel--mobile-drawer.email-folder-panel--drawer-open {
    transform: translateX(0);
  }

  [dir="rtl"] .email-folder-panel.email-folder-panel--mobile-drawer,
  body.rtl .email-folder-panel.email-folder-panel--mobile-drawer {
    inset-inline-start: auto;
    inset-inline-end: 0;
    left: auto;
    right: 0;
    transform: translateX(100%);
  }

  [dir="rtl"] .email-folder-panel.email-folder-panel--mobile-drawer.email-folder-panel--drawer-open,
  body.rtl .email-folder-panel.email-folder-panel--mobile-drawer.email-folder-panel--drawer-open {
    transform: translateX(0);
  }

  .app--mobile-email-connected .sidebar__panels .email-list-panel {
    margin-inline-start: 0 !important;
  }

  /* Bottom “Ready” / processing strip — hidden on small screens */
  #statusBar.sidebar__status {
    display: none !important;
  }

  body.email-folder-panel-drawer-open {
    overflow: hidden;
  }

  /* AI Draft Reply / Manual Reply: full-width compose — hide bottom nav and drop FAB offset */
  .app:has(#threadView.thread-view--compose) {
    --app-mobile-footer-height: 0px;
  }

  .app:has(#threadView.thread-view--compose) #appMobileFooter {
    display: none !important;
  }

  .app-mobile-footer {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: var(--app-mobile-footer-height);
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: var(--color-surface, #fff);
    border-top: 1px solid var(--color-border, #e8e8e8);
    z-index: var(--z-sticky, 20);
  }

  .app-mobile-footer__primary {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 16px calc(4px + env(safe-area-inset-bottom, 0));
    min-height: var(--app-mobile-footer-height);
    box-sizing: border-box;
  }

  /* Future: bulk actions / secondary groups swap visibility with primary via JS */
  .app-mobile-footer__alternate {
    display: none;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    gap: 4px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0));
    border-top: 1px solid var(--color-border, #e8e8e8);
  }

  .app-mobile-footer__alternate:not([hidden]) {
    display: flex;
  }

  .app-mobile-footer__cell {
    display: flex;
    align-items: center;
    min-width: 0;
  }

  /* display:flex above wins over the [hidden] attribute otherwise — keep docked cells off when JS sets hidden */
  .app-mobile-footer__cell[hidden] {
    display: none !important;
  }

  .app-mobile-footer__cell--start {
    justify-content: flex-start;
  }

  .app-mobile-footer__cell--end {
    justify-content: flex-end;
  }

  .app--mobile-footer-mode .header__left-sep {
    display: none;
  }

  /* Guest: login button lives in prime; hide empty slot in header actions */
  .app--mobile-footer-mode .header__actions .user-menu:empty {
    display: none;
  }

  /* Help (?): circular accent in footer */
  .app-mobile-footer .header__help {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .app-mobile-footer .header__help-btn,
  .app-mobile-footer .tour-help-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: var(--color-primary, #2563eb);
    color: #fff;
    border: none;
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.25);
  }

  /* AI Tools: vertical icon + label (tab style) */
  .app-mobile-footer .ai-tools {
    max-width: none;
    flex-shrink: 0;
  }

  /* Column icon + label: base rules in ai-tools.css @media (max-width: 768px) */
  .app-mobile-footer .ai-tools__trigger {
    min-width: 72px;
    max-width: 100px;
    border: none;
    background: transparent;
    color: var(--color-text, #1a1a1a);
    box-shadow: none;
  }

  .app-mobile-footer .ai-tools__trigger:hover,
  .app-mobile-footer .ai-tools__trigger[aria-expanded="true"] {
    background: var(--color-primary-light, rgba(37, 99, 235, 0.08));
    color: var(--color-primary, #2563eb);
    box-shadow: none;
  }

  .app-mobile-footer .ai-tools__label {
    max-width: 88px;
  }

  .app-mobile-footer .ai-tools__icon {
    width: 22px;
    height: 22px;
  }

  /* Four-up row: match Settings + Calendar label/icon weight (overrides ai-tools.css font-weight: 600 on mobile) */
  .app-mobile-footer__primary--four-up #appMobileFooterCellAi .ai-tools__trigger {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--app-footer-nav-stack-gap);
    min-width: 0;
    max-width: 100px;
    padding: 0 4px;
    color: var(--app-footer-nav-icon-color);
  }

  .app-mobile-footer__primary--four-up #appMobileFooterCellAi .ai-tools__label {
    font-size: var(--app-footer-nav-label-fs);
    font-weight: var(--app-footer-nav-label-fw);
    line-height: 1.15;
    color: var(--app-footer-nav-label-color);
    max-width: 88px;
  }

  .app-mobile-footer__primary--four-up #appMobileFooterCellAi .ai-tools__icon {
    width: var(--app-footer-nav-icon-size);
    height: var(--app-footer-nav-icon-size);
  }

  .app-mobile-footer__primary--four-up #appMobileFooterCellAi .ai-tools__trigger:hover,
  .app-mobile-footer__primary--four-up #appMobileFooterCellAi .ai-tools__trigger[aria-expanded="true"] {
    color: var(--color-primary, #2563eb);
  }

  .app-mobile-footer__primary--four-up #appMobileFooterCellAi .ai-tools__trigger:hover .ai-tools__label,
  .app-mobile-footer__primary--four-up #appMobileFooterCellAi .ai-tools__trigger[aria-expanded="true"] .ai-tools__label {
    color: var(--color-primary, #2563eb);
  }

  /* Prime state: Login & Connect / Connect + account */
  .prime-state__header-cta {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
  }

  .prime-state__header-cta[hidden] {
    display: none !important;
  }

  .prime-state__header-cta .user-menu {
    width: 100%;
    max-width: 320px;
    justify-content: center;
  }

  .prime-state__header-cta .user-menu--guest .btn {
    width: 100%;
    justify-content: center;
    padding: 12px 20px;
    font-size: 15px;
    border-radius: 10px;
  }

  .prime-state__header-cta .user-menu--with-connect {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
  }

  .prime-state__header-cta .user-menu--with-connect .btn--primary {
    flex: 1 1 auto;
    min-width: 140px;
    justify-content: center;
    padding: 12px 16px;
    border-radius: 10px;
  }

  .app.app--mobile-hide-top-header #header,
  .app.app--mobile-hide-top-header #headerTabsMobile {
    display: none;
  }

  /* FAB sits above the footer bar */
  .app--mobile-footer-mode #supportPilotFabStack.sp-fab-stack,
  .app--mobile-footer-mode .sp-fab-stack {
    bottom: calc(var(--app-mobile-footer-height) + 8px + env(safe-area-inset-bottom, 0px));
  }

  /* Email list bulk selection: taller footer row (icon + label per action) */
  .app--mobile-list-select-mode .app-mobile-footer {
    --app-mobile-footer-height: 64px;
  }

  .app-mobile-footer-bulk.app-mobile-footer__alternate {
    align-items: stretch;
    justify-content: space-between;
    gap: 2px;
    padding: 6px 4px calc(8px + env(safe-area-inset-bottom, 0px));
    min-height: 60px;
    box-sizing: border-box;
  }

  .app-mobile-bulk__btn {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    padding: 4px 2px;
    margin: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text, #1a1a1a);
    font-family: inherit;
    font-size: 10px;
    font-weight: 500;
    line-height: 1.15;
    cursor: pointer;
  }

  .app-mobile-bulk__btn:hover {
    background: var(--color-background-alt, #f8fafc);
  }

  .app-mobile-bulk__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-secondary, #64748b);
  }

  /* Selection mode: only bulk row visible — hide primary footer row */
  .app--mobile-list-select-mode .app-mobile-footer__primary {
    display: none !important;
  }
}

/* Footer hidden on desktop via hidden attribute; no desktop rules needed */
