/**
 * Phase 0 — Mobile / iPad shell (drawer nav, top bar, bottom tabs, safe areas).
 * Breakpoints: mobile ≤768px, tablet 769–1024px, desktop >1024px.
 */

html[data-shell="dashboard"] {
  --bp-mobile-max: 768px;
  --bp-tablet-max: 1024px;
  --mobile-top-h: 54px;
  --shell-mobile-top-offset: 0px;
  --mobile-tab-h: 68px;
  --shell-pad-x: 14px;
}

html[data-shell="dashboard"].has-mobile-top-bar {
  --shell-mobile-top-offset: var(--mobile-top-h);
}

/* ── Compact shell wrapper ── */
@media (max-width: 1024px) {
  html[data-shell="dashboard"] body {
    overflow: hidden;
    /* Avoid dark navy “frame” around the content panel on compact */
    background: #f6f8fc;
  }

  html[data-shell="dashboard"] .app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: #f6f8fc;
  }

  html[data-shell="dashboard"] .app-shell .app {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    padding: 0;
    gap: 0;
    background: transparent;
  }

  html[data-shell="dashboard"] .app-shell .stage-center {
    flex: 1;
    min-height: 0;
  }

  /* Flatten desktop “floating card” (.main-scroll border-radius + --shadow-card) */
  html[data-shell="dashboard"] .app-shell .main-scroll {
    border-radius: 0 !important;
    box-shadow: none !important;
    padding-top: 0;
    padding-left: 0;
    padding-right: 0;
    padding-bottom: calc(var(--mobile-tab-h) + env(safe-area-inset-bottom, 0px));
    background: #f6f8fc;
  }

  html[data-shell="dashboard"] .app-shell .main-scroll:not(.main-scroll--module) {
    background: var(--explore-section-bg, #eef2fc);
  }

  html[data-shell="dashboard"] .app-shell .main-scroll--module {
    padding-bottom: calc(var(--mobile-tab-h) + env(safe-area-inset-bottom, 0px) + 8px);
  }
}

/* ── Mobile top bar ── */
.mobile-top-bar {
  flex-shrink: 0;
  display: none;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px;
  min-height: var(--mobile-top-h);
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: linear-gradient(180deg, #000a2a 0%, rgba(0, 10, 42, 0.97) 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 120;
}

@media (max-width: 1024px) {
  .mobile-top-bar {
    display: grid;
  }
}

.mobile-top-bar__menu {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s;
}

.mobile-top-bar__menu:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
}

.mobile-top-bar__brand {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.mobile-top-bar__logo {
  width: 30px;
  height: 30px;
  object-fit: contain;
  flex-shrink: 0;
  transform: translateY(-2px);
}

.mobile-top-bar__title {
  margin: 0;
  min-width: 0;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
  color: #fff;
  letter-spacing: -0.02em;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.mobile-top-bar__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.mobile-top-bar__icon-btn {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}

.mobile-top-bar__icon-btn svg {
  width: 17px;
  height: 17px;
}

.mobile-top-bar__icon-btn:hover,
.mobile-top-bar__icon-btn:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  outline: none;
}

.mobile-top-bar__icon-btn.is-muted {
  color: rgba(255, 255, 255, 0.45);
}

.mobile-top-bar__avatar {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  justify-self: end;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.mobile-top-bar__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.mobile-top-bar__avatar-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.02em;
}

.mobile-top-bar__avatar:hover {
  border-color: rgba(255, 255, 255, 0.32);
  transform: scale(1.03);
}

.mobile-top-bar__avatar.is-active {
  border-color: #60a5fa;
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.28);
}

/* ── Drawer sidebar ── */
@media (max-width: 1024px) {
  html[data-shell="dashboard"] .app-shell .sidebar-left {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 86vw);
    z-index: 200;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 16px;
    background: var(--bg-sidebar);
    box-shadow: none;
    transform: translateX(-105%);
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.32s cubic-bezier(0.22, 1, 0.36, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    pointer-events: none;
  }

  html[data-shell="dashboard"] .app-shell.is-nav-drawer-open .sidebar-left {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.45);
    pointer-events: auto;
  }

  html[data-shell="dashboard"] .nav-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 190;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
  }

  /* Drawer always shows full labels */
  html[data-shell="dashboard"] .app-shell .sidebar-left .brand-text {
    display: block !important;
    opacity: 1 !important;
    max-width: none !important;
  }

  html[data-shell="dashboard"] .app-shell .sidebar-left .nav-label,
  html[data-shell="dashboard"] .app-shell .sidebar-left .chat-card-inner,
  html[data-shell="dashboard"] .app-shell .sidebar-left .btn-chat {
    display: flex !important;
    opacity: 1 !important;
    max-width: none !important;
  }

  html[data-shell="dashboard"] .app-shell .sidebar-left .btn-chat-compact {
    display: none !important;
  }

  html[data-shell="dashboard"] .app-shell .sidebar-left .sidebar-toggle {
    display: none !important;
  }

  html[data-shell="dashboard"] .app-shell .sidebar-left .sidebar-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
    padding-top: 0;
  }

  html[data-shell="dashboard"] .app-shell .sidebar-left .brand {
    flex: 1;
    min-width: 0;
    width: auto;
    justify-content: flex-start;
    padding: 8px 4px 16px;
    gap: 12px;
  }

  html[data-shell="dashboard"] .app-shell .sidebar-left .brand-logo {
    width: 50px;
    height: 50px;
  }

  html[data-shell="dashboard"] .app-shell .sidebar-left .sidebar-close {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: none;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
  }

  html[data-shell="dashboard"] .app-shell .sidebar-left .sidebar-close:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
  }

  html[data-shell="dashboard"] .app-shell .sidebar-left .sidebar-close svg {
    width: 18px;
    height: 18px;
  }

  html[data-shell="dashboard"] .app-shell .sidebar-left .nav-menu li a {
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 14px;
    min-height: 44px;
  }
}

/* ── Mobile bottom tab bar ── */
.mobile-tab-bar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 110;
  align-items: stretch;
  justify-content: space-around;
  gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  background: rgba(11, 14, 30, 0.98);
  backdrop-filter: blur(14px);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
}

@media (max-width: 1024px) {
  .mobile-tab-bar {
    display: flex;
  }
}

.mobile-tab-bar__item {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 6px 4px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.72);
  text-decoration: none;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, background 0.15s;
}

.mobile-tab-bar__item img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  opacity: 0.88;
  transition: opacity 0.15s, transform 0.15s;
}

.mobile-tab-bar__item span {
  display: block;
  width: 100%;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 0 2px;
}

.mobile-tab-bar__item.active {
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.2);
}

.mobile-tab-bar__item.active img {
  opacity: 1;
  transform: scale(1.05);
}

.mobile-tab-bar__item.active span {
  font-weight: 800;
  color: #bfdbfe;
}

/* ── Module prompt dock — sit above tab bar on compact ── */
@media (max-width: 1024px) {
  html[data-shell="dashboard"] .app-shell .main-scroll--module:has(.chat-workspace--compact),
  html[data-shell="dashboard"] .app-shell .main-scroll--module:has(.image-studio--compact),
  html[data-shell="dashboard"] .app-shell .main-scroll--module:has(.video-studio--compact) {
    padding-bottom: 0;
  }

  html[data-shell="dashboard"].hide-mobile-tab-bar .app-shell .main-scroll {
    padding-bottom: 0;
  }

  html[data-shell="dashboard"] .main-scroll--module .prompt-dock {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(var(--mobile-tab-h) + env(safe-area-inset-bottom, 0px) + 10px);
    transform: none;
    width: auto;
    max-width: none;
    z-index: 105;
  }

  html[data-shell="dashboard"] .main-scroll--module .chat-workspace--compact .prompt-dock {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    transform: none;
    width: 100%;
    max-width: none;
    z-index: 1;
  }

  html[data-shell="dashboard"] .main-scroll--module .image-studio--compact .prompt-dock,
  html[data-shell="dashboard"] .main-scroll--module .video-studio--compact .prompt-dock {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    transform: none;
    width: 100%;
    max-width: none;
    z-index: 1;
  }

  /* Mobile-native composers — in-flow footer, never fixed overlay */
  html[data-shell="dashboard"] .main-scroll--module .img-mobile-composer,
  html[data-shell="dashboard"] .main-scroll--module .vid-mobile-panel {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    transform: none;
    width: 100%;
    max-width: none;
    z-index: 1;
  }

  html[data-shell="dashboard"] .main-scroll--module .prompt-dock .prompt-bar {
    border-radius: 18px;
  }

  html[data-shell="dashboard"] .main-scroll--module .prompt-dock .prompt-body {
    padding: 12px 14px 4px;
  }

  html[data-shell="dashboard"] .main-scroll--module .prompt-dock .prompt-footer {
    padding: 8px 12px 12px;
  }
}

/* ── Tablet-only tweaks (iPad) ── */
@media (min-width: 769px) and (max-width: 1024px) {
  html[data-shell="dashboard"] .hero-banner {
    min-height: 280px;
  }
}

/* ── Small phone tweaks ── */
@media (max-width: 768px) {
  html[data-shell="dashboard"] {
    --mobile-tab-h: 64px;
  }

  .mobile-tab-bar__item {
    font-size: 11px;
    gap: 4px;
  }

  .mobile-tab-bar__item span {
    font-size: 11px;
  }

  .mobile-tab-bar__item img {
    width: 26px;
    height: 26px;
  }

  html[data-shell="dashboard"] .cards-row--6,
  html[data-shell="dashboard"] .world-row--6,
  html[data-shell="dashboard"] .explore-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  html[data-shell="dashboard"] .hero-title-gradient {
    font-size: clamp(26px, 7vw, 34px);
  }
}

@media (max-width: 480px) {
  html[data-shell="dashboard"] .explore-grid {
    grid-template-columns: 1fr !important;
  }
}

/* Hide legacy floating bottom nav (replaced by mobile-tab-bar) */
.bottom-nav {
  display: none !important;
}
